Added support for a couple of MIME Content- headers.
authorindiri69 <indiri69@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Sun, 11 Jan 2004 02:55:17 +0000 (02:55 +0000)
committerindiri69 <indiri69@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Sun, 11 Jan 2004 02:55:17 +0000 (02:55 +0000)
git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@6379 7612ce4b-ef26-0410-bec9-ea0150e637f0

class/mime/Rfc822Header.class.php

index 9a63be0..4dc03fa 100644 (file)
@@ -36,6 +36,8 @@ class Rfc822Header {
         $priority = 3,
         $dnt = '',
         $encoding = '',
+        $content_id = '',
+        $content_desc = '',
         $mlist = array(),
         $more_headers = array(); /* only needed for constructing headers
                                     in smtp.php */
@@ -169,6 +171,16 @@ class Rfc822Header {
                 $value = $this->stripComments($value);
                 $this->parseDisposition($value);
                 break;
+            case 'content-transfer-encoding':
+                $this->encoding = $value;
+                break;
+            case 'content-description':
+                $this->content_desc = $value;
+                break;
+            case 'content-id':
+                $value = $this->stripComments($value);
+                $this->content_id = $value;
+                break;
             case 'user-agent':
             case 'x-mailer':
                 $this->xmailer = $value;
@@ -181,11 +193,11 @@ class Rfc822Header {
                 $this->mlist('post', $value);
                 break;
             case 'list-reply':
-                $value = $this->stripComments($value);            
+                $value = $this->stripComments($value);
                 $this->mlist('reply', $value);
                 break;
             case 'list-subscribe':
-                $value = $this->stripComments($value);            
+                $value = $this->stripComments($value);
                 $this->mlist('subscribe', $value);
                 break;
             case 'list-unsubscribe':
@@ -235,7 +247,7 @@ class Rfc822Header {
                    $i = $iEnd;
                 }
                 $sToken = str_replace($aReplace, $aSpecials,$sToken);
-                if($sToken) $aTokens[] = $sToken;
+                if ($sToken) $aTokens[] = $sToken;
                 break;
             case '"':
                 $iEnd = strpos($address,$cChar,$i+1);
@@ -315,7 +327,7 @@ class Rfc822Header {
                     }
                 }
                 $sToken = str_replace($aReplace, $aSpecials,$sToken);
-                if($sToken) $aTokens[] = $sToken;
+                if ($sToken) $aTokens[] = $sToken;
                 break;
             case ',':
             case ':':
@@ -347,7 +359,7 @@ class Rfc822Header {
         }
         if (count($aStack)) {
             $sPersonal = trim(implode('',$aStack));
-        } else { 
+        } else {
             $sPersonal = '';
         }
         if (!$sPersonal && count($aComment)) {
@@ -375,18 +387,18 @@ class Rfc822Header {
     }
 
     /*
-     * parseAddress: recursive function for parsing address strings and store 
+     * parseAddress: recursive function for parsing address strings and store
      *               them in an address stucture object.
      *               input: $address = string
      *                      $ar      = boolean (return array instead of only the
      *                                 first element)
      *                      $addr_ar = array with parsed addresses // obsolete
      *                      $group   = string // obsolete
-     *                      $host    = string (default domainname in case of 
+     *                      $host    = string (default domainname in case of
      *                                 addresses without a domainname)
      *                      $lookup  = callback function (for lookup address
      *                                 strings which are probably nicks
-     *                                 (without @ ) ) 
+     *                                 (without @ ) )
      *               output: array with addressstructure objects or only one
      *                       address_structure object.
      *  personal name: encoded: =?charset?Q|B?string?=
@@ -409,7 +421,7 @@ class Rfc822Header {
             case '=':
             case '"':
             case ' ':
-                $aStack[] = $sToken; 
+                $aStack[] = $sToken;
                 break;
             case '(':
                 $aComment[] = substr($sToken,1,-1);
@@ -420,7 +432,7 @@ class Rfc822Header {
                     $oAddr = end($aAddress);
                     if(!$oAddr || ((isset($oAddr)) && !$oAddr->mailbox && !$oAddr->personal)) {
                         $sEmail = $sGroup . ':;';
-                    } 
+                    }
                     $aAddress[] = $this->createAddressObject($aStack,$aComment,$sEmail,$sGroup);
                     $sGroup = '';
                     $aStack = $aComment = array();
@@ -429,7 +441,7 @@ class Rfc822Header {
             case ',':
                 $aAddress[] = $this->createAddressObject($aStack,$aComment,$sEmail,$sGroup);
                 break;
-            case ':': 
+            case ':':
                 $sGroup = trim(implode(' ',$aStack));
                 $sGroup = preg_replace('/\s+/',' ',$sGroup);
                 $aStack = array();
@@ -439,7 +451,7 @@ class Rfc822Header {
                break;
             case '>':
                /* skip */
-               break; 
+               break;
             default: $aStack[] = $sToken; break;
             }
         }
@@ -478,20 +490,20 @@ class Rfc822Header {
                 if ($sHost && $oAddr->mailbox) {
                     $oAddr->host = $sHost;
                 }
-           }
+            }
           }
           if (!$aAddrBookAddress && $oAddr->mailbox) {
               $aProcessedAddress[] = $oAddr;
           } else {
-              $aProcessedAddress = array_merge($aProcessedAddress,$aAddrBookAddress); 
+              $aProcessedAddress = array_merge($aProcessedAddress,$aAddrBookAddress);
           }
         }
