Source for file rfc822_addresses.php
Documentation is available at rfc822_addresses.php
* {metadocument}<?xml version="1.0" encoding="ISO-8859-1" ?>
* <package>net.manuellemos.mimeparser</package>
* <copyright>Copyright © (C) Manuel Lemos 2006 - 2008</copyright>
* <title>RFC 822 e-mail addresses parser</title>
* <author>Manuel Lemos</author>
* <authoraddress>mlemos-at-acm.org</authoraddress>
* <purpose>Parse e-mail addresses from headers of <link>
* <url>http://www.ietf.org/rfc/rfc822.txt</url>
* </link> compliant e-mail messages.</purpose>
* <usage>Use the function <functionlink>ParseAddressList</functionlink>
* function to retrieve the list of e-mail addresses contained in
* e-mail message headers like <tt>From</tt>, <tt>To</tt>, <tt>Cc</tt>
* or <tt>Bcc</tt>.</usage>
<purpose>Store the message that is returned when an error
<usage>Check this variable to understand what happened when a call to
any of the class functions has failed.<paragraphbreak />
This class uses cumulative error handling. This means that if one
class functions that may fail is called and this variable was
already set to an error message due to a failure in a previous call
to the same or other function, the function will also fail and does
not do anything.<paragraphbreak />
This allows programs using this class to safely call several
functions that may fail and only check the failure condition after
the last function call.<paragraphbreak />
Just set this variable to an empty string to clear the error
<name>error_position</name>
<purpose>Point to the position of the message data or file that
refers to the last error that occurred.</purpose>
<usage>Check this variable to determine the relevant position of the
message when a parsing error occurs.</usage>
<name>ignore_syntax_errors</name>
<purpose>Specify whether the class should ignore syntax errors in
malformed addresses.</purpose>
<usage>Set this variable to <booleanvalue>0</booleanvalue> if it is
necessary to verify whether message data may be corrupted due to
to eventual bugs in the program that generated the
message.<paragraphbreak />
Currently the class only ignores some types of syntax errors.
Other syntax errors may still cause the
<functionlink>ParseAddressList</functionlink> to fail.</usage>
<purpose>Return a list of positions of the original message that
contain syntax errors.</purpose>
<usage>Check this variable to retrieve eventual message syntax
errors that were ignored when the
<variablelink>ignore_syntax_errors</variablelink> is set to
<booleanvalue>1</booleanvalue>.<paragraphbreak />
The indexes of this array are the positions of the errors. The
array values are the corresponding syntax error messages.</usage>
* dummy docblock makes error-free autodocs
* dummy docblock makes error-free autodocs
* dummy docblock makes error-free autodocs
* dummy docblock makes error-free autodocs
* dummy docblock makes error-free autodocs
Function QDecode($p, &$value, &$encoding)
$encoding = $charset = null;
if(GetType($q = strpos($value, '=?', $s)) != 'integer')
$decoded .= substr($value, $s);
$decoded .= substr($value, $s, $q - $s);
if(GetType($c = strpos($value, '?', $q)) != 'integer'
if(strcmp($charset, $another_charset)
&& strcmp($another_charset, 'ascii'))
return($this->SetWarning('it is not possible to decode an encoded value using mixed character sets into a single value', $p + $q));
if(!strcmp($charset, 'ascii'))
if(GetType($t = strpos($value, '?', $c)) != 'integer'
if(GetType($e = strpos($value, '?=', $t)) != 'integer')
|| GetType($binary) != 'string')
* dummy docblock makes error-free autodocs
&& GetType(strchr("\t\r\n ()\\\0", $c = $v[$p])) != 'string'
* dummy docblock makes error-free autodocs
|| GetType(strchr("\t\r\n \"\\\0", $c = $v[$p])) == 'string')
* dummy docblock makes error-free autodocs
&& GetType(strchr("\r\n\0", $c = $v[$p + 1])) != 'string'
* dummy docblock makes error-free autodocs
* dummy docblock makes error-free autodocs
* dummy docblock makes error-free autodocs
$comment = substr($v, $p, $c - $p);
* dummy docblock makes error-free autodocs
* dummy docblock makes error-free autodocs
* dummy docblock makes error-free autodocs
if(preg_match('/^([-'. ($dot ? '.' : ''). 'A-Za-z0-9!#$&\'*+\\/=?^_{|}~]+)/', substr($this->v, $a), $m))
elseif(Ord($v[$a]) < 128)
$atom = substr($this->v, $p, $a - $p);
* dummy docblock makes error-free autodocs
for($string = '';$s < $l;)
$string .= substr($v, $w, $s - $w);
$string .= substr($v, $w, $s - $w);
$quoted_string = $string;
* dummy docblock makes error-free autodocs
* dummy docblock makes error-free autodocs
$string .= substr($v, $w, $ph - $w);
* dummy docblock makes error-free autodocs
* dummy docblock makes error-free autodocs
$local_part = trim($local_part);
$addr_spec = $local_part. '@'. $domain;
* dummy docblock makes error-free autodocs
* dummy docblock makes error-free autodocs
$address = array('address'=> $addr);
if(!$this->QDecode($p, $display_name, $encoding))
$address['name'] = trim($display_name);
$address['encoding'] = $encoding;
* dummy docblock makes error-free autodocs
if(!IsSet ($display_name))
if(!$this->QDecode($p, $display_name, $encoding))
'name' => trim($display_name)
$address['encoding'] = $encoding;
* dummy docblock makes error-free autodocs
$address = array('address'=> $addr_spec);
* dummy docblock makes error-free autodocs
$addresses = array($address);
$mailbox_group = $addresses;
* dummy docblock makes error-free autodocs
if(!IsSet ($mailbox_group))
$mailbox_group = array();
if(!$this->QDecode($p, $display_name, $encoding))
$address['encoding'] = $encoding;
* dummy docblock makes error-free autodocs
<name>ParseAddressList</name>
<purpose>Parse and extract e-mail addresses eventually from headers
of an e-mail message.</purpose>
<usage>Pass a string value with a list of e-mail addresses to the
<function>ParseAddressList</function>
<argument>value</argument>
</argumentlink>. The <argumentlink>
<function>ParseAddressList</function>
<argument>addresses</argument>
</argumentlink> returns the list of e-mail addresses found.</usage>
<returnvalue>This function returns <booleanvalue>1</booleanvalue> if
the specified value is parsed successfully. Otherwise,
check the variables <variablelink>error</variablelink> and
<variablelink>error_position</variablelink> to determine what
error occurred and the relevant value position.</returnvalue>
<purpose>String with a list of e-mail addresses to parse.</purpose>
<purpose>Return the list of parsed e-mail addresses.
Each entry in the list is an associative array.<paragraphbreak />
For normal addresses, this associative array has the entry
<stringvalue>address</stringvalue> set to the e-mail address.
If the address has an associated name, it is stored in the
entry <stringvalue>name</stringvalue>.<paragraphbreak />
For address groups, there is the entry
<stringvalue>name</stringvalue>.
The group addresses list are stored in the entry
<stringvalue>group</stringvalue> as an array. The structure of
the group addresses list array is the same as this addresses
list array argument.</purpose>
* dummy docblock makes error-free autodocs
return($this->SetPositionedError('multiple addresses must be separated by commas: ', $p));
return($this->SetPositionedError('it was not specified a valid address after comma', $p));
|