Copied!

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 {@see https://pimple.symfony.com/ \Pimple\ServiceProviderInterface} 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
CloneableInstantiable
Constants
public ZBateson\MailMimeParser\MailMimeParser::DEFAULT_CHARSET = 'UTF-8'
 
  • var string 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()).
Methods
public __construct()
 

Initializes the dependency container if not already initialized.

To configure custom {@see https://pimple.symfony.com/ \Pimple\ServiceProviderInterface} objects, call {@see \MailMimeParser::configureDependencyContainer()} before creating a MailMimeParser instance.

public static configureDependencyContainer(array $providers = [])
 

(Re)creates the container using the passed providers.

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.

  • param \Pimple\ServiceProviderInterface[] $providers
public static getDependencyContainer()
 

Returns the container.

  • return \Container
public parse( $resource, $attached)
 

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

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.

  • param resource|\StreamInterface|string $resource The resource handle to the input stream of the mime message, or a string containing a mime message.
  • param bool $attached pass true to have it attached to the returned IMessage and destroyed with it.
  • return \ZBateson\MailMimeParser\IMessage
public static setDependencyContainer(?ZBateson\MailMimeParser\Container $di = NULL)
 

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.

  • param \Container $di
Properties
protected static $di = NULL
 
  • var \Container dependency injection container
protected $messageParser = NULL
 
  • var \MessageParser for parsing messages
Properties
protected static $di = NULL
 
  • var \Container dependency injection container
Methods
public static configureDependencyContainer(array $providers = [])
 

(Re)creates the container using the passed providers.

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.

  • param \Pimple\ServiceProviderInterface[] $providers
public static getDependencyContainer()
 

Returns the container.

  • return \Container
public static setDependencyContainer(?ZBateson\MailMimeParser\Container $di = NULL)
 

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.

  • param \Container $di
© 2024 Bruce Wells
Search Namespaces \ Classes
Configuration