Fix bug 1045417 - Event attendee with a comma in display name gets splitted in two attendees. r=philipp
authorMakeMyDay <makemyday@gmx-topmail.de>
Sun, 03 Aug 2014 19:22:42 +0200
changeset 25467 a032736616b7700184ee817b368430550bcd9a8b
parent 25466 3a73a2988e74f1c7fe624ba522bf0c722b11b1ef
child 25468 0da77eea6c8196c006caf2a4f088dbb30e9fe06b
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
bugs1045417
Fix bug 1045417 - Event attendee with a comma in display name gets splitted in two attendees. r=philipp
calendar/base/content/dialogs/calendar-event-dialog-attendees.xml
--- a/calendar/base/content/dialogs/calendar-event-dialog-attendees.xml
+++ b/calendar/base/content/dialogs/calendar-event-dialog-attendees.xml
@@ -1034,52 +1034,45 @@
           return val;
         ]]></setter>
       </property>
 
       <method name="returnHit">
         <parameter name="element"/>
         <parameter name="noAdvance"/>
         <body><![CDATA[
-          function parseHeaderValue(email, name, fullname) {
-              if (name && name.match(/[<>@,]/)) {
-                  return '"' + name + '" <' + email + '>';
-              } else if (email.length) {
-                  return fullname;
+          function parseHeaderValue(aMsgIAddressObject) {
+              if (aMsgIAddressObject.name.match(/[<>@,]/)) {
+                  // special handling only needed for a name with a comma which are not already quoted
+                  return ((aMsgIAddressObject.name.match(/^".*"$/))
+                          ? aMsgIAddressObject.name
+                          : '"' + aMsgIAddressObject.name + '"'
+                         ) + ' <' + aMsgIAddressObject.email + '>';
               } else {
-                  return name;
+                  return aMsgIAddressObject.toString();
               }
           }
 
           let arrowLength = 1;
           if (element.value.contains(",")) {
               let strippedAddresses = element.value.replace(/.* >> /, "");
-              let emailAddresses = {};
-              let names = {};
-              let fullNames = {};
-
-              MailServices.headerParser.parseHeadersWithArray(strippedAddresses,
-                                                              emailAddresses,
-                                                              names,
-                                                              fullNames);
+              let addresses = MailServices.headerParser.makeFromDisplayAddress(strippedAddresses);
+              element.value = parseHeaderValue(addresses[0]);
 
-              emailAddresses = emailAddresses.value || [];
-              names = names.value || [];
-              fullNames = fullNames.value || [];
-
-              if (emailAddresses.length > 1) {
-                  element.value = parseHeaderValue(emailAddresses[0], names[0], fullNames[0]);
-                  let insertAfterItem = this.getListItem(this.getRowByInputElement(element));
-                  for (let i = 1; i < fullNames.length; i++) {
+              // the following code is needed to split attendees, if the user enters a comma
+              // separated list of attendees without using autocomplete functionality
+              let insertAfterItem = this.getListItem(this.getRowByInputElement(element));
+              for (let key in addresses) {
+                  if (key > 0) {
                       insertAfterItem = this.appendNewRow(false, insertAfterItem);
                       let textinput = this.getInputFromListitem(insertAfterItem);
-                      textinput.value = parseHeaderValue(emailAddresses[i], names[i], fullNames[i]);
+                      textinput.value = parseHeaderValue(addresses[key]);
                   }
               }
-              arrowLength = emailAddresses.length;
+              arrowLength = addresses.length;
           }
 
           if (!noAdvance) {
               this.arrowHit(element, arrowLength);
           }
         ]]></body>
       </method>