浏览代码

Added correct References header support per rfc2822
removed References from small_header_array and created
a get_reference_header function in imap_messages.
Also added a calculate_reference function to smtp.php
to determine correct reference header.

jmunro 23 年之前
父节点
当前提交
0f18e9fbb8
共有 2 个文件被更改,包括 57 次插入12 次删除
  1. 19 9
      functions/imap_messages.php
  2. 38 3
      functions/smtp.php

+ 19 - 9
functions/imap_messages.php

@@ -75,6 +75,21 @@ function sqimap_message_list_squisher($messages_array) {
     return $msgs_str;
 }
 
+/* returns the references header lines */
+function get_reference_header ($imap_stream, $message) {
+    $responses = array ();
+    $sid = sqimap_session_id();
+	$results = array();
+	$references = "";
+    $query = "$sid FETCH $message BODY.PEEK[HEADER.FIELDS (References)]\r\n";
+    fputs ($imap_stream, $query);
+	$responses = sqimap_read_data_list($imap_stream, $sid, true, $responses, $message);
+    if (!eregi("^\\* ([0-9]+) FETCH", $responses[0][0], $regs)) {
+	    $responses = array ();
+	}
+	return $responses;
+}
+
 function sqimap_get_small_header_list ($imap_stream, $msg_list, $issent) {
     global $squirrelmail_language, $color, $data_dir, $username;
 
@@ -95,7 +110,7 @@ function sqimap_get_small_header_list ($imap_stream, $msg_list, $issent) {
         $id2index[$msg_list[$i]] = $i;
     }
 
-    $query = "$sid FETCH $msgs_str BODY.PEEK[HEADER.FIELDS (Date To From Cc Subject Message-Id X-Priority Content-Type References In-Reply-To)]\r\n";
+    $query = "$sid FETCH $msgs_str BODY.PEEK[HEADER.FIELDS (Date To From Cc Subject Message-Id X-Priority Content-Type In-Reply-To)]\r\n";
     fputs ($imap_stream, $query);
     $readin_list = sqimap_read_data_list($imap_stream, $sid, true, $response, $message);
 
@@ -157,8 +172,7 @@ function sqimap_get_small_header_list ($imap_stream, $msg_list, $issent) {
         $date = "";
         $type[0] = "";
         $type[1] = "";
-        $ref = "";
-        $inreplyto = "";
+        $inrepto = "";
         $read = $read_list[$msgi];
 
         foreach ($read as $read_part) {
@@ -188,10 +202,8 @@ function sqimap_get_small_header_list ($imap_stream, $msg_list, $issent) {
                 if (!isset($type[1])) {
                     $type[1] = '';
                 }
-            } else if (eregi ("^references:(.*)$", $read_part, $regs)) {
-                $ref = $regs[1];  
             } else if (eregi ("^in-reply-to:(.*)$", $read_part, $regs)) {
-                $inreplyto = $regs[1];
+                $inrepto = trim($regs[1]);
             }
         }
         $internaldate = getPref($data_dir, $username, 'internal_date_sort');
@@ -223,9 +235,7 @@ function sqimap_get_small_header_list ($imap_stream, $msg_list, $issent) {
         $header->size = $size;
         $header->type0 = $type[0];
         $header->type1 = $type[1];
-        $header->references = $ref;
-        $header->inreplyto = $inreplyto;
-
+		$header->inrepto = $inrepto;
         $result[] = $header;
     }
     return $result;

+ 38 - 3
functions/smtp.php

@@ -680,6 +680,37 @@ function errorCheck($line, $smtpConnection, $verbose = false) {
     return $err_num;
 }
 
+/* create new reference header per rfc2822 */
+
+function calculate_references($refs, $inreplyto, $old_reply_to) {
+    $refer = "";
+    for ($i=1;$i<count($refs[0]);$i++) {
+        if (!empty($refs[0][$i])) {
+            if (preg_match("/^References:(.+)$/", $refs[0][$i], $regs)) {
+                $refer = trim($regs[1]);
+            }
+            else {   
+                $refer .= ' ' . trim($refs[0][$i]);
+            }
+        }
+    }
+    $refer = trim($refer);
+    if (strlen($refer) > 2) {
+        $refer .= ' ' . $inreplyto;
+    }
+    else {
+        if (!empty($old_reply_to)) {
+            $refer .= $old_reply_to . ' ' . $inreplyto;
+        }
+        else {
+            $refer .= $inreplyto;
+        }			
+    }
+    trim($refer);
+    $refer = str_replace(' ', "\r\n        ", $refer);
+    return $refer;
+}
+
 function sendMessage($t, $c, $b, $subject, $body, $reply_id, $MDN, $prio = 3, $session) {
     global $useSendmail, $msg_id, $is_reply, $mailbox, $onetimepad,
            $data_dir, $username, $domain, $key, $version, $sent_folder, $imapServerAddress, 
@@ -698,12 +729,16 @@ function sendMessage($t, $c, $b, $subject, $body, $reply_id, $MDN, $prio = 3, $s
         /* 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.
+         * with the message ID appended, and now it is (jmunro)
          */
         $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;
+            $refs = get_reference_header ($imap_stream, $reply_id);
+            $inreplyto = $hdr->message_id;
+			$old_reply_to = $hdr->inrepto;
+            $refer = calculate_references ($refs, $inreplyto, $old_reply_to);
+            $more_headers['In-Reply-To'] = $inreplyto;
+            $more_headers['References']  = $refer;
         }
     }
     if ($default_use_priority) {