PHP Classes

Outputting file as eml

Recommend this page to a friend!

      POP3 e-mail client  >  All threads  >  Outputting file as eml  >  (Un) Subscribe thread alerts  
Subject:Outputting file as eml
Summary:Outputting file as eml for bounce tracking
Messages:9
Author:Dave Watkins
Date:2008-04-09 16:28:49
Update:2008-07-01 13:09:00
 

  1. Outputting file as eml   Reply   Report abuse  
Picture of Dave Watkins Dave Watkins - 2008-04-09 16:28:50
Firstly thank you so much for this class it is absolutely fantastic and even better that you provide it for everyone to use on here like this. Thanks so much.

I am using it in tandem with the Bounce Handler class by Chris Fortune (thanks for that as well) in order to clean my mailing list. I have it set to check the messages in my pop3 mailbox and download them as eml files so that i can then use the Bounce Handler class to check their validity and update my memberbase accordingly.

This all works perfectly, however i am currently writing the eml file by outputting each individual header line and then body lines to a file eg

$addline=HtmlSpecialChars($headers[$line])
fwrite($handle, $addline)

$addline=HtmlSpecialChars($body[$line]).'
fwrite($handle, $addline);

from within a similar script to test_pop3.php. This doesn't seem very efficient and I assume there is probably a much simpler, more elegant and way less prone to errors to do this. The SaveBody parameter within browse_mailbox.php is so nearly what i want, but it doesn't output the header, which i need for the Bounce Handler. Is there a way to include the header in this?

Any pointers anyone could give me would be very much appreciated as i can't work out how to do this and i think if i can get that working then it is pretty much perfect for what i need.

Thanks again,

Dave

  2. Re: Outputting file as eml   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2008-04-09 22:23:25 - In reply to message 1 from Dave Watkins
Yes, you can use OpenMessage and GetMessage calls to retrieve the original message data altogether.

Anyway, if you just want to figure if the message is a bounce and what addresses are bouncing, you may use this POP3 class together with the MIME parser class.

phpclasses.org/mimeparser

The parser class can read the message directly from the mailbox using a pop3:// URL. Then it parses the message and if it is a bounce report it simply returns the original bouncing addresses.

  3. Re: Outputting file as eml   Reply   Report abuse  
Picture of Dave Watkins Dave Watkins - 2008-04-10 09:57:48 - In reply to message 2 from Manuel Lemos
Thanks so much for your speedy reply Manuel, it really is very much appreciated. I have done what you said and am looping through the messages using the method within pop3_test.php and am using a variation on the parse_message.php script using pop3:// to access and parse the message and retrieve the headers etc.

You said in your message "it parses the message and if it is a bounce report it simply returns the original bouncing addresses.". Is this something that the mime parser class does itself or do i need to write code to do this/use the bounce handler class? At the moment i am retrieving the header info via $results['Data']/$results['Subject']/$results['From'][0]['address']/$results['To'][0]['address'] etc. Am i right in thinking you are saying i should then use check these values to establish whether it's a bounce and then deal with it accordingly or is there an integrated/other way i should be doing it?

Thanks so much for your help Manuel, you are a star!

Dave

  4. Re: Outputting file as eml   Reply   Report abuse  
Picture of Dave Watkins Dave Watkins - 2008-04-10 10:29:40 - In reply to message 3 from Dave Watkins
Just as an addendum to my last post, i have just noticed the Type and Recipients/Action etc variables from analyse that appear to return the bounce information that i need, however the type variable always seems to return text or html even on a bounced message (which it's marking as text). I presume the type not being marked as delivery-status is why but i am also unable to retrieve the Action/Recipient/Status variables at all. I assume if i can get this working then this is exactly what i wanted without having to use other classes and i'd be really grateful if you could clarify how i make use of this?

Thanks so much once again Manuel,

Dave

  5. Re: Outputting file as eml   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2008-04-10 10:40:54 - In reply to message 4 from Dave Watkins
I am not sure what kind of message you are considering a bounce. The fact is that not all mail servers send a well formed delivery-status message as bounce. If that is the case, you need to apply some custom logic.

If the bounce is an actual delivery-status message and for some reason the class is not recognizing it as such, you may want to send it to me so I can figure what is going on.

  6. Re: Outputting file as eml   Reply   Report abuse  
Picture of Dave Watkins Dave Watkins - 2008-04-10 11:04:43 - In reply to message 5 from Manuel Lemos
That makes sense. The bounce is a message i sent to a non existent yahoo account, i can forward it to you or post the pertinent information on here if you would like, just let me know. So doing it this way if it is a delivery-status then those other variables would be available and i can use them to establish the type of bounce, otherwise i should manually use the data/address variables to manually assess it?

Presumably, as you mentioned earlier, the other alternative is to use the pop3:// url to allow the bounce handler class to access the message directly which it could then assess and i could then deal with the results accordingly. I'm not sure if it should be possible, but the bounce handler uses file_get_contents($emlfile) to read the eml file into a string. Is it possible to use the pop3 url defined within $message_file as the file in some way (so something like

$message_file='pop3://'.$user.':'.$password.'@localhost/'.$message.'?debug='.$debug.'&html_debug='.$html_debug.'&realm='.$realm.'&workstation='.$workstation.'&apop='.$apop.'&authentication_mechanism='.$authentication_mechanism;
then
file_get_contents($message_file)

as this would then allow me to use Chris' function directly to check the bounce status etc? This obviously isn't right as i get:

Warning: file_get_contents(pop3://...@localhost/1?debug=0&html_debug=0&realm=&workstation=&apop=0&authentication_mechanism=USER) [function.file-get-contents]: failed to open stream: "pop3_stream::stream_open" call failed in /xxxx/parse_message.php on line 88

Or would you say it is better to access the message in another way if i was going to use the bounce handler class to access it?

Thanks so much for your help i really massively appreciate it,

Dave

  7. Re: Outputting file as eml   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2008-04-10 22:00:40 - In reply to message 6 from Dave Watkins
First make sure you are not using the SkipBody option in the Decode function, so the class can access the message body data to analyze it.

If the message is not really delivery-status, currently the class does not interpret it as different mail systems format it in a non-uniform way.

Using the pop3:// stream handler is just a different way to feed messages to the MIME parser. No interaction with mail server happens.

The idea is to save memory by not having to load the whole message in memory all at once. So you should not use file_get_contents, but rather use that pop3:// path and pass it to the MIME parser class as file name parameter.

  8. Re: Outputting file as eml   Reply   Report abuse  
Picture of Cuong Chung Cuong Chung - 2008-07-01 09:01:08 - In reply to message 2 from Manuel Lemos
Dear Manuel Lemos
Can we get and check Email Notification from Mail-Admin-Deamon if we send email to not-exist-email using your classes?
Your classes are great :)


  9. Re: Outputting file as eml   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2008-07-01 13:09:00 - In reply to message 8 from Cuong Chung
That has nothing to do with POP 3 class. You need to use a mail sending class to specify where e-mail bounces will go. Try for instance this MIME message class:

phpclasses.org/mimemessage