PHP Classes

Parsing txt attachments

Recommend this page to a friend!

      PHP MIME Email Message Parser  >  All threads  >  Parsing txt attachments  >  (Un) Subscribe thread alerts  
Subject:Parsing txt attachments
Summary:Parsing txt attachments
Messages:4
Author:Fabrizio
Date:2008-11-19 16:25:04
Update:2008-11-20 08:47:46
 

  1. Parsing txt attachments   Reply   Report abuse  
Picture of Fabrizio Fabrizio - 2008-11-19 16:25:04
Hi,
i must parse details.txt (text message on Returned mail: Domain not found" error and others..).
how i can do this?
i need to catch "Original-Recipient: "....
can u help me?
thanks a lot!

  2. Re: Parsing txt attachments   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2008-11-19 18:23:44 - In reply to message 1 from Fabrizio
Can you provide a sample message complete with headers and body so I can understand what kind message you are talking about?

  3. Re: Parsing txt attachments   Reply   Report abuse  
Picture of Fabrizio Fabrizio - 2008-11-20 08:13:09 - In reply to message 2 from Manuel Lemos
This is the output of browse_mailbox.php:

1C RETR 1
S +OK 2908 octets
S Received: from mx.sample.it
S by mx.sample.it (ServerPro1 V1) with SMTP id ZUA21804
S for <[email protected]>; Wed, 19 Nov 2008 10:33:04 +0100
S Date: Wed, 19 Nov 2008 10:33:04 +0100
S From: Merak Mail Server V1 <[email protected]>
S To: <[email protected]>
S Message-Id: <[email protected]>
S Content-Type: text/plain; charset="utf-8"
S Content-Transfer-Encoding: 8bit
S Subject: Returned mail: Domain not found
S Content-Type: multipart/report; report-type=delivery-status; boundary="[email protected]"
S
S [email protected]
S Content-Type: text/plain; charset="utf-8"
S Content-Transfer-Encoding: 8bit
S
S The original message was received at Wed, 19 Nov 2008 10:33:04 +0100
S
S ----- The following addresses had permanent fatal errors -----
S <[email protected]>
S
S ----- Transcript of session follows -----
S ... while issuing MX query to xxx.xxx.x.xx
S 554 Domain not found
S
S [email protected]
S Content-Type: message/delivery-status
S
S Reporting-MTA: DNS; mx.sample.it
S Arrival-Date: Wed, 19 Nov 2008 10:33:06 +0100
S
S Original-Recipient: RFC822; <[email protected]>
S Final-Recipient: RFC822; <[email protected]>
S Action: failed
S Last-Attempt-Date: Wed, 19 Nov 2008 10:33:04 +0100
S
S [email protected]
S Content-Type: message/rfc822
S
S Return-Path: <[email protected]>
S Received: from localhost ([192.168.0.172])
S by mx.sample.it (ServerPro1 V1) with ASMTP id ZUA84303
S for <[email protected]>; Wed, 19 Nov 2008 10:33:03 +0100
S Date: Wed, 19 Nov 2008 10:31:40 +0100
S Return-Path: [email protected]
S To: Josh Adams <[email protected]>
S From: Mailer <[email protected]>
S Reply-to: Information <[email protected]>
S Subject: prova
S Message-ID: <477fdd7a6daad597adfa16508f67f72a@localhost>
S X-Priority: 3
S X-Mailer: PHPMailer (phpmailer.codeworxtech.com) [version 2.3]
S MIME-Version: 1.0
S Content-Type: multipart/mixed;
S boundary="b1_477fdd7a6daad597adfa16508f67f72a"
S X-Spam-IndexStatus: 0
S
S
S --b1_477fdd7a6daad597adfa16508f67f72a
S Content-Type: multipart/alternative;
S boundary="b2_477fdd7a6daad597adfa16508f67f72a"
S
S --b2_477fdd7a6daad597adfa16508f67f72a
S Content-Type: text/plain; charset = "iso-8859-1"
S Content-Transfer-Encoding: 8bit
S
S
S aaaaa
S
S
S --b2_477fdd7a6daad597adfa16508f67f72a
S Content-Type: text/html; charset = "iso-8859-1"
S Content-Transfer-Encoding: 8bit
S
S
S aaaaa
S
S
S
S --b2_477fdd7a6daad597adfa16508f67f72a--
S --b1_477fdd7a6daad597adfa16508f67f72a
S Content-Type: application/octet-stream; name="prova.txt"
S Content-Transfer-Encoding: base64
S Content-Disposition: attachment; filename="prova.txt"
S
S YWFhYWFhYWFhYWFhYWFhYQ0KYWFhYWFhYWFhYWFhYWFhDQphYWFhYWFhYWFhYWFhYWFhYWFhDQoN
S Cg0KDQoNCi0tLS0tLS0tLS0tLS0tLS0tLS0tLQ0KDQoNCg0KDQoNCg0KDQoNCg0KDQphYWFhYWFh
S YWFhYWFhYWFhYWFhYWFhYWFhYWE=
S
S
S --b1_477fdd7a6daad597adfa16508f67f72a--
S
S
S
S [email protected]
S .

--------------------
Mittente 1 = [email protected]

MIME message 1 decoding successful
Message 1structure
array(3) {
["Headers"]=>
array(8) {
["received:"]=>
string(135) "from mx.sample.it by mx.sample.it (ServerPro1 V1) with SMTP id ZUA21804 for ; Wed, 19 Nov 2008 10:33:04 +0100"
["date:"]=>
string(31) "Wed, 19 Nov 2008 10:33:04 +0100"
["from:"]=>
string(42) "Merak Mail Server V1 "
["to:"]=>
string(16) ""
["message-id:"]=>
string(23) "<[email protected]>"
["content-type:"]=>
array(2) {
[0]=>
string(27) "text/plain; charset="utf-8""
[1]=>
string(97) "multipart/report; report-type=delivery-status; boundary="[email protected]""
}
["content-transfer-encoding:"]=>
string(4) "8bit"
["subject:"]=>
string(31) "Returned mail: Domain not found"
}
["Parts"]=>
array(3) {
[0]=>
array(4) {
["Headers"]=>
array(2) {
["content-type:"]=>
string(27) "text/plain; charset="utf-8""
["content-transfer-encoding:"]=>
string(4) "8bit"
}
["Parts"]=>
array(0) {
}
["BodyPart"]=>
int(1)
["BodyLength"]=>
int(273)
}
[1]=>
array(4) {
["Headers"]=>
array(1) {
["content-type:"]=>
string(23) "message/delivery-status"
}
["Parts"]=>
array(0) {
}
["BodyPart"]=>
int(2)
["BodyLength"]=>
int(247)
}
[2]=>
array(4) {
["Headers"]=>
array(1) {
["content-type:"]=>
string(14) "message/rfc822"
}
["Parts"]=>
array(0) {
}
["BodyPart"]=>
int(3)
["BodyLength"]=>
int(1529)
}
}
["ExtractedAddresses"]=>
array(2) {
["from:"]=>
array(1) {
[0]=>
array(2) {
["address"]=>
string(19) "[email protected]"
["name"]=>
string(20) "Merak Mail Server V1"
}
}
["to:"]=>
array(1) {
[0]=>
array(1) {
["address"]=>
string(14) "[email protected]"
}
}
}
}

Message 1 analysis
array(7) {
["Type"]=>
string(4) "text"
["Description"]=>
string(12) "Text message"
["Encoding"]=>
string(5) "utf-8"
["Subject"]=>
string(31) "Returned mail: Domain not found"
["Date"]=>
string(31) "Wed, 19 Nov 2008 10:33:04 +0100"
["From"]=>
array(1) {
[0]=>
array(2) {
["address"]=>
string(19) "[email protected]"
["name"]=>
string(20) "Merak Mail Server V1"
}
}
["To"]=>
array(1) {
[0]=>
array(1) {
["address"]=>
string(14) "[email protected]"
}
}
}


this is the output of a returned mail....and the attachements are 2:
prova.txt (file I attached) and details.txt...

I need to estract text inside details.txt (need to know errors from email andresses for write them into db):

Reporting-MTA: DNS; mx.sample.it
Arrival-Date: Wed, 19 Nov 2008 10:02:22 +0100

Original-Recipient: RFC822; <[email protected]>
Final-Recipient: RFC822; <[email protected]>
Action: failed
Last-Attempt-Date: Wed, 19 Nov 2008 10:02:21 +0100



Thanks for your help and sorry for my bad english :D


  4. Re: Parsing txt attachments   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2008-11-20 08:47:46 - In reply to message 3 from Fabrizio
The class would parse the bounce report information, but it is malformed because it has two content-type headers. Therefore it is treated as a regular text message.

You also must not use the SkipBody parameter in the Decode function call.