Bug 1439868 - Move email/scheduling related functions into calEmailUtils.jsm and calItipUtils.jsm - automatic changes itip. r=MakeMyDay
authorPhilipp Kewisch <mozilla@kewis.ch>
Wed, 21 Feb 2018 07:37:07 +0100
changeset 31375 8c53d1a42b1da035c3bcfe5addd9d1db82fb5e7c
parent 31374 c496bccd43b0c2b33e64a8cde2323ccb2a9fbc89
child 31376 242cd0982d20fe587b18ed025cb2add0d17010c8
push id383
push userclokep@gmail.com
push dateMon, 07 May 2018 21:52:48 +0000
reviewersMakeMyDay
bugs1439868
Bug 1439868 - Move email/scheduling related functions into calEmailUtils.jsm and calItipUtils.jsm - automatic changes itip. r=MakeMyDay MozReview-Commit-ID: 80Hil54sz5u
calendar/base/content/calendar-common-sets.js
calendar/base/content/calendar-invitations-manager.js
calendar/base/content/calendar-item-editing.js
calendar/base/content/calendar-ui-utils.js
calendar/base/content/calendar-view-core.xml
calendar/base/content/dialogs/calendar-dialog-utils.js
calendar/base/content/dialogs/calendar-invitations-list.xml
calendar/base/modules/calItipUtils.jsm
calendar/itip/calItipEmailTransport.js
calendar/lightning/content/imip-bar.js
calendar/lightning/modules/ltnInvitationUtils.jsm
calendar/providers/gdata/components/calGoogleCalendar.js
calendar/test/unit/test_calutils.js
calendar/test/unit/test_gdata_provider.js
--- a/calendar/base/content/calendar-common-sets.js
+++ b/calendar/base/content/calendar-common-sets.js
@@ -475,17 +475,17 @@ var calendarController = {
                     selected_events_readonly++;
                 }
                 if (item.calendar.getProperty("requiresNetwork") &&
                     !item.calendar.getProperty("cache.enabled") &&
                     !item.calendar.getProperty("cache.always")) {
                     selected_events_requires_network++;
                 }
 
