Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

imap_fetchbody - Encoded body error

Tags:

android

php

imap

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.

like image 493
Kit Avatar asked Mar 15 '11 11:03

Kit


1 Answers

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);
}
like image 151
Aaron W. Avatar answered Sep 18 '22 22:09

Aaron W.