Insert In-Reply-To and References headers when replying to a message.
authorpallo <pallo@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Tue, 4 Jul 2000 15:26:08 +0000 (15:26 +0000)
committerpallo <pallo@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Tue, 4 Jul 2000 15:26:08 +0000 (15:26 +0000)
git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@585 7612ce4b-ef26-0410-bec9-ea0150e637f0

functions/imap_messages.php
functions/mime.php
functions/smtp.php

index 28af70265ef2ba9488da2824c65b05be95fad333..dda230f547be998ade6a7247cd050ac19f9ea617 100755 (executable)
    /******************************************************************************
     **  Returns some general header information -- FROM, DATE, and SUBJECT
     ******************************************************************************/
-       class small_header {
-               var $from, $subject, $date, $to, $priority;
-       }
+   class small_header {
+      var $from, $subject, $date, $to, $priority, $message_id;
+   }
         
    function sqimap_get_small_header ($imap_stream, $id, $sent) {
-      fputs ($imap_stream, "a001 FETCH $id BODY.PEEK[HEADER.FIELDS (Date To From Subject X-Priority)]\r\n");
+      fputs ($imap_stream, "a001 FETCH $id BODY.PEEK[HEADER.FIELDS (Date To From Subject Message-Id X-Priority)]\r\n");
       $read = sqimap_read_data ($imap_stream, "a001", true, $response, $message);
 
       $subject = _("(no subject)");
       $from = _("Unknown Sender");
       $priority = "0";
-               $g = 0;
+      $messageid = "<>";
+
+      $g = 0;
       for ($i = 0; $i < count($read); $i++) {
          if (eregi ("^to:", $read[$i])) {
             $to = sqimap_find_displayable_name(substr($read[$i], 3));
-                       }       
+        }      
          if (eregi ("^from:", $read[$i])) {
             $from = sqimap_find_displayable_name(substr($read[$i], 5));
-                       }       
+        }      
          if (eregi ("^x-priority:", $read[$i])) {
             $priority = trim(substr($read[$i], 11));
          }
+         if (eregi ("^message-id:", $read[$i])) {
+            $messageid = trim(substr($read[$i], 11));
+         }
          if (eregi ("^date:", $read[$i])) {
             $date = substr($read[$i], 5);
          } else if (eregi ("^subject:", $read[$i])) {
             if (trim($subject) == "")
                $subject = _("(no subject)");
          }
-               }       
+      }
 
-               $header = new small_header;
+      $header = new small_header;
       if ($sent == true)
          $header->from = $to;
       else   
-                  $header->from = $from;
-               $header->date = $date;
-               $header->subject = $subject;
+        $header->from = $from;
+
+      $header->date = $date;
+      $header->subject = $subject;
       $header->to = $to;
       $header->priority = $priority;
-               return $header;
+      $header->message_id = $messageid;
+
+      return $header;
    }
 
    /******************************************************************************
index cd647bc73337436671c13c9b024ce92e33d7c682..25406a60ce41d86846df0be6ed3199158ee317be 100644 (file)
@@ -26,7 +26,7 @@
       var $type0, $type1, $boundary, $charset, $encoding;
       var $to, $from, $date, $cc, $bcc, $reply_to, $subject;
       var $id, $mailbox, $description;
-      var $entity_id;
+      var $entity_id, $message_id;
    }
    
    class message {
index a002d65834e8f26b095433bf801984ed2573cbcd..498bc0c5f201f966021b54a67e37ffc2b8d83e1d 100644 (file)
    }
 
    /* Print all the needed RFC822 headers */
-   function write822Header ($fp, $t, $c, $b, $subject) {
+   function write822Header ($fp, $t, $c, $b, $subject, $more_headers) {
       global $REMOTE_ADDR, $SERVER_NAME, $REMOTE_PORT;
       global $data_dir, $username, $domain, $version, $useSendmail;
       global $default_charset;
          $header .= "Subject: $subject\r\n";
          $header .= "From: $from\r\n";
          $header .= "To: $to_list \r\n";    // Who it's TO
-         
+
+        /* Insert headers from the $more_headers array */
+        if(is_array($more_headers)) {
+           reset($more_headers);
+           while(list($h_name, $h_val) = each($more_headers)) {
+              $header .= sprintf("%s: %s\r\n", $h_name, $h_val);
+           }
+        }
+
          if ($cc_list) {
             $header .= "Cc: $cc_list\r\n"; // Who the CCs are
          }
    }
 
    // Send mail using the sendmail command
-   function sendSendmail($t, $c, $b, $subject, $body) {
+   function sendSendmail($t, $c, $b, $subject, $body, $more_headers) {
       global $sendmail_path, $username, $domain;
 
       // open pipe to sendmail
       $fp = popen (escapeshellcmd("$sendmail_path -t -f$username@$domain"), "w");
       
-      $headerlength = write822Header ($fp, $t, $c, $b, $subject);
+      $headerlength = write822Header ($fp, $t, $c, $b, $subject, $more_headers);
       $bodylength = writeBody($fp, $body);
 
       pclose($fp);
       }
    }
 
-   function sendSMTP($t, $c, $b, $subject, $body) {
+   function sendSMTP($t, $c, $b, $subject, $body, $more_headers) {
       global $username, $domain, $version, $smtpServerAddress, $smtpPort,
          $data_dir, $color;
 
       errorCheck($tmp);
 
       // Send the message
-      $headerlength = write822Header ($smtpConnection, $t, $c, $b, $subject);
+      $headerlength = write822Header ($smtpConnection, $t, $c, $b, $subject, $more_headers);
       $bodylength = writeBody($smtpConnection, $body);
 
       fputs($smtpConnection, ".\r\n"); // end the DATA part
    function sendMessage($t, $c, $b, $subject, $body, $reply_id) {
       global $useSendmail, $msg_id, $is_reply, $mailbox;
       global $data_dir, $username, $domain, $key, $version, $sent_folder, $imapServerAddress, $imapPort;
+      $more_headers = Array();
 
       $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 1);
+
       if ($reply_id) {
          sqimap_mailbox_select ($imap_stream, $mailbox);
          sqimap_messages_flag ($imap_stream, $reply_id, $reply_id, "Answered");
+
+        // Insert In-Reply-To and References headers if the 
+        // message-id of the message we reply to is set (longer than "<>")
+        // The References header should really be the old Referenced header
+        // with the message ID appended, but it can be only the message ID too.
+        $hdr = sqimap_get_small_header ($imap_stream, $reply_id, false);
+        if(strlen($hdr->message_id) > 2) {
+           $more_headers["In-Reply-To"] = $hdr->message_id;
+           $more_headers["References"]  = $hdr->message_id;
+        }
       }
       
       if ($useSendmail==true) {  
-         $length = sendSendmail($t, $c, $b, $subject, $body);
+         $length = sendSendmail($t, $c, $b, $subject, $body, $more_headers);
       } else {
-         $length = sendSMTP($t, $c, $b, $subject, $body);
+         $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);
+         write822Header ($imap_stream, $t, $c, $b, $subject, $more_headers);
          writeBody ($imap_stream, $body); 
          sqimap_append_done ($imap_stream);
       }