Bug 1165612 - Port Thunderbird Bug 1130248 (Allow email addresses in address name fields) r=IanN sr=Mnyromyr a=IanN for comm-aurora and comm-beta CLOSED TREE
authorPhilip Chee <philip.chee@gmail.com>
Thu, 21 May 2015 00:31:57 +0800
changeset 26057 d9530439f36cbd2857f0492a296b23e2c24dc64e
parent 26056 92621b795cda80fd1bd4343e7a5c55f3b12e5899
child 26058 885507d2d9211b5129da5841bd6c4d6cdb7f5470
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)
reviewersIanN, Mnyromyr, IanN
bugs1165612, 1130248
Bug 1165612 - Port Thunderbird Bug 1130248 (Allow email addresses in address name fields) r=IanN sr=Mnyromyr a=IanN for comm-aurora and comm-beta CLOSED TREE
suite/mailnews/mailContextMenus.js
--- a/suite/mailnews/mailContextMenus.js
+++ b/suite/mailnews/mailContextMenus.js
@@ -1,13 +1,15 @@
 /* -*- Mode: javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
+Components.utils.import("resource:///modules/mailServices.js");
+
 //NOTE: gMessengerBundle must be defined and set or this Overlay won't work
 
 /**
  * Function to change the highlighted row back to the row that is currently
  * outline/dotted without loading the contents of either rows. This is
  * triggered when the context menu for a given row is hidden/closed
  * (onpopuphiding).
  * @param tree the tree element to restore selection for
@@ -445,33 +447,35 @@ function EditContact(aEmailAddressNode)
 function SendMailToNode(emailAddressNode, aEvent)
 {
   if (emailAddressNode)
     SendMailTo(emailAddressNode.getAttribute("fullAddress"), aEvent);
 }
 
 function SendMailTo(fullAddress, aEvent)
 {
-  var fields = Components.classes["@mozilla.org/messengercompose/composefields;1"].createInstance(Components.interfaces.nsIMsgCompFields);
-  var params = Components.classes["@mozilla.org/messengercompose/composeparams;1"].createInstance(Components.interfaces.nsIMsgComposeParams);
-  if (fields && params)
-  {
-    fields.to = fullAddress;
-    params.type = Components.interfaces.nsIMsgCompType.New;
+  var fields = Components.classes["@mozilla.org/messengercompose/composefields;1"]
+                         .createInstance(Components.interfaces.nsIMsgCompFields);
+  var params = Components.classes["@mozilla.org/messengercompose/composeparams;1"]
+                         .createInstance(Components.interfaces.nsIMsgComposeParams);
+
+  var headerParser = MailServices.headerParser;
+  var addresses = headerParser.makeFromDisplayAddress(fullAddress);
+  fields.to = headerParser.makeMimeHeader(addresses, 1);
+  params.type = Components.interfaces.nsIMsgCompType.New;
 
-    // If aEvent is passed, check if Shift key was pressed for composition in
-    // non-default format (HTML vs. plaintext).
-    params.format = (aEvent && aEvent.shiftKey) ? 
-      Components.interfaces.nsIMsgCompFormat.OppositeOfDefault :
-      Components.interfaces.nsIMsgCompFormat.Default;
+  // If aEvent is passed, check if Shift key was pressed for composition in
+  // non-default format (HTML vs. plaintext).
+  params.format = (aEvent && aEvent.shiftKey) ?
+    Components.interfaces.nsIMsgCompFormat.OppositeOfDefault :
+    Components.interfaces.nsIMsgCompFormat.Default;
 
-    params.identity = accountManager.getFirstIdentityForServer(GetLoadedMsgFolder().server);
-    params.composeFields = fields;
-    msgComposeService.OpenComposeWindowWithParams(null, params);
-  }
+  params.identity = accountManager.getFirstIdentityForServer(GetLoadedMsgFolder().server);
+  params.composeFields = fields;
+  MailServices.compose.OpenComposeWindowWithParams(null, params);
 }
 
 // CopyEmailAddress takes the email address title button, extracts
 // the email address we stored in there and copies it to the clipboard
 function CopyEmailAddress(emailAddressNode)
 {
   if (emailAddressNode)
     CopyString(emailAddressNode.getAttribute("emailAddress"));