class EmlReader

Class to parse an EML file et get a MailContent object

Properties

static string $lastError

Methods

static 
_error(string $msg)

Sets error message

static 
destroy(MailContent $mail)

Clear temp files used for embeddings and attachments

static string
decodeHeader(string $header, string|NULL $value = NULL)

Decode a header

static string|NULL
decodeBody(string $body, string $encoding)

Decode body with content-transfer-encoding (usually, quoted printable or base64)

static string|NULL
decodeCharset(string $body, string $charset)

Decode body according to a charset (may be read from Content-Type header)

static string|NULL
decodeCharsetFromContentTypeHeader(string $body, string $ct)

Decode body content according to it's content-type to UTF-8

static MailContent|NULL
decodeContent(string $body, string[] $headers, string $contentType)

Decode part content

static MailContent|NULL
fromContentType(string $ct, string[] $headers, string $body)

Decode email from it's top level content-type

static string
getHeaders(string $eml, string $linefeed)

Extract headers to a string, and set the linefeed (parameter by reference), by detecting linefeed characters in headers

static MailContent|NULL
fromString(string $data)

Decode email from a string

static MailContent
fromFile(string $file)

Decode email from a file

Details

at line 39
static protected _error(string $msg)

Sets error message

Parameters

string $msg Error message

at line 51
static destroy(MailContent $mail)

Clear temp files used for embeddings and attachments

Parameters

MailContent $mail Mail object to process

at line 87
static string decodeHeader(string $header, string|NULL $value = NULL)

Decode a header

If $value is null, we return the first value (the value before ';') ; if $value is a string we return the parameter named according to it's value. For example, in :

text/plain; charset="UTF-8"; format=flowed

we have the first value (text/plain) and two parameters (charset and format)

Parameters

string $header Header to parse
string|NULL $value Parameter to return ; to get the full header value, pass NULL as value

Return Value

string Returns the header value, or the value for the parameter named as $value content

at line 123
static string|NULL decodeBody(string $body, string $encoding)

Decode body with content-transfer-encoding (usually, quoted printable or base64)

Parameters

string $body Content to decode
string $encoding Content-Transfer-Encoding for the $body

Return Value

string|NULL Body decoded or NULL if an error occured

at line 155
static string|NULL decodeCharset(string $body, string $charset)

Decode body according to a charset (may be read from Content-Type header)

Parameters

string $body Body string to decode
string $charset Charset to use to decode

Return Value

string|NULL Body decoded or NULL if an error occured

at line 181
static string|NULL decodeCharsetFromContentTypeHeader(string $body, string $ct)

Decode body content according to it's content-type to UTF-8

Parameters

string $body Body to decode
string $ct Content-Type header from which the charset will be extracted and use for decoding

Return Value

string|NULL The body with charset decoded to UTF-8 or NULL if an error occured

at line 206
static MailContent|NULL decodeContent(string $body, string[] $headers, string $contentType)

Decode part content

We get some MailPieces\MailContent classes, depending on Content-Type and Content-disposition headers :

  • MailPieces\MailTextPlainContent
  • MailPieces\MailHtmlPlainContent
  • MailPieces\MailAttachment
  • MailPieces\MailEmbedding

Parameters

string $body Body to decode
string[] $headers Headers array
string $contentType Content-Type header value

Return Value

MailContent|NULL Returns the part decoded to a MailContent instance or NULL if an error occured

at line 264
static MailContent|NULL fromContentType(string $ct, string[] $headers, string $body)

Decode email from it's top level content-type

Parameters

string $ct Content-Type header value
string[] $headers Headers array
string $body Body to decode

Return Value

MailContent|NULL A MailContent object constructed or NULL if an error occured

at line 353
static string getHeaders(string $eml, string $linefeed)

Extract headers to a string, and set the linefeed (parameter by reference), by detecting linefeed characters in headers

Parameters

string $eml Email raw content
string $linefeed Will be set with the linefeed character detected

Return Value

string Headers string extracted

at line 386
static MailContent|NULL fromString(string $data)

Decode email from a string

Parameters

string $data Email string to decode

Return Value

MailContent|NULL MailContent object constructed or NULL if an error occured

at line 414
static MailContent fromFile(string $file)

Decode email from a file

Parameters

string $file Path to email to read

Return Value

MailContent MailContent object constructed or NULL if an error occured