Jump to content

Trying to automatically detect and parse encoding or content type from e-mails


imekul

Recommended Posts

I have piping set up, where when I send an e-mail to a certain address, a script executes.

 

This script will parse the e-mail and will post the body of the e-mails (along with a picture, if attached) to a blog.

 

This all works okay, except the problem I keep running into is when I send from different devices (desktop, Android phone, BlackBerry), the e-mails have different character sets or encoding.  So one e-mail will show up just fine, and then the body of another will look something like this:

 

--90e6ba6e83a0846c8504926b9478

Content-Type: text/html; charset=ISO-8859-1

 

This is the content of the e-mail.

 

--90e6ba6e83a0846c8504926b9478--

 

So what I'm wondering is if there is any way to detect the charset/encoding and automatically decode it properly?  The only solution I have so far -- and I'm not very good with PHP, I'll admit -- is to just "hack" my way through, by using stristr() to see if the body contains certain characters (like "ISO-8859-1"), and then extracting the text that is in between, say, "ISO-8859-1" and "--".

 

Of course, this is very crude, and has many problems on its own.  So what I am looking for is if there is some sort of way to automatically get the body of an e-mail in plain text, regardless of whether the e-mail has an attachment, how it's encoded, or what mail client was used.

 

Thanks for your time!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.