• Sign in
 
  •  
  • MSDN Blogs
  • Microsoft Blog Images
  • More ...

  • Blog Home
  • About
  • Email Blog Author
  • Share this
  • RSS for posts
  • Atom
  • RSS for comments
  • CDO (25)
  • Code Snippet (43)
  • Custom Providers (17)
  • Debugging (7)
  • DevMsgTeam (301)
  • Documentation (109)
  • DST (8)
  • EWS (7)
  • Exchange (109)
  • Gotchas (97)
  • Hotfix (28)
  • MAPI (240)
  • MAPI Download (54)
  • MFCMAPI (101)
  • MSDN (59)
  • Non Dev (11)
  • OOM (17)
  • Outlook (171)
  • Outlook 2007 Auxiliary Reference (45)
  • Outlook Integration API (12)
  • Protocol Docs (20)
  • PST/OST (23)
  • Referrals (8)
  • Vista (12)
  • WrapPST (18)
Links:
  • Download MFCMAPI
  • MFCMAPI on Facebook
  • Troubleshooting Outlook Crashes
  • Office Update Center
  • Developer Messaging Team Blog
This site is provided "AS IS" with no warranties, and confers no rights. Use of included code samples are subject to the terms specified in the Terms of Use.
Archives
  • May 2013 (3)
  • April 2013 (1)
  • March 2013 (2)
  • February 2013 (2)
  • January 2013 (2)
  • December 2012 (4)
  • November 2012 (2)
  • October 2012 (2)
  • September 2012 (1)
  • August 2012 (3)
  • June 2012 (2)
  • May 2012 (1)
  • April 2012 (3)
  • March 2012 (3)
  • February 2012 (3)
  • January 2012 (1)
  • December 2011 (3)
  • November 2011 (1)
  • October 2011 (3)
  • September 2011 (1)
  • August 2011 (1)
  • July 2011 (4)
  • June 2011 (3)
  • May 2011 (3)
  • April 2011 (3)
  • March 2011 (5)
  • February 2011 (1)
  • January 2011 (2)
  • December 2010 (1)
  • November 2010 (4)
  • October 2010 (1)
  • September 2010 (3)
  • August 2010 (5)
  • July 2010 (3)
  • June 2010 (3)
  • May 2010 (1)
  • April 2010 (3)
  • March 2010 (3)
  • February 2010 (3)
  • January 2010 (2)
  • December 2009 (3)
  • November 2009 (5)
  • October 2009 (4)
  • September 2009 (5)
  • August 2009 (5)
  • July 2009 (11)
  • June 2009 (6)
  • May 2009 (5)
  • April 2009 (3)
  • March 2009 (18)
  • February 2009 (10)
  • January 2009 (3)
  • December 2008 (2)
  • November 2008 (2)
  • October 2008 (5)
  • September 2008 (4)
  • August 2008 (10)
  • July 2008 (6)
  • June 2008 (8)
  • May 2008 (2)
  • April 2008 (4)
  • March 2008 (2)
  • February 2008 (2)
  • January 2008 (5)
  • December 2007 (3)
  • November 2007 (2)
  • October 2007 (3)
  • September 2007 (1)
  • August 2007 (4)
  • July 2007 (5)
  • June 2007 (3)
  • May 2007 (4)
  • April 2007 (1)
  • March 2007 (6)
  • February 2007 (3)
  • January 2007 (2)
  • December 2006 (4)
  • November 2006 (3)
  • October 2006 (1)
  • August 2006 (1)
  • June 2006 (5)
  • May 2006 (5)
  • December 2005 (1)
  • November 2005 (4)
  • October 2005 (2)
  • September 2005 (1)
  • April 2005 (3)
  • December 2004 (2)
  • September 2004 (2)
  • August 2004 (3)
  • July 2004 (3)

Outlook Rules - At Least When You Tell It To

MSDN Blogs > SGriffin's MAPI Internals > Outlook Rules - At Least When You Tell It To

Outlook Rules - At Least When You Tell It To

Stephen Griffin - MSFT
11 Jan 2008 4:50 PM
  • Comments 20

