About OPENSMTP message headers are messed up after a long time

Source: Internet
Author: User
Smtp

OPENSMTP is a good mail delivery component on the. Net platform, but there are some bugs affecting our use, I encountered in the use of the message subject length is large, the message appears garbled.

After examining the source code found that the original process is problematic: first, the theme is encoded by ASCII, followed by the use of QP encoding, but did not consider the difference between the subject and content.

When encoding in a topic, each line must be encoded separately, and the subject cannot be encoded all at once.

In contrast to Outlook Express, add a method to the MailEncoding class that specifically Base64 code for the subject of the message

public static string ConvertHeaderToBase64 (string s, String charset)
{
int linelength = 40; Processing 40 bytes per line
Encoding Encoding = encoding.getencoding (charset); Take the specified encoding
byte[] buffer = encoding.       GetBytes (s); Convert to byte code
StringBuilder sb = new StringBuilder (); Save Final results
String linebase64;
int block = buffer. Length%linelength==0?buffer. Length/linelength:buffer. Length/linelength + 1;
for (int i=0; i< blocks; i++)
{
if (buffer). Length-i*linelength >=linelength)
Linebase64 = convert.tobase64string (buffer, i*linelength, linelength);
Else
Linebase64 = convert.tobase64string (buffer, i*linelength, buffer. Length-i*linelength);
Sb. Append ("=?");
Sb. Append (CharSet);
Sb. Append ("? B? ");
Sb. Append (LINEBASE64);
Sb. Append ("? =\r\n\t");
}
Sb. Remove (sb.)          Length-3, 3); Delete last newline symbol
Return SB. ToString ();
}

Then, modify the handling of the message subject in the ToString method in the MailMessage class to invoke the custom method


Sb. Append ("Subject:" + MAILENCODER.CONVERTHEADERTOQP (cleansubject.tostring (), CharSet) + "\ r \ n");
Sb. Append ("Subject:" + mailencoder.convertheadertobase64 (cleansubject.tostring (), CharSet) + "\ r \ n");

Re-compiling can



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.