Jim
Jim

Reputation: 1

I need to extract email addresses from yahoo full headers and need help matching them

I have several thousand emails saved in a directory. These emails are opened with file_get_contents. I need to match all reply-to: emails from these headers. How do I match them?

Upvotes: 0

Views: 440

Answers (3)

ghostdog74
ghostdog74

Reputation: 342413

you don't have to really create a complicated regex to parse emails. Use PHP's string methods to find where the word "reply-to" is, then get the next word after it and check for "@". These should be your emails. Leave the "checking" of valid email to the MTA servers when you send them out.

Upvotes: 0

Tim Lytle
Tim Lytle

Reputation: 17624

From my answer on the eerily similar question - I agree that parsing e-mails (which I've had to do) is surprisingly painful:


Some mail sending libraries can parse raw email, while not that well documented Zend_Mail should be able to do that by passing your raw email to a Zend_Mail_Message object. (Note: Reading mailboxes is well documented, from what I've seen, reading a raw message isn't.)

$message = new Zend_Mail_Message(array(), $filename);
$sender = $message->getHeader('Reply-To');

If all you need is the sender, then a good RegEx would be better to use, however, if you will be testing other headers/manipulating the body/mime parts, then using a library will be worth it.

Upvotes: 1

Pascal MARTIN
Pascal MARTIN

Reputation: 401022

Parsing e-mails is going to be a pain (I've seen people try to parse e-mails, and always fail in some cases they didn't think about... ) ; I would nto go with parsing them by hand, and possibly re-inventing the wheel...

A solution I would prefer is using some existing library, that parses e-mails and extract data from them, like, for instance, Zend_Mail.


If you really cannot (or don't want to) use any existing library, I suppose a couple of regex might do the trick... But don't forget to read the RFC about e-mails : it will help you identify some cases you wouldn't think about...

Upvotes: 0

Related Questions