AnewtMailMessage class

Representation of an email message.

Class Overview

Representation of an email message.

This class provides both functionality for reading and sending email messages.

Todo

Header/body formatting so that it can be used correctly to output a complete mail message.

Todo

What to do with multipart messages?

Todo

What to do with different encodings?

Public Static Methods

static from_string($data) [static]

Creates a new message by parsing a string containing a complete mail message.

The headers are parsed and stored; the body is left intact.

Parameters

$data

A string with a complete mail message

Return value

A new AnewtMailMessage instance

static from_stream($stream) [static]

Creates a new message by reading from a stream containing a complete mail message.

The headers are parsed and stored; the body is left intact.

Parameters

$stream

An open stream resource, eg. from fopen()

Return value

A new AnewtMailMessage instance

static from_file($filename) [static]

Creates a new message by reading from a file containing a complete mail message.

The headers are parsed and stored; the body is left intact.

Parameters

$filename

The filename of the file to read

Return value

A new AnewtMailMessage instance

Public Methods

__construct()

Initializes a new AnewtMailMessage instance.

add_header($name, $value)

Adds a header to the message instance.

If the header already existed, the value is converted to an array and the new values is appended.

Parameters

$name

The name of the header

$value

The value of the header

get_header($name)

Returns the specified header.

Parameters

$name

The name of the header

Return value

A string containing the header value or an array containing multiple string values (if the header occurred more than once)

has_header($name)

Checks if a header is defined.

Parameters

$name

The name of the header

Return value

True if the header was found, false otherwise

send($force=false)

Sends the mail message.

This method tries to use the sendmail binary directly (falls back to the PHP mail() function) to actually send the message. Note that only messages which have the 'can-send' attribute set to true are considered for sending. Messages that were parsed from a file, stream or a string (using the static methods of this class) will have this attribute set to false, because sending a message you just parsed is not generally what you want.

Parameters

$force

Optional parameter to force sending of non-sendable messages

Return value

True if the message was sent successfully, false if an error occurred

Todo

Handle name/address rfc822 addresses correctly

Todo

Include all headers instead of just a few

Private Methods

parse_body($body) [private]

Parses the raw body of a message and stores the result in this message.

This method should only be called once during parsing. Bodies that are encoded using as 'quoted-printable' are converted to normal strings.

Parameters

$body

A string that contains the body text

parse_headers($headers) [private]

Parses raw headers and stores them in this message.

This method should only be called once during parsing.

Parameters

$headers

A string or array that contains the headers to be parsed

Private Attributes

$headers [private]

Object holding all header data.

Inheritance

Base Classes

Inherited members