zbateson / mail-mime-parser

An email parser written in PHP
https://mail-mime-parser.org/
BSD 2-Clause "Simplified" License
442 stars 56 forks source link

How to get Value from Received #164

Closed ibnbd closed 1 year ago

ibnbd commented 3 years ago

Hello there @zbateson, I am testing this email and try to get the value for <8293j283@postfix.mydomain.com> from Received. Is there any in-script way to get this? Thank you in advance


From ubuntu@postfix.mydomain.com  Thu Feb 18 16:56:46 2021
Received: from postfix.mydomain.com (localhost [127.0.0.1])
        by postfix.mydomain.com (Postfix) with ESMTP id A981B3F932
        for <8293j283@postfix.mydomain.com>; Thu, 18 Feb 2021 16:56:46 -0500 (EST)
Subject: Test random emails
Message-Id: <20210218215646.A981B3F932@postfix.mydomain.com>
Date: Thu, 18 Feb 2021 16:56:46 -0500 (EST)
From: ubuntu@postfix.mydomain.com

Sounds good!```
ibnbd commented 3 years ago

Actually, I only need the email address 8293j283@postfix.mydomain.com, whom the email was for.

zbateson commented 3 years ago

Hi @ibnbd --

Yup, there's a general usage guide on the main readme here and on the website if you're looking for general usage (how to read a header), and documentation on specifics of the Received header here: https://mail-mime-parser.org/api/1.3/classes/ZBateson-MailMimeParser-Header-ReceivedHeader.html -- this is the relevant part for you:

The parsed parts of a Received header can be accessed as parameters. To check if a part exists, call ReceivedHeader::hasParameter() with the name of the part, for example: $header->hasParameter('from') or $header->hasParameter('id'). The value of the part can be obtained by calling ReceivedHeader::getValueFor(), for example $header->getValueFor('with');.

Al the best