-        if ($ar) { 
+        if ($ar) {
             return $aProcessedAddress;
         } else {
             return $aProcessedAddress[0];
         }
-    } 
+    }
 
     function parseContentType($value) {
         $pos = strpos($value, ';');
@@ -512,37 +524,39 @@ class Rfc822Header {
         }
         $this->content_type = $content_type;
     }
-    
+
     /* RFC2184 */
-    function processParameters($aParameters) { 
+    function processParameters($aParameters) {
         $aResults = array();
-       $aCharset = array();
-       // handle multiline parameters
+        $aCharset = array();
+        // handle multiline parameters
         foreach($aParameters as $key => $value) {
-           if ($iPos = strpos($key,'*')) {
-               $sKey = substr($key,0,$iPos);
-               if (!isset($aResults[$sKey])) {
-                   $aResults[$sKey] = $value;
-                   if (substr($key,-1) == '*') { // parameter contains language/charset info
-                       $aCharset[] = $sKey;
-                   }
-               } else {
-                   $aResults[$sKey] .= $value;
-               }
-           }
+            if ($iPos = strpos($key,'*')) {
+                $sKey = substr($key,0,$iPos);
+                if (!isset($aResults[$sKey])) {
+                    $aResults[$sKey] = $value;
+                    if (substr($key,-1) == '*') { // parameter contains language/charset info
+                        $aCharset[] = $sKey;
+                    }
+                } else {
+                    $aResults[$sKey] .= $value;
+                }
+            } else {
+                $aResults[$key] = $value;
+            }
+        }
+        foreach ($aCharset as $key) {
+            $value = $aResults[$key];
+            // extract the charset & language
+            $charset = substr($value,0,strpos($value,"'"));
+            $value = substr($value,strlen($charset)+1);
+            $language = substr($value,0,strpos($value,"'"));
+            $value = substr($value,strlen($charset)+1);
+            // FIX ME What's the status of charset decode with language information ????
+            $value = charset_decode($charset,$value);
+            $aResults[$key] = $value;
         }
-       foreach ($aCharset as $key) {
-           $value = $aResults[$key];
-           // extract the charset & language
-           $charset = substr($value,0,strpos($value,"'"));
-           $value = substr($value,strlen($charset)+1);
-           $language = substr($value,0,strpos($value,"'"));
-           $value = substr($value,strlen($charset)+1);
-           // FIX ME What's the status of charset decode with language information ????
-           $value = charset_decode($charset,$value);
-           $aResults[$key] = $value;
-       }
-       return $aResults;    
+        return $aResults;
     }
 
     function parseProperties($value) {
@@ -671,7 +685,7 @@ class Rfc822Header {
         }
         return $arr;
     }
-    
+
     function findAddress($address, $recurs = false) {
         $result = false;
         if (is_array($address)) {
@@ -686,7 +700,7 @@ class Rfc822Header {
                         $result = $i;
                     }
                 }
-                ++$i;        
+                ++$i;
             }
         } else {
             if (!is_array($this->cc)) $this->cc = array();
@@ -726,7 +740,7 @@ class Rfc822Header {
                 return true;
             } else {
                 return false;
-            }        
+            }
         }
         //exit;
         return $result;