Documentation

Horde_Mail_Rfc822
in package

RFC 822/2822/3490/5322 Email parser/validator.

Tags
author

Richard Heyes richard@phpguru.org

author

Chuck Hagenbuch chuck@horde.org

author

Michael Slusarz slusarz@horde.org

author

Timo Sirainen tss@iki.fi

category

Horde

copyright

2001-2010 Richard Heyes

copyright

2002-2011 Timo Sirainen

copyright

2011-2017 Horde LLC

license

http://www.horde.org/licenses/bsd New BSD License

Table of Contents

ATEXT  = '!#$%&\'*+-./0123456789=?ABCDEFGHIJKLMNOPQRSTUVWXYZ^_`abcdefghijklmnopqrstuvwxyz{|}~'
Valid atext characters.
ENCODE_FILTER  = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\n\v\f\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\"(),:;<>@[\\]"
Excluded (in ASCII decimal): 0-8, 10-31, 34, 40-41, 44, 58-60, 62, 64, 91-93, 127
$_comments  : string
Comment cache.
$_data  : string
The address string to parse.
$_datalen  : int
Length of the address string.
$_listob  : Horde_Mail_Rfc822_List
List object to return in parseAddressList().
$_params  : array<string|int, mixed>
Configuration parameters.
$_ptr  : int
Data pointer.
approximateCount()  : int
Returns an approximate count of how many addresses are in the string.
encode()  : string
Quotes and escapes the given string if necessary using rules contained in RFC 2822 [3.2.5].
isValidInetAddress()  : mixed
Validates whether an email is of the common internet form: <user>@<domain>. This can be sufficient for most people.
parseAddressList()  : Horde_Mail_Rfc822_List
Starts the whole process.
trimAddress()  : string
If an email address has no personal information, get rid of any angle brackets (<>) around it.
_curr()  : string
Return current character.
_parseAddress()  : mixed
address = mailbox / group
_parseAddressList()  : mixed
address-list = (address *("," address)) / obs-addr-list
_parseAddrSpec()  : mixed
addr-spec = local-part "@" domain
_parseAngleAddr()  : mixed
"<" [ "@" route ":" ] local-part "@" domain ">"
_parseDomainList()  : array<string|int, mixed>
obs-domain-list = "@" domain *(*(CFWS / "," ) [CFWS] "@" domain)
_parseGroup()  : bool
group = display-name ":" [mailbox-list / CFWS] ";" [CFWS] display-name = phrase
_parseLocalPart()  : string
local-part = dot-atom / quoted-string / obs-local-part obs-local-part = word *("." word)
_parseMailbox()  : mixed
mailbox = name-addr / addr-spec
_parseNameAddr()  : mixed
name-addr = [display-name] angle-addr display-name = phrase
_rfc822IsAtext()  : bool
Check if data is an atom.
_rfc822ParseAtomOrDot()  : mixed
atom = [CFWS] 1*atext [CFWS] atext = ; Any character except controls, SP, and specials.
_rfc822ParseDomain()  : mixed
domain = dot-atom / domain-literal / obs-domain domain-literal = [CFWS] "[" *([FWS] dcontent) [FWS] "]" [CFWS] obs-domain = atom *("." atom)
_rfc822ParseDomainLiteral()  : mixed
domain-literal = [CFWS] "[" *([FWS] dcontent) [FWS] "]" [CFWS] dcontent = dtext / quoted-pair dtext = NO-WS-CTL / ; Non white space controls %d33-90 / ; The rest of the US-ASCII %d94-126 ; characters not including "[", ; "]", or "\"
_rfc822ParseDotAtom()  : mixed
dot-atom = [CFWS] dot-atom-text [CFWS] dot-atom-text = 1*atext *("." 1*atext)
_rfc822ParsePhrase()  : mixed
phrase = 1*word / obs-phrase word = atom / quoted-string obs-phrase = word *(word / "." / CFWS)
_rfc822ParseQuotedString()  : mixed
_rfc822SkipComment()  : mixed
_rfc822SkipLwsp()  : mixed

Constants

ATEXT

