Workaround for Courier when sending mixed messages with nested multipart/alternative...
[squirrelmail.git] / class / deliver / Deliver.class.php
index 136a8b60e5561ebb0b5a416dbef2260906b44cda..b05f20cfe89c9ac316ce035cdeba36d110237342 100644 (file)
@@ -76,8 +76,17 @@ class Deliver {
         if ($boundary && $message->entity_id && count($message->entities)) {
             if (strpos($boundary,'_part_')) {
                 $boundary = substr($boundary,0,strpos($boundary,'_part_'));
+
+            // the next four lines use strrev to reverse any nested boundaries 
+            // as a workaround for Courier-IMAP, which will stop parsing 
+            // when it sees the original outer boundary string and ignore
+            // our "_part_..." addition to that string.  a bug report has been
+            // made, but in the meantime...
+            //
+            } else if (strpos($boundary,'_trap_')) {
+                $boundary = substr(strrev($boundary),0,strpos(strrev($boundary),'_part_'));
             }
-            $boundary_new = $boundary . '_part_'.$message->entity_id;
+            $boundary_new = strrev($boundary . '_part_'.$message->entity_id);
         } else {
             $boundary_new = $boundary;
         }
@@ -133,6 +142,8 @@ class Deliver {
         case 'message':
             if ($message->body_part) {
                 $body_part = $message->body_part;
+                // remove NUL characters
+                $body_part = str_replace("\0",'',$body_part);
                 $length += $this->clean_crlf($body_part);
                 if ($stream) {
                     $this->preWriteToStream($body_part);
@@ -290,7 +301,7 @@ class Deliver {
         $contenttype = 'Content-Type: '. $mime_header->type0 .'/'.
                         $mime_header->type1;
         if (count($message->entities)) {
-            $contenttype .= ";\r\n " . 'boundary="'.$boundary.'"';
+            $contenttype .= ';' . 'boundary="'.$boundary.'"';
         }
         if (isset($mime_header->parameters['name'])) {
             $contenttype .= '; name="'.
@@ -467,9 +478,6 @@ class Deliver {
             case 1:
                 $header[] = 'X-Priority: 1 (Highest)'.$rn;
                 $header[] = 'Importance: High'. $rn; break;
-            case 3:
-                $header[] = 'X-Priority: 3 (Normal)'.$rn;
-                $header[] = 'Importance: Normal'. $rn; break;
             case 5:
                 $header[] = 'X-Priority: 5 (Lowest)'.$rn;
                 $header[] = 'Importance: Low'. $rn; break;