public String generateAntiSpamMailto ( String name , String email ) { StringTokenizer st = new StringTokenizer ( email , "@" ) ; if ( Security . containsXssRiskyCharacters ( email ) || st . countTokens ( ) != 2 ) { throw new IllegalArgumentException ( "Invalid email address: " + email ) ; } String before = st . nextToken ( ) ; String after = st . nextToken ( ) ; StringBuffer buffer = new StringBuffer ( ) ; buffer . append ( "Contact " ) ; buffer . append ( Security . replaceXmlCharacters ( name ) ) ; buffer . append ( " using: <span id=\"asmgLink\"></span>\n" ) ; buffer . append ( "<script type='text/javascript'>\n" ) ; buffer . append ( "var before = '" ) ; buffer . append ( before ) ; buffer . append ( "';\n" ) ; buffer . append ( "var after = '" ) ; buffer . append ( after ) ; buffer . append ( "';\n" ) ; buffer . append ( "var link = \"<a href='mail\" + \"to:\" + before + '@' + after + \"'>\" + before + '@' + after + \"</a>\";\n" ) ; buffer . append ( "document.getElementById(\"asmgLink\").innerHTML = link;\n" ) ; buffer . append ( "</script>\n" ) ; buffer . append ( "<noscript>[" ) ; buffer . append ( before ) ; buffer . append ( " at " ) ; buffer . append ( after ) ; buffer . append ( "]</noscript>\n" ) ; return buffer . toString ( ) ; }
Generate an anti - spam mailto link from an email address