ReceivedDomainPart
extends ReceivedPart
in package
Holds extra information about a parsed Received header part, for FROM and BY parts, namely: ehlo name, hostname, and address.
The parsed parts would be mapped as follows:
FROM ehlo name (hostname [address]), for example: FROM computer (domain.com [1.2.3.4]) would contain "computer" for getEhloName(), domain.com for getHostname and 1.2.3.4 for getAddress().
This doesn't change if the ehlo name is an address, it is still returned in getEhloName(), and not in getAddress(). Additionally square brackets are not stripped from getEhloName() if its an address. For example: "FROM [1.2.3.4]" would return "[1.2.3.4]" in a call to getEhloName().
For further information on how the header's parsed, check the documentation for DomainConsumer.
Tags
Table of Contents
- $address : string|null
- $canIgnoreSpacesAfter : bool
- $canIgnoreSpacesBefore : bool
- $charsetConverter : MbWrapper
- $children : array<string|int, HeaderPart>
- $ehloName : string|null
- $hostname : string|null
- $isSpace : bool
- True if the part is a space token
- $logger : LoggerInterface
- $name : string
- $value : string
- $errors : array<string|int, mixed>
- $validated : bool
- __construct() : mixed
- __toString() : string
- Returns the value of the part (which is a string).
- addError() : static
- Creates and adds an Error object to this ErrorBag.
- getAddress() : string|null
- Returns the address of the server, or whatever string that looks like an address in the address position when parsing (but never a hostname).
- getAllErrors() : array<string|int, Error>
- Returns any errors on this object, and all IErrorBag children of this object at or above the passed PSR log level from Psr\Log\LogLevel (defaulting to LogLevel::ERROR).
- getChildParts() : array<string|int, IHeaderPart>
- Returns the child parts this container part consists of.
- getComments() : array<string|int, CommentPart>
- Returns any CommentParts under this part container.
- getEhloName() : string|null
- Returns the name used to identify the server in the first part of the extended-domain line.
- getErrorLoggingContextName() : string
- Returns the class name. Override to identify objects in logs.
- getErrors() : array<string|int, Error>
- Returns any local errors this object has at or above the passed PSR log level in Psr\Log\LogLevel (defaulting to LogLevel::ERROR).
- getHostname() : string|null
- Returns the hostname of the server, or whatever string in the hostname position when parsing (but never an address).
- getName() : string
- Returns the name of the name/value part.
- getValue() : string
- Returns the part's representative value after any necessary processing has been performed. For the raw value, call getRawValue().
- hasAnyErrors() : bool
- Returns true if there are errors on this object, or any IErrorBag child of this object at or above the passed PSR log level in Psr\Log\LogLevel (defaulting to LogLevel::ERROR). Note that this will stop after finding the first error and return, so may be slightly more performant if an error actually exists over calling getAllErrors if only interested in whether an error exists.
- hasErrors() : bool
- Returns true if this object has an error in its error bag at or above the passed $minPsrLevel (defaults to ERROR). If $validate is true, additional validation may be performed.
- convertEncoding() : string
- Ensures the encoding of the passed string is set to UTF-8.
- filterIgnoredSpaces() : array<string|int, HeaderPart>
- Filters out ignorable space tokens.
- getErrorBagChildren() : array<string|int, IErrorBag>
- Return any children ErrorBag objects.
- getNameFromParts() : string
- Creates the string 'name' representation of this part constructed from the child name parts passed to it.
- getValueFromParts() : string
- Creates the string value representation of this part constructed from the child parts passed to it.
- validate() : void
- Perform any extra validation and call 'addError'.
Properties
$address
protected
string|null
$address
= null
The address.
$canIgnoreSpacesAfter
protected
bool
$canIgnoreSpacesAfter
= false
set to true to ignore spaces after this part
$canIgnoreSpacesBefore
protected
bool
$canIgnoreSpacesBefore
= false
set to true to ignore spaces before this part
$charsetConverter
protected
MbWrapper
$charsetConverter
the charset converter used for converting strings in HeaderPart::convertEncoding
$children
protected
array<string|int, HeaderPart>
$children
= []
parts that were used to create this part, collected for proper error reporting and validation.
$ehloName
protected
string|null
$ehloName
= null
The name used to identify the server in the EHLO line.
$hostname
protected
string|null
$hostname
= null
The hostname.
$isSpace
True if the part is a space token
protected
bool
$isSpace
= false
$logger
protected
LoggerInterface
$logger
$name
protected
string
$name
the name of the part
$value
protected
string
$value
the representative value of the part after any conversion or processing has been done on it (e.g. removing new lines, converting, whatever else).
$errors
private
array<string|int, mixed>
$errors
= []
array of Error objects belonging to this object.
$validated
private
bool
$validated
= false
true once the object has been validated.
Methods
__construct()
public
__construct(LoggerInterface $logger, MbWrapper $charsetConverter, string $name, array<string|int, HeaderPart> $children) : mixed
Parameters
- $logger : LoggerInterface
- $charsetConverter : MbWrapper
- $name : string
- $children : array<string|int, HeaderPart>
Return values
mixed —__toString()
Returns the value of the part (which is a string).
public
__toString() : string
Return values
string —the value
addError()
Creates and adds an Error object to this ErrorBag.
public
addError(string $message, string $psrLogLevel[, Throwable|null $exception = null ]) : static
Parameters
- $message : string
- $psrLogLevel : string
- $exception : Throwable|null = null
Return values
static —getAddress()
Returns the address of the server, or whatever string that looks like an address in the address position when parsing (but never a hostname).
public
getAddress() : string|null
Return values
string|null —getAllErrors()
Returns any errors on this object, and all IErrorBag children of this object at or above the passed PSR log level from Psr\Log\LogLevel (defaulting to LogLevel::ERROR).
public
getAllErrors([bool $validate = false ][, string $minPsrLevel = LogLevel::ERROR ]) : array<string|int, Error>
Care should be taken using this if the intention is to only 'preview' a message without parsing it entirely, since this will cause the whole message to be parsed as it traverses children, and could be slow on messages with large attachments, etc...
If $validate is true, additional validation may be performed on children to check for errors.
Parameters
- $validate : bool = false
- $minPsrLevel : string = LogLevel::ERROR
Return values
array<string|int, Error> —getChildParts()
Returns the child parts this container part consists of.
public
getChildParts() : array<string|int, IHeaderPart>
Return values
array<string|int, IHeaderPart> —getComments()
Returns any CommentParts under this part container.
public
getComments() : array<string|int, CommentPart>
Return values
array<string|int, CommentPart> —getEhloName()
Returns the name used to identify the server in the first part of the extended-domain line.
public
getEhloName() : string|null
Note that this is not necessarily the name used in the EHLO line to an SMTP server, since implementations differ so much, not much can be guaranteed except the position it was parsed in.
Return values
string|null —getErrorLoggingContextName()
Returns the class name. Override to identify objects in logs.
public
getErrorLoggingContextName() : string
Return values
string —getErrors()
Returns any local errors this object has at or above the passed PSR log level in Psr\Log\LogLevel (defaulting to LogLevel::ERROR).
public
getErrors([bool $validate = false ][, string $minPsrLevel = LogLevel::ERROR ]) : array<string|int, Error>
If $validate is true, additional validation may be performed on the object to check for errors.
Parameters
- $validate : bool = false
- $minPsrLevel : string = LogLevel::ERROR
Return values
array<string|int, Error> —getHostname()
Returns the hostname of the server, or whatever string in the hostname position when parsing (but never an address).
public
getHostname() : string|null
Return values
string|null —getName()
Returns the name of the name/value part.
public
getName() : string
Return values
string —getValue()
Returns the part's representative value after any necessary processing has been performed. For the raw value, call getRawValue().
public
getValue() : string
Return values
string —The value of the part
hasAnyErrors()
Returns true if there are errors on this object, or any IErrorBag child of this object at or above the passed PSR log level in Psr\Log\LogLevel (defaulting to LogLevel::ERROR). Note that this will stop after finding the first error and return, so may be slightly more performant if an error actually exists over calling getAllErrors if only interested in whether an error exists.
public
hasAnyErrors([bool $validate = false ][, string $minPsrLevel = LogLevel::ERROR ]) : bool
Care should be taken using this if the intention is to only 'preview' a message without parsing it entirely, since this will cause the whole message to be parsed as it traverses children, and could be slow on messages with large attachments, etc...
If $validate is true, additional validation may be performed to check for errors.
Parameters
- $validate : bool = false
- $minPsrLevel : string = LogLevel::ERROR
Return values
bool —hasErrors()
Returns true if this object has an error in its error bag at or above the passed $minPsrLevel (defaults to ERROR). If $validate is true, additional validation may be performed.
public
hasErrors([bool $validate = false ][, string $minPsrLevel = LogLevel::ERROR ]) : bool
The PSR levels are defined in Psr\Log\LogLevel.
Parameters
- $validate : bool = false
- $minPsrLevel : string = LogLevel::ERROR
Return values
bool —convertEncoding()
Ensures the encoding of the passed string is set to UTF-8.
protected
convertEncoding(string $str[, string $from = 'ISO-8859-1' ][, bool $force = false ]) : string
The method does nothing if the passed $from charset is UTF-8 already, or if $force is set to false and mb_check_encoding for $str returns true for 'UTF-8'.
Parameters
- $str : string
- $from : string = 'ISO-8859-1'
- $force : bool = false
Return values
string —utf-8 string
filterIgnoredSpaces()
Filters out ignorable space tokens.
protected
filterIgnoredSpaces(array<string|int, HeaderPart> $parts) : array<string|int, HeaderPart>
Spaces are removed if parts on either side of it have their canIgnoreSpaceAfter/canIgnoreSpaceBefore properties set to true.
Parameters
- $parts : array<string|int, HeaderPart>
Return values
array<string|int, HeaderPart> —getErrorBagChildren()
Return any children ErrorBag objects.
protected
abstract getErrorBagChildren() : array<string|int, IErrorBag>
Return values
array<string|int, IErrorBag> —getNameFromParts()
Creates the string 'name' representation of this part constructed from the child name parts passed to it.
protected
getNameFromParts(array<string|int, HeaderParts> $parts) : string
Parameters
- $parts : array<string|int, HeaderParts>
Return values
string —getValueFromParts()
Creates the string value representation of this part constructed from the child parts passed to it.
protected
getValueFromParts(array<string|int, HeaderParts> $parts) : string
The default implementation filters out ignorable whitespace between parts, and concatenates parts calling 'getValue'.
Parameters
- $parts : array<string|int, HeaderParts>
Return values
string —validate()
Perform any extra validation and call 'addError'.
protected
validate() : void
getErrors and getAllErrors call validate() if their $validate parameter is true. validate() is only called once on an object with getErrors getAllErrors.