From 67c2f5eac0033585381d9c7d268d6ad540d2ed15 Mon Sep 17 00:00:00 2001 From: jmunro Date: Thu, 21 Mar 2002 06:50:03 +0000 Subject: [PATCH] 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. git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@2617 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- functions/imap_messages.php | 28 +++++++++++++++++-------- functions/smtp.php | 41 ++++++++++++++++++++++++++++++++++--- 2 files changed, 57 insertions(+), 12 deletions(-) diff --git a/functions/imap_messages.php b/functions/imap_messages.php index 8a1e129b..710f6b11 100755 --- a/functions/imap_messages.php +++ b/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; diff --git a/functions/smtp.php b/functions/smtp.php index 1e539585..8565da37 100644 --- a/functions/smtp.php +++ b/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 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) { -- 2.25.1