From 90e0029a8ecd7d8f7e35f4501877dae58a8eea05 Mon Sep 17 00:00:00 2001
From: Patrick Simpson
Date: Thu, 9 Feb 2017 16:00:21 +0100
Subject: [PATCH] Added option to disable item event hooking
---
.../AcaciaZPushPlugin/Features/Feature.cs | 5 +----
.../AcaciaZPushPlugin/Features/GAB/FeatureGAB.cs | 2 +-
.../Features/ReplyFlags/FeatureReplyFlags.cs | 14 ++++++++++----
.../Features/SendAs/FeatureSendAs.cs | 10 ++++++++--
.../AcaciaZPushPlugin/GlobalOptions.cs | 9 +++++++++
.../AcaciaZPushPlugin/Stubs/IAddIn.cs | 2 ++
.../Stubs/OutlookWrappers/AddInWrapper.cs | 1 +
.../AcaciaZPushPlugin/ThisAddIn.cs | 16 ++++++++++++++++
8 files changed, 48 insertions(+), 11 deletions(-)
diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Features/Feature.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Features/Feature.cs
index 32ab950..abd39a4 100644
--- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Features/Feature.cs
+++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Features/Feature.cs
@@ -194,14 +194,11 @@ namespace Acacia.Features
#region Event helpers
- private static MailEvents _mailEvents;
protected static MailEvents MailEvents
{
get
{
- if (_mailEvents == null)
- _mailEvents = new MailEvents(ThisAddIn.Instance);
- return _mailEvents;
+ return ThisAddIn.Instance.MailEvents;
}
}
diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Features/GAB/FeatureGAB.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Features/GAB/FeatureGAB.cs
index 2e8d6e9..28b23c6 100644
--- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Features/GAB/FeatureGAB.cs
+++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Features/GAB/FeatureGAB.cs
@@ -64,7 +64,7 @@ namespace Acacia.Features.GAB
public override void Startup()
{
- if (SuppressModifications)
+ if (SuppressModifications && MailEvents != null)
{
MailEvents.BeforeDelete += SuppressEventHandler_Delete;
MailEvents.Write += SuppressEventHandler_Modify;
diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Features/ReplyFlags/FeatureReplyFlags.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Features/ReplyFlags/FeatureReplyFlags.cs
index 2e00658..c03b4fb 100644
--- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Features/ReplyFlags/FeatureReplyFlags.cs
+++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Features/ReplyFlags/FeatureReplyFlags.cs
@@ -47,15 +47,21 @@ namespace Acacia.Features.ReplyFlags
if (ReadEvent)
{
// As a fallback, add an event handler to update the message when displaying it
- MailEvents.Read += UpdateReplyStatus;
+ if (MailEvents != null)
+ {
+ MailEvents.Read += UpdateReplyStatus;
+ }
}
if (SendEvents)
{
// Hook reply and send events to update local state to server
- MailEvents.Reply += OnReply;
- MailEvents.ReplyAll += OnReplyAll;
- MailEvents.Forward += OnForwarded;
+ if (MailEvents != null)
+ {
+ MailEvents.Reply += OnReply;
+ MailEvents.ReplyAll += OnReplyAll;
+ MailEvents.Forward += OnForwarded;
+ }
}
}
diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Features/SendAs/FeatureSendAs.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Features/SendAs/FeatureSendAs.cs
index 0641b13..25c8678 100644
--- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Features/SendAs/FeatureSendAs.cs
+++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Features/SendAs/FeatureSendAs.cs
@@ -49,7 +49,10 @@ namespace Acacia.Features.SendAs
public override void Startup()
{
- MailEvents.ItemSend += MailEvents_ItemSend;
+ if (MailEvents != null)
+ {
+ MailEvents.ItemSend += MailEvents_ItemSend;
+ }
if (SendAsOwner)
{
@@ -57,7 +60,10 @@ namespace Acacia.Features.SendAs
_sharedFolders = ThisAddIn.Instance.GetFeature();
if (_sharedFolders != null)
{
- MailEvents.Respond += MailEvents_Respond;
+ if (MailEvents != null)
+ {
+ MailEvents.Respond += MailEvents_Respond;
+ }
}
}
}
diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/GlobalOptions.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/GlobalOptions.cs
index b31b125..e413474 100644
--- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/GlobalOptions.cs
+++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/GlobalOptions.cs
@@ -118,6 +118,15 @@ namespace Acacia
}
}
+ [AcaciaOption("Enables or disables item event hooking." +
+ "Note that if this is disabled, several features may not work correctly.")]
+ virtual public bool HookItemEvents
+ {
+ get { return GetOption(null, HOOK_ITEM_EVENTS); }
+ set { SetOption(null, HOOK_ITEM_EVENTS, value); }
+ }
+ private static readonly BoolOption HOOK_ITEM_EVENTS = new BoolOption("HookItemEvents", true);
+
#region UI Options
[AcaciaOption("Completely enables or disables modifications to the Outlook UI." +
diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/IAddIn.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/IAddIn.cs
index a581a84..642ebce 100644
--- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/IAddIn.cs
+++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/IAddIn.cs
@@ -1,5 +1,6 @@
using Acacia.Features;
using Acacia.UI.Outlook;
+using Acacia.Utils;
using Acacia.ZPush;
using System;
using System.Collections.Generic;
@@ -16,6 +17,7 @@ namespace Acacia.Stubs
NSOutlook.Application RawApp { get; } // TODO: remove
ZPushWatcher Watcher { get; }
+ MailEvents MailEvents { get; }
IEnumerable Features { get; }
IEnumerable> COMAddIns { get; }
string Version { get; }
diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/AddInWrapper.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/AddInWrapper.cs
index 444a6af..290617f 100644
--- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/AddInWrapper.cs
+++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/AddInWrapper.cs
@@ -85,6 +85,7 @@ namespace Acacia.Stubs.OutlookWrappers
public OutlookUI OutlookUI { get { return _thisAddIn.OutlookUI; } }
public ZPushWatcher Watcher { get { return _thisAddIn.Watcher; } }
+ public MailEvents MailEvents { get { return _thisAddIn.MailEvents; } }
public IEnumerable Features { get { return _thisAddIn.Features; } }
public IEnumerable> COMAddIns
{
diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/ThisAddIn.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/ThisAddIn.cs
index 5db7f0d..36b9a77 100644
--- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/ThisAddIn.cs
+++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/ThisAddIn.cs
@@ -63,6 +63,22 @@ namespace Acacia
private set;
}
+ private MailEvents _mailEvents;
+ public MailEvents MailEvents
+ {
+ get
+ {
+ if (_mailEvents == null)
+ {
+ if (GlobalOptions.INSTANCE.HookItemEvents)
+ {
+ _mailEvents = new MailEvents(Instance);
+ }
+ }
+ return _mailEvents;
+ }
+ }
+
#region Startup / Shutdown
private void ThisAddIn_Startup(object sender, System.EventArgs args)