[This is now documented here: http://msdn.microsoft.com/en-us/library/ff960239.aspx ]

We just had a customer whose Wrapped PST based store wasn't getting rules to fire in Outlook 2007, when everything was working in 2003. In the course of figuring their issue out, we found a few flags that we should have documented before.

Suppose you built a message store based on the Wrapped PST provider. When your new messages are delivered to your backend database and you create matching messages in the PST, how do you inform Outlook that a new mail has arrived? In Outlook 2003, the way you solve this is to use the IMAPISupport object that was passed to you during logon. From there, you would call Notify, passing fnewNewMail and the details of the new message. When Outlook gets this new message notification, it passes the Entry ID over to the rules engine and everything is hunky dory.

Unfortunately, this doesn't work in Outlook 2007. You fire your notification, Outlook sees it, then Outlook decides not to run rules on the message. Why? Because when Outlook 2007 looked at PR_STORE_SUPPORT_MASK on the wrapped PST, it found the STORE_ITEMPROC flag was set. This means the wrapped PST is an "Item Proc" store, and handles rules differently. Without getting into too many details about "Item Proc", the general idea is that such stores will feed new items into a pipeline where rules, junk mail, and spam processing can happen before listening clients will get a notification. This concept was introduced in Outlook 2007 as a way to streamline the processing.

When an Item Proc store knows it has a new message, it calls a special callback function in Outlook to run it through the rules engine. In the PST, the concept of "newly delivered message" is handled through internal flags. These flags may be set or not set depending on how the message arrives in the PST. For instance, if the PST is being used as an OST and new mail is synchronized from an Exchange server, the flags will be set. Similarly, when the PST is being used as a back end POP3/IMAP, the flags will be set when a new mail is delivered.

For a wrapped PST, however, the way you set these flags is to pass ITEMPROC_FORCE in the SaveChanges call when the newly delivered message is committed to the store. This tells the PST to set its internal flags and mark the item as being eligible for the callback.

There's a twist though. If the mail being delivered to the PST came from Exchange, then rules would already have run on the server and the message has to be handled differently. And the default assumption is that the mail came from Exchange. So you have to indicate that Exchange was not the source of the mail by also passing the NON_EMS_XP_SAVE flag. When both flags are passed, the item will go through rules/junk/spam processing as soon as you call SaveChanges if Outlook is running, and shortly after Outlook starts if it wasn't.

Definitions of the new flags:

ITEMPROC_FORCE 0x00000800 A client can call IMAPIProp::SaveChanges setting the ITEMPROC_FORCE flag in the ulFlags parameter to indicate that a message is being delivered to a PST and should be eligible for rules processing. This flag is only available if the message is being saved to a PST. A wrapped PST store would use this flag to indicate new mail is being delivered through IMAPIFolder::CreateMessage and IMAPIProp::SaveChanges. If this flag is not passed in combination with NON_EMS_XP_SAVE when a message is delivered in this fashion rules will not fire.
NON_EMS_XP_SAVE 0x00001000 A client can call IMAPIProp::SaveChanges setting the NON_EMS_XP_SAVE flag in the ulFlags parameter to indicate that a message is being delivered to a PST and should be eligible for rules processing, and that the mail was not delivered from Exchange. This flag is only available if the message is being saved to a PST. A wrapped PST store would use this flag to indicate new mail is being delivered through IMAPIFolder::CreateMessage and IMAPIProp::SaveChanges. If this flag is not passed in combination with ITEMPROC_FORCE when a message is delivered in this fashion rules will not fire.
STORE_ITEMPROC 0x00200000 The message store implements Item Proc logic. Outlook 2007 will not fire rules on messages in this store when it receives an fnevNewMessage notification.
  • 20 Comments
MAPI, WrapPST, Documentation, Outlook 2007 Auxiliary Reference, DevMsgTeam, MSDN
Comments
  • Lev
    13 Jan 2008 12:13 PM

    If I'm offline in OST mode, create a new message and set the above flags before the first SaveChanges, should I expect to see rules kick in?

  • Stephen Griffin - MSFT
    13 Jan 2008 12:41 PM

    To clarify, those flags are for SaveChanges, so you would set them in, not before, the first SaveChanges call. That said, I don't know about the OST case. Give it a test and let us know what you find.

  • Lev
    13 Jan 2008 6:54 PM

    Works like a charm with OST. ( tested with OL 07 )

    Thanks!

    P.S.  Is there any way from the client side to trigger a new-mail notification as well? ( create a message, populate appropriately, call SaveChanges & make Outlook think that it's a new mail )...  I don't keep my hopes up here, but it certainly would be nice.

  • Stephen Griffin - MSFT
    13 Jan 2008 7:54 PM

    Well, as noted, if you're a message store, like a wrapped PST, you got a support object during Logon that you can use to send notifications. If you're not a mesage store, then I think you're out of luck.

  • Lev
    14 Jan 2008 12:52 AM

    To avoid crisis after rolling out an update, is setting NON_EMS_XP_SAVE to indicate that "the mail was not delivered from Exchange" going to affect anything other than rule processing?

    Thanks.

  • Mahesh
    14 Jan 2008 1:26 AM

    ==

    "Item Proc", the general idea is that such stores will feed new items into a pipeline where rules, junk mail, and spam processing can happen before listening clients will get a notification

    ===

    You mention Junk mail here. Is it possible similarly to get client Junk mail filters working with the wrapped PST provider (Third party MAPI providers).

    Thanks,

    Mahesh

  • Stephen Griffin - MSFT
    14 Jan 2008 9:15 AM

    Lev - as far as I can tell, right now NON_EMS_XP_SAVE only affects rules.

    Mahesh - You should look at SPAMFILTER_ONSAVE: http://msdn2.microsoft.com/en-us/library/bb820947.aspx

  • Lev
    17 Jan 2008 12:40 AM

    What does one need to do to trigger rules on the sending side? ( as opposite to the receiving side above ).

    Thanks.

  • Stephen Griffin - MSFT
    17 Jan 2008 2:51 PM

    Hrmm - I didn't investigate sender rules.

  • Hai
    18 Jan 2008 10:25 AM

    Griffin, is there anything else that needs to be done for this to work for a normal PST in Outlook 2007? I tried to set both flags when calling SaveChanges() the first time for a new message added to a PST. The Client Side Rule does not fire on it. Outlook 2007 shows the new mail desktop alert notification window, but the rule does not fire after that.

    The only difference is that I am using a normal PST instead of the Wrapped PST. However, using the normal PST in Outlook 2003 does fire the Client Side Rule properly...

    Should I include these flags each time calling SaveChanges(), or just for the very first call? Also does calling SaveChanges() with these flags multiple times has any side-effects?

    Thanks.

  • Hai
    18 Jan 2008 4:54 PM

    Following up for my previous comment, actually the Client Side Rule did fire :-) Because I was testing a rule to set a category, and there is a default rule in Outlook 2007 to remove category...

    However, it did only work partially so far. After the rule is fire, the category is added for the message. Then it looks like the SetProps() + SaveChanges() are not called on the message to commit the change to PST.

    So, the really next question is: does the Client Side Rule makes the change directly from within PST, or should the rule fire through the wrapping message store interface?

  • Mahesh
    21 Jan 2008 4:16 AM

    After setting these flags if I call getcontents table on the Inbox, sometimes the new message saved is not being listed in the contents table. Any idea how to overcome this ?

    Thanks,

  • Hai
    23 Jan 2008 5:23 PM

    "When an Item Proc store knows it has a new message, it calls a special callback function in Outlook to run it through the rules engine."

    Does this means that the PST gives out a message interface to Outlook, and Outlook makes changes to the message directly through that interface (or callback)? If this is the case, then it also means that the wrapping store provider has no way to detect that some changes are made under the hood because of a Client-Side Rule.

    Is there a way that the wrapping store provider can detect that some changes will be/has been made because of Client-Side Rule?

    Or, it there a way to restore the Outlook 2003 behavior for Client-Side Rules?

    Thanks,

    Hai

  • Lev
    18 Feb 2008 7:24 PM

    OL 03/SP 3 no longer supports NON_EMS_XP_SAVE | ITEMPROC_FORCE - I get 0x80040106 ( MAPI_E_UNKNOWN_FLAGS )...

  • Stephen Griffin - MSFT
    19 Feb 2008 10:37 AM

    They only ever worked in Outlook 2007. They were never available in 2003. But you don't need to special case your code - check for STORE_ITEMPROC - if it's there, the store supports the flags, if not, it doesn't.

Page 1 of 2 (20 items) 12
Leave a Comment
  • Please add 6 and 6 and type the answer here:
  • Post
  • © 2013 Microsoft Corporation.
  • Terms of Use
  • Trademarks
  • Privacy & Cookies
  • Report Abuse
  • 5.6.426.415