How to detect deleted IMAP messages using MAPI/Outlook Object Model API

  • Thread starter Thread starter Alex Fostiy
  • Start date Start date
A

Alex Fostiy

Hi,

I would like to find out which messages are marked as deleted in IMAP
mailbox programmatically using MAPI or Outlook Object Model and would be
grateful for any help.

My ultimate goal is to use MAPI to construct a restriction that only returns
messages that are not marked as deleted from IMAP mail folder in addition to
other criteria. I have already implemented the restriction which works well
using FindRow API on Exchange, POP3 and Hotmail message stores.

The only issue is with IMAP where I also get back messages that are already
marked deleted but not yet purged from the IMAP mail server.

Searching various MAPI properties using OutlookSpy shows that no properties
are changed when a message is marked as deleted, except last message
modification time (PR_LAST_MODIFICATION_TIME) which is not reliable for my
needs because it can mean other changes have made to the message besides the
message deletion.

However, the "deleted" state information clearly persists locally since
after Outlook is closed and started again, the message "deleted" state is
still
there and visible with a cross-through line in Outlook folder view.

I am developing an Outlook add-in in C++ and have access to all MAPI and
Outlook COM API.

Thank you in advance,
Alex
 
Dmitry,

Thank you, this works.

One more question I have is this:
After calling GetIDsFromNames with your named property, I get back a
property tag which has no data type set.
I am setting it to PT_LONG before calling HrGetOneProp to read the actual
property value.

Is PT_LONG a correct data type?

This works fine with Outlook 2003 and Outlook 2002 I tested with; Value.l
and Value.b are correctly set to 0 (message not deleted) and 1 (message
deleted), but I would like you to confirm the data type usage.

All the best,
Alex

This seems to be working consistenly across different versions of Outlook
 
Yes, I did, and Outlook spy does not display that named property for a
message. I figured you limited named properties to PS_MAPI and
PS_PUBLIC_STRINGS. GetIDsFromNames lists it but that is the only place it
can be found.

Quick test using PT_BOOLEAN showed incorrect behavior so I'll use PT_LONG.

I have noticed something else in regard to IMAP which is still on the
subject.

If I save a custom property with IMAP message, the API (SetProps,
SaveChanges variety) always return S_OK but my property is never actually
saved judging by the fact that OutlookSpy does not display it.
The same set of API calls work correctly on Exchange and POP3 and I can see
my custom property with OutlookSpy. Hotmail fails consistently with both my
add-in and OutlookSpy.

Here is a twist. If I use OutlookSpy "AddProperty" dialog box to create a
custom property on IMAP message with the same tag value, the data type and
the data value this always succeeds!

Makes me wonder if I create the custom property correctly because the
results are clearly different on IMAP.

Here is a simplified code that saves the property:
SPropValue pv;
pv.ulPropTag = PROP_TAG(PT_LONG,0x7FF7);
pv.Value.ft = 123;
HRESULT hr = pMessage->SetProps(1, &pv, NULL);
if(SUCCEEDED(hr))
hr = pMessage->SaveChanges(KEEP_OPEN_READWRITE);

If you see anything different or missing from what you do, I'd be grateful
if you let me know.

Regards,
Alex
 
1. No, OutlookSpy never filters any properties out, it uses whatever
IMessage::GetPropList() returns. Next version of OutlookSpy will let you
specify extra properties to list and retrieve besides those returned by
GetPropList().

2. Change the line
pv.Value.ft = 123;
to
pv.Value.l = 123;

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
Back
Top