X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=class%2Fmime%2FRfc822Header.class.php;h=eed274fdda4ee98b02243e8c31a03a80ab5e9d28;hb=6f6ed9a7dad95211b4dae43cfc610c7004fd3050;hp=ba22d2568615bdcaeb5554ad665a498f2bee0fe2;hpb=47ccfad452e8d345542d09e59112cac317cffed8;p=squirrelmail.git diff --git a/class/mime/Rfc822Header.class.php b/class/mime/Rfc822Header.class.php index ba22d256..eed274fd 100644 --- a/class/mime/Rfc822Header.class.php +++ b/class/mime/Rfc822Header.class.php @@ -5,7 +5,7 @@ * * This file contains functions needed to handle headers in mime messages. * - * @copyright © 2003-2006 The SquirrelMail Project Team + * @copyright © 2003-2007 The SquirrelMail Project Team * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version $Id$ * @package squirrelmail @@ -29,6 +29,11 @@ class Rfc822Header { * @var mixed */ var $date = -1; + /** + * Original date header as fallback for unparsable dates + * @var mixed + */ + var $date_unparsed = ''; /** * Subject header * @var string @@ -107,9 +112,15 @@ class Rfc822Header { */ var $priority = 3; /** + * Disposition notification for requesting message delivery notification (MDN) * @var mixed */ var $dnt = ''; + /** + * Delivery notification (DR) + * @var mixed + */ + var $drnt = ''; /** * @var mixed */ @@ -126,6 +137,11 @@ class Rfc822Header { * @var mixed */ var $mlist = array(); + /** + * SpamAssassin 'x-spam-status' header + * @var mixed + */ + var $x_spam_status = array(); /** * Extra header * only needed for constructing headers in delivery class @@ -223,6 +239,7 @@ class Rfc822Header { $d = strtr($value, array(' ' => ' ')); $d = explode(' ', $d); $this->date = getTimeStamp($d); + $this->date_unparsed = strtr($value,'<>',' '); break; case 'subject': $this->subject = $value; @@ -260,11 +277,14 @@ class Rfc822Header { $this->references = $value; break; case 'x-confirm-reading-to': - case 'return-receipt-to': case 'disposition-notification-to': $value = $this->stripComments($value); $this->dnt = $this->parseAddress($value); break; + case 'return-receipt-to': + $value = $this->stripComments($value); + $this->drnt = $this->parseAddress($value); + break; case 'mime-version': $value = $this->stripComments($value); $value = str_replace(' ', '', $value); @@ -329,6 +349,9 @@ class Rfc822Header { $value = $this->stripComments($value); $this->mlist('id', $value); break; + case 'x-spam-status': + $this->x_spam_status = $this->parseSpamStatus($value); + break; default: break; } @@ -625,15 +648,16 @@ class Rfc822Header { * X-MS-Mail-Priority is not parsed because it always coincides * with one of the other headers. * - * NOTE: this is actually a duplicate from the function in - * functions/imap_messages. I'm not sure if it's ok here to call + * NOTE: this is actually a duplicate from the code in + * functions/imap_messages:parseFetch(). + * I'm not sure if it's ok here to call * that function? * @param string $sValue literal priority name * @return integer */ function parsePriority($sValue) { // don't use function call inside array_shift. - $aValue = split('/\w/',trim($sValue)); + $aValue = preg_split('/\s/',trim($sValue)); $value = strtolower(array_shift($aValue)); if ( is_numeric($value) ) { @@ -776,6 +800,53 @@ class Rfc822Header { $this->mlist[$field] = $res_a; } + /** + * Parses the X-Spam-Status header + * @param string $value + */ + function parseSpamStatus($value) { + // Header value looks like this: + // No, score=1.5 required=5.0 tests=MSGID_FROM_MTA_ID,NO_REAL_NAME,UPPERCASE_25_50 autolearn=disabled version=3.1.0-gr0 + + $spam_status = array(); + + if (preg_match ('/^(No|Yes),\s+score=(-?\d+\.\d+)\s+required=(-?\d+\.\d+)\s+tests=(.*?)\s+autolearn=(.*?)\s+version=(.+?)$/', $value, $matches)) { + // full header + $spam_status['bad_format'] = 0; + $spam_status['value'] = $matches[0]; + // is_spam + if (isset($matches[1]) + && strtolower($matches[1]) == 'yes') { + $spam_status['is_spam'] = true; + } else { + $spam_status['is_spam'] = false; + } + + // score + $spam_status['score'] = $matches[2]; + + // required + $spam_status['required'] = $matches[3]; + + // tests + $tests = array(); + $tests = explode(',', $matches[4]); + foreach ($tests as $test) { + $spam_status['tests'][] = trim($test); + } + + // autolearn + $spam_status['autolearn'] = $matches[5]; + + // version + $spam_status['version'] = $matches[6]; + } else { + $spam_status['bad_format'] = 1; + $spam_status['value'] = $value; + } + return $spam_status; + } + /** * function to get the address strings out of the header. * example1: header->getAddr_s('to'). @@ -940,5 +1011,3 @@ class Rfc822Header { return $this->content_type->properties; } } - -?>