/**
* Rfc822Header.class.php
*
- * Copyright (c) 2003-2004 The SquirrelMail Project Team
+ * Copyright (c) 2003-2005 The SquirrelMail Project Team
* Licensed under the GNU GPL. For full terms see the file COPYING.
*
* This contains functions needed to handle mime messages.
*
- * $Id$
+ * @version $Id$
* @package squirrelmail
*/
* @package squirrelmail
*/
class Rfc822Header {
- var $date = '',
+ var $date = -1,
$subject = '',
$from = array(),
$sender = '',
if (is_array($hdr)) {
$hdr = implode('', $hdr);
}
- /* First we unfold the header */
- $hdr = trim(str_replace(array("\r\n\t", "\r\n "),array(' ', ' '), $hdr));
+ /* First we replace \r\n by \n and unfold the header */
+ $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 */
- $hdr = explode("\r\n" , $hdr);
+ $hdr = explode("\n" , $hdr);
foreach ($hdr as $line) {
$pos = strpos($line, ':');
if ($pos > 0) {
$this->xmailer = $value;
break;
case 'x-priority':
- $this->priority = $value;
+ case 'importance':
+ case 'priority':
+ $this->priority = $this->parsePriority($value);
break;
case 'list-post':
$value = $this->stripComments($value);
function getAddressTokens($address) {
$aTokens = array();
- $aAddress = array();
$aSpecials = array('(' ,'<' ,',' ,';' ,':');
$aReplace = array(' (',' <',' ,',' ;',' :');
$address = str_replace($aSpecials,$aReplace,$address);
function parseAddress($address,$ar=false,$aAddress=array(),$sGroup='',$sHost='',$lookup=false) {
$aTokens = $this->getAddressTokens($address);
- $sPersonal = $sEmail = $sComment = $sGroup = '';
+ $sPersonal = $sEmail = $sGroup = '';
$aStack = $aComment = array();
foreach ($aTokens as $sToken) {
$cChar = $sToken{0};
}
}
+ /**
+ * Normalise the different Priority headers into a uniform value,
+ * namely that of the X-Priority header (1, 3, 5). Supports:
+ * Prioirty, X-Priority, Importance.
+ * 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
+ * that function?
+ */
+ function parsePriority($value) {
+ $value = strtolower(array_shift(split('/\w/',trim($value))));
+ if ( is_numeric($value) ) {
+ return $value;
+ }
+ if ( $value == 'urgent' || $value == 'high' ) {
+ return 1;
+ } elseif ( $value == 'non-urgent' || $value == 'low' ) {
+ return 5;
+ }
+ // default is normal priority
+ return 3;
+ }
+
function parseContentType($value) {
$pos = strpos($value, ';');
$props = '';
if ($pos > 0) {
$key = trim(substr($prop, 0, $pos));
$val = trim(substr($prop, $pos+1));
- if ($val{0} == '"') {
+ if (strlen($val) > 0 && $val{0} == '"') {
$val = substr($val, 1, -1);
}
$propResultArray[$key] = $val;
if (is_array($arr)) {
foreach($arr as $arg) {
if ($this->getAddr_s($arg, $separator, $encoded)) {
- $s .= $separator . $result;
+ $s .= $separator;
}
}
$s = ($s ? substr($s, 2) : $s);
$i=0;
foreach($address as $argument) {
$match = $this->findAddress($argument, true);
- $last = end($match);
if ($match[1]) {
return $i;
} else {
}
}
-?>
+?>
\ No newline at end of file