From 2dbc2d787a7d9acf85ac8b048d6a8a6c479ab428 Mon Sep 17 00:00:00 2001
From: alecpl <alec@alec.pl>
Date: Sat, 20 Jun 2009 02:55:17 -0400
Subject: [PATCH] - typo (#1485933)

---
 program/lib/Mail/mimePart.php |   41 ++++++++++++++++++++++++-----------------
 1 files changed, 24 insertions(+), 17 deletions(-)

diff --git a/program/lib/Mail/mimePart.php b/program/lib/Mail/mimePart.php
index ab7dda3..c478c82 100644
--- a/program/lib/Mail/mimePart.php
+++ b/program/lib/Mail/mimePart.php
@@ -185,6 +185,9 @@
 	
         if (isset($contentType['type'])) {
             $headers['Content-Type'] = $contentType['type'];
+	    if (isset($contentType['charset'])) {
+                $headers['Content-Type'] .= "; charset={$contentType['charset']}";
+            }
             if (isset($contentType['name'])) {
                 $headers['Content-Type'] .= ';' . MAIL_MIMEPART_CRLF;
                 $headers['Content-Type'] .=
@@ -192,8 +195,6 @@
                         isset($contentType['charset']) ? $contentType['charset'] : 'US-ASCII', 
                         isset($contentType['language']) ? $contentType['language'] : NULL,
 			isset($params['name-encoding']) ?  $params['name-encoding'] : NULL);
-            } elseif (isset($contentType['charset'])) {
-                $headers['Content-Type'] .= "; charset=\"{$contentType['charset']}\"";
             }
         }
 
@@ -242,7 +243,6 @@
         $encoded =& $this->_encoded;
 
         if (count($this->_subparts)) {
-            srand((double)microtime()*1000000);
             $boundary = '=_' . md5(rand() . microtime());
             $this->_headers['Content-Type'] .= ';' . MAIL_MIMEPART_CRLF . "\t" . 'boundary="' . $boundary . '"';
 
@@ -397,29 +397,36 @@
      */
     function _buildHeaderParam($name, $value, $charset=NULL, $language=NULL, $paramEnc=NULL, $maxLength=78)
     {
-        // RFC 2183/2184/2822: 
+        // RFC 2045: 
 	// value needs encoding if contains non-ASCII chars or is longer than 78 chars
         if (!preg_match('#[^\x20-\x7E]#', $value)) { // ASCII
-	    $quoted = addcslashes($value, '\\"');
-	    if (strlen($name) + strlen($quoted) + 6 <= $maxLength)
-		return " {$name}=\"{$quoted}\"; ";
+	    // token
+    	    if (!preg_match('#([^\x21,\x23-\x27,\x2A,\x2B,\x2D,\x2E,\x30-\x39,\x41-\x5A,\x5E-\x7E])#', $value)) {
+		if (strlen($name) + strlen($value) + 3 <= $maxLength)
+		    return " {$name}={$value};";
+	    } else { // quoted-string
+		$quoted = addcslashes($value, '\\"');
+		if (strlen($name) + strlen($quoted) + 5 <= $maxLength)
+		    return " {$name}=\"{$quoted}\";";
+	    }
 	}
 
-	// use quoted-printable/base64 encoding (RFC2047)
+	// RFC2047: use quoted-printable/base64 encoding
 	if ($paramEnc == 'quoted-printable' || $paramEnc == 'base64')
 	    return $this->_buildRFC2047Param($name, $value, $charset, $paramEnc);
 
-        $encValue = preg_replace('#([^\x20-\x7E])#e', '"%" . strtoupper(dechex(ord("\1")))', $value);
+	// RFC2231:
+        $encValue = preg_replace('#([^\x21,\x23,\x24,\x26,\x2B,\x2D,\x2E,\x30-\x39,\x41-\x5A,\x5E-\x7E])#e',
+			'"%" . strtoupper(dechex(ord("\1")))', $value);
         $value = "$charset'$language'$encValue";
 
-        $header = " {$name}*=\"{$value}\"; ";
+        $header = " {$name}*={$value};";
         if (strlen($header) <= $maxLength) {
             return $header;
         }
 
-        $preLength = strlen(" {$name}*0*=\"");
-        $sufLength = strlen("\";");
-        $maxLength = max(16, $maxLength - $preLength - $sufLength - 2);
+        $preLength = strlen(" {$name}*0*=");
+        $maxLength = max(16, $maxLength - $preLength - 3);
         $maxLengthReg = "|(.{0,$maxLength}[^\%][^\%])|";
 
         $headers = array();
@@ -428,15 +435,15 @@
             $matches = array();
             $found = preg_match($maxLengthReg, $value, $matches);
             if ($found) {
-                $headers[] = " {$name}*{$headCount}*=\"{$matches[0]}\"";
+                $headers[] = " {$name}*{$headCount}*={$matches[0]}";
                 $value = substr($value, strlen($matches[0]));
             } else {
-                $headers[] = " {$name}*{$headCount}*=\"{$value}\"";
-                $value = "";
+                $headers[] = " {$name}*{$headCount}*={$value}";
+                $value = '';
             }
             $headCount++;
         }
-        $headers = implode(MAIL_MIMEPART_CRLF, $headers) . ';';
+        $headers = implode(';' . MAIL_MIMEPART_CRLF, $headers) . ';';
         return $headers;
     }
 

--
Gitblit v1.9.1