Bug 1135610 Changing identity doesn't actually change From: address r=mkmelin a=rkent
authorNeil Rashbrook <neil@parkwaycc.co.uk>
Thu, 26 Mar 2015 22:26:31 +0000
changeset 25820 d3e7a38fe3c5b6c691c76f85c96bea899f7dc986
parent 25819 83e056f26c1a2c911b42f47506753912888c00c7
child 25821 c4bd6ea94b44fd258ff51b77fedef14cae27d605
push id1850
push userclokep@gmail.com
push dateWed, 08 Mar 2017 19:29:12 +0000
treeherdercomm-esr52@028df196b2d9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmkmelin, rkent
bugs1135610
Bug 1135610 Changing identity doesn't actually change From: address r=mkmelin a=rkent
mail/components/compose/content/MsgComposeCommands.js
mail/test/mozmill/composition/test-address-widgets.js
mail/test/mozmill/composition/test-send-button.js
mail/test/mozmill/composition/test-signature-updating.js
--- a/mail/components/compose/content/MsgComposeCommands.js
+++ b/mail/components/compose/content/MsgComposeCommands.js
@@ -2143,17 +2143,18 @@ function ComposeStartup(recycled, aParam
   if (!params.identity || params.identity.identityName == " <>") {
     // no pre selected identity, so use the default account
     let identities = MailServices.accounts.defaultAccount.identities;
     if (identities.length == 0)
       identities = MailServices.accounts.allIdentities;
     params.identity = identities.queryElementAt(0, Components.interfaces.nsIMsgIdentity);
   }
 
-  identityList.value = params.identity.key;
+  identityList.selectedItem =
+    identityList.getElementsByAttribute("identitykey", params.identity.key)[0];
   LoadIdentity(true);
 
   // Get the <editor> element to startup an editor
   var editorElement = GetCurrentEditorElement();
   gMsgCompose = MailServices.compose.initCompose(params, window, editorElement.docShell);
 
   // Set the close listener.
   gMsgCompose.recyclingListener = gComposeRecyclingListener;
@@ -2437,16 +2438,17 @@ function DoSpellCheckBeforeSend()
  * Handles message sending operations.
  * @param msgType nsIMsgCompDeliverMode of the operation.
  */
 function GenericSendMessage(msgType)
 {
   var msgCompFields = gMsgCompose.compFields;
 
   Recipients2CompFields(msgCompFields);
+  msgCompFields.from = GetMsgIdentityElement().value;
   var subject = GetMsgSubjectElement().value;
   msgCompFields.subject = subject;
   Attachments2CompFields(msgCompFields);
   // Some other msgCompFields have already been updated instantly in their respective
   // toggle functions, e.g. ToggleReturnReceipt(), ToggleDSN(),  ToggleAttachVCard(),
   // and toggleAttachmentReminder().
 
   let sending = msgType == nsIMsgCompDeliverMode.Now ||
@@ -3208,45 +3210,53 @@ function FillIdentityList(menulist)
         menulist.menupopup.appendChild(separator);
       }
       accountHadSeparator = needSeparator;
     }
     firstAccountWithIdentities = false;
 
     for (let i = 0; i < identities.length; i++) {
       let identity = identities[i];
-      let item = menulist.appendItem(identity.identityName, identity.key,
+      let item = menulist.appendItem(identity.identityName,
+                                     identity.identityName,
                                      account.incomingServer.prettyName);
+      item.setAttribute("identitykey", identity.key);
       item.setAttribute("accountkey", account.key);
       if (i == 0) {
         // Mark the first identity as default.
         item.setAttribute("default", "true");
       }
     }
   }
 }
 
-function getCurrentIdentity()
-{
-  var identityKey = document.getElementById("msgIdentity").value;
-  return MailServices.accounts.getIdentity(identityKey);
-}
-
 function getCurrentAccountKey()
 {
     // get the accounts key
     var identityList = document.getElementById("msgIdentity");
     return identityList.selectedItem.getAttribute("accountkey");
 }
 
+function getCurrentIdentityKey()
+{
+  // get the identity key
+  var identityList = GetMsgIdentityElement();
+  return identityList.selectedItem.getAttribute("identitykey");
+}
+
 function getIdentityForKey(key)
 {
     return MailServices.accounts.getIdentity(key);
 }
 
