* I really didn't like the old attachment code
[squirrelmail.git] / functions / smtp.php
index 9d7bce9e12f3944163e47a008dd1e4ae3ed66ed0..0c66f44e96779aecea0d956e03ef2925b49ed5d9 100644 (file)
       $length = 0;
 
       if (isMultipart()) {
-         reset($attachments);
-         while (list($localname, $remotename) = each($attachments)) {
-            // This is to make sure noone is giving a filename in another
-            // directory
-            $localname = ereg_replace ("\\/", '', $localname);
-            
-            $fileinfo = fopen ($attachment_dir.$localname.'.info', 'r');
-            $filetype = fgets ($fileinfo, 8192);
-            fclose ($fileinfo);
-            $filetype = trim ($filetype);
-            if ($filetype=='')
+         foreach ($attachments as $info)
+        {
+           $filetype = $info['type'];
+            if ($filetype == '')
                $filetype = 'application/octet-stream';
             
             $header = '--'.mimeBoundary()."\r\n";
-            $header .= "Content-Type: $filetype;name=\"$remotename\"\r\n";
-            $header .= "Content-Disposition: attachment; filename=\"$remotename\"\r\n";
+            $header .= "Content-Type: $filetype; name=\"" .
+               $info['remotefilename'] . "\"\r\n";
+            $header .= "Content-Disposition: attachment; filename=\"" .
+               $info['remotefilename'] . "\"\r\n";
             $header .= "Content-Transfer-Encoding: base64\r\n\r\n";
             fputs ($fp, $header);
             $length += strlen($header);
             
-            $file = fopen ($attachment_dir.$localname, 'r');
+            $file = fopen ($attachment_dir . $info['localfilename'], 'r');
             while ($tmp = fread($file, 570)) {
                $encoded = chunk_split(base64_encode($tmp));
                $length += strlen($encoded);
       static $mimeBoundaryString;
 
       if ($mimeBoundaryString == "") {
-         $mimeBoundaryString = "----=" . 
+         $mimeBoundaryString = "----=_" . 
             GenerateRandomString(60, '\'()+,-./:=?_', 7);
       }
 
       errorCheck($tmp, $smtpConnection);
 
       /** Ok, who is sending the message? */
-      fputs($smtpConnection, "MAIL FROM:<$from_addr>\r\n");
+      fputs($smtpConnection, "MAIL FROM: <$from_addr>\r\n");
       $tmp = fgets($smtpConnection, 1024);
       errorCheck($tmp, $smtpConnection);
 
          errorCheck($tmp, $smtpConnection);
       }
       for ($i = 0; $i < count($cc); $i++) {
-         fputs($smtpConnection, "RCPT TO:<$cc[$i]>\r\n");
+         fputs($smtpConnection, "RCPT TO: $cc[$i]\r\n");
          $tmp = fgets($smtpConnection, 1024);
          errorCheck($tmp, $smtpConnection);
       }
       for ($i = 0; $i < count($bcc); $i++) {
-         fputs($smtpConnection, "RCPT TO:<$bcc[$i]>\r\n");
+         fputs($smtpConnection, "RCPT TO: $bcc[$i]\r\n");
          $tmp = fgets($smtpConnection, 1024);
          errorCheck($tmp, $smtpConnection);
       }
       }
       sqimap_logout($imap_stream);
       // Delete the files uploaded for attaching (if any).
-      deleteAttachments();
+      ClearAttachments();
    }
 
 ?>