Valid atext characters.

public mixed ATEXT = '!#$%&\'*+-./0123456789=?ABCDEFGHIJKLMNOPQRSTUVWXYZ^_`abcdefghijklmnopqrstuvwxyz{|}~'
Tags
deprecated
since
2.0.3

ENCODE_FILTER

Excluded (in ASCII decimal): 0-8, 10-31, 34, 40-41, 44, 58-60, 62, 64, 91-93, 127

public mixed ENCODE_FILTER = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\n\v\f\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\"(),:;<>@[\\]"
Tags
since
2.0.3

Properties

$_comments

Comment cache.

protected string $_comments = array()

$_data

The address string to parse.

protected string $_data

$_datalen

Length of the address string.

protected int $_datalen

$_params

Configuration parameters.

protected array<string|int, mixed> $_params = array()

$_ptr

Data pointer.

protected int $_ptr

Methods

approximateCount()

Returns an approximate count of how many addresses are in the string.

public approximateCount(string $data) : int

This is APPROXIMATE as it only splits based on a comma which has no preceding backslash.

Parameters
$data : string

Addresses to count.

Return values
int

Approximate count.

encode()

Quotes and escapes the given string if necessary using rules contained in RFC 2822 [3.2.5].

public encode(string $str[, string $type = 'address' ]) : string
Parameters
$str : string

The string to be quoted and escaped.

$type : string = 'address'

Either 'address', 'comment' (@since 2.6.0), or 'personal'.

Return values
string

The correctly quoted and escaped string.

isValidInetAddress()

Validates whether an email is of the common internet form: <user>@<domain>. This can be sufficient for most people.

public isValidInetAddress(string $data[, bool $strict = false ]) : mixed

Optional stricter mode can be utilized which restricts mailbox characters allowed to: alphanumeric, full stop, hyphen, and underscore.

Parameters
$data : string

Address to check.

$strict : bool = false

Strict check?

Return values
mixed

False if it fails, an indexed array username/domain if it matches.

parseAddressList()

Starts the whole process.

public parseAddressList(mixed $address[, array<string|int, mixed> $params = array() ]) : Horde_Mail_Rfc822_List
Parameters
$address : mixed

The address(es) to validate. Either a string, a Horde_Mail_Rfc822_Object, or an array of strings and/or Horde_Mail_Rfc822_Objects.

$params : array<string|int, mixed> = array()

Optional parameters:

  • default_domain: (string) Default domain/host. DEFAULT: None
  • group: (boolean) Return a GroupList object instead of a List object? DEFAULT: false
  • limit: (integer) Stop processing after this many addresses. DEFAULT: No limit (0)
  • validate: (mixed) Strict validation of personal part data? If false, attempts to allow non-ASCII characters and non-quoted strings in the personal data, and will silently abort if an unparseable address is found. If true, does strict RFC 5322 (ASCII-only) parsing. If 'eai' (@since 2.5.0), allows RFC 6532 (EAI/UTF-8) addresses. DEFAULT: false
Tags
throws
Horde_Mail_Exception
Return values
Horde_Mail_Rfc822_List

A list object.

trimAddress()

If an email address has no personal information, get rid of any angle brackets (<>) around it.

public trimAddress(string $address) : string
Parameters
$address : string

The address to trim.

Return values
string

The trimmed address.

_curr()

Return current character.

protected _curr([bool $advance = false ]) : string
Parameters
$advance : bool = false

If true, advance the cursor.

Return values
string

The current character (false if EOF reached).

_parseAddress()

address = mailbox / group

protected _parseAddress() : mixed
Return values
mixed

_parseAddressList()

address-list = (address *("," address)) / obs-addr-list

protected _parseAddressList() : mixed
Return values
mixed

_parseAddrSpec()

addr-spec = local-part "@" domain

protected _parseAddrSpec() : mixed
Tags
throws
Horde_Mail_Exception
Return values
mixed

Mailbox object.

_parseAngleAddr()

"<" [ "@" route ":" ] local-part "@" domain ">"

protected _parseAngleAddr() : mixed
Tags
throws
Horde_Mail_Exception
Return values
mixed

