Bug 1608539 - Fix the use of m_headerstartpos. Based on contributions by ISHIKAWA, Chiaki. r=mkmelin
authorKai Engert <kaie@kuix.de>
Mon, 27 Jan 2020 12:52:58 +0100
changeset 37140 3420cbdab2ab5f2627d5a8535790bf65222f7928
parent 37139 64e8cb1308b1d96e071f79c383fcf46264a18467
child 37141 62a84e316dab6346317e77a75d50e79239a17936
push id2552
push userclokep@gmail.com
push dateMon, 10 Feb 2020 21:24:16 +0000
treeherdercomm-beta@f95a6f4408a3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmkmelin
bugs1608539
Bug 1608539 - Fix the use of m_headerstartpos. Based on contributions by ISHIKAWA, Chiaki. r=mkmelin
mailnews/local/src/nsParseMailbox.cpp
--- a/mailnews/local/src/nsParseMailbox.cpp
+++ b/mailnews/local/src/nsParseMailbox.cpp
@@ -548,19 +548,20 @@ NS_IMETHODIMP nsParseMailMessageState::C
   m_envelope_pos = 0;
   m_new_key = nsMsgKey_None;
   ClearAggregateHeader(m_toList);
   ClearAggregateHeader(m_ccList);
   m_headers.ResetWritePos();
   m_envelope.ResetWritePos();
   m_receivedTime = 0;
   m_receivedValue.Truncate();
-  for (uint32_t i = 0; i < m_customDBHeaders.Length(); i++)
+  for (uint32_t i = 0; i < m_customDBHeaders.Length(); i++) {
     m_customDBHeaderValues[i].length = 0;
-
+  }
+  m_headerstartpos = 0;
   return NS_OK;
 }
 
 NS_IMETHODIMP nsParseMailMessageState::SetState(nsMailboxParseState aState) {
   m_state = aState;
   return NS_OK;
 }
 
@@ -1163,17 +1164,17 @@ nsresult nsParseMailMessageState::Finali
   struct message_header *ccList;
   struct message_header *bccList;
   struct message_header *mdn_dnt;
   struct message_header md5_header;
   struct message_header *content_type;
   char md5_data[50];
 
   uint32_t flags = 0;
-  uint32_t delta = 0;
+  uint32_t deltaToMozStatus = 0;
   nsMsgPriorityValue priorityFlags = nsMsgPriority::notSet;
   uint32_t labelFlags = 0;
 
   if (!m_mailDB)  // if we don't have a valid db, skip the header.
     return NS_OK;
 
   struct message_header to;
   GetAggregateHeader(m_toList, &to);
@@ -1215,18 +1216,20 @@ nsresult nsParseMailMessageState::Finali
                    "Expected 4 hex digits for flags.");
       flags = MsgUnhex(mozstatus->value, 4);
       // strip off and remember priority bits.
       flags &= ~nsMsgMessageFlags::RuntimeOnly;
       priorityFlags =
           (nsMsgPriorityValue)((flags & nsMsgMessageFlags::Priorities) >> 13);
       flags &= ~nsMsgMessageFlags::Priorities;
     }
-    delta = m_headerstartpos + (mozstatus->value - m_headers.GetBuffer()) -
-            (X_MOZILLA_STATUS_LEN + 2 /* for ": " */) - m_envelope_pos;
+
+    deltaToMozStatus =
+        m_headerstartpos + (mozstatus->value - m_headers.GetBuffer()) -
+        (X_MOZILLA_STATUS_LEN + 2 /* for ": " */) - m_envelope_pos;
   }
 
   if (mozstatus2) {
     uint32_t flags2 = 0;
     sscanf(mozstatus2->value, " %x ", &flags2);
     flags |= flags2;
   }
 
@@ -1302,20 +1305,27 @@ nsresult nsParseMailMessageState::Finali
                       strncmp(replyTo->value, sender->value, sender->length)))
         m_newMsgHdr->SetStringProperty("replyTo", replyTo->value);
       // convert the flag values (0xE000000) to label values (0-5)
       if (mozstatus2)  // only do this if we have a mozstatus2 header
       {
         labelFlags = ((flags & nsMsgMessageFlags::Labels) >> 25);
         m_newMsgHdr->SetLabel(labelFlags);
       }
-      if (delta < 0xffff) { /* Only use if fits in 16 bits. */
-        m_newMsgHdr->SetStatusOffset((uint16_t)delta);
+      NS_ASSERTION(!mozstatus || deltaToMozStatus < 0xffff,
+                   "unexpected deltaToMozStatus");
+      if (mozstatus &&
+          deltaToMozStatus < 0xffff) { /* Only use if fits in 16 bits. */
+        m_newMsgHdr->SetStatusOffset((uint16_t)deltaToMozStatus);
         if (!m_IgnoreXMozillaStatus) {  // imap doesn't care about
                                         // X-MozillaStatus
+          // TODO: Clarify, why is it necessary to query the value we've just
+          // set? Does querying trigger some kind of side effect? Or is the
+          // following assertion check the only need for querying? If it seems
+          // unnecessary, the following lines should be removed.
           uint32_t offset;
           (void)m_newMsgHdr->GetStatusOffset(&offset);
           NS_ASSERTION(offset < 10000,
                        "invalid status offset"); /* ### Debugging hack */
         }
       }
       if (sender) m_newMsgHdr->SetAuthor(sender->value);
       if (recipient == &m_newsgroups) {