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 specific implementation, see the code.
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)
{
Int tmp = rnd. Next (1, len + 1 );

List. Add (input. Substring (idx, tmp ));

Idx + = tmp;
Len-= tmp;
}

Return list;
}

// Encode string. ASCII: % xx format; double bytes: uxxxx format.
Protected string EncodeString (string input)
{
StringBuilder output = new StringBuilder (input. Length * 4 );

Foreach (char c in input)
{
Int charValue = (int) c;

If (charValue> 255)
{
Output. AppendFormat ("\ u {0: x4}", charValue );
}
Else
{
Output. AppendFormat ("% {0: x2}", charValue );
}
}

Return output. ToString ();
}

// Generate unique variable name.
Protected string GenerateVarName ()
{
Random rnd = new Random ();
String output = (char) (int)
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.