1
from __future__ import generators
2
# Set items to read/unread
7
from win32com.mapi import mapi, mapiutil
8
from win32com.mapi.mapitags import *
12
CLEAR_READ_FLAG = 0x00000004
13
CLEAR_RN_PENDING = 0x00000020
14
CLEAR_NRN_PENDING = 0x00000040
15
SUPPRESS_RECEIPT = 0x1
19
def SetReadState(driver, mapi_folder, subject, unread):
20
hr, data = mapi_folder.GetProps( (PR_DISPLAY_NAME_A,), 0)
23
for item in driver.GetItemsWithValue(mapi_folder, PR_SUBJECT_A, subject):
24
flags_base = mapi.MAPI_DEFERRED_ERRORS | SUPPRESS_RECEIPT
26
item.SetReadFlag(mapi.MAPI_DEFERRED_ERRORS|CLEAR_READ_FLAG)
28
item.SetReadFlag(flags_base)
30
# Check the set worked.
31
hr, props = item.GetProps((PR_MESSAGE_FLAGS,), 0)
32
((tag, val), ) = props
33
if val & MSGFLAG_READ == unread:
34
print "MAPI SetReadState appears to have failed to change the message state"
35
print "Requested set to unread=%s but the MAPI field after was %r" % \
37
print "Processed", num, "items"
40
folder_doc = driver.GetFolderNameDoc()
42
Usage: %s [-u] subject of the message
43
-f - Search for the message in the specified folder (default = Inbox)
46
Marks as read (or unread) all messages that match the subject. Subject
47
matching is substring and ignore-case.
50
Use the -n option to see all top-level folder names from all stores.""" \
51
% (os.path.basename(sys.argv[0]),folder_doc)
55
driver = mapi_driver.MAPIDriver()
59
opts, args = getopt.getopt(sys.argv[1:], "u")
60
except getopt.error, e:
68
for opt, opt_val in opts:
76
folder_name = "Inbox" # Assume this exists!
78
subject = " ".join(args)
80
print "You must specify a subject"
86
folder = driver.FindFolder(folder_name)
87
except ValueError, details:
91
SetReadState(driver, folder, subject, unread)
93
if __name__=='__main__':