Nicolas du Toit
Great class, and working very well except for one issue:
Messages with an attachment of type ".msg" (Outlook message format), do not parse correctly.
The message attachment gets parsed with no "Filename" even though the following is correctly decoded:
[Attachments] => Array
 => Array
[Type] => message
[Description] => E-mail message
[Data] => Received: from ...
We save all attachments as files, but for this type, we get no filename back, and can thus not complete the code to save it as a .msg attachment.
Thank you in advance
|2012-08-29 23:13:41 - In reply to message 1 from Nicolas du Toit|
|The file name is not necessarily present in the message. In that case the class does not assign any file name to it.|
Maybe if you provide the original sample message I can confirm that is the case.
Nicolas du Toit
|2012-08-30 07:13:21 - In reply to message 2 from Manuel Lemos|
Thank you for the reply. Can I e-mail the message to you? I do not wish to post it here as I'd have to remove a lot of info in the message for privacy reasons.
I wrote some code to create a "newfilename1" for example if no name is found, and then the file gets saved, but in this case when I try to re-open the file it says it is corrupted. It seems when you attach a .msg file to another message, the orignal "Subject:" field of the attached message becomes the filename of the attachment.
I will send you also the Decoded and Analysed array from the class, for analysis.
Nicolas du Toit
|2012-08-30 11:46:43 - In reply to message 2 from Manuel Lemos|
I thank you for your time but it seems I have figured it out in the end.
When you send an Outlook message file (.msg) as an attachment to an email, the message actually gets sent in the format of an .eml file. If I try to name the attachment "myAttachment.msg", as it was on my computer before sending it, the file shows up as corrupt. If on the other hand I name the attachment that is Decoded by your mime class to "myAttachment.eml" the file opens as expected by Outlook without any issues.
I added the following to my code to deal with this:
if ($attachment['Type'] == 'message' AND $attachment['SubType'] == 'rfc822')
$titlemsg = preg_match("/Subject:\s(.*)\s/", $data, $newMSGname);
if ($filename == '') $filename = "Attached email message.eml";
$filename = utf8_encode(mb_decode_mimeheader($newMSGname.".eml"));
$filename = trim($filename);
$filename = str_replace(' ', '_', $filename);
$filename = clean_fspath($filename);
Thus, in the case where the [content-type:] = message/rfc822 (which is the case for message attachments, Search the Body for the "Subject:" and use that as the name for the attachment, and with the extension ".eml"
I have tested it and so far it seems to be working without a hitch. Your class was working fine, but it seems that in our application where we want to save the attached message as a file, that can be downloaded / opened, we just needed to understand the output we received.
PS: If you still want those debug files please let me know, I'll be glad to share them.
|2012-08-30 11:55:11 - In reply to message 4 from Nicolas du Toit|
|No, it is not necessary, as you figured out it was not really a bug in the class.|