Bug 1271353 - check own email addresses case-insensitively in correspondents column and ignore plus addressing part. r+a=jorgk
authorMagnus Melin <mkmelin+mozilla@iki.fi>
Wed, 21 Nov 2018 10:40:25 +0200
changeset 33518 4430faa4264c60c921601d72f611bf846b1b0394
parent 33517 cb577e1c5a9ec73ac9f426a92f3cb16f0beeb064
child 33519 2bc79ecf12c5ea75fe3f3b642807efece7d4f092
push id387
push userclokep@gmail.com
push dateMon, 10 Dec 2018 21:30:47 +0000
bugs1271353
Bug 1271353 - check own email addresses case-insensitively in correspondents column and ignore plus addressing part. r+a=jorgk
mailnews/base/src/nsMsgDBView.cpp
--- a/mailnews/base/src/nsMsgDBView.cpp
+++ b/mailnews/base/src/nsMsgDBView.cpp
@@ -906,26 +906,44 @@ nsMsgDBView::FetchLabel(nsIMsgDBHdr *aHd
     return NS_OK;
   }
 
   // We need to subtract 1 because mLabelPrefDescriptions is 0 based.
   aLabelString = mLabelPrefDescriptions[label - 1];
   return NS_OK;
 }
 
+/**
+ * Lowercase the email and remove a possible plus addressing part.
+ * E.g. John+test@example.com -> john@example.com.
+ */
+static void
+ToLowerCaseDropPlusAddessing(nsCString& aEmail)
+{
+  ToLowerCase(aEmail);
+  int32_t indPlus;
+  if ((indPlus = aEmail.FindChar('+')) == kNotFound)
+    return;
+  int32_t indAt;
+  indAt = aEmail.FindChar('@', indPlus);
+  if (indAt == kNotFound)
+    return;
+  aEmail.ReplaceLiteral(indPlus, indAt - indPlus, "");
+}
+
 bool
 nsMsgDBView::IsOutgoingMsg(nsIMsgDBHdr* aHdr)
 {
   nsString author;
   aHdr->GetMime2DecodedAuthor(author);
 
   nsCString emailAddress;
   nsString name;
   ExtractFirstAddress(DecodedHeader(author), name, emailAddress);
-
+  ToLowerCaseDropPlusAddessing(emailAddress);
   return mEmails.Contains(emailAddress);
 }
 
 
 // If you call SaveAndClearSelection make sure to call RestoreSelection(),
 // otherwise m_saveRestoreSelectionDepth will be incorrect and will lead to
 // selection msg problems.
 nsresult
@@ -2554,22 +2572,26 @@ nsMsgDBView::Open(nsIMsgFolder *folder,
   for (uint32_t i = 0; i < count; i++)
   {
     nsCOMPtr<nsIMsgIdentity> identity(do_QueryElementAt(identities, i));
     if (!identity)
       continue;
 
     nsCString email;
     identity->GetEmail(email);
-    if (!email.IsEmpty())
+    if (!email.IsEmpty()) {
+      ToLowerCaseDropPlusAddessing(email);
       mEmails.PutEntry(email);
+    }
 
     identity->GetReplyTo(email);
-    if (!email.IsEmpty())
+    if (!email.IsEmpty()) {
+      ToLowerCaseDropPlusAddessing(email);
       mEmails.PutEntry(email);
+    }
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsMsgDBView::Close()
 {