an alternative CF function method of obfuscating mailto links from harvesters...


function safeAddress(emailAddress) {
// returns mailto link with escaped email address to try and avoid harvesting
// based on safeAddress() PHP function by Dan Benjamin - http://hivelogic.com/
// Adapted for ColdFusion by Mark Woods

// function can be called with up to four arguments - safeAddress(emailAddress, theText, theTitle, xhtml)
// only required argument is emailAddress
// the other arguments are determined from the arguments array so if you want to pass a value for theTitle or xhtml, you gotta pass all the preceding arguments too
// the first three arguments are strings, xhtml is boolean

// new line sequence, change this if required
var newLine = chr(13) & chr(10);

// variables for optional arguments
var theText = "";
var theTitle = "";
var xhtml = false;
// how many optional arguments?
var howmanyarguments = arrayLen(arguments);

// create escaped user and domain values
var ent = "";
var userName = "";
var domainName = "";
var c = "";
var s = "";
for (i = 1; i lte len(emailAddress); i = i+1) {
c = mid(emailAddress, i, 1);
if (c eq "@") {
userName = ent;
ent = "";
} else {
ent = ent & "&##" & asc(c) & ";";
}
}
domainName = ent;

// link text
if ( howmanyarguments gt 1 ) {
theText = arguments[2];
}

// link title
if ( howmanyarguments gt 2 ) {
theTitle = arguments[3];
}

// xhtml safe output?
if ( howmanyarguments gt 3 and isBoolean(arguments[4]) ) {
xhtml = arguments[4];
}
if (xhtml) {
prefix = "<script type=""text/javascript"">";
} else {
prefix = "<script language=""JavaScript"" type=""text/javascript"">";
}


        // create output string
        ent = "
                var first = 'ma';
                var second = 'il';
                var third = 'to:';
                var address = '#userName#';
                var domain = '#domainName#';
                document.write('<a href=\""');
                document.write(first+second+third);
                document.write(address);
                document.write('&##64;');
                document.write(domain);
                document.write('"" title=""'); ";
        if ( (trim(theTitle) eq "") or ( trim(theTitle) eq trim(emailAddress) ) ) {
                ent = ent & "
                document.write(address);
                document.write('&##64;');
                document.write(domain); ";
        } else {
                // if email address in title, escape the title
                if ( find("@",theTitle) ) {
                        s = "";
                        for (i = 1; i lte len(theTitle); i = i+1) {
                                c = mid(theTitle, i, 1);
                                s = s & "&##" & asc(c) & ";";
                        }
                        theTitle = s;
                }
                ent = ent & "
                document.write('#theTitle#'); ";
        }
        ent = ent & "
                document.write('"">'); ";
        if ( (trim(theText) eq "") or ( trim(theText) eq trim(emailAddress) ) ) {
                ent = ent & "
                document.write(address);
                document.write('&##64;');
                document.write(domain); ";
        } else {
                // if email address in text, escape the text
                if ( find("@",theText) ) {
                        s = "";
                        for (i = 1; i lte len(theText); i = i+1) {
                                c = mid(theText, i, 1);
                                s = s & "&##" & asc(c) & ";";
                        }
                        theText = s;
                }
                ent = ent & "
                document.write('#theText#'); ";
        }
        ent = ent & "
                document.write('<\/a>');
                </script>
        ";
        safeAddress = prefix & newLine & trim(ent);

        // return output string
        return safeAddress;
}


-- ** Archive: http://www.mail-archive.com/dev%40lists.cfdeveloper.co.uk/

To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
For human help, e-mail: [EMAIL PROTECTED]



Reply via email to