greatly improved smtp error handling (doesn't trash messages if an error occurs)
authorlkehresman <lkehresman@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Sun, 22 Apr 2001 04:59:05 +0000 (04:59 +0000)
committerlkehresman <lkehresman@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Sun, 22 Apr 2001 04:59:05 +0000 (04:59 +0000)
git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@1284 7612ce4b-ef26-0410-bec9-ea0150e637f0

ChangeLog
functions/mime.php
functions/smtp.php
src/compose.php

index c98bd5a..4f8cd0b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,6 @@
 Version 1.1.0 -- DEVELOPMENT
 ----------------------------
+- Much improved SMTP error handling (patch by Jeff Evans)
 - Preferences are now cached instead of read in every page load.
 - Improved URL parser
 - Added ability to read HTML messages by default instead of plain text (Display Options)
index daae91b..b700ace 100644 (file)
          if (isset($message->entities[0])) {
             $body .= formatAttachments ($message, $ent_num, $message->header->mailbox, $id);
          }
+            $body .= "</TD></TR></TABLE>";
       } else {
          $body = formatAttachments ($message, -1, $message->header->mailbox, $id);
       }
index 3b9e657..b033490 100644 (file)
          exit;
       }
       $tmp = fgets($smtpConnection, 1024);
-      errorCheck($tmp, $smtpConnection);
+      if (errorCheck($tmp, $smtpConnection)!=5) return(0);
 
       $to_list = getLineOfAddrs($to);
       $cc_list = getLineOfAddrs($cc);
       if (! isset ($use_authenticated_smtp) || $use_authenticated_smtp == false) {
          fputs($smtpConnection, "HELO $domain\r\n");
          $tmp = fgets($smtpConnection, 1024);
-         errorCheck($tmp, $smtpConnection);
+      if (errorCheck($tmp, $smtpConnection)!=5) return(0);
       } else {
          fputs($smtpConnection, "EHLO $domain\r\n");
          $tmp = fgets($smtpConnection, 1024);
-         errorCheck($tmp, $smtpConnection);
+         if (errorCheck($tmp, $smtpConnection)!=5) return(0);
 
          fputs($smtpConnection, "AUTH LOGIN\r\n");
          $tmp = fgets($smtpConnection, 1024);
-         errorCheck($tmp, $smtpConnection);
+         if (errorCheck($tmp, $smtpConnection)!=5) return(0);
 
          fputs($smtpConnection, base64_encode ($username) . "\r\n");
          $tmp = fgets($smtpConnection, 1024);
-         errorCheck($tmp, $smtpConnection);
+         if (errorCheck($tmp, $smtpConnection)!=5) return(0);
 
          fputs($smtpConnection, base64_encode ($OneTimePadDecrypt($key, $onetimepad)) . "\r\n");
          $tmp = fgets($smtpConnection, 1024);
-         errorCheck($tmp, $smtpConnection);
+         if (errorCheck($tmp, $smtpConnection)!=5) return(0);
       }
 
       /** Ok, who is sending the message? */
       fputs($smtpConnection, "MAIL FROM: <$from_addr>\r\n");
       $tmp = fgets($smtpConnection, 1024);
-      errorCheck($tmp, $smtpConnection);
+      if (errorCheck($tmp, $smtpConnection)!=5) return(0);
 
       /** send who the recipients are */
       for ($i = 0; $i < count($to); $i++) {
          fputs($smtpConnection, "RCPT TO: $to[$i]\r\n");
          $tmp = fgets($smtpConnection, 1024);
-         errorCheck($tmp, $smtpConnection);
+         if (errorCheck($tmp, $smtpConnection)!=5) return(0);
       }
       for ($i = 0; $i < count($cc); $i++) {
          fputs($smtpConnection, "RCPT TO: $cc[$i]\r\n");
          $tmp = fgets($smtpConnection, 1024);
-         errorCheck($tmp, $smtpConnection);
+         if (errorCheck($tmp, $smtpConnection)!=5) return(0);
       }
       for ($i = 0; $i < count($bcc); $i++) {
          fputs($smtpConnection, "RCPT TO: $bcc[$i]\r\n");
          $tmp = fgets($smtpConnection, 1024);
-         errorCheck($tmp, $smtpConnection);
+         if (errorCheck($tmp, $smtpConnection)!=5) return(0);
       }
 
       /** Lets start sending the actual message */
       fputs($smtpConnection, "DATA\r\n");
       $tmp = fgets($smtpConnection, 1024);
-      errorCheck($tmp, $smtpConnection);
+      if (errorCheck($tmp, $smtpConnection)!=5) return(0);
 
       // Send the message
       $headerlength = write822Header ($smtpConnection, $t, $c, $b, $subject, $more_headers);
 
       fputs($smtpConnection, ".\r\n"); // end the DATA part
       $tmp = fgets($smtpConnection, 1024);
-      $num = errorCheck($tmp, $smtpConnection);
+      $num = errorCheck($tmp, $smtpConnection, verbose);
       if ($num != 250) {
-        $tmp = nl2br(htmlspecialchars($tmp));
-         echo "ERROR<BR>Message not sent!<BR>Reason given: $tmp<BR></BODY></HTML>";
+         $tmp = nl2br(htmlspecialchars($tmp));
+         displayPageHeader($color, 'None');
+         include ("../functions/display_messages.php");
+         $lines = nl2br(htmlspecialchars($lines));
+         $msg  = "Message not sent!<br>\nReason given: $tmp";
+         plain_error_message($msg, $color);
+         return(0);
       }
 
       fputs($smtpConnection, "QUIT\r\n"); // log off
                      $status = 0;
                      break;
 
-         case 235:   return; break;
+         case 235:   return(5); break;
          case 250:   $message = 'Requested mail action okay, completed';
                      $status = 5;
                      break;
          case 251:   $message = 'User not local; will forward';
                      $status = 5;
                      break;
-         case 334:   return; break;
+         case 334:   return(5); break;
          case 450:   $message = 'Requested mail action not taken:  mailbox unavailable';
                      $status = 0;
                      break;
 
       if ($status == 0) {
          displayPageHeader($color, 'None');
-         echo '<TT>';
-         echo "<br><b><font color=\"$color[1]\">ERROR</font></b><br><br>";
-         echo "&nbsp;&nbsp;&nbsp;<B>Error Number: </B>$err_num<BR>";
-         echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<B>Reason: </B>$message<BR>";
+                include ("../functions/display_messages.php");
          $lines = nl2br(htmlspecialchars($lines));
-         echo "<B>Server Response: </B>$lines<BR>";
-         echo '<BR>MAIL NOT SENT';
-         echo '</TT></BODY></HTML>';
-         exit;
+                $msg  = $message . "<br>\nServer replied: $lines";
+                plain_error_message($msg, $color);
       }
+      if ($verbose == "") return $status;
       return $err_num;
    }
 
index eb6dbcf..1389e1f 100644 (file)
          // Set $default_charset to correspond with the user's selection
         // of language interface.
         set_my_charset();
-        sendMessage($send_to, $send_to_cc, $send_to_bcc, $subject, $body, $reply_id);
-         header ("Location: right_main.php?mailbox=$urlMailbox&sort=$sort&startMessage=1");
+         if (sendMessage($send_to, $send_to_cc, $send_to_bcc, $subject, $body, $reply_id) == 0) {showInputForm(); exit();}
+//         header ("Location: right_main.php?mailbox=$urlMailbox&sort=$sort&startMessage=1");
       } else {
          //$imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
          displayPageHeader($color, $mailbox);