-2

I am sending hundreds of emails with an unique id through email header. I have to track the bounced mails for the particular unique id.

I can see the bounced emails with an attached EML file in my mailbox. Unfortunately the unique ID which I am looking for is placed in the attached EML file's header instead of bounced email's header.

I am using PHP's IMAP function to read the headers and body sections. But unable to read EML attachment.

Could any one explain how to read or parse the EML attachment using IMAP function.

Thanks.

Balaji
  • 850
  • 7
  • 15
  • possible duplicate of [How to parse a .eml file in php?](http://stackoverflow.com/questions/11409235/how-to-parse-a-eml-file-in-php) – pdu Feb 21 '14 at 14:44
  • Welcome to StackOverflow. Please read the FAQ to know how things work in here, and use the search function, as your question is not the first one. – pdu Feb 21 '14 at 14:45
  • thanks a lot! thanks for your advice pduersteler. The link given by you is for parse the .eml file from the server path not from the mailbox. I would like to know how to read the .eml attachment from my inbox using IMAP function. – Balaji Feb 21 '14 at 15:15
  • No, not a duplicate. It's the other issue. – arnt Feb 21 '14 at 18:13
  • I should elaborate. That other question was about how to parse an email message attached to another. This one is about how to access bits of the same thing (the IMAP server will parse if you ask it to). – arnt Feb 21 '14 at 18:31

1 Answers1

0

The .eml is most properly described as a message/rfc822 bodypart; it comprises one part of a multipart/report.

In IMAP each bodypart has its own part number, and you can access headers and individual fields by supplying the number. In many bounces, the number of the message/rfc822 is 3, and you can access e.g. the subject using f uid fetch 123456 body.peek[3.1.header.fields (subject)]. The server will do the parsing you want and give you back the subject field.

The usual way to get the part number is to use bodystructure.

Expressing this using PHP is left as an exercise for the reader. Good luck.

arnt
  • 8,949
  • 5
  • 24
  • 32
  • You are great arnt. 3 worked. I got the attached .eml file header using `imap_fetchbody($imap_stream, $msg_number, 3)`. – Balaji Feb 21 '14 at 19:29
  • 1
    Note that it isn't always part number 3. It's the one with content-type message/rfc822 or text/rfc822-headers. – arnt Feb 22 '14 at 11:11