Page 1 of 1
detecting error codes in emails using IMAP
Posted: Sun Sep 07, 2008 12:44 am
by s.dot
I'm writing an email bounce detection script using the PHP IMAP functions. I've gotten as far as reading the messages. Now I'm at the part where I need to scan the contents for error codes.
It would be nice if the structure of the email had the error code in it somewhere so I can just analyze that part (is there a part with the error code).
Right now I'm sticking to regexp's but they come in many different forms, such as:
Code: Select all
550: error message
Sorry, I couldn't find any host named example.tld. (#5.1.2)
Who knows how many other forms there are. I don't want to accidentally mark a valid email as bounced (though this is a dedicated
noreply@example.tld mailbox).
Is this the best way to scan for an error code?
Re: detecting error codes in emails using IMAP
Posted: Mon Sep 08, 2008 1:03 am
by josh
theres open source mime parsers that will give you the bounce code, and whether the error was transient or permanent. Can't recall any in particular but I've found and used them before
Re: detecting error codes in emails using IMAP
Posted: Mon Sep 08, 2008 1:54 am
by s.dot
The error codes are returned in the mime headers?
Re: detecting error codes in emails using IMAP
Posted: Mon Sep 08, 2008 7:06 am
by josh
http://www.phpclasses.org/browse/package/2691.html
I forget, but that class should do it, all you really want to look at is if its permanent or transient
Re: detecting error codes in emails using IMAP
Posted: Mon Sep 08, 2008 8:59 pm
by s.dot
Thanks.
That class isn't doing anything that I'm not doing.. which is checking for error codes and certain messages, so I think I'll stick to my code.. simply because I'll be able to more easily append to it.
It would be nice if the codes were returned in a specific body structure part or in the headers.
Re: detecting error codes in emails using IMAP
Posted: Tue Sep 09, 2008 2:44 am
by josh
Either way I'd add a layer behind your bounce functions to do some mime decoding.. email can come in different encodings, if you just regex the raw string you might match some text out of the email attachments. An email can have another email as an attachment. To write a 100% reliable regex you'd have to read the RFCs which would be a huge pain, 99.9% of the time a simple regex will do the job, its just that .01% that worries me lol