MailMimeParser 2.1

MailMimeParser
in package

Parses a MIME message into an {@see IMessage} object.

The class sets up the Pimple dependency injection container with the ability to override and/or provide specialized provider https://pimple.symfony.com/ classes to extend default classes used by MailMimeParser.

To invoke, call parse on a MailMimeParser object.

$parser = new MailMimeParser();
// the resource is attached due to the second parameter being true and will
// be closed when the returned IMessage is destroyed
$message = $parser->parse(fopen('path/to/file.txt'), true);
// use $message here
Tags
author

Zaahid Bateson

Table of Contents

DEFAULT_CHARSET  = 'UTF-8'
$di  : Container
$messageParser  : MessageParser
__construct()  : mixed
Initializes the dependency container if not already initialized.
configureDependencyContainer()  : mixed
(Re)creates the container using the passed providers.
getDependencyContainer()  : Container
Returns the container.
parse()  : IMessage
Parses the passed stream handle or string into an {@see IMessage} object and returns it.
setDependencyContainer()  : mixed
Override the dependency container completely. If multiple configurations are known to be needed, it would be better to keep the different Container configurations and call setDependencyContainer instead of {@see MailMimeParser::configureDependencyContainer}, which instantiates a new {@see Container} on every call.

Constants

DEFAULT_CHARSET

public string DEFAULT_CHARSET = 'UTF-8'

the default charset used to encode strings (or string content like streams) returned by MailMimeParser (for e.g. the string returned by calling $message->getTextContent()).

Properties

Methods

configureDependencyContainer()

(Re)creates the container using the passed providers.

public static configureDependencyContainer([array<string|int, ServiceProviderInterface$providers = [] ]) : mixed

This is necessary if configuration needs to be reset to parse emails differently.

Note that reconfiguring the dependency container can have an affect on existing objects -- for instance if a provider were to override a factory class, and an operation on an existing instance were to try to create an object using that factory class, the new factory class would be returned. In other words, references to the Container are not maintained in a non-static context separately, so care should be taken when reconfiguring the parser.

Parameters
$providers : array<string|int, ServiceProviderInterface> = []
Return values
mixed

parse()

Parses the passed stream handle or string into an {@see IMessage} object and returns it.

public parse(resource|StreamInterface|string $resource, bool $attached) : IMessage

If the passed $resource is a resource handle or StreamInterface, the resource must remain open while the returned IMessage object exists. Pass true as the second argument to have the resource attached to the IMessage and closed for you when it's destroyed, or pass false to manually close it if it should remain open after the IMessage object is destroyed.

Parameters
$resource : resource|StreamInterface|string

The resource handle to the input stream of the mime message, or a string containing a mime message.

$attached : bool

pass true to have it attached to the returned IMessage and destroyed with it.

Return values
IMessage

setDependencyContainer()

Override the dependency container completely. If multiple configurations are known to be needed, it would be better to keep the different Container configurations and call setDependencyContainer instead of {@see MailMimeParser::configureDependencyContainer}, which instantiates a new {@see Container} on every call.

public static setDependencyContainer([Container $di = null ]) : mixed
Parameters
$di : Container = null
Return values
mixed

Search results