Merge with default sync
authorThomas
Mon, 15 Apr 2019 15:35:42 +0200
branchsync
changeset 2616b9e529090877
parent 2614 105311c70875
parent 2615 ad5b3224993e
child 2617 d0fa927c6a46
Merge with default
     1.1 --- a/Wrappers/WatchedExplorer.cs	Mon Apr 15 08:49:51 2019 +0200
     1.2 +++ b/Wrappers/WatchedExplorer.cs	Mon Apr 15 15:35:42 2019 +0200
     1.3 @@ -181,7 +181,7 @@
     1.4                           *         selects another one. So, in the latter case, we would basically override a user decision.
     1.5                           * Note: This whole procedure is a workaround because we can only set the Explorer's current view and not the folder's
     1.6                           *       current view directly.
     1.7 -                         */                           
     1.8 +                         */
     1.9                          if (customView == null)
    1.10                          {
    1.11                              customView = views.Add(Properties.Resources.LastUsedFolderName, Outlook.OlViewType.olTableView, Outlook.OlViewSaveOption.olViewSaveOptionThisFolderEveryone) as Outlook.TableView;
    1.12 @@ -293,6 +293,32 @@
    1.13          /// </summary>
    1.14          private void Explorer_SelectionChange()
    1.15          {
    1.16 +            // If the current folder is the outbox, don't process
    1.17 +            Outlook.Folder currentFolder = null;
    1.18 +            Outlook.Folder outbox = null;
    1.19 +            Outlook.Store store = null;
    1.20 +            try
    1.21 +            {
    1.22 +                currentFolder = this.Explorer.CurrentFolder as Outlook.Folder;
    1.23 +                store = currentFolder.Store;
    1.24 +                outbox = store.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderOutbox) as Outlook.Folder;
    1.25 +
    1.26 +                if (currentFolder?.EntryID?.Equals(outbox?.EntryID) == true)
    1.27 +                {
    1.28 +                    return;
    1.29 +                }
    1.30 +            }
    1.31 +            catch (Exception ex)
    1.32 +            {
    1.33 +                Log.Error("Explorer_SelectionChange: Error determining if current folder is outbox. " + ex.ToString());
    1.34 +            }
    1.35 +            finally
    1.36 +            {
    1.37 +                currentFolder = null;
    1.38 +                outbox = null;
    1.39 +                store = null;
    1.40 +            }
    1.41 +
    1.42              Outlook.Selection selection = null;
    1.43              try
    1.44              {
    1.45 @@ -302,62 +328,58 @@
    1.46                  /* Do only process the item if one individual item is selected.
    1.47                   * Do not process a selected range of items.
    1.48                   */
    1.49 -                if (selection.Count == 1)
    1.50 +                if ((selection.Count == 1) &&
    1.51 +                    (selection[1] is Outlook.MailItem omi))
    1.52                  {
    1.53 -                    this.CurrentMailItem = selection[1] as Outlook.MailItem;
    1.54 -                    if (this.CurrentMailItem != null)
    1.55 +                    this.CurrentMailItem = omi;
    1.56 +                    omi = null;
    1.57 +
    1.58 +                    /* Check if inline response. Note: in Outlook 2010, there is no inline response.
    1.59 +                     * IMPORTANT: Never call Explorer.ActiveInlineResponse on Outlook 2010
    1.60 +                     *            as this might lead to a crash of Outlook (even inside a
    1.61 +                     *            try/catch block)
    1.62 +                     */
    1.63 +                    bool isInlineResponse = false;
    1.64 +                    if (Globals.OutlookVersion != Globals.Version.Outlook2010)
    1.65                      {
    1.66 -                        /* Check if inline response. Note: in Outlook 2010, there is no inline response.
    1.67 -                         * IMPORTANT: Never call Explorer.ActiveInlineResponse on Outlook 2010
    1.68 -                         *            as this might lead to a crash of Outlook (even inside a
    1.69 -                         *            try/catch block)
    1.70 -                         */
    1.71 -                        bool isInlineResponse = false;
    1.72 -                        if (Globals.OutlookVersion != Globals.Version.Outlook2010)
    1.73 +                        Outlook.MailItem inlineResponse = null;
    1.74 +                        try
    1.75                          {
    1.76 -                            Outlook.MailItem inlineResponse = null;
    1.77 -                            try
    1.78 +                            inlineResponse = this.Explorer?.ActiveInlineResponse as Outlook.MailItem;
    1.79 +                            if (inlineResponse != null)
    1.80                              {
    1.81 -                                inlineResponse = this.Explorer?.ActiveInlineResponse as Outlook.MailItem;
    1.82 -                                if (inlineResponse != null)
    1.83 -                                {
    1.84 -                                    isInlineResponse = true;
    1.85 -                                    this.CurrentMailItem = inlineResponse;
    1.86 -                                }
    1.87 -                            }
    1.88 -                            catch (Exception ex)
    1.89 -                            {
    1.90 -                                Log.Error("Explorer_SelectionChange: Error determining whether it is an inline response. " + ex.ToString());
    1.91 -                            }
    1.92 -                            finally
    1.93 -                            {
    1.94 -                                inlineResponse = null;
    1.95 -                            }
    1.96 -
    1.97 -                            /* If a different mail is clicked in an Window, the SelectionChange
    1.98 -                             * event is always called twice. To prevent a double processing, we only
    1.99 -                             * process a mail item if it is different from the last one that has been
   1.100 -                             * processed.
   1.101 -                             */
   1.102 -                            string entryId = isInlineResponse ? null : this.CurrentMailItem?.EntryID;
   1.103 -                            if (entryId?.Equals(lastProcessedEntryId, StringComparison.OrdinalIgnoreCase) == true)
   1.104 -                            {
   1.105 -                                Log.Verbose("Explorer_SelectionChange: Same EntryId as last item. Skipped processing of item with EntryId " + entryId);
   1.106 -                                return;
   1.107 -                            }
   1.108 -                            else
   1.109 -                            {
   1.110 -                                this.lastProcessedEntryId = entryId;
   1.111 +                                isInlineResponse = true;
   1.112 +                                this.CurrentMailItem = inlineResponse;
   1.113                              }
   1.114                          }
   1.115 +                        catch (Exception ex)
   1.116 +                        {
   1.117 +                            Log.Error("Explorer_SelectionChange: Error determining whether it is an inline response. " + ex.ToString());
   1.118 +                        }
   1.119 +                        finally
   1.120 +                        {
   1.121 +                            inlineResponse = null;
   1.122 +                        }
   1.123  
   1.124 -                        // Initialize mail item
   1.125 -                        this.InitializeWindow(isInlineResponse);
   1.126 -                    }                    
   1.127 -                    else
   1.128 -                    {
   1.129 -                        Log.Error("Explorer_SelectionChange: Error getting current selection.");
   1.130 +                        /* If a different mail is clicked in an Window, the SelectionChange
   1.131 +                         * event is always called twice. To prevent a double processing, we only
   1.132 +                         * process a mail item if it is different from the last one that has been
   1.133 +                         * processed.
   1.134 +                         */
   1.135 +                        string entryId = isInlineResponse ? null : this.CurrentMailItem?.EntryID;
   1.136 +                        if (entryId?.Equals(lastProcessedEntryId, StringComparison.OrdinalIgnoreCase) == true)
   1.137 +                        {
   1.138 +                            Log.Verbose("Explorer_SelectionChange: Same EntryId as last item. Skipped processing of item with EntryId " + entryId);
   1.139 +                            return;
   1.140 +                        }
   1.141 +                        else
   1.142 +                        {
   1.143 +                            this.lastProcessedEntryId = entryId;
   1.144 +                        }
   1.145                      }
   1.146 +
   1.147 +                    // Initialize mail item
   1.148 +                    this.InitializeWindow(isInlineResponse);
   1.149                  }
   1.150              }
   1.151              catch (Exception ex)