Charset output - is this the correct way?

H

Hugh Oxford

I am writing a custom email client to integrate into my application. I
use the various php imap functions to get message bodies etc.

I am using ajax (xajax to be precise) to display the message body - I
populate a div with it.

I can retrieve the character encoding of the message body by using the
imap_bodystruct() function.

I then use that character encoding in the header of the ajax output in
the content type before outputting the message to the browser.

So far it seems to work fine. Is this the best way to do it? Or would I
be better off changing the message body to a different charset?
 
B

Bart Van der Donck

Hugh said:
I am writing a custom email client to integrate into my application.

Not as easy as it sounds. Not impossible, but technically very
advanced, and much, much code.
I use the various php imap functions to get message bodies etc.
I am using ajax (xajax to be precise) to display the message body - I
populate a div with it.

I can retrieve the character encoding of the message body by using the
imap_bodystruct() function.
I then use that character encoding in the header of the ajax output in
the content type before outputting the message to the browser.
So far it seems to work fine.

I'm quite sure you are only looking at the top of the iceberg. It
might work for extremely simple messages: no attachments, no quoted-
printables, no codepoints over 255 (or maybe even 127), only a few
elementary Content-Types, no base64, ...
Is this the best way to do it? Or would I be better off
changing the message body to a different charset?

I'm not sure you realize what is involved. A few examples:

- Take a 'Content-Transfer-Encoding: quoted-printable', it's one of
the most popular mail encodings, but not applicable for HTML (unless
you would decode it manually).
- The message body might be base64-encoded, e.g. a 'Content-Type: text/
plain; charset=KOI8-R'
together with a 'Content-Transfer-Encoding: base64'. Other
combinations might be UTF-8 together with quoted-printable, etc. etc.
- 8-bit versus 7-bit mails.
- Subject lines, e.g. Café could be written as =?ISO-8859-1?Q?Caf=E9?
=, =?ISO-8859-1?B?Q2Fm6Q==?=, =?UTF-8?Q?Caf=C3=A9?=, =?UTF-8?B?
Q2Fmw6k=?=, and this is just for ISO-8859-1 and UTF-8; there are many
more charsets.
- Multipart messages need to be split into their applicable character
sets, files, encodings.
- ...

I would suggest to install one of the PHP mail handlers with a good
reputation. Personally I'm using SquirrelMail since 3 years:
http://www.squirrelmail.org/

Hope this helps,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top