Forums / Developer / eZ components MailParser - accessing more from the headers

eZ components MailParser - accessing more from the headers

Author Message

Joe Jenkins

Wednesday 02 May 2007 2:21:42 pm

Hi everyone,

First off, thanks for your efforts. Today is my first time using your components and they are exceptional. I looked here for an answering to the following but had no luck:

When using ezcMailParser(), I can get information out of the headers as follows:

$set = new ezcMailFileSet( array( $currentEmail ));
$parser = new ezcMailParser();
$mail = $parser->parseMail( $set );

$mailFrom = $mail[0]->from;
$mailTo = $mail[0]->to;
$mailCC = $mail[0]->cc;
$mailBCC = $mail[0]->bcc;
$mailSubject = $mail[0]->subject;
$mailTimeStamp = date(DATE_RFC822, $mail->timestamp);
$mailMessageID = $mail[0]->messageId;

This works just fine when I pass in a file of a single email. I need to be able to get more information out of the header, though, and if I print_r($mail) I can see quite a bit of information in there I need for my application. I just don't know how to extract it in PHP. For example,

[map:private] => Array
(
[Return-Path] => <joe@nerdnet.com>
[X-Spam-Checker-Version] => SpamAssassin 3.1.8 (2007-02-13) on rsgmann.x.x
[X-Spam-Level] =>
[X-Spam-Status] => No, score=-3.6 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00, SPF_HELO_PASS autolearn=ham version=3.1.8
[Received] => from 70.96.x.x ([70.96.x.x]) by mail.server.com

I need to be able to get the "Received" field there to grab an IP address out of it, but I can't figure out how to access it inside the object. Can you provide any info on this?

Thanks very much.

Frederik Holljen

Friday 11 May 2007 1:09:43 pm

hi, thank you for using eZ components.

If you take a look at the documentation (http://ez.no/doc/components/view/2006.2/(file)/Mail/ezcMail.html) you'll see the method getHeader() which can be used to fetch any header. ezcMail also inherits ezcMailPart which has the property $headers (http://ez.no/doc/components/view/2006.2/(file)/Mail/ezcMailPart.html). This property can also be used to fetch headers.

For further questions about the components use the mailinglists: http://ez.no/ezcomponents/mailinglists. They are more frequently read by the components developers than the eZ publish forums.

Cheers.