greatly improved speed and memory management of download of attachments.
[squirrelmail.git] / functions / smtp.php
index ad7a257ae29ddaf697a8c1ae68cd4f37eeb0621f..dae83a2a6f22fdf9516ebcec33721d531cd80ae9 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);
          $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);
             $more_headers["In-Reply-To"] = $hdr->message_id;
             $more_headers["References"]  = $hdr->message_id;
          }
-         sqimap_mailbox_close($imap_stream);
       }
-      
-      if ($useSendmail) {  
+
+      // In order to remove the problem of users not able to create
+         // messages with "." on a blank line, RFC821 has made provision
+         // in section 4.5.2 (Transparency).
+         $body = ereg_replace("\n\.", "\n\.\.", $body);
+         $body = ereg_replace("^\.", "\.\.", $body);
+
+      // 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();
    }
-   
+
 ?>