remove unnessecarry \r\n
authorstekkel <stekkel@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Thu, 5 Sep 2002 12:48:44 +0000 (12:48 +0000)
committerstekkel <stekkel@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Thu, 5 Sep 2002 12:48:44 +0000 (12:48 +0000)
git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@3565 7612ce4b-ef26-0410-bec9-ea0150e637f0

class/deliver/Deliver.class.php

index 403506c6d2aa0f6ab6d13bd9f14913f9789ea71c..2dfb2c71880d8b1d57fcabb4c9d3df879695f964 100644 (file)
@@ -56,7 +56,7 @@ class Deliver {
            if ($i == $entCount-1) $last = true;
        }
         if ($boundary && $last) {
-           $s = "\r\n--".$boundary."--\r\n\r\n";
+           $s = "--".$boundary."--\r\n\r\n";
            $length_raw += strlen($s);
            if ($stream) {
                 $this->preWriteToStream($s);
@@ -71,6 +71,8 @@ class Deliver {
        } else {
           $type0 = $message->rfc822_header->content_type->type0;
        }
+       
+       $body_part_trailing = $last = '';
        switch ($type0) {
        case 'text':
        case 'message':
@@ -81,15 +83,17 @@ class Deliver {
                   $this->preWriteToStream($body_part);     
                  $this->writeToStream($stream, $body_part);
               }
+              $last = $body_part;
            } elseif ($message->att_local_name) {
                $filename = $message->att_local_name;
                $file = fopen ($filename, 'rb');
-               while ($tmp = fgets($file, 4096)) {
-                  $length += $this->clean_crlf($tmp);
+               while ($body_part = fgets($file, 4096)) {
+                  $length += $this->clean_crlf($body_part);
                   if ($stream) {
-                     $this->preWriteToStream($tmp);
-                     $this->writeToStream($stream, $tmp);
+                     $this->preWriteToStream($body_part);
+                     $this->writeToStream($stream, $body_part);
                    }
+                  $last = $body_part;
                }
                fclose($file);
             }
@@ -104,22 +108,28 @@ class Deliver {
            } elseif ($message->att_local_name) {
                $filename = $message->att_local_name;
                $file = fopen ($filename, 'rb');
+               $encoded = '';
                while ($tmp = fread($file, 570)) {
-                  $encoded = chunk_split(base64_encode($tmp));
-                  
+                  $body_part = chunk_split(base64_encode($tmp));
+                  $length += $this->clean_crlf($body_part);
                   if ($stream) {
-                     $this->writeToStream($stream, $encoded);
+                     $this->writeToStream($stream, $body_part);
                   }
                }
                fclose($file);
            }
            break;
        }
-       $body_part_trailing = "\r\n";
-       $length += strlen($body_part_trailing);
-       if ($stream) {
-           $this->preWriteToStream($body_part_trailing);     
-          $this->writeToStream($stream, $body_part_trailing);
+       $body_part_trailing = '';
+       if ($last && substr($last,-1) != "\n") {
+          $body_part_trailing = "\r\n";
+       }
+       if ($body_part_trailing) {
+           $length += strlen($body_part_trailing);
+           if ($stream) {
+               $this->preWriteToStream($body_part_trailing);     
+               $this->writeToStream($stream, $body_part_trailing);
+           }
        }
     }