C # code email address, fire prevention, anti-spam

Source: Internet
Author: User
Tags encode string

Many enthusiastic bloggers leave their own email addresses on their blogs to help others. To prevent spam, the email address is published in the form of an image or text with the @ symbol (AT) or. This will inevitably cause inconvenience to others. When I browsed my brother-in-law's blog, I found that the email link was somewhat interesting. After a little research, I split the email address and encoded it. It seems that it is not an email address at all. In this way, the "email address Collector" can be crossed ". In the experiment, we found that mailto: can be identified by outlook, while other mail clients are not tested.
It took a bag of cigarettes to write a small tool. The idea is: concatenate the email address into "mailto: youremail@domain.com? Subject = ", then the string is randomly split, encoded and assigned to the Javascript variable. Add the Javascript variables. The encoding method is to encode single-byte characters in the form of % XX, and (UNICODE) double-byte characters in the form of \ uxxxx. For details, seeCode.
For the effect, see the announcement board.

How much code should I stick to? (Khan ...)

// Divide the string to some parts.
Protected List < String > Partstring ( String Input)
{
List < String > List = New List < String > ();
Random RND = New Random ();
Int Len = Input. length;
Int Idx = 0 ;

While(Len> 0)
{
IntTMP=RND. Next (1, Len+ 1);

List. Add (input. substring (idx, TMP ));

Idx+ =TMP;
Len-=TMP;
}

ReturnList;
}

// encode string. ASCII: % XX format; Double Bytes: \ uxxxx format.
protected string encodestring ( string input)
{< br> stringbuilder output = New stringbuilder (input. length * 4 );

Foreach(CharCInInput)
{
IntCharvalue=(Int) C;

If (Charvalue > 255 )
{
Output. appendformat ( " \ U {0: X4} " , Charvalue );
}
Else
{
Output. appendformat ( " % {0: X2} " , Charvalue );
}
}

ReturnOutput. tostring ();
}

// Generate unique variable name.
Protected String Generatevarname ()
{
Random RND = New Random ();
String Output = (( Char )(( Int ) ' A ' + RND. Next ( 0 , 26 ). Tostring () + RND. Next ( 0 , 10 );

While (Vars. containskey (output ))
{
Output = (( Char )(( Int ) ' A ' + RND. Next ( 0 , 26 ). Tostring () + RND. Next ( 0 , 10 );
}

ReturnOutput;
}

Demo address: http://www.xianfen.net/Article148.aspx
Download Code: click here

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.