Bug 1199942 - Event approval dialog does not filter calendars anymore;r=philipp
authorMakeMyDay <makemyday@gmx-topmail.de>
Sat, 05 Sep 2015 22:57:50 +0200
changeset 26344 555745edb8a603ffcc8bbdd413bfc09c1b2ca4e5
parent 26343 9906d29195ced733840482ac39f4cbe232db2bf1
child 26345 32968d0d7746f06f14b119afeefc82faa51b31f1
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
bugs1199942
Bug 1199942 - Event approval dialog does not filter calendars anymore;r=philipp
calendar/base/src/calAttendee.js
calendar/test/unit/test_bug1199942.js
calendar/test/unit/xpcshell-shared.ini
--- a/calendar/base/src/calAttendee.js
+++ b/calendar/base/src/calAttendee.js
@@ -1,12 +1,13 @@
 /* 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://calendar/modules/calUtils.jsm");
 Components.utils.import("resource://calendar/modules/calIteratorUtils.jsm");
 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
 
 function calAttendee() {
     this.wrappedJSObject = this;
     this.mProperties = new calPropertyBag();
 }
 
@@ -161,17 +162,18 @@ calAttendee.prototype = {
     },
 
     get id() {
         return this.mId;
     },
     set id(aId) {
         this.modify();
         // RFC 1738 para 2.1 says we should be using lowercase mailto: urls
-        return (this.mId = (aId ? aId.replace(/^mailto:/i, "mailto:") : null));
+        // we enforce prepending the mailto prefix for email type ids as migration code bug 1199942
+        return (this.mId = (aId ? cal.prependMailTo(aId) : null));
     },
 
     toString: function calAttendee_toString() {
         const emailRE = new RegExp("^mailto:", "i");
         let stringRep = (this.id || "").replace(emailRE, "");
         let commonName = this.commonName;
 
         if (commonName) {
new file mode 100644
--- /dev/null
+++ b/calendar/test/unit/test_bug1199942.js
@@ -0,0 +1,69 @@
+/* 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://calendar/modules/calUtils.jsm");
+
+function run_test() {
+    // Test the graceful handling of attendee ids for bug 1199942
+    createAttendee_test();
+    serializeEvent_test();
+}
+
+function createAttendee_test() {
+    let data = [{input: "mailto:user1@example.net", expected: "mailto:user1@example.net"},
+                {input: "MAILTO:user2@example.net", expected: "mailto:user2@example.net"},
+                {input: "user3@example.net", expected: "mailto:user3@example.net"},
+                {input: "urn:uuid:user4", expected: "urn:uuid:user4"}];
+    let event = cal.createEvent();
+    for (let test of data) {
+        let attendee = cal.createAttendee();
+        attendee.id = test.input;
+        event.addAttendee(attendee);
+        let readAttendee = event.getAttendeeById(cal.prependMailTo(test.input));
+        equal(readAttendee.id, test.expected);
+    }
+}
+
+function serializeEvent_test() {
+    let ics= "BEGIN:VCALENDAR\n" +
+             "PRODID:-//Mozilla.org/NONSGML Mozilla Calendar V1.1//EN\n" +
+             "VERSION:2.0\n" +
+             "BEGIN:VEVENT\n" +
+             "CREATED:20150801T213509Z\n" +
+             "LAST-MODIFIED:20150830T164104Z\n" +
+             "DTSTAMP:20150830T164104Z\n" +
+             "UID:a84c74d1-cfc6-4ddf-9d60-9e4afd8238cf\n" +
+             "SUMMARY:New Event\n" +
+             "ORGANIZER;RSVP=TRUE;CN=Tester1;PARTSTAT=ACCEPTED;ROLE=CHAIR:mailto:user1@example.net\n" +
+             "ATTENDEE;RSVP=TRUE;PARTSTAT=NEEDS-ACTION;ROLE=REQ-PARTICIPANT:MAILTO:user2@example.net\n" +
+             "ATTENDEE;RSVP=TRUE;PARTSTAT=NEEDS-ACTION;ROLE=REQ-PARTICIPANT:mailto:user3@example.net\n" +
+             "ATTENDEE;RSVP=TRUE;PARTSTAT=NEEDS-ACTION;ROLE=REQ-PARTICIPANT:user4@example.net\n" +
+             "ATTENDEE;RSVP=TRUE;PARTSTAT=NEEDS-ACTION;ROLE=REQ-PARTICIPANT:urn:uuid:user5\n" +
+             "DTSTART:20150729T103000Z\n" +
+             "DTEND:20150729T113000Z\n" +
+             "TRANSP:OPAQUE\n" +
+             "END:VEVENT\n" +
+             "END:VCALENDAR\n";
+
+    let expectedIds = ["mailto:user2@example.net",
+                       "mailto:user3@example.net",
+                       "mailto:user4@example.net",
+                       "urn:uuid:user5"];
+    let event = createEventFromIcalString(ics);
+    let attendees = event.getAttendees({});
+
+    // check whether all attendees get returned with expected id
+    for (let attendee of attendees) {
+        ok(expectedIds.some(id => id == attendee.id));
+    }
+
+    // serialize the event again and check whether the attendees still are in shape
+    let serializer = Components.classes["@mozilla.org/calendar/ics-serializer;1"]
+                               .createInstance(Components.interfaces.calIIcsSerializer);
+    serializer.addItems([event], [event].length);
+    let serialized = ics_unfoldline(serializer.serializeToString());
+    for (let id of expectedIds) {
+        ok(serialized.search(id) != -1);
+    }
+}
--- a/calendar/test/unit/xpcshell-shared.ini
+++ b/calendar/test/unit/xpcshell-shared.ini
@@ -1,12 +1,13 @@
 [test_alarm.js]
 [test_alarmservice.js]
 [test_attachment.js]
 [test_attendee.js]
+[test_bug1199942.js]
 [test_bug272411.js]
 [test_bug343792.js]
 [test_bug350845.js]
 [test_bug356207.js]
 [test_bug485571.js]
 [test_bug486186.js]
 [test_bug494140.js]
 [test_bug523860.js]