Saturday, February 19, 2005

Base64 Encoding Fun

And now for some encoding fun :P

The most common encoding that I like to use is Base64 Encode. Over the past 1 years plus, this encoding have proved to be very useful and I shall some tricks and tips that I discover! For fun with online base64 encode or decode check this site out.

1) Base64 encoding and decoding is dependent on the language charset that you set in. For example if you are encoding in a page with iso-8859-1 and a utf-8, the result encoding is different. I believed this is due to the different byte used and the character set used in the encoding.

2) Base64 encoding is useful to hide away clear text message.

3) My most important topic here! Base64 encoding can used in email subject and content. While working with mult-lingual email. the challenge is always to get the correct character displayed with showing gibberish stuffs. For my experiments before, I found out that base64 encode subject line are more reliable than quote-text for double-byte language email.

Due to the various different sytems operating in their settings and configuration, when a double-byte mail subject is quote-text, the result maybe displayed incorrectly. On some machine, it might displayed as you wanted, but not for some especially for those web-based email viewed online!

To send out double-byte character email ,the provided CDONTS and CDOSYS system on Microsoft Windows platform needs you to set the correct Session Codepage and encode the mail subject using quote-texted. When checked the reference, both the CDONTS and CDOSYS does not allow the mail subject to be base64 encoded! So for those mail subject that I received and does not appear correctly, how do we tackle this problem? One way you can do is change the subject liner to some other content. But what if the client insisted on it?

My solution that I discovered that it worked.

  • With the double byte mail subject, go to the online base64 encoding/decoding site link.
  • Set the page to the correct charset, ie: for Simplified Chinese, set the charset encoding to "gb2312"
  • Paste the subject string into the text box and encode it.
  • Copy the encoded string from the site.
  • In your server script, (I am using asp with CDONTS as example below), set the mail subject line to the use the base64 encoded text with defined encoding used.
    ie: =?gb2312?b?xxxxxSubject-base64xxxxx==?=
    Example with ASP using CDONTS
    <%
    'Create the e-mail server object
    Set objCDOSYSMail = Server.CreateObject("CDO.Message")

    'Update the CDOSYS Configuration
    Set objCDOSYSMail.Configuration = objCDOSYSCon
    With objCDOSYSMail
    .From = strEmail
    .To = strFriendEmail
    .Subject = "=?gb2312?b?" & strSubject & "==?="
    End With ' objCDOSYSMail
    %>

  • Send out the email in the script, and when you receive your email, you see that the subject is displayed in the correct encoding! The above mail subject is set to follow the rfc mail header standard and it seems that once you specify the encoding there, it will overwrite the quote-text encoding in there!

2 Comments:

At September 14, 2006 at 5:06 PM, Anonymous Anonymous said...

Hi I tried ur method for the subject title but it doesnt work...

 
At September 14, 2006 at 5:06 PM, Anonymous Anonymous said...

Hi I tried ur method for the subject title but it doesnt work...

 

Post a Comment

<< Home