Bug 1205287 - Diacritics in From header garbled;r+a=philipp
authormakemyday@gmx-topmail.de
Sun, 20 Sep 2015 14:27:31 +0200
changeset 22206 4754895d71c3631dc6cec390f6f136ecac0bcd75
parent 22205 c3c1799f76641a75905ae317d4fcaff86f8eff39
child 22207 842492b73ad4db11161c1964e04eeb1ea6770e0f
push id65
push usermakemyday@gmx-topmail.de
push dateSun, 15 Nov 2015 23:12:31 +0000
treeherdercomm-esr38@842492b73ad4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1205287
Bug 1205287 - Diacritics in From header garbled;r+a=philipp
calendar/itip/calItipEmailTransport.js
--- a/calendar/itip/calItipEmailTransport.js
+++ b/calendar/itip/calItipEmailTransport.js
@@ -232,17 +232,17 @@ calItipEmailTransport.prototype = {
                 let messageId = composeUtils.msgGenerateMessageId(identity);
                 let mailFile = this._createTempImipFile(compatMode, toList, aSubject, aBody, aItem, identity, messageId);
                 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;
-                    let mailfrom = (!identity.fullName.length) ? identity.mail : identity.fullName + " <" + identity.mail + ">";
+                    let mailfrom = (!identity.fullName.length) ? identity.email : identity.fullName + " <" + identity.email + ">";
                     composeFields.from = (cal.validateRecipientList(mailfrom) == mailfrom)
                                          ? mailfrom : identity.email;
                     composeFields.replyTo = identity.replyTo;
                     composeFields.organization = identity.organization;
                     composeFields.messageId = messageId;
                     let validRecipients;
                     if (identity.doCc) {
                         validRecipients = cal.validateRecipientList(identity.doCcList);
@@ -293,21 +293,21 @@ calItipEmailTransport.prototype = {
         return false;
     },
 
     _createTempImipFile: function cietCTIF(compatMode, aToList, aSubject, aBody, aItem, aIdentity, aMessageId) {
         try {
             function encodeUTF8(text) {
                 return convertFromUnicode("UTF-8", text).replace(/(\r\n)|\n/g, "\r\n");
             }
-            function encodeMimeHeader(header) {
-                let fieldNameLen = (header.indexOf(": ") + 2);
+            function encodeMimeHeader(aHeader, aIsEmail = false) {
+                let fieldNameLen = (aHeader.indexOf(": ") + 2);
                 return MailServices.mimeConverter
-                                   .encodeMimePartIIStr_UTF8(header,
-                                                             false,
+                                   .encodeMimePartIIStr_UTF8(aHeader,
+                                                             aIsEmail,
                                                              "UTF-8",
                                                              fieldNameLen,
                                                              Components.interfaces.nsIMimeConverter.MIME_ENCODED_WORD_SIZE);
             }
 
             let itemList = aItem.getItemList({});
             let serializer = Components.classes["@mozilla.org/calendar/ics-serializer;1"]
                                        .createInstance(Components.interfaces.calIIcsSerializer);
@@ -321,35 +321,35 @@ calItipEmailTransport.prototype = {
             let fullFrom = !aIdentity.fullName.length ? null :
                            cal.validateRecipientList(aIdentity.fullName + "<" + aIdentity.email + ">");
 
             // Home-grown mail composition; I'd love to use nsIMimeEmitter, but it's not clear to me whether
             // it can cope with nested attachments,
             // 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: " + (fullFrom || aIdentity.email) + "\r\n" +
+                             ? "Return-path: " + encodeMimeHeader(aIdentity.replyTo, true) + "\r\n" : "") +
+                            "From: " + encodeMimeHeader(fullFrom || aIdentity.email, true) + "\r\n" +
                             (aIdentity.organization
-                             ? "Organization: " + aIdentity.organization + "\r\n" : "") +
+                             ? "Organization: " + encodeMimeHeader(aIdentity.organization) + "\r\n" : "") +
                             "Message-ID: " + aMessageId + "\r\n" +
-                            "To: " + aToList + "\r\n" +
+                            "To: " + encodeMimeHeader(aToList, true) + "\r\n" +
                             "Date: " + (new Date()).toUTCString() + "\r\n" +
                             "Subject: " + encodeMimeHeader(aSubject.replace(/(\n|\r\n)/, "|")) + "\r\n");
             let validRecipients;
             if (aIdentity.doCc) {
                 validRecipients = cal.validateRecipientList(aIdentity.doCcList);
                 if (validRecipients != "") {
-                    mailText += ("Cc: " + validRecipients + "\r\n");
+                    mailText += ("Cc: " + encodeMimeHeader(validRecipients, true) + "\r\n");
                 }
             }
             if (aIdentity.doBcc) {
                 validRecipients = cal.validateRecipientList(aIdentity.doBccList);
                 if (validRecipients != "") {
-                    mailText += ("Bcc: " + validRecipients + "\r\n");
+                    mailText += ("Bcc: " + encodeMimeHeader(validRecipients, true) + "\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" +