Fix bug 1041299 - Sending invitations with configured cc/bcc is broken. r=philipp
authorMakeMyDay <makemyday@gmx-topmail.de>
Fri, 25 Jul 2014 06:38:53 +0200
changeset 25468 0da77eea6c8196c006caf2a4f088dbb30e9fe06b
parent 25467 a032736616b7700184ee817b368430550bcd9a8b
child 25469 47e507c3084ea9a4181ab7cf00c5e61610943882
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)
reviewersphilipp
bugs1041299
Fix bug 1041299 - Sending invitations with configured cc/bcc is broken. r=philipp
calendar/base/modules/calUtils.jsm
calendar/itip/calItipEmailTransport.js
--- a/calendar/base/modules/calUtils.jsm
+++ b/calendar/base/modules/calUtils.jsm
@@ -240,23 +240,34 @@ let cal = {
         let calendar = cal.wrapInstance(aItem.calendar, Components.interfaces.calISchedulingSupport);
         if (calendar) {
             isInvitation = calendar.isInvitation(aItem);
         }
         return isInvitation;
     },
 
     /**
-     * Returns a basically checked recipient string - malformed parts will be removed
+     * Returns a basically checked recipient list - malformed elements will be removed
+     *
+     * @param   string aRecipients  a comma-seperated list of e-mail addresses
+     * @return  string              a comma-seperated list of e-mail addresses
      */
-    validateRecipients: function cal_validRecipients(aRecipients) {
-        let fields = Components.classes["@mozilla.org/messengercompose/composefields;1"]
-                     .createInstance(Components.interfaces.nsIMsgCompFields);
+    validateRecipientList: function (aRecipients) {
+        let compFields = Components.classes["@mozilla.org/messengercompose/composefields;1"]
+                                   .createInstance(Components.interfaces.nsIMsgCompFields);
+        // Resolve the list considering also configured display names
         let result = compFields.splitRecipients(aRecipients, false, {});
-        return (!result.length) ? result.join(",") : "";
+        // Malformed e-mail addresses with display name in list will result in "Display name <>".
+        // So, we need an additional check on the e-mail address itself and sort out malformed
+        // entries from the previous list (both objects have always the same length)
+        if (result.length > 0) {
+            let resultAddress = compFields.splitRecipients(aRecipients, true, {});
+            result = result.filter((v, idx) => !!resultAddress[idx]);
+        }
+        return result.join(",");
     },
 
     /**
      * Shortcut function to check whether an item is an invitation copy and
      * has a participation status of either NEEDS-ACTION or TENTATIVE.
      *
      * @param aItem either calIAttendee or calIItemBase 
      */
--- a/calendar/itip/calItipEmailTransport.js
+++ b/calendar/itip/calItipEmailTransport.js
@@ -231,21 +231,28 @@ calItipEmailTransport.prototype = {
                 if (mailFile) {
                     // compose fields for message: from/to etc need to be specified both here and in the file
                     let composeFields = Components.classes["@mozilla.org/messengercompose/composefields;1"]
                                                   .createInstance(Components.interfaces.nsIMsgCompFields);
                     composeFields.characterSet = "UTF-8";
                     composeFields.to = toList;
                     composeFields.from = identity.email;
                     composeFields.replyTo = identity.replyTo;
+                    let validRecipients;
                     if (identity.doCc) {
-                        composeFields.cc = cal.validateRecipients(identity.doCcList);
+                        validRecipients = cal.validateRecipientList(identity.doCcList);
+                        if (validRecipients != "") {
+                            composeFields.cc = validRecipients;
+                        }
                     }
                     if (identity.doBcc) {
-                        composeFields.bcc = cal.validateRecipients(identity.doBccList);
+                        validRecipients = cal.validateRecipientList(identity.doBccList);
+                        if (validRecipients != "") {
+                            composeFields.bcc = validRecipients;
+                        }
                     }
 
                     // xxx todo: add send/progress UI, maybe recycle
                     //           "@mozilla.org/messengercompose/composesendlistener;1"
                     //           and/or "chrome://messenger/content/messengercompose/sendProgress.xul"
                     // i.e. bug 432662
                     let msgSend = Components.classes["@mozilla.org/messengercompose/send;1"]
                                             .createInstance(Components.interfaces.nsIMsgSend);
@@ -309,22 +316,29 @@ calItipEmailTransport.prototype = {
             // like multipart/alternative with enclosed text/calendar and text/plain.
             let mailText = ("MIME-version: 1.0\r\n" +
                             (aIdentity.replyTo
                              ? "Return-path: " + aIdentity.replyTo + "\r\n" : "") +
                             "From: " + aIdentity.email + "\r\n" +
                             "To: " + aToList + "\r\n" +
                             "Date: " + (new Date()).toUTCString() + "\r\n" +
                             "Subject: " + encodeMimeHeader(aSubject.replace(/(\n|\r\n)/, "|")) + "\r\n");
-                            if (aIdentity.doCc) {
-                                mailText += ("Cc: " + cal.validRecipients(aIdentity.doCcList) + "\r\n");
-                            }
-                            if (aIdentity.doBcc) {
-                                mailText += ("Bcc: " + cal.validRecipients(aIdentity.doBccList) + "\r\n");
-                            }
+            let validRecipients;
+            if (aIdentity.doCc) {
+                validRecipients = cal.validateRecipientList(aIdentity.doCcList);
+                if (validRecipients != "") {
+                    mailText += ("Cc: " + validRecipients + "\r\n");
+                }
+            }
+            if (aIdentity.doBcc) {
+                validRecipients = cal.validateRecipientList(aIdentity.doBccList);
+                if (validRecipients != "") {
+                    mailText += ("Bcc: " + validRecipients + "\r\n");
+                }
+            }
             switch (compatMode) {
                 case 1:
                     mailText += ("Content-class: urn:content-classes:calendarmessage\r\n" +
                                  "Content-type: text/calendar; method=" + aItem.responseMethod + "; charset=UTF-8\r\n" +
                                  "Content-transfer-encoding: 8BIT\r\n" +
                                  "\r\n" +
                                  utf8CalText +
                                  "\r\n");