zhuguoxi / php-mime-mail-parser

Automatically exported from code.google.com/p/php-mime-mail-parser
0 stars 0 forks source link

getAttachement not working with email sent using thunderbird. #4

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
I tried to parse the email sent through thunderbird 2.0.0.23 but i'm not
able to get the attachments out of that email. i can read other headers
through this script but getAttachment method is returning a empty array.
Please help me. I;ve attached a test email file along with the issue.

Original issue reported on code.google.com by kalehri...@gmail.com on 25 Oct 2009 at 2:50

Attachments:

GoogleCodeExporter commented 9 years ago
kalehrishi, I'm not able to reproduce your problem. Here's what I did to test. 
I took your attached "eml" file and piped it through example2.php (in the 
examples directory) :

cat ../../test\ message\ generated\ in\ thunderbird.eml | php example2.php

And this correctly dumped information about the attachments :

string(20) "kalehrishi@gmail.com"
bool(false)
string(38) "Hrishikesh Kale <kalehrishi@gmail.com>"
string(37) "test message generated in thunderbird"
string(48) "hi,

this is test message body.

Regards

"
bool(false)
array(2) {
  [0]=>
  object(MimeMailParser_attachment)#2 (7) {
    ["filename"]=>
    string(17) "Code Snippets.rar"
    ["content_type"]=>
    string(24) "application/octet-stream"
    ["content":"MimeMailParser_attachment":private]=>
    NULL
    ["extension":"MimeMailParser_attachment":private]=>
    NULL
    ["content_disposition"]=>
    string(10) "attachment"
    ["headers"]=>
    string(1) "U"
    ["stream":"MimeMailParser_attachment":private]=>
    resource(12) of type (stream)
  }
  [1]=>
  object(MimeMailParser_attachment)#3 (7) {
    ["filename"]=>
    string(16) "attachment 1.rar"
    ["content_type"]=>
    string(24) "application/octet-stream"
    ["content":"MimeMailParser_attachment":private]=>
    NULL
    ["extension":"MimeMailParser_attachment":private]=>
    NULL
    ["content_disposition"]=>
    string(10) "attachment"
    ["headers"]=>
    string(1) "U"
    ["stream":"MimeMailParser_attachment":private]=>
    resource(13) of type (stream)
  }
}

I then took the code block from the main page ( 
http://code.google.com/p/php-mime-mail-parser/ ) :

$save_dir = '/path/to/save/attachments/';
foreach($attachments as $attachment) {
  // get the attachment name
  $filename = $attachment->filename;
  // write the file to the directory you want to save it in
  if ($fp = fopen($save_dir.$filename, 'w')) {
    while($bytes = $attachment->read()) {
      fwrite($fp, $bytes);
    }
    fclose($fp);
  }
}

And ran it against your test email which saved out two files :

attachment 1.rar
Code Snippets.rar

I unrarred those rar files and got :

element.dispatchEvent.htm
event.htm
New Text Document (2).txt
New Text Document.txt

I examined those files and they have good content (valid HTML, other data)

Go ahead and try these steps yourself and let me know if you're able to 
reproduce the problem and if so we can dig into it further.

Original comment by gene.wood.temp on 22 Oct 2010 at 5:07