1

I have a script which should scrap selected email from the inbox. Everything works except BODY. Subject, date, sender and etc.. were scraped without problems but the body were returned like this:

VG9kYXkncyBGcmVlIGFuZCBCYXJnYWluIEJvb2tzCgpVcGRhdGUgUHJlZmVyZW5jZXM6ICBodHRw Oi8vd3d3LmJvb2tnb3JpbGxhLmNvbS9wcmVmZXJlbmNlcz9oPTZjNTgxNDEyYjkzMTdiMWZlNjc1 ZDcwNDFjODJhYTc5Ckludml0ZSBGcmllbmRzOiBodHRwOi8vd3d3LmJvb2tnb3JpbGxhLmNvbS9p bnZpdGU/aD02YzU4MTQxMmI5MzE3YjFmZTY3NWQ3MDQxYzgyYWE3OQpVbnN1YnNjcmliZTogaHR0 cDovL3d3dy5ib29rZ29yaWxsYS5jb20vdW5zdWJzY3JpYmU/aD02YzU4MTQxMmI5MzE3YjFmZTY3 NWQ3MDQxYzgyYWE3OQoKQWxsIHByaWNlcyB3ZXJlIHZlcmlmaWVkIGJ5IEJvb2tHb3JpbGxhIHBy aW9yIHRvIHRoaXMgZW1haWwgYmVpbmcgc2VudCwgYnV0IHByaWNlcyBtYXkgY2hhbmdlIHdpdGhv dXQgbm90aWNlIHNvIHBsZWFzZSB2ZXJpZnkgdGhhdCB0aGUgYm9vayBpcyBzdGlsbCBmcmVlIG9y IGJhcmdhaW4gcHJpY2VkIGJlZm9yZSBjb25maXJtaW5nIHlvdXIgb3JkZXIuIFNvbWUgYm9va3Mg bWF5IG5vdCBiZSBmcmVlIG91dHNpZGUgdGhlIFVuaXRlZCBTdGF0ZXMuIFdlIHdlbGNvbWUgeW91 ciBmZWVkYmFjaywgc28gcGxlYXNlIHJlcGx5IHRvIHRoaXMgZW1haWwgaWYgeW91IGhhdmUgYW55 IGNvbW1lbnRzIG9yIHN1Z2dlc3Rpb25zIHlvdSB3b3VsZCBsaWtlIHRvIHNoYXJlIHdpdGggdXMu CgoKCi0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0t LS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0NCg0KRG9uJ3Qg bWlzcyB0aGlzIEJFU1QgUFJJQ0UgRVZFUiBvbiBEZWJiaWUgTWFjb21iZXIncyBjbGFzc2ljIERl Y2VtYmVyIDIwMTMgcmVsZWFzZSE8YnIgLz48YnIgLz5GcmllbmRzLS1BbmQgVGhlbiBTb21lPGJy IC8+KERlYmJpZSBNYWNvbWJlciBDbGFzc2ljcykNCkJ5IERlYmJpZSBNYWNvbWJlcjxiciAvPjxi ciAvPjY3JSBQcmljZSBDdXQgVGhpcyBXZWVrIQ0KDQoqKioqKiBTVEFSUkVEIFRJVExFICoqKioq CgogT25lIG9mIGFjY2xhaW1lZCBhdXRob3IgRGViYmllIE1hY29tYmVy4oCZcyBjbGFzc2ljIG5v dmVscywgdGhpcyB0ZW5kZXIgc3Rvcnkgb2YgdHdvIHBlb3BsZSBkYXJpbmcgdG8gYmUgbW9yZSB0 aGFuIOKAnGp1c3QgZnJpZW5kc+KAnSBpcyBhdmFpbGFibGUgZm9yIHRoZSBmaXJzdCB0aW1lIGlu IHRoZSBLaW5kbGUgc3RvcmUhDQoNClRvZGF5J3MgQmFyZ2FpbiBQcmljZTogJDAuOTkNCg0KR2V0 IEl0IE5vdw0KaHR0cDovL3d3dy5ib29rZ29yaWxsYS5jb20vbGluaz9sPWh0dHAlM0ElMkYlMkZ

And I have no idea why is it? This is a code I'm using:

$inbox_details = $this->email_main->getInboxDetails($data['inbox_id']); // select inbox data by inbox id
    $message_id = $inbox_details['last_sended_email_id'] + 1;

    $imap = imap_open('{'. $data['inbox_data']['inbox_server'] .'}INBOX', ''. $data['inbox_data']['inbox_email'] .'', ''. $data['inbox_data']['inbox_password'] .''); 
    if (!$imap)
        $this->email_main->insertError(imap_last_error(), $data['inbox_data']['id']);

    $header = imap_header($imap, $message_id);
    $message = array(
        'subject' => $header->subject,
        'fromname' => $header->fromaddress,
        'fromaddress' => $header->from[0]->mailbox.'@'.$header->from[0]->host,
        'toaddress' => $header->toaddress,
        'date' => $header->date,
        'timestamp' => $header->udate,
        'body' => imap_qprint(imap_fetchbody($imap, $message_id, 2)), // $message_id = 1
    );

any ideas folks?

2
  • Looks to be base64, use the base64_decode method to get your info.
    – Jon
    Commented Feb 21, 2014 at 14:40
  • the decoded texts supplies links to modify settings for [email protected] account on bookGorilla ... FYI
    – David Chan
    Commented Feb 21, 2014 at 14:44

1 Answer 1

3

Your content is encoded in base64.

 base64_decode($content);

Will decode it :)

Edit: Decoded with http://www.base64decode.org/ to get 'Today's Free and Bargain Books'

6
  • 1
    and You just made my friday! Thanks ;) Commented Feb 21, 2014 at 14:42
  • No problem good sir. Do not forget to mark the question as answered so it can be seen as closed.
    – Ne Ma
    Commented Feb 21, 2014 at 14:43
  • +1 - Now I know where to get me some "Free Bargain Books" ;-) Commented Feb 21, 2014 at 14:52
  • 1
    Bwahahahah so true. Maybe OP didn't actually have any problems but just a genius advertising campaign based on appeasing the score hungry needs of SO users :)
    – Ne Ma
    Commented Feb 21, 2014 at 14:58
  • this can be true, all the time script worked fine and only now it came with problems. First problem with that encoding now I have problem to get parsed details. Commented Feb 21, 2014 at 15:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.