fixed bug with one line length text message with an attachment not displaying.
[squirrelmail.git] / functions / smtp.php
index 334edd95e769fa81df00812074a7543d8171d1b7..9f595ca09dc354979055ebc3eb07ef12dfc64dd4 100644 (file)
@@ -50,7 +50,7 @@
                $filetype = "application/octet-stream";
             
             $header = "--".mimeBoundary()."\r\n";
-            $header .= "Content-Type: $filetype\r\n";
+            $header .= "Content-Type: $filetype;name=\"$remotename\"\r\n";
             $header .= "Content-Disposition: attachment; filename=\"$remotename\"\r\n";
             $header .= "Content-Transfer-Encoding: base64\r\n\r\n";
             fputs ($fp, $header);
@@ -97,6 +97,8 @@
 
    /* Time offset for correct timezone */
    function timezone () {
+      global $invert_time;
+      
       $diff_second = date("Z");
       if ($invert_time)
           $diff_second = - $diff_second;
          $to_list = getLineOfAddrs($to);
          $cc_list = getLineOfAddrs($cc);
          $bcc_list = getLineOfAddrs($bcc);
-         
+
          /* Encoding 8-bit characters and making from line */
          $subject = sqStripSlashes(encodeHeader($subject));
          if ($from == "")
             $body .= "Content-Type: text/plain\r\n";
 
          $body .= "Content-Transfer-Encoding: 8bit\r\n\r\n";
-         $body .= sqStripSlashes($passedBody) . "\r\n";
+         $body .= sqStripSlashes($passedBody) . "\r\n\r\n";
          fputs ($fp, $body);
 
          $attachmentlength = attachFiles($fp);
          }
          sqimap_mailbox_close($imap_stream);
       }
-      
-      if ($useSendmail) {  
+
+      // this is to catch all plain \n instances and
+      // replace them with \r\n.  
+      $body = ereg_replace("\r\n", "\n", $body);
+      $body = ereg_replace("\n", "\r\n", $body);
+
+      if ($useSendmail) {
          $length = sendSendmail($t, $c, $b, $subject, $body, $more_headers);
       } else {
          $length = sendSMTP($t, $c, $b, $subject, $body, $more_headers);
       if (sqimap_mailbox_exists ($imap_stream, $sent_folder)) {
          sqimap_append ($imap_stream, $sent_folder, $length);
          write822Header ($imap_stream, $t, $c, $b, $subject, $more_headers);
-         writeBody ($imap_stream, $body); 
+         writeBody ($imap_stream, $body);
          sqimap_append_done ($imap_stream);
-      }   
-      sqimap_logout($imap_stream); 
+      }
+      sqimap_logout($imap_stream);
       // Delete the files uploaded for attaching (if any).
       deleteAttachments();
    }
-   
+
 ?>