Source for file Rfc822Header.class.php
Documentation is available at Rfc822Header.class.php
* This file contains functions needed to handle headers in mime messages.
* @copyright © 2003-2006 The SquirrelMail Project Team
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @version $Id: Rfc822Header.class.php,v 1.55 2006/09/15 19:31:32 stevetruckstuff Exp $
* input: header_string or array
* You must call parseHeader() function after creating object in order to fill object's
* @todo FIXME: there is no constructor function and class should ignore all input args.
* Mail-Followup-To header
* Disposition notification for requesting message delivery notification (MDN)
* Delivery notification (DR)
* only needed for constructing headers in delivery class
* @param mixed $hdr string or array with message headers
/* First we replace \r\n by \n and unfold the header */
/* FIXME: unfolding header with multiple spaces "\n( +)" */
$hdr =
trim(str_replace(array("\r\n", "\n\t", "\n "),array("\n", ' ', ' '), $hdr));
/* Now we can make a new header array with */
/* each element representing a headerline */
foreach ($hdr as $line) {
$field =
substr($line, 0, $pos);
if (!strstr($field,' ')) { /* valid field */
for ($i =
0; $i <
$cnt; ++
$i) {
while ((++
$i <
$cnt) &&
($value{$i} !=
'"')) {
if ($value{$i} ==
'\\') {
while (($depth >
0) &&
(++
$i <
$cnt)) {
* Parse header field according to field type
* @param string $field field name
* @param string $value field value
$d =
strtr($value, array(' ' =>
' '));
case 'x-confirm-reading-to':
case 'disposition-notification-to':
case 'return-receipt-to':
$this->mime =
($value ==
'1.0' ?
true :
$this->mime);
case 'content-disposition':
case 'content-transfer-encoding':
case 'content-description':
$this->mlist('post', $value);
$this->mlist('reply', $value);
$this->mlist('subscribe', $value);
$this->mlist('unsubscribe', $value);
$this->mlist('archive', $value);
$this->mlist('owner', $value);
$this->mlist('help', $value);
$this->mlist('id', $value);
$aSpecials =
array('(' ,'<' ,',' ,';' ,':');
$aReplace =
array(' (',' <',' ,',' ;',' :');
$iEnd =
strpos($address,'>',$i+
1);
$sToken =
substr($address,$i);
$sToken =
substr($address,$i,$iEnd -
$i +
1);
if ($sToken) $aTokens[] =
$sToken;
$iEnd =
strpos($address,$cChar,$i+
1);
$prev_char =
$address{$iEnd-
1};
while ($prev_char ===
'\\' &&
substr($address,$iEnd-
2,2) !==
'\\\\') {
$iEnd =
strpos($address,$cChar,$iEnd+
1);
$prev_char =
$address{$iEnd-
1};
$sToken =
substr($address,$i);
// also remove the surrounding quotes
$sToken =
substr($address,$i+
1,$iEnd -
$i -
1);
if ($sToken) $aTokens[] =
$sToken;
$iEnd =
strpos($address,')',$i);
$sToken =
substr($address,$i);
while (($iDepth >
0) &&
(++
$iComment <
$iCnt)) {
$cCharComment =
$address{$iComment};
$sToken =
substr($address,$i,$iComment -
$i +
1);
$sToken =
substr($address,$i,$iEnd -
$i +
1);
// check the next token in case comments appear in the middle of email addresses
$prevToken =
end($aTokens);
if (!in_array($prevToken,$aSpecials,true)) {
if ($i+
1<
strlen($address) &&
!in_array($address{$i+
1},$aSpecials,true)) {
$iEnd =
strpos($address,' ',$i+
1);
$sNextToken =
trim(substr($address,$i+
1,$iEnd -
$i -
1));
// create token and add it again
$sNewToken =
$prevToken .
$sNextToken;
if($sNewToken) $aTokens[] =
$sNewToken;
if ($sToken) $aTokens[] =
$sToken;
$iEnd =
strpos($address,' ',$i+
1);