Bug 969358 - Reply-All on an email I previously sent To:myself with Bcc:others has no recipients. r=irving, r+a=standard8
authorMagnus Melin <mkmelin+mozilla@iki.fi>
Wed, 26 Feb 2014 22:45:31 +0200
changeset 19410 fa1d2b9991516361080e9227dffad1b344668168
parent 19409 180cac6ac8fec38e9712306a663f81de94a93a3d
child 19411 de02227c0b4eea2d5a1bd7afeba822b0c43bbe68
push idunknown
push userunknown
push dateunknown
reviewersirving, r
bugs969358
Bug 969358 - Reply-All on an email I previously sent To:myself with Bcc:others has no recipients. r=irving, r+a=standard8
mail/test/mozmill/composition/test-reply-addresses.js
mailnews/compose/src/nsMsgCompose.cpp
--- a/mail/test/mozmill/composition/test-reply-addresses.js
+++ b/mail/test/mozmill/composition/test-reply-addresses.js
@@ -846,16 +846,87 @@ function testReplyToOtherIdentity() {
     {
       "addr_to": ["secretary@example.com", "barney@example.com"],
       "addr_cc": ["Lisa <lisa@example.com>"]
     }
   );
 }
 
 /**
+ * Tests that addresses get set properly for a reply all to self w/ bccs -
+ * this should be treated as a followup.
+ */
+function testReplyToSelfWithBccs() {
+  let msg0 = create_message({
+    from: myEmail,
+    to: myEmail,
+    cc: myEmail2 + ", Lisa <lisa@example.com>",
+    subject: "testReplyToSelfWithBccs - reply to self",
+    clobberHeaders: {
+      "Bcc": "Moe <moe@example.com>, Barney <barney@example.com>",
+      "Reply-To": myEmail2
+    }
+  });
+  add_message_to_folder(folder, msg0);
+
+  be_in_folder(folder);
+  let msg = select_click_row(i++);
+  assert_selected_and_displayed(mc, msg);
+
+  ensureNoAutoCc(identity);
+  checkReply(
+    open_compose_with_reply_to_all,
+    // To: original To
+    // Cc: original Cc
+    // Bcc: original Bcc
+    // Reply-To: original Reply-To
+    {
+      "addr_to": [myEmail],
+      "addr_cc": [myEmail2, "Lisa <lisa@example.com>"],
+      "addr_bcc": ["Moe <moe@example.com>", "Barney <barney@example.com>"],
+      "addr_reply": [myEmail2]
+    }
+  );
+}
+
+/**
+ * Tests that addresses get set properly for a reply all to other identity w/ bccs -
+ * this be treated as a followup.
+ */
+function testReplyToOtherIdentityWithBccs() {
+  let msg0 = create_message({
+    from: myEmail,
+    to: myEmail2,
+    cc: "Lisa <lisa@example.com>",
+    subject: "testReplyToOtherIdentityWithBccs - reply to other identity",
+    clobberHeaders: {
+      "Bcc": "Moe <moe@example.com>, Barney <barney@example.com>"
+    }
+  });
+  add_message_to_folder(folder, msg0);
+
+  be_in_folder(folder);
+  let msg = select_click_row(i++);
+  assert_selected_and_displayed(mc, msg);
+
+  ensureNoAutoCc(identity);
+  checkReply(
+    open_compose_with_reply_to_all,
+    // To: original To
+    // Cc: original Cc
+    // Bcc: original Bcc
+    {
+      "addr_to": [myEmail2],
+      "addr_cc": ["Lisa <lisa@example.com>"],
+      "addr_bcc": ["Moe <moe@example.com>", "Barney <barney@example.com>"]
+    }
+  );
+}
+
+/**
  * Tests that addresses get set properly for a nntp reply-all.
  */
 function testNewsgroupsReplyAll() {
   let msg0 = create_message({
     from: "Homer <homer@example.com>",
     to: "test1-list@example.org",
     subject: "testNewsgroupsReplyAll - sent to two newsgroups and a list",
     clobberHeaders: {
--- a/mailnews/compose/src/nsMsgCompose.cpp
+++ b/mailnews/compose/src/nsMsgCompose.cpp
@@ -2528,34 +2528,46 @@ NS_IMETHODIMP QuotingOutputStreamListene
 
           nsCString curIdentityEmail;
           lookupIdentity->GetEmail(curIdentityEmail);
 
           // See if it's a reply to own message, but not a reply between identities.
           if (curIdentityEmail.Equals(fromEmailAddress))
           {
             isReplyToSelf = true;
-            // For a true reply-to-self, NONE of your identities are normally in
-            // To or CC. If you auto-Cc yourself it could be in Cc - but we
-            // can't detect this case 100%, so lets just treat it like a normal
-            // reply.
+            // For a true reply-to-self, none of your identities are normally in
+            // To or Cc. We need to avoid doing a reply-to-self for people that
+            // have multiple identities set and sometimes *uses* the other
+            // identity and sometimes *mails* the other identity.
+            // E.g. husband+wife or own-email+company-role-mail.
             for (uint32_t j = 0; j < count; j++)
             {
               nsCOMPtr<nsIMsgIdentity> lookupIdentity2;
               rv = identities->QueryElementAt(j, NS_GET_IID(nsIMsgIdentity),
                                               getter_AddRefs(lookupIdentity2));
               if (NS_FAILED(rv))
                 continue;
 
               nsCString curIdentityEmail2;
               lookupIdentity2->GetEmail(curIdentityEmail2);
-              if (toEmailAddresses.Contains(curIdentityEmail2) ||
-                  ccEmailAddresses.Contains(curIdentityEmail2))
+              if (toEmailAddresses.Contains(curIdentityEmail2))
               {
-                // An identity among the recipients -> not reply-to-self.
+                // However, "From:me To:me" should be treated as
+                // reply-to-self if we have a Bcc. If we don't have a Bcc we
+                // might have the case of a generated mail of the style
+                // "From:me To:me Reply-To:customer". Then we need to to do a
+                // normal reply to the customer.
+                isReplyToSelf = !bcc.IsEmpty(); // true if bcc is set
+                break;
+              }
+              else if (ccEmailAddresses.Contains(curIdentityEmail2))
+              {
+                // If you auto-Cc yourself your email would be in Cc - but we
+                // can't detect why it is in Cc so lets just treat it like a
+                // normal reply.
                 isReplyToSelf = false;
                 break;
               }
             }
             break;
           }
         }
       }