3

As far as I can find there is no property on a MailItem one can access to discover if a MailItem is a draft.

One could check MailItem.Categories and see if it includes Drafts but this seems insufficient because:

Drafts don't have to be stored in the Drafts folder, they can be dragged and dropped into other folders.

The fact that a draft email retains its draftyness even if moved out of the Drafts folder indicates there must be some other way in which a MailItem is marked as a draft, but I haven't been able to find it.

Suggestions?

Dave Mackey
  • 4,306
  • 21
  • 78
  • 136

2 Answers2

2

New items don't have the EntryID property set. The value is assigned by the store provider when an item is saved to the store.

If the item is already saved to the store you can use the PR_MESSAGE_FLAGS property value which contains a bitmask of flags that indicate the origin and current state of a message.

This property is initialized by the client or message store provider when a message is created and saved for the first time and then updated periodically by the message store provider, a transport provider, and the MAPI spooler as the message is processed and its state changes.

Try to check for the MSGFLAG_UNSENT value which stands for the following:

The message is still being composed. It is saved, but has not been sent. The client or provider has read/write access to this flag until the first IMAPIProp::SaveChanges call and read-only thereafter. If a client doesn't set this flag by the time the message is sent, the message store provider sets it when IMessage::SubmitMessage is called. Typically, this flag is cleared after the message is sent.

See PidTagMessageFlags Canonical Property for more information about possible values.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
1

Use the MailItem.Sent property - it will be false for the draft (editable) messages.

Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78
  • I was under the impression that MailItems included all emails and thus that this flag might be misleading for emails received? – Dave Mackey Mar 26 '22 at 20:05
  • `MailItem` object represents both sent and unsent messages. `Sent` property distinguishes between the two types - it will be true for both sent and received messages. And false for the unsent drafts messages. `MSGFLAG_UNSENT` bit in the `PR_MESSAGE_FLAGS` MAPI property is the only difference. Take a look at a message in MFCMAPI or OutlookSpy (click IMessage button). – Dmitry Streblechenko Mar 26 '22 at 22:39