Bug 1241600 - cannot accept calendar invitation ("This message contains a sent out event that is not in your calendar anymore");r=philipp CLOSED TREE THUNDERBIRD452b1_2016051723_RELBRANCH
authorMakeMyDay <makemyday@gmx-topmail.de>
Sat, 19 Mar 2016 09:58:19 -0400
branchTHUNDERBIRD452b1_2016051723_RELBRANCH
changeset 27075 1c2d8e2b4b20964c08d6576172c0bf3e2acac3cb
parent 27074 4c9a6d612b107d01c23e86a22c8a00dec559cf34
child 27076 4b6dee0de358f03bd8dd26119239043819bc9507
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
bugs1241600
Bug 1241600 - cannot accept calendar invitation ("This message contains a sent out event that is not in your calendar anymore");r=philipp CLOSED TREE
calendar/lightning/content/imip-bar.js
--- a/calendar/lightning/content/imip-bar.js
+++ b/calendar/lightning/content/imip-bar.js
@@ -198,23 +198,42 @@ var ltnImipBar = {
         let data = cal.itip.getOptionsText(itipItem, rc, actionFunc, foundItems);
 
         if (Components.isSuccessCode(rc)) {
             ltnImipBar.itipItem = itipItem;
             ltnImipBar.actionFunc = actionFunc;
             ltnImipBar.foundItems = foundItems;
         }
 
-        // we override the bar label for sent out invitations and in case the event does not exist
+        // We need this to determine whether this is an outgoing or incoming message because
+        // Thunderbird doesn't provide a distinct flag on message level to do so. Relying on
+        // folder flags only may lead to false positives.
+        let isOutgoing = function(aMsgHdr) {
+            let author = aMsgHdr.mime2DecodedAuthor;
+            let isSentFolder = aMsgHdr.folder.flags & nsMsgFolderFlags.SentMail;
+            if (author && isSentFolder) {
+                let am = MailServices.accounts;
+                for (let identity in fixIterator(am.allIdentities,
+                                                 Components.interfaces.nsIMsgIdentity)) {
+                    if (author.includes(identity.email) && !identity.fccReplyFollowParent) {
+                        return true;
+                    }
+                }
+            }
+            return false;
+        }
+
+        // We override the bar label for sent out invitations and in case the event does not exist
         // anymore, we also clear the buttons if any to avoid e.g. accept/decline buttons
-        if (gMessageDisplay.displayedMessage.folder.flags & nsMsgFolderFlags.SentMail) {
-            if (ltnImipBar.foundItems[0]) {
+        if (isOutgoing(gMessageDisplay.displayedMessage)) {
+            if (ltnImipBar.foundItems && ltnImipBar.foundItems[0]) {
                 data.label = ltn.getString("lightning", "imipBarSentText");
             } else {
-                data = {label: ltn.getString("lightning", "imipBarSentButRemovedText")};
+                data = {label: ltn.getString("lightning", "imipBarSentButRemovedText"),
+                        buttons: [], hideMenuItems: []};
             }
         }
 
         imipBar.setAttribute("label", data.label);
         // let's reset all buttons first
         ltnImipBar.resetButtons();
         // menu items are visible by default, let's hide what's not available
         data.hideMenuItems.forEach(aElementId => hideElement(document.getElementById(aElementId)));
@@ -224,17 +243,18 @@ var ltnImipBar = {
         ltnImipBar.conformButtonType();
         ltnImipBar.displayModifications();
     },
 
     /**
      * Displays changes in case of invitation updates in invitation overlay
      */
     displayModifications: function () {
-        if (!ltnImipBar.msgOverlay || !msgWindow || !ltnImipBar.foundItems[0] || !ltnImipBar.itipItem) {
+        if (!ltnImipBar.msgOverlay || !msgWindow || !ltnImipBar.foundItems ||
+            !ltnImipBar.foundItems[0] || !ltnImipBar.itipItem) {
             return;
         }
 
         let msgOverlay = ltnImipBar.msgOverlay;
         let diff = cal.itip.compare(ltnImipBar.itipItem.getItemList({})[0], ltnImipBar.foundItems[0]);
         // displaying chnages is only needed if that is enabled, an item already exists and there are
         // differences
         if (diff != 0 && Preferences.get('calendar.itip.displayInvitationChanges', false)) {