Copied!

Represents a Received header.

The returned header value (as returned by a call to {@see \ReceivedHeader::getValue()}) for a ReceivedHeader is the same as the raw value (as returned by a call to {@see \ReceivedHeader::getRawValue()}) since the header doesn't have a single 'value' to consider 'the value'.

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

Additional parsing is performed on the "FROM" and "BY" parts of a received header in an attempt to extract the self-identified name of the server, its hostname, and its address (depending on what's included). These can be accessed directly from the ReceivedHeader object by calling one of the following methods:

o {@see \ReceivedHeader::getFromName()} -- the name portion of the FROM part o {@see \ReceivedHeader::getFromHostname()} -- the hostname of the FROM part o {@see \ReceivedHeader::getFromAddress()} -- the adddress portion of the FROM part o {@see \ReceivedHeader::getByName()} -- same as getFromName, but for the BY part, and etc... below o {@see \ReceivedHeader::getByHostname()} o {@see \ReceivedHeader::getByAddress()}

The parsed parts of the FROM and BY parts are determined as follows:

o Anything outside and before a parenthesized expression is considered "the name", for example "FROM AlainDeBotton", "AlainDeBotton" would be the name, but also if the name is an address, but exists outside the parenthesized expression, it's still considered "the name". For example: "From [1.2.3.4]", getFromName would return "[1.2.3.4]". o A parenthesized expression MUST match what looks like either a domain name on its own, or a domain name and an address. Otherwise the parenthesized expression is considered a comment, and not parsed into hostname and address. The rules are defined loosely because many implementations differ in how strictly they follow the standard. For a domain, it's enough that the expression starts with any alphanumeric character and contains at least one '.', followed by any number of '.', '-' and alphanumeric characters. The address portion must be surrounded in square brackets, and contain any sequence of '.', ':', numbers, and characters 'a' through 'f'. In addition the string 'ipv6' may start the expression (for instance, '[ipv6:::1]' would be valid). A port number may also be considered valid as part of the address, for example: [1.2.3.4:3231]. No additional validation on the address is done, and so an invalid address such as '....' could be returned, so users using the 'address' header are encouraged to validate it before using it. The square brackets are parsed out of the returned address, so the value returned by getFromAddress() would be "2.2.2.2", not "[2.2.2.2]".

The date/time stamp can be accessed as a DateTime object by calling {@see \ReceivedHeader::getDateTime()}.

Parsed comments can be accessed by calling {@see \ReceivedHeader::getComments()}. Some implementations may include connection encryption information or other details in non-standardized comments.

CloneableInstantiable
Methods
public __construct(string $name, string $value, ?Psr\Log\LoggerInterface $logger = NULL, ?ZBateson\MailMimeParser\Header\Consumer\ReceivedConsumerService $consumerService = NULL)
public ZBateson\MailMimeParser\Header\AbstractHeader::__toString() : string
public ZBateson\MailMimeParser\ErrorBag::addError(string $message, string $psrLogLevel, ?Throwable $exception = NULL) : static
public static ZBateson\MailMimeParser\Header\AbstractHeader::from(string $nameOrLine, ?string $value = NULL) : ZBateson\MailMimeParser\Header\IHeader
 

Parses the passed parameters into an IHeader object.

The type of returned IHeader is determined by the name of the header. See {@see \HeaderFactory::newInstance} for more details.

The required $nameOrLine parameter may contain either the name of a header to parse, or a full header line, e.g. From: email@example.com. If passing a full header line, the $value parameter must be set to null (the default).

Note that more specific types can be called on directly. For instance an AddressHeader may be created by calling AddressHeader::from() which will ignore the name of the header, and always return an AddressHeader, or by calling new AddressHeader('name', 'value') directly.

  • param string $nameOrLine The header's name or full header line.
  • param string|null $value The header's value, or null if passing a full header line to parse.
public ZBateson\MailMimeParser\ErrorBag::getAllErrors(bool $validate = false, string $minPsrLevel = 'error'Psr\Log\LogLevel::ERROR) : array
public ZBateson\MailMimeParser\Header\AbstractHeader::getAllParts() : array
 
  • return \IHeaderPart[]
public getByAddress() : ?string
 

Returns the address part of a parenthesized BY part or null if not defined or the format wasn't parsed.

For example, "BY name ([1.2.3.4])" would return the string "1.2.3.4". Validation of the address is not performed, and the returned value may not be valid. More details on how the value is parsed and extracted can be found in the class description for {@see \ReceivedHeader}.

  • return ?string The 'BY' address.
public getByHostname() : ?string
 

Returns the hostname part of a parenthesized BY part or null if not defined or the format wasn't parsed.

For example, "BY name (host.name)" would return the string "host.name". Validation of the hostname is not performed, and the returned value may not be valid. More details on how the value is parsed and extracted can be found in the class description for {@see \ReceivedHeader}.

  • return ?string The 'BY' hostname.
public getByName() : ?string
 

Returns the name identified in the BY part of the header or null if not defined or the format wasn't parsed.

The returned value may either be a name or an address in the form "[1.2.3.4]". Validation is not performed on this value, and so whatever exists in this position is returned -- be it contains spaces, or invalid characters, etc...

  • return ?string The 'BY' name.
public ZBateson\MailMimeParser\Header\AbstractHeader::getComments() : array
 
  • return string[]
public getDateTime() : ?DateTime
 

Returns the date/time stamp for the received header if set, or null otherwise.

public ZBateson\MailMimeParser\Header\AbstractHeader::getErrorLoggingContextName() : string
public ZBateson\MailMimeParser\ErrorBag::getErrors(bool $validate = false, string $minPsrLevel = 'error'Psr\Log\LogLevel::ERROR) : array
public getFromAddress() : ?string
 

Returns the address part of a parenthesized FROM part or null if not defined or the format wasn't parsed.

For example, "FROM name ([1.2.3.4])" would return the string "1.2.3.4". Validation of the address is not performed, and the returned value may not be valid. More details on how the value is parsed and extracted can be found in the class description for {@see \ReceivedHeader}.

  • return ?string The 'FROM' address.
public getFromHostname() : ?string
 

Returns the hostname part of a parenthesized FROM part or null if not defined or the format wasn't parsed.

For example, "FROM name (host.name)" would return the string "host.name". Validation of the hostname is not performed, and the returned value may not be valid. More details on how the value is parsed and extracted can be found in the class description for {@see \ReceivedHeader}.

  • return ?string The 'FROM' hostname.
public getFromName() : ?string
 

Returns the name identified in the FROM part of the header or null if not defined or the format wasn't parsed.

The returned value may either be a name or an address in the form "[1.2.3.4]". Validation is not performed on this value, and so whatever exists in this position is returned -- be it contains spaces, or invalid characters, etc...

  • return ?string The 'FROM' name.
public ZBateson\MailMimeParser\Header\AbstractHeader::getName() : string
public ZBateson\MailMimeParser\Header\AbstractHeader::getParts() : array
 
  • return \IHeaderPart[]
public ZBateson\MailMimeParser\Header\AbstractHeader::getRawValue() : string
public getValue() : ?string
 

Returns the raw, unparsed header value, same as {@see ReceivedHeader::getRawValue()}.

public ZBateson\MailMimeParser\Header\ParameterHeader::getValueFor(string $name, ?string $defaultValue = NULL) : ?string
 

Returns the value of the parameter with the given name, or $defaultValue if not set.

  • param string $name The parameter to retrieve.
  • param string $defaultValue Optional default value (defaulting to null if not provided).
  • return string|null The parameter's value.
public ZBateson\MailMimeParser\ErrorBag::hasAnyErrors(bool $validate = false, string $minPsrLevel = 'error'Psr\Log\LogLevel::ERROR) : bool
public ZBateson\MailMimeParser\ErrorBag::hasErrors(bool $validate = false, string $minPsrLevel = 'error'Psr\Log\LogLevel::ERROR) : bool
public ZBateson\MailMimeParser\Header\ParameterHeader::hasParameter(string $name) : bool
 

Returns true if a parameter exists with the passed name.

  • param string $name The parameter to look up.
Properties
protected array ZBateson\MailMimeParser\Header\AbstractHeader::$allParts = []
 
  • var \IHeaderPart[] the header's parts (as returned from the consumer), including commentParts
protected Psr\Log\LoggerInterface ZBateson\MailMimeParser\ErrorBag::$logger
protected string ZBateson\MailMimeParser\Header\AbstractHeader::$name
 
  • var string the name of the header
protected array ZBateson\MailMimeParser\Header\ParameterHeader::$parameters = []
 
  • var \ParameterPart[] key map of lower-case parameter names and associated ParameterParts.
protected array ZBateson\MailMimeParser\Header\AbstractHeader::$parts = []
 
  • var \IHeaderPart[] all parts not including CommentParts.
protected string ZBateson\MailMimeParser\Header\AbstractHeader::$rawValue
 
  • var string the raw value
Methods
protected ZBateson\MailMimeParser\Header\AbstractHeader::filterAndAssignToParts() : void
 

Filters $this->allParts into the parts required by $this->parts and assigns it.

The AbstractHeader::filterAndAssignToParts method filters out CommentParts.

protected ZBateson\MailMimeParser\Header\AbstractHeader::getErrorBagChildren() : array
protected static ZBateson\MailMimeParser\Header\AbstractHeader::getHeaderPartsFrom(string $nameOrLine, ?string $value = NULL) : array
 

Checks if the passed $value parameter is null, and if so tries to parse a header line from $nameOrLine splitting on first occurrence of a ':' character.

The returned array always contains two elements. The first being the name (or blank if a ':' char wasn't found and $value is null), and the second being the value.

  • return string[]
protected ZBateson\MailMimeParser\Header\ParameterHeader::parseHeaderValue(ZBateson\MailMimeParser\Header\Consumer\IConsumerService $consumer, string $value) : void
 

Overridden to assign ParameterParts to a map of lower-case parameter names to ParameterParts.

protected ZBateson\MailMimeParser\Header\AbstractHeader::validate() : void
Properties
private ?DateTime $date = NULL
 
  • var \DateTime the date/time stamp in the header.
private bool $dateSet = false
 
  • var bool set to true once $date has been looked for
Methods
public static ZBateson\MailMimeParser\Header\AbstractHeader::from(string $nameOrLine, ?string $value = NULL) : ZBateson\MailMimeParser\Header\IHeader
 

Parses the passed parameters into an IHeader object.

The type of returned IHeader is determined by the name of the header. See {@see \HeaderFactory::newInstance} for more details.

The required $nameOrLine parameter may contain either the name of a header to parse, or a full header line, e.g. From: email@example.com. If passing a full header line, the $value parameter must be set to null (the default).

Note that more specific types can be called on directly. For instance an AddressHeader may be created by calling AddressHeader::from() which will ignore the name of the header, and always return an AddressHeader, or by calling new AddressHeader('name', 'value') directly.

  • param string $nameOrLine The header's name or full header line.
  • param string|null $value The header's value, or null if passing a full header line to parse.
protected static ZBateson\MailMimeParser\Header\AbstractHeader::getHeaderPartsFrom(string $nameOrLine, ?string $value = NULL) : array
 

Checks if the passed $value parameter is null, and if so tries to parse a header line from $nameOrLine splitting on first occurrence of a ':' character.

The returned array always contains two elements. The first being the name (or blank if a ':' char wasn't found and $value is null), and the second being the value.

  • return string[]
© 2024 Bruce Wells
Search Namespaces \ Classes
Configuration