소스 검색

Make message ID available after message is sent. Not the best solution, but it's smallish and SM design doesn't suit very well

pdontthink 17 년 전
부모
커밋
9880c85539
2개의 변경된 파일24개의 추가작업 그리고 7개의 파일을 삭제
  1. 16 3
      class/deliver/Deliver.class.php
  2. 8 4
      src/compose.php

+ 16 - 3
class/deliver/Deliver.class.php

@@ -28,6 +28,13 @@
  */
 class Deliver {
 
+    /**
+     * Most recently calculated Message-ID
+     * External code should NEVER access this directly!
+     * @var string
+     */
+    var $message_id;
+
     /**
      * function mail - send the message parts to the SMTP stream
      *
@@ -52,8 +59,12 @@ class Deliver {
      *                               an overloaded version of this method
      *                               if needed.
      *
-     * @return integer $raw_length The number of bytes written (or that would 
-     *                             have been written) to the output stream
+     * @return array An array containing at least these elements in this order:
+     *                  - The number of bytes written (or that would have been
+     *                    written) to the output stream
+     *                  - The message ID (WARNING: if $stream is FALSE, this
+     *                    may not be supplied, or may not be accurate)
+     *
      */
     function mail($message, $stream=false, $reply_id=0, $reply_ent_id=0,
                   $extra=NULL) {
@@ -104,7 +115,7 @@ class Deliver {
 
         $this->send_mail($message, $header, $boundary, $stream, $raw_length, $extra);
 
-        return $raw_length;
+        return array($raw_length, $this->message_id);
     }
 
     /**
@@ -505,6 +516,8 @@ class Deliver {
             $message_id.= $REMOTE_ADDR;
         }
         $message_id .= '.' . time() . '.squirrel@' . $SERVER_NAME .'>';
+        $this->message_id = $message_id;
+
         /* Make an RFC822 Received: line */
         if (isset($REMOTE_HOST)) {
             $received_from = "$REMOTE_HOST ([$REMOTE_ADDR])";

+ 8 - 4
src/compose.php

@@ -1469,10 +1469,14 @@ function getByteSize($ini_size) {
  * In the future the responsible backend should be automaticly loaded
  * and conf.pl should show a list of available backends.
  * The message also should be constructed by the message class.
+ *
+ * @return boolean FALSE if delivery failed, or some non-FALSE value
+ *                 upon success.
+ *
  */
 function deliverMessage($composeMessage, $draft=false) {
     global $send_to, $send_to_cc, $send_to_bcc, $mailprio, $subject, $body,
-        $username, $identity, $idents, $data_dir,
+        $username, $identity, $idents, $data_dir, $message_id,
         $request_mdn, $request_dr, $default_charset, $useSendmail,
         $domain, $action, $default_move_to_sent, $move_to_sent,
         $imapServerAddress, $imapPort, $sent_folder, $key;
@@ -1596,11 +1600,11 @@ function deliverMessage($composeMessage, $draft=false) {
         if (sqimap_mailbox_exists ($imap_stream, $draft_folder)) {
             require_once(SM_PATH . 'class/deliver/Deliver_IMAP.class.php');
             $imap_deliver = new Deliver_IMAP();
-            $length = $imap_deliver->mail($composeMessage, $imap_stream, $reply_id, $reply_ent_id, $draft_folder);
+            list($success, $ignore) = $imap_deliver->mail($composeMessage, $imap_stream, $reply_id, $reply_ent_id, $draft_folder);
             sqimap_logout($imap_stream);
             unset ($imap_deliver);
             $composeMessage->purgeAttachments();
-            return $length;
+            return $success;
         } else {
             $msg  = '<br />'.sprintf(_("Error: Draft folder %s does not exist."), htmlspecialchars($draft_folder));
             plain_error_message($msg);
@@ -1609,7 +1613,7 @@ function deliverMessage($composeMessage, $draft=false) {
     }
     $success = false;
     if ($stream) {
-        $length = $deliver->mail($composeMessage, $stream, $reply_id, $reply_ent_id);
+        list($ignore, $message_id) = $deliver->mail($composeMessage, $stream, $reply_id, $reply_ent_id);
         $success = $deliver->finalizeStream($stream);
     }
     if (!$success) {