UTF-8 in e-mail subject - quoted printable?

Everything else that doesn't fall into one of the other PB categories.
User avatar
Kukulkan
Addict
Addict
Posts: 1423
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

UTF-8 in e-mail subject - quoted printable?

Post by Kukulkan »

Hi,

I use UTF-8 encoded templates to design messages for sending using gnozals PureSMTP. The used subject is encoded in this template, too. I set

Content-Type: text/html; charset=utf-8;

and the complete body is ok. Using Outlook and Thunderbird, the UTF-8 encoded subject is correct, too. But some e-mail programs (tobit david for example) fail to display the UTF-8 encoded subject of the e-mail.

How do I need to convert the subject for all kind of e-mail clients? Is there a quoted printable encoding algorithm available for PureBasic?

Kukulkan
User avatar
pdwyer
Addict
Addict
Posts: 2813
Joined: Tue May 08, 2007 1:27 pm
Location: Chiba, Japan

Post by pdwyer »

My understanding is that the subject of an email must be in 7bit ascii to be standard. For subjects that contain other codings (like UTF8 etc) they have a type marker and then the bytes encoded in base64.

like this

Subject: =?utf-8?B?UkEU6IEVNUyAtIFRFU1Q5IOCuOOCueOBmOOFg+OBquOBj+OBpg==?=
=?utf-8?B?
Paul Dwyer

“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
User avatar
Kukulkan
Addict
Addict
Posts: 1423
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

Post by Kukulkan »

Hi pdwyer,

Thank you. Your information completed the puzzle.

I found the following way to manage the problem using PB:

Code: Select all

Subject.s = "UTF-8 encoded string like Versandbestätigung"
SubjectBase64.s = Space(Len(Subject.s) * 2)
Base64Encoder(@Subject.s, Len(Subject.s), @SubjectBase64.s, Len(SubjectBase64.s))
Subject.s = "=?UTF-8?B?" + SubjectBase64.s + "?="
Seems to work without any problems...

Kukulkan
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Useful. Thanks.
I may look like a mule, but I'm not a complete ass.
User avatar
pdwyer
Addict
Addict
Posts: 2813
Joined: Tue May 08, 2007 1:27 pm
Location: Chiba, Japan

Post by pdwyer »

Cheers, I was wondering if that would work... :)

Now I don't need to spend the time! Thanks
Paul Dwyer

“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
Seymour Clufley
Addict
Addict
Posts: 1267
Joined: Wed Feb 28, 2007 9:13 am
Location: London

Post by Seymour Clufley »

Is there a quoted printable encoding algorithm available for PureBasic?
Now I need such a function!

I found this VB function but it involves using something called "CDO.Message object".

Can anyone help out?
User avatar
Kukulkan
Addict
Addict
Posts: 1423
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

Post by Kukulkan »

Hi,

Quoted Printable seem to be less complicated than UTF-8. The result may be such a string:

Original: Hätten Hüte ein ß im Namen, wären sie möglicherweise keine Hüte mehr, sondern Hüße.

QP: H=E4tten H=FCte ein =DF im Namen, w=E4ren sie m=F6glicherweise keine H=FCte= mehr, sondern H=FC=DFe.

Every byte that is not between 33–60 and 62–126 will be replaced by = followed by the uppercase hex value.

Here is more information:
http://en.wikipedia.org/wiki/Quoted-printable

Will be only a work of some minutes.

Kukulkan
Post Reply