-                if (cal.isInvitation(item)) {
+                if (cal.itip.isInvitation(item)) {
                     selected_events_invitation++;
                 } else if (item.organizer) {
                     // If we are the organizer and there are attendees, then
                     // this is likely also an invitation.
                     let calOrgId = item.calendar.getProperty("organizerId");
                     if (item.organizer.id == calOrgId && item.getAttendees({}).length) {
                         selected_events_invitation++;
                     }
@@ -614,17 +614,17 @@ var calendarController = {
     },
 
 
     get todo_items_invitation() {
         let selectedTasks = getSelectedTasks();
         let selected_tasks_invitation = 0;
 
         for (let item of selectedTasks) {
-            if (cal.isInvitation(item)) {
+            if (cal.itip.isInvitation(item)) {
                 selected_tasks_invitation++;
             } else if (item.organizer) {
                 // If we are the organizer and there are attendees, then
                 // this is likely also an invitation.
                 let calOrgId = item.calendar.getProperty("organizerId");
                 if (item.organizer.id == calOrgId && item.getAttendees({}).length) {
                     selected_tasks_invitation++;
                 }
--- a/calendar/base/content/calendar-invitations-manager.js
+++ b/calendar/base/content/calendar-invitations-manager.js
@@ -333,17 +333,17 @@ InvitationsManager.prototype = {
     /**
      * Adds an item to the internal item list.
      * XXXdbo       Please document these correctly.
      *
      * @param item      The item to add.
      */
     addItem: function(item) {
         let recInfo = item.recurrenceInfo;
-        if (recInfo && !cal.isOpenInvitation(item)) {
+        if (recInfo && !cal.itip.isOpenInvitation(item)) {
             // scan exceptions:
             let ids = recInfo.getExceptionIds({});
             for (let id of ids) {
                 let ex = recInfo.getExceptionFor(id);
                 if (ex && this.validateItem(ex) && !this.hasItem(ex)) {
                     this.mItemList.push(ex);
                 }
             }
@@ -410,11 +410,11 @@ InvitationsManager.prototype = {
      * @return          A boolean indicating if the item is a valid invitation.
      */
     validateItem: function(item) {
         if (item.calendar instanceof Components.interfaces.calISchedulingSupport &&
             !item.calendar.isInvitation(item)) {
             return false; // exclude if organizer has invited himself
         }
         let start = item[cal.dtz.startDateProp(item)] || item[cal.dtz.endDateProp(item)];
-        return cal.isOpenInvitation(item) && start.compare(this.mStartDate) >= 0;
+        return cal.itip.isOpenInvitation(item) && start.compare(this.mStartDate) >= 0;
     }
 };
--- a/calendar/base/content/calendar-item-editing.js
+++ b/calendar/base/content/calendar-item-editing.js
@@ -724,18 +724,18 @@ function setContextPartstat(aTarget, aIt
      * Provides the participation representing the user for a provided item
      *
      * @param   {calEvent|calTodo}  aItem  The calendar item to inspect
      * @returns {?calIAttendee}            An calIAttendee object or null if no
      *                                       participant was detected
      */
     function getParticipant(aItem) {
         let party = null;
-        if (cal.isInvitation(aItem)) {
-            party = cal.getInvitedAttendee(aItem);
+        if (cal.itip.isInvitation(aItem)) {
+            party = cal.itip.getInvitedAttendee(aItem);
         } else if (aItem.organizer && aItem.getAttendees({}).length) {
             let calOrgId = aItem.calendar.getProperty("organizerId");
             if (calOrgId.toLowerCase() == aItem.organizer.id.toLowerCase()) {
                 party = aItem.organizer;
             }
         }
         return party;
     }
--- a/calendar/base/content/calendar-ui-utils.js
+++ b/calendar/base/content/calendar-ui-utils.js
@@ -799,18 +799,18 @@ function setupAttendanceMenu(aMenu, aIte
      *
      * @param   {calEvent|calTodo}  aItem  The calendar item to inspect
      * @returns {?String}                  The participation status string
      *                                       as per RfC 5545 or null if no
      *                                       participant was detected
      */
     function getInvitationStatus(aItem) {
         let party = null;
-        if (cal.isInvitation(aItem)) {
-            party = cal.getInvitedAttendee(aItem);
+        if (cal.itip.isInvitation(aItem)) {
+            party = cal.itip.getInvitedAttendee(aItem);
         } else if (aItem.organizer && aItem.getAttendees({}).length) {
             let calOrgId = aItem.calendar.getProperty("organizerId");
             if (calOrgId.toLowerCase() == aItem.organizer.id.toLowerCase()) {
                 party = aItem.organizer;
             }
         }
         return party && (party.participationStatus || "NEEDS-ACTION");
     }
--- a/calendar/base/content/calendar-view-core.xml
+++ b/calendar/base/content/calendar-view-core.xml
@@ -238,18 +238,18 @@
             if (item.hasProperty("CLASS")) {
                 this.setAttribute("itemclass", item.getProperty("CLASS"));
             }
 
             // calendar name
             this.setAttribute("calendar", item.calendar.name.toLowerCase());
 
             // Invitation
-            if (cal.isInvitation(item)) {
-                this.setAttribute("invitation-status", cal.getInvitedAttendee(item).participationStatus);
+            if (cal.itip.isInvitation(item)) {
+                this.setAttribute("invitation-status", cal.itip.getInvitedAttendee(item).participationStatus);
                 this.setAttribute("readonly", "true");
             } else if (!cal.acl.isCalendarWritable(item.calendar)) {
                 this.setAttribute("readonly", "true");
             }
         ]]></body>
       </method>
 
       <method name="startEditing">
--- a/calendar/base/content/dialogs/calendar-dialog-utils.js
+++ b/calendar/base/content/dialogs/calendar-dialog-utils.js
@@ -617,17 +617,17 @@ function setupAttendees() {
                                                       [attendee.toString()]);
                 let roleString = cal.calGetString("calendar", "dialog.tooltip.attendeeRole2." + role,
                                                   [userTypeString]);
                 let partstatString = cal.calGetString("calendar", "dialog.tooltip.attendeePartStat2." + partstat,
                                                       [label]);
                 let tooltip = cal.calGetString("calendar", "dialog.tooltip.attendee.combined",
                                                [roleString, partstatString]);
 
-                let del = cal.resolveDelegation(attendee, window.attendees);
+                let del = cal.itip.resolveDelegation(attendee, window.attendees);
                 if (del.delegators != "") {
                     del.delegators = cal.calGetString("calendar",
                                                       "dialog.attendee.append.delegatedFrom",
                                                       [del.delegators]);
                     label += " " + del.delegators;
                     tooltip += " " + del.delegators;
                 }
                 if (del.delegatees != "") {
--- a/calendar/base/content/dialogs/calendar-invitations-list.xml
+++ b/calendar/base/content/dialogs/calendar-invitations-list.xml
@@ -176,33 +176,33 @@
                     organizerString += org.id.replace(/^mailto:/i, "");
                 }
             }
             organizerLabel.setAttribute("value", organizerString);
 
             let attendeeLabel = document.getAnonymousElementByAttribute(
                 this, "anonid", "attendee");
             let attendeeString = this.mStrings.attendee;
-            let att = cal.getInvitedAttendee(aItem);
+            let att = cal.itip.getInvitedAttendee(aItem);
             if (att) {
                 if (att.commonName && att.commonName.length > 0) {
                     attendeeString += att.commonName;
                 } else if (att.id) {
                     attendeeString += att.id.replace(/^mailto:/i, "");
                 }
             }
             attendeeLabel.setAttribute("value", attendeeString);
             this.setAttribute("itemId", aItem.hashId);
         ]]></body>
       </method>
 
       <method name="getCalendarItemParticipationStatus">
         <parameter name="aItem"/>
         <body><![CDATA[
-            let att = cal.getInvitedAttendee(aItem);
+            let att = cal.itip.getInvitedAttendee(aItem);
             return (att ? att.participationStatus : null);
         ]]></body>
       </method>
 
       <method name="setCalendarItemParticipationStatus">
         <parameter name="aItem"/>
         <parameter name="aStatus"/>
         <body><![CDATA[
--- a/calendar/base/modules/calItipUtils.jsm
+++ b/calendar/base/modules/calItipUtils.jsm
@@ -322,17 +322,17 @@ var calitip = {
             if (foundItems && foundItems.length) {
                 data.showItems.push("imipDetailsButton");
                 if (itipItem.receivedMethod == "COUNTER" && itipItem.sender) {
                     if (disallowedCounter) {
                         data.label = _gs("imipBarDisallowedCounterText");
                     } else {
                         let comparison;
                         for (let item of itipItem.getItemList({})) {
-                            let attendees = cal.getAttendeesBySender(
+                            let attendees = cal.itip.getAttendeesBySender(
                                     item.getAttendees({}),
                                     itipItem.sender
                             );
                             if (attendees.length == 1) {
                                 comparison = calitip.compareSequence(item, foundItems[0]);
                                 if (comparison == 1) {
                                     data.label = _gs("imipBarCounterErrorText");
                                     break;
@@ -1790,17 +1790,17 @@ ItipItemFinder.prototype = {
                                 case "REPLY": {
                                     let attendees = itipItemItem.getAttendees({});
                                     if (method == "REPLY") {
                                         cal.ASSERT(
                                             attendees.length == 1,
                                             "invalid number of attendees in REPLY!"
                                         );
                                     } else {
-                                        attendees = cal.getAttendeesBySender(
+                                        attendees = cal.itip.getAttendeesBySender(
                                             attendees,
                                             this.mItipItem.sender
                                         );
                                         cal.ASSERT(
                                             attendees.length == 1,
                                             "ambiguous resolution of replying attendee in COUNTER!"
                                         );
                                     }
--- a/calendar/itip/calItipEmailTransport.js
+++ b/calendar/itip/calItipEmailTransport.js
@@ -124,17 +124,17 @@ calItipEmailTransport.prototype = {
                     "itipDeclineCounterBody",
                     [item.organizer ? item.organizer.toString() : "", summary],
                     "lightning"
                 );
                 break;
             }
             case "REPLY": {
                 // Get my participation status
-                let att = cal.getInvitedAttendee(item, aItipItem.targetCalendar);
+                let att = cal.itip.getInvitedAttendee(item, aItipItem.targetCalendar);
                 if (!att && aItipItem.identity) {
                     att = item.getAttendeeById(cal.email.prependMailTo(aItipItem.identity));
                 }
                 if (!att) { // should not happen anymore
                     return false;
                 }
 
                 // work around BUG 351589, the below just removes RSVP:
--- a/calendar/lightning/content/imip-bar.js
+++ b/calendar/lightning/content/imip-bar.js
@@ -318,17 +318,17 @@ var ltnImipBar = {
                     QueryInterface: XPCOMUtils.generateQI([Components.interfaces.calIOperationListener]),
                     onOperationComplete: function(aCalendar, aStatus, aOperationType, aId, aDetail) {
                         if (Components.isSuccessCode(aStatus) && isDeclineCounter) {
                             // TODO: move the DECLINECOUNTER stuff to actionFunc
                             aItipItem.getItemList({}).forEach(aItem => {
                                 // we can rely on the received itipItem to reply at this stage
                                 // already, the checks have been done in cal.itip.processFoundItems
                                 // when setting up the respective aActionFunc
-                                let attendees = cal.getAttendeesBySender(
+                                let attendees = cal.itip.getAttendeesBySender(
                                     aItem.getAttendees({}),
                                     aItipItem.sender
                                 );
                                 let status = true;
                                 if (attendees.length == 1 && ltnImipBar.foundItems &&
                                     ltnImipBar.foundItems.length) {
                                     // we must return a message with the same sequence number as the
                                     // counterproposal - to make it easy, we simply use the received
@@ -397,17 +397,17 @@ var ltnImipBar = {
                     let proposedItem = ltnImipBar.itipItem.getItemList({})[0];
                     let proposedRID = proposedItem.getProperty("RECURRENCE-ID");
                     if (proposedRID) {
                         // if this is a counterproposal for a specific occurrence, we use
                         // that to compare with
                         item = item.recurrenceInfo.getOccurrenceFor(proposedRID).clone();
                     }
                     let parsedProposal = ltn.invitation.parseCounter(proposedItem, item);
-                    let potentialProposers = cal.getAttendeesBySender(
+                    let potentialProposers = cal.itip.getAttendeesBySender(
                         proposedItem.getAttendees({}),
                         ltnImipBar.itipItem.sender
                     );
                     let proposingAttendee = potentialProposers.length == 1 ?
                                             potentialProposers[0] : null;
                     if (proposingAttendee &&
                         ["OK", "OUTDATED", "NOTLATESTUPDATE"].includes(parsedProposal.result.type)) {
                         counterProposal = {
@@ -468,17 +468,17 @@ var ltnImipBar = {
                 let dialogTitle = ltnGetString("lightning", "confirmProcessInvitationTitle");
                 if (delTime && !Services.prompt.confirm(window, dialogTitle, dialogText)) {
                     return false;
                 }
             }
 
             if (aParticipantStatus == "X-SAVECOPY") {
                 // we create and adopt copies of the respective events
-                let saveitems = ltnImipBar.itipItem.getItemList({}).map(cal.getPublishLikeItemCopy.bind(cal));
+                let saveitems = ltnImipBar.itipItem.getItemList({}).map(cal.itip.getPublishLikeItemCopy.bind(cal));
                 if (saveitems.length > 0) {
                     let methods = { receivedMethod: "PUBLISH", responseMethod: "PUBLISH" };
                     let newItipItem = cal.itip.getModifiedItipItem(ltnImipBar.itipItem,
                                                                    saveitems, methods);
                     // control to avoid processing _execAction on later user changes on the item
                     let isFirstProcessing = true;
                     // setup callback and trigger re-processing
                     let storeCopy = function(aItipItem, aRc, aActionFunc, aFoundItems) {
--- a/calendar/lightning/modules/ltnInvitationUtils.jsm
+++ b/calendar/lightning/modules/ltnInvitationUtils.jsm
@@ -36,17 +36,17 @@ ltn.invitation = {
                     header = ltn.getString("lightning",
                                            "itipCancelBody",
                                            [organizerString, summary]);
                     break;
                 case "COUNTER":
                     // falls through
                 case "REPLY": {
                     let attendees = item.getAttendees({});
-                    let sender = cal.getAttendeesBySender(attendees, aItipItem.sender);
+                    let sender = cal.itip.getAttendeesBySender(attendees, aItipItem.sender);
                     if (sender.length == 1) {
                         if (aItipItem.responseMethod == "COUNTER") {
                             header = cal.calGetString("lightning",
                                                       "itipCounterBody",
                                                       [sender[0].toString(), summary],
                                                       "lightning");
                         } else {
                             let statusString = (sender[0].participationStatus == "DECLINED" ?
@@ -231,17 +231,17 @@ ltn.invitation = {
         doc.getElementById("imipHtml-organizer-row").hidden = !aEvent.organizer;
 
         let setupAttendee = function(aAttendee) {
             let row = attendeeTemplate.cloneNode(true);
             row.removeAttribute("id");
             row.removeAttribute("hidden");
 
             // resolve delegatees/delegators to display also the CN
-            let del = cal.resolveDelegation(aAttendee, attendees);
+            let del = cal.itip.resolveDelegation(aAttendee, attendees);
             if (del.delegators != "") {
                 del.delegators = " " + ltn.getString("lightning", "imipHtml.attendeeDelegatedFrom",
                                                      [del.delegators]);
             }
 
             // display itip icon
             let role = aAttendee.role || "REQ-PARTICIPANT";
             let partstat = aAttendee.participationStatus || "NEEDS-ACTION";
--- a/calendar/providers/gdata/components/calGoogleCalendar.js
+++ b/calendar/providers/gdata/components/calGoogleCalendar.js
@@ -434,17 +434,17 @@ calGoogleCalendar.prototype = {
             request.calendar = this;
             if (cal.item.isEvent(aNewItem)) {
                 let googleId = getGoogleId(aNewItem, this.offlineStorage);
                 request.uri = this.createEventsURI("events", googleId);
 
                 // Updating invitations often causes a forbidden error becase
                 // some parts are not writable. Using PATCH ignores anything
                 // that isn't allowed.
-                if (cal.isInvitation(aNewItem)) {
+                if (cal.itip.isInvitation(aNewItem)) {
                     request.type = request.PATCH;
                 }
 
                 if (Preferences.get("calendar.google.sendEventNotifications", false)) {
                     request.addQueryParameter("sendNotifications", "true");
                 }
             } else if (cal.item.isToDo(aNewItem)) {
                 request.uri = this.createTasksURI("tasks", aNewItem.id);
--- a/calendar/test/unit/test_calutils.js
+++ b/calendar/test/unit/test_calutils.js
@@ -115,17 +115,17 @@ function getAttendeesBySender_test() {
             let attendee = cal.createAttendee();
             attendee.id = att.id;
             if (att.sentBy) {
                 attendee.setProperty("SENT-BY", att.sentBy);
             }
             attendees.push(attendee);
         }
         let detected = [];
-        cal.getAttendeesBySender(attendees, test.input.sender).forEach(att => {
+        cal.itip.getAttendeesBySender(attendees, test.input.sender).forEach(att => {
             detected.push(att.id);
         });
         ok(detected.every(aId => test.expected.includes(aId)), "(test #" + i + " ok1)");
         ok(test.expected.every(aId => detected.includes(aId)), "(test #" + i + " ok2)");
     }
 }
 
 function getRecipientList_test() {
@@ -293,17 +293,17 @@ function resolveDelegation_test() {
         let attendees = [];
         for (let att of test.input.attendees) {
             let attendee = cal.createAttendee();
             attendee.icalString = att;
             attendees.push(attendee);
         }
         let attendee = cal.createAttendee();
         attendee.icalString = test.input.attendee;
-        let result = cal.resolveDelegation(attendee, attendees);
+        let result = cal.itip.resolveDelegation(attendee, attendees);
         equal(result.delegatees, test.expected.delegatees, "(test #" + i + " - delegatees)");
         equal(result.delegators, test.expected.delegators, "(test #" + i + " - delegators)");
     }
 }
 
 function validateRecipientList_test() {
     let data = [{
         input: "first.last@example.net",
--- a/calendar/test/unit/test_gdata_provider.js
+++ b/calendar/test/unit/test_gdata_provider.js
@@ -1282,17 +1282,17 @@ add_task(function* test_modify_invitatio
     // Case #1: User is attendee
     let client = yield gServer.getClient();
     let pclient = cal.async.promisifyCalendar(client.wrappedJSObject);
 
     let items = yield pclient.getAllItems();
     equal(items.length, 1);
 
     let item = items[0];
-    let att = cal.getInvitedAttendee(item);
+    let att = cal.itip.getInvitedAttendee(item);
     let newItem = item.clone();
 
     notEqual(att, null);
     equal(att.id, "mailto:" + attendee.email);
     equal(att.participationStatus, "NEEDS-ACTION");
 
     newItem.removeAttendee(att);
     att = att.clone();