imap_fetchbody - Encoded body error
Asked Answered
S

1

5

I am trying to fetch a particular section of an email body using:

$message = imap_fetchbody ($imap_stream,$n,1);

This works fine for emails sent using Outlook, Hotmail, Yahoo etc. But when I try and fetch the body of the an email sent from a Blackberry or Andriod device, the message is encoded and scrambled such as:

xmb250IHN0eWxlPSdjb2xvcjojRjk3MWIxMDNiMTEyYjExOGI0N2I1MWI1

Although the body is encoded, the header is fine. How do I decode the message body of en email sent from an Android or Blackberry device?

Thank you,

Chris.

Splotch answered 15/3, 2011 at 11:8 Comment(0)
C
8

You should be able to run imap_fetchstructure to get the encoded value. If that value equals 3 you need to decode via imap_base64.

I've used the following before (Can't remember if it was ever tested with sent mobile email before though):

$structure = imap_fetchstructure($stream, $msgno);
$text = imap_fetchbody($stream, $msgno, $partnum);   
if($structure->encoding == 3) {
    $text = imap_base64($text);
} else if($structure->encoding == 4) {
    $text = imap_qprint($text);
}
Capitate answered 15/3, 2011 at 11:22 Comment(3)
Thank you. It is working on some of the emails. Some of the emails encode values are O but are still encoded. I am looking into the imap_fetchstructure array in detail at present. Will get back to you.Splotch
Sorted. I just had to catch a different location of the encoded value in the array for a different email client using: if($structure->parts[0]->encoding == 3 ||$structure->encoding == 3 ) . All working now. Thank you. Upvoted.Splotch
Careful. $structure->parts can not be exist. Use : if (($obj_structure->encoding == 3) || isset($obj_structure->parts) && ($obj_structure->parts[0]->encoding == 3)) {Dehiscent

© 2022 - 2024 — McMap. All rights reserved.