[nycphp-talk] Text file to MySQL entries
csnyder
chsnyder at gmail.com
Fri Mar 10 18:04:54 EST 2006
On 3/10/06, Alberto dos Santos <yournway at gmail.com> wrote:
> Hi all.
>
> Sorry for not knowing my file handling routines 101, but I'm somewhat
> desperate at this stage, so here it goes.
>
> I have a mail server that sends 200 000 emails daily, no mistake 200K with
> qmail-send, to a mailing list.
> Sometimes older users just add another email address and fail to erase the
> old one so I need to comb through the mailbox regularly to find which
> addresses are bouncing so I can delete them.
> all messages have more or less the same configuration, and we have a shell
> app that compiles the name of the email file and the header onto a text
> file, something like this:
>
> ./1141578003.21775.ns31756.ovh.net,S=41699
> Return-Path: <>
> Delivered-To: root at myserver
> Received: (qmail 20952 invoked for bounce); 5 Mar 2006 16:59:17 -0000
> Date: 5 Mar 2006 16:59:17 -0000
> From: MAILER-DAEMON at myserver
> To: root at myserver
> Subject: failure notice
>
> Hi. This is the qmail-send program at myserver.
> I'm afraid I wasn't able to deliver your message to the following
> addresses.
> This is a permanent error; I've given up. Sorry it didn't work out.
>
> <the recipient>:
> IPADDRESS does not like recipient.
> Remote host said: 550 <the recipient> is not a valid mailbox
> Giving up on IPADDRESS
>
> --- Below this line is a copy of the message.
>
>
>
> Now, I need to extract the file name, the date, the recipient and the error
> onto a database to check which addresses have bounced and why.
>
> Anybody has some ideas on how I can do that?
> I looked on the net and the php manual and found some disparate tentatives
> but no solid solution when we are not using an xml file.
>
> TIA
> --
> Alberto dos Santos
> Consultor em TI
> IT Consultant
>
If your script handles these as individual emails, then you could use
PEAR's MIME parser or one of the imap functions to parse the headers.
Otherwise, well, each message can be converted to an array of lines
using explode(). Each line of the headers starts with a label. Then
there's a blank line, and then the message body itself.
Liberal use of strpos(), substr(), etc. should be all you need. Maybe
some preg_match() if the regular string functions aren't quite enough.
--
Chris Snyder
http://chxo.com/
More information about the talk
mailing list