AfterItemMove?

Add-in Express™ Support Service
That's what is more important than anything else

AfterItemMove?
 
Subscribe
Sandra Watt




Posts: 8
Joined: 2021-01-22
Hi there,

Is there a way to take action in Outlook after an item has moved into a folder? I thought ItemAdd would do that, but when I move a message from Inbox to another folder, it doesn't fire.

Thanks,
Sandra
Posted 01 Feb, 2021 20:40:21 Top
Sandra Watt




Posts: 8
Joined: 2021-01-22
I should add that I've tried BeforeItemMove, but it's too early. Ideally I need the item to have already moved.
Posted 01 Feb, 2021 20:41:32 Top
Sandra Watt




Posts: 8
Joined: 2021-01-22
I see this in another post about ItemAdd

ItemsEvents.ConnectTo(AddinExpress.MSO.ADXOlDefaultFolders.olFolderInbox, True)

I think that's the answer - use ItemAdd rather than BeforeItemMove.

However, I need to react to ItemAdd on any of 144 specific folders. Do I have to .ConnectTo each one??

Sorry for the addendums. :)

Thanks,
Sandra
Posted 01 Feb, 2021 20:49:02 Top
Andrei Smolin


Add-in Express team


Posts: 17613
Joined: 2006-05-11
Hello Sandra,

Yes, you'd need to connect to all of them. But maybe you are okay to intercept BeforeItemMove and assume that in 5 seconds the item is already landed to the target folder?

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 02 Feb, 2021 02:05:31 Top
Sandra Watt




Posts: 8
Joined: 2021-01-22
Ok so two-pronged follow-up then.

1. Using ItemAdd on 144 folders. Is it a significant impact if I do that? Like, will it take a lot of time / performance impact while Connecting them all. Or maybe it will slow down Outlook actions that users take, monitoring all those folders. Or maybe it will have a large memory impact setting up 144 of those... ? Or is it just 144 little objects in memory without much impact at all?

2. Taking action 5 seconds later. As long as I'm running code in BeforeItemMove, the item doesn't move. It only moves once that event handler is finished. So, in BeforeItemMove, I would need to take no action except to make note of which item has just moved, and call/trigger/queue something else to actually do action on the moved item. Something like SendMessage?

Thanks so much!
Sandra
Posted 02 Feb, 2021 08:39:02 Top
Andrei Smolin


Add-in Express team


Posts: 17613
Joined: 2006-05-11
Hello Sandra,

With BeforeItemMove there's a simpler way. I assume you know (or you can find out when the add-in starts) all the 144 folder paths.

When BeforeItemMove occurs, you check whether the target folder is one of them. Then you check if the dictionary of the System.Generic.Dictionary<string, OutlookItemsEvents1> type already contains an item for the target folder. If not, you create a new OutlookItemsEvents1 class (it descends from ADXOutlookItemsEvents and it intercepts the ItemAdd event in the specified folder) and add it to the dictionary using the folder path as key.

This means you only connect to folders for which BeforeItemMove was triggered.

If you to connect to all of these folder because they may be modified from outside of your Outlook, you should assume that connecting to them may take a while. At least I'm almost sure there will be scenarios were this delay will be significant enough for your users to complain. Imagine a poor connection line.

To avoid delays on the UI thread, you should split this task in chunks and execute one chunk (say, connect to 5 folders) in a go, then wait for a while (300-500ms), then execute the next chunk, etc. After thinking about the 5-sec approach, I admit that it would require you to do the same: split the task in chunks and execute one chunk in a go. The 5-sec approach may be faster only if you know the folder in which the email is going to land; this is a variation of the BeforeItemMove scenario. Otherwise you'll need to scan the 144 folders trying to find the target one.

The one-chunk-in-a-go scenario requires using SendMessage to signal the begin and end of the chunk, etc. A simple approach to waiting between chunks is to start a Thread executing Thread.Sleep(someMilliseconds) and then sending the StartHandlingNextChunk message.

If no poor-line scenario is possible, you can check how this works on your side: it is possible that 144 folders is sort of okay.

But do not start connecting to all of them at startup: wait for a little while. SendMessage is pretty useful here.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 02 Feb, 2021 09:39:04 Top
Sandra Watt




Posts: 8
Joined: 2021-01-22
Andrei, this is terrific information! I can't wait to dig in. It may be Friday before I do, as I have other clients till then, but I think I'm well armed now! Thanks so much, and I'll report back the approach that worked in the end.
-Sandra
Posted 02 Feb, 2021 16:22:50 Top
Andrei Smolin


Add-in Express team


Posts: 17613
Joined: 2006-05-11
Great!

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 03 Feb, 2021 10:08:26 Top
Sandra Watt




Posts: 8
Joined: 2021-01-22
So just to follow up. I ended up using the subfolders method. It's instant, so works great for now.

ItemsEvents.ConnectSubFolders();
Posted 11 Mar, 2021 18:02:52 Top
Andrei Smolin


Add-in Express team


Posts: 17613
Joined: 2006-05-11
Thank you very much!

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 12 Mar, 2021 03:39:51 Top