+function getCurrentIdentity()
+{
+  return getIdentityForKey(getCurrentIdentityKey());
+}
+
 function AdjustFocus()
 {
   //dump("XXX adjusting focus\n");
   var element = awGetInputElement(awGetNumberOfRecipients());
   if (element.value == "") {
       //dump("XXX focus on address\n");
       awSetFocus(awGetNumberOfRecipients(), element);
   }
@@ -3910,17 +3920,17 @@ function hideIrrelevantAddressingOptions
 }
 
 function LoadIdentity(startup)
 {
     var identityElement = document.getElementById("msgIdentity");
     var prevIdentity = gCurrentIdentity;
 
     if (identityElement) {
-        var idKey = identityElement.value;
+        var idKey = identityElement.selectedItem.getAttribute("identitykey");
         gCurrentIdentity = MailServices.accounts.getIdentity(idKey);
 
         let accountKey = null;
         // Set the account key value on the menu list.
         if (identityElement.selectedItem) {
           accountKey = identityElement.selectedItem.getAttribute("accountkey");
           identityElement.setAttribute("accountkey", accountKey);
           hideIrrelevantAddressingOptions(accountKey);
--- a/mail/test/mozmill/composition/test-address-widgets.js
+++ b/mail/test/mozmill/composition/test-address-widgets.js
@@ -120,27 +120,27 @@ function test_address_types() {
 
   // Now try the same accounts but choosing them in the From dropdown
   // inside compose window.
   be_in_folder(accountPOP3.incomingServer.rootFolder);
   cwc = open_compose_new_mail();
   check_nntp_address_types();
 
   let NNTPidentity = accountNNTP.defaultIdentity.key;
-  cwc.click_menus_in_sequence(cwc.e("msgIdentityPopup"), [ { value: NNTPidentity } ]);
+  cwc.click_menus_in_sequence(cwc.e("msgIdentityPopup"), [ { identitykey: NNTPidentity } ]);
   check_nntp_address_types();
 
   // In a News account, choose "Newsgroup:" as the address type.
   cwc.click_menus_in_sequence(cwc.e("addressCol1#1").menupopup,
                               [ { value: "addr_newsgroups" } ]);
   check_nntp_address_types();
 
   // And switch back to the POP3 account.
   let POP3identity = accountPOP3.defaultIdentity.key;
-  cwc.click_menus_in_sequence(cwc.e("msgIdentityPopup"), [ { value: POP3identity } ]);
+  cwc.click_menus_in_sequence(cwc.e("msgIdentityPopup"), [ { identitykey: POP3identity } ]);
   check_nntp_address_types();
 
   close_compose_window(cwc);
 
   remove_NNTP_account();
 
   // Now the NNTP account is lost, so we should be back to mail only addressees.
   be_in_folder(accountPOP3.incomingServer.rootFolder);
--- a/mail/test/mozmill/composition/test-send-button.js
+++ b/mail/test/mozmill/composition/test-send-button.js
@@ -122,22 +122,22 @@ function test_send_enabled_prefilled_add
   let identityPicker = cwc.e("msgIdentity");
   assert_equals(identityPicker.selectedIndex, 0);
 
   // Switch to the second identity that has no CC. Send should be disabled.
   assert_true(account.identities.length >= 2);
   let identityWithoutCC = account.identities.queryElementAt(1, Ci.nsIMsgIdentity);
   assert_false(identityWithoutCC.doCc);
   cwc.click_menus_in_sequence(cwc.e("msgIdentityPopup"),
-                              [ { value: identityWithoutCC.key } ]);
+                              [ { identitykey: identityWithoutCC.key } ]);
   check_send_commands_state(cwc, false);
 
   // Check the first identity again.
   cwc.click_menus_in_sequence(cwc.e("msgIdentityPopup"),
-                              [ { value: identityWithCC.key } ]);
+                              [ { identitykey: identityWithCC.key } ]);
   check_send_commands_state(cwc, true);
 
   close_compose_window(cwc);
   identityWithCC.doCcList = "";
   identityWithCC.doCc = false;
 }
 
 /**
--- a/mail/test/mozmill/composition/test-signature-updating.js
+++ b/mail/test/mozmill/composition/test-signature-updating.js
@@ -92,19 +92,17 @@ function plaintextComposeWindowSwitchSig
     assert_equals(brNode.localName, "br");
     sigNode = brNode.nextSibling;
   }
 
   let expectedText = "Tinderbox is soo 90ies";
   assert_equals(sigNode.textContent, expectedText);
 
   // Now switch identities!
-  let menuID = cwc.e("msgIdentity");
-  menuID.value = "id2";
-  menuID.click();
+  cwc.click_menus_in_sequence(cwc.e("msgIdentityPopup"), [ { identitykey: "id2" } ]);
 
   node = contentFrame.contentDocument.body.lastChild;
 
   // The last node is a BR - this allows users to put text after the
   // signature without it being styled like the signature.
   assert_equals(node.localName, "br");
   node = node.previousSibling;
 
@@ -171,19 +169,17 @@ function HTMLComposeWindowSwitchSignatur
   assert_equals(node.className, "moz-signature");
   node = node.firstChild; // text node containing the signature divider
   if (suppressSigSep)
     assert_equals(node.nodeValue, "Tinderbox is soo 90ies");
   else
     assert_equals(node.nodeValue, "-- \nTinderbox is soo 90ies");
 
   // Now switch identities!
-  let menuID = cwc.e("msgIdentity");
-  menuID.value = "id2";
-  menuID.click();
+  cwc.click_menus_in_sequence(cwc.e("msgIdentityPopup"), [ { identitykey: "id2" } ]);
 
   node = contentFrame.contentDocument.body.lastChild;
 
   // In html compose, the signature is inside the last node
   // with class="moz-signature".
   assert_equals(node.className, "moz-signature");
   node = node.firstChild; // text node containing the signature divider
   if (!suppressSigSep) {