Mailbox object, or false.

_parseDomainList()

obs-domain-list = "@" domain *(*(CFWS / "," ) [CFWS] "@" domain)

protected _parseDomainList() : array<string|int, mixed>
Tags
throws
Horde_Mail_Exception
Return values
array<string|int, mixed>

Routes.

_parseGroup()

group = display-name ":" [mailbox-list / CFWS] ";" [CFWS] display-name = phrase

protected _parseGroup() : bool
Tags
throws
Horde_Mail_Exception
Return values
bool

True if a group was parsed.

_parseLocalPart()

local-part = dot-atom / quoted-string / obs-local-part obs-local-part = word *("." word)

protected _parseLocalPart() : string
Tags
throws
Horde_Mail_Exception
Return values
string

The local part.

_parseMailbox()

mailbox = name-addr / addr-spec

protected _parseMailbox() : mixed
Return values
mixed

Mailbox object if mailbox was parsed, or false.

_parseNameAddr()

name-addr = [display-name] angle-addr display-name = phrase

protected _parseNameAddr() : mixed
Return values
mixed

Mailbox object, or false.

_rfc822IsAtext()

Check if data is an atom.

protected _rfc822IsAtext(string $chr[, string $validate = null ]) : bool
Parameters
$chr : string

The character to check.

$validate : string = null

If in non-validate mode, use these characters as the non-atom delimiters.

Return values
bool

True if a valid atom.

_rfc822ParseAtomOrDot()

atom = [CFWS] 1*atext [CFWS] atext = ; Any character except controls, SP, and specials.

protected _rfc822ParseAtomOrDot(string &$str) : mixed

This method doesn't just silently skip over WS.

Parameters
$str : string

The atom/dot data.

Tags
throws
Horde_Mail_Exception
Return values
mixed

_rfc822ParseDomain()

domain = dot-atom / domain-literal / obs-domain domain-literal = [CFWS] "[" *([FWS] dcontent) [FWS] "]" [CFWS] obs-domain = atom *("." atom)

protected _rfc822ParseDomain(string &$str) : mixed
Parameters
$str : string

The domain string.

Tags
throws
Horde_Mail_Exception
Return values
mixed

_rfc822ParseDomainLiteral()

domain-literal = [CFWS] "[" *([FWS] dcontent) [FWS] "]" [CFWS] dcontent = dtext / quoted-pair dtext = NO-WS-CTL / ; Non white space controls %d33-90 / ; The rest of the US-ASCII %d94-126 ; characters not including "[", ; "]", or "\"

protected _rfc822ParseDomainLiteral(string &$str) : mixed
Parameters
$str : string

The domain string.

Tags
throws
Horde_Mail_Exception
Return values
mixed

_rfc822ParseDotAtom()

dot-atom = [CFWS] dot-atom-text [CFWS] dot-atom-text = 1*atext *("." 1*atext)

protected _rfc822ParseDotAtom(string &$str[, string $validate = null ]) : mixed

atext = ; Any character except controls, SP, and specials.

For RFC-822 compatibility allow LWSP around '.'.

Parameters
$str : string

The atom/dot data.

$validate : string = null

Use these characters as delimiter.

Tags
throws
Horde_Mail_Exception
Return values
mixed

_rfc822ParsePhrase()

phrase = 1*word / obs-phrase word = atom / quoted-string obs-phrase = word *(word / "." / CFWS)

protected _rfc822ParsePhrase(string &$phrase) : mixed
Parameters
$phrase : string

The phrase data.

Tags
throws
Horde_Mail_Exception
Return values
mixed

_rfc822ParseQuotedString()

protected _rfc822ParseQuotedString(mixed &$str) : mixed
Parameters
$str : mixed
Tags
throws
Horde_Mail_Exception
Return values
mixed

_rfc822SkipLwsp()

protected _rfc822SkipLwsp([bool $advance = false ]) : mixed
Parameters
$advance : bool = false

Advance cursor?

Tags
throws
Horde_Mail_Exception
Return values
mixed

Search results