diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Features/GAB/GABHandler.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Features/GAB/GABHandler.cs index a8b7106..ddcbae0 100644 --- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Features/GAB/GABHandler.cs +++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Features/GAB/GABHandler.cs @@ -327,7 +327,7 @@ namespace Acacia.Features.GAB return null; // Scan a few of the newest items, in case there is some junk in the ZPush folder - // TODO: this shouldn't happen in production. + // This shouldn't happen in production, but check anyway. int i = 0; foreach(IItem item in Folder.Items.Sort("LastModificationTime", true)) { diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/AddressBookWrapper.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/AddressBookWrapper.cs index 515fd61..5589974 100644 --- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/AddressBookWrapper.cs +++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/AddressBookWrapper.cs @@ -33,7 +33,6 @@ namespace Acacia.Stubs.OutlookWrappers } - // TODO: it would be nice if this could return IAddressBook public override IFolder Clone() { return new AddressBookWrapper(CloneComObject()); diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/FolderWrapper.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/FolderWrapper.cs index fdfab8f..78b56ae 100644 --- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/FolderWrapper.cs +++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/FolderWrapper.cs @@ -343,10 +343,8 @@ namespace Acacia.Stubs.OutlookWrappers { if (_beforeItemMove != null) { - // TODO: there is a tiny potential for a leak here, if there is an exception in the wrap methods. Should - // only happen if Outlook sends the wrong type object though - using (IItem itemWrapped = Mapping.Wrap(item)) - using (IFolder targetWrapped = Mapping.Wrap(target)) + using (IItem itemWrapped = Mapping.Wrap(item, false)) + using (IFolder targetWrapped = Mapping.Wrap(target, false)) { if (itemWrapped != null && targetWrapped != null) { @@ -354,11 +352,6 @@ namespace Acacia.Stubs.OutlookWrappers } } } - else - { - // TODO: check this - ComRelease.Release(item, target); - } } catch(System.Exception e) { diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/Mapping.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/Mapping.cs index 050491f..3bddb65 100644 --- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/Mapping.cs +++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/Mapping.cs @@ -105,7 +105,7 @@ namespace Acacia.Stubs.OutlookWrappers if (wrapped is Type) return (Type)wrapped; - // TODO: release if required + // Release if required if (wrapped != null) wrapped.Dispose(); return default(Type); diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/OutlookWrapper.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/OutlookWrapper.cs index d798c10..0618d79 100644 --- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/OutlookWrapper.cs +++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/OutlookWrapper.cs @@ -124,7 +124,7 @@ namespace Acacia.Stubs.OutlookWrappers return null; return val; } - catch(System.Exception) { return null; } // TODO: is this fine everywhere? + catch(System.Exception) { return null; } } public void SetProperty(string property, object value) diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/RecipientWrapper.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/RecipientWrapper.cs index ea4b032..a43ab23 100644 --- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/RecipientWrapper.cs +++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/RecipientWrapper.cs @@ -37,7 +37,6 @@ namespace Acacia.Stubs.OutlookWrappers get { return _item.Address; - // TODO:? return _item.AddressEntry.Address } } diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/StoresWrapper.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/StoresWrapper.cs index 2ad6dbc..386952c 100644 --- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/StoresWrapper.cs +++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/StoresWrapper.cs @@ -49,17 +49,18 @@ namespace Acacia.Stubs.OutlookWrappers public void Start() { // Check existing stores - // TODO: do this in background? foreach(NSOutlook.Store store in _item) { - StoreAdded(store); + Tasks.Task(null, "AddStore", () => + { + StoreAdded(store); + }); } // Register for new stores // The store remove event is not sent, so don't bother registering for that _item.StoreAdd += StoreAdded; - if (GlobalOptions.INSTANCE.AccountTimer) { // Set up timer to check for removed accounts @@ -70,42 +71,59 @@ namespace Acacia.Stubs.OutlookWrappers /// /// Event handler for Stores.StoreAdded event. /// - private void StoreAdded(NSOutlook.Store s) + private void Event_StoreAdded(NSOutlook.Store _) { - IStore store = null; try { // Accessing the store object causes random crashes, simply iterate to find new stores - Logger.Instance.Trace(this, "StoreAdded: {0}", s.StoreID); + Logger.Instance.Trace(this, "StoreAdded"); foreach (NSOutlook.Store rawStore in _item) { if (!_accountsByStoreId.ContainsKey(rawStore.StoreID)) { - store = new StoreWrapper(rawStore); - Logger.Instance.Trace(this, "New store: {0}", rawStore.DisplayName); - AccountWrapper account = TryCreateFromRegistry(store); - if (account == null) - { - // Add it to the cache so it is not evaluated again. - _accountsByStoreId.Add(store.StoreID, null); - Logger.Instance.Trace(this, "Not an account store: {0}", store.DisplayName); - store.Dispose(); - } - else - { - // Account has taken ownership of the store - Logger.Instance.Trace(this, "New account store: {0}: {1}", store.DisplayName, account); - OnAccountDiscovered(account); - } + StoreAdded(rawStore); } else ComRelease.Release(rawStore); } } catch (System.Exception e) { - Logger.Instance.Error(this, "StoreAdded Exception: {0}", e); - if (store != null) - store.Dispose(); + Logger.Instance.Error(this, "Event_StoreAdded Exception: {0}", e); + } + } + + /// + /// Performs the actions required to handle a new store. + /// + /// The new store. Ownership is transferred + private void StoreAdded(NSOutlook.Store rawStore) + { + IStore store = new StoreWrapper(rawStore); + try + { + Logger.Instance.Trace(this, "New store: {0}", rawStore.DisplayName); + AccountWrapper account = TryCreateFromRegistry(store); + if (account == null) + { + // Add it to the cache so it is not evaluated again. + _accountsByStoreId.Add(store.StoreID, null); + Logger.Instance.Trace(this, "Not an account store: {0}", store.DisplayName); + } + else + { + Logger.Instance.Trace(this, "New account store: {0}: {1}", store.DisplayName, account); + // Account has taken ownership of the store + store = null; + OnAccountDiscovered(account); + } + } + catch (System.Exception e) + { + Logger.Instance.Error(this, "Event_StoreAdded Exception: {0}", e); + } + finally + { + store?.Dispose(); } }