[Spambayes-checkins] spambayes/Outlook2000 msgstore.py,1.40,1.41
Mark Hammond
mhammond at users.sourceforge.net
Thu Mar 6 22:29:14 EST 2003
Update of /cvsroot/spambayes/spambayes/Outlook2000
In directory sc8-pr-cvs1:/tmp/cvs-serv12556
Modified Files:
msgstore.py
Log Message:
Handle MAPI exceptions better. Centralize detection of "not found"
exceptions, and suppress errors when the hotmail connector can't save
the message.
Please let me know of any weird exceptions or messages, or if there are
any other problems filtering hotmail mail.
Index: msgstore.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/Outlook2000/msgstore.py,v
retrieving revision 1.40
retrieving revision 1.41
diff -C2 -d -r1.40 -r1.41
*** msgstore.py 14 Feb 2003 01:24:21 -0000 1.40
--- msgstore.py 7 Mar 2003 06:29:12 -0000 1.41
***************
*** 95,98 ****
--- 95,107 ----
USE_DEFERRED_ERRORS = mapi.MAPI_DEFERRED_ERRORS # or set to zero to see what changes <wink>
+ def IsNotFoundCOMException(exc_val):
+ hr, msg, exc, arg_err = exc_val
+ return hr in [mapi.MAPI_E_OBJECT_DELETED, mapi.MAPI_E_NOT_FOUND]
+
+ def GetCOMExceptionString(exc_val):
+ hr, msg, exc, arg_err = exc_val
+ err_string = mapiutil.GetScodeString(hr)
+ return "Exception 0x%x (%s): %s" % (hr, err_string, msg)
+
class MAPIMsgStore(MsgStore):
def __init__(self, outlook = None):
***************
*** 208,218 ****
folder = self._OpenEntry(folder_id)
table = folder.GetContentsTable(0)
! except pythoncom.com_error, (hr, msg, exc, arg_err):
# We will ignore *all* such errors for the time
# being, but warn for results we don't know about.
! if hr not in [mapi.MAPI_E_OBJECT_DELETED, mapi.MAPI_E_NOT_FOUND]:
print "WARNING: Unexpected MAPI error opening folder"
! print "Error:", mapiutil.GetScodeString(hr)
! print "Exception Message:", msg
continue
rc, props = folder.GetProps( (PR_DISPLAY_NAME_A,), 0)
--- 217,226 ----
folder = self._OpenEntry(folder_id)
table = folder.GetContentsTable(0)
! except pythoncom.com_error, details:
# We will ignore *all* such errors for the time
# being, but warn for results we don't know about.
! if not IsNotFoundCOMException(details):
print "WARNING: Unexpected MAPI error opening folder"
! print GetCOMExceptionString(details)
continue
rc, props = folder.GetProps( (PR_DISPLAY_NAME_A,), 0)
***************
*** 225,244 ****
def GetFolder(self, folder_id):
# Return a single folder given the ID.
! if hasattr(folder_id, "EntryID"):
! # An Outlook object
! folder_id = mapi.BinFromHex(folder_id.StoreID), \
! mapi.BinFromHex(folder_id.EntryID)
! else:
folder_id = self.NormalizeID(folder_id)
try:
folder = self._OpenEntry(folder_id)
table = folder.GetContentsTable(0)
! except pythoncom.com_error, (hr, msg, exc, arg_err):
# We will ignore *all* such errors for the time
# being, but warn for results we don't know about.
! if hr not in [mapi.MAPI_E_OBJECT_DELETED, mapi.MAPI_E_NOT_FOUND]:
print "WARNING: Unexpected MAPI error opening folder"
! print "Error:", mapiutil.GetScodeString(hr)
! print "Exception Message:", msg
return None
# Ensure we have a long-term ID.
--- 233,261 ----
def GetFolder(self, folder_id):
# Return a single folder given the ID.
! try:
! sid = mapi.BinFromHex(folder_id.StoreID)
! eid = mapi.BinFromHex(folder_id.EntryID)
! folder_id = sid, eid
! except AttributeError:
! # No 'EntryID'/'StoreID' properties - a 'normal' ID
folder_id = self.NormalizeID(folder_id)
+ except pythoncom.com_error, details:
+ if IsNotFoundCOMException(details):
+ print "Unable to open folder '%r'" \
+ "- the folder was not found" % folder_id
+ else:
+ print "Unexpected MAPI error opening folder"
+ print GetCOMExceptionString(details)
+ return None
+ # Also catch COM exceptions opening the folder and table.
try:
folder = self._OpenEntry(folder_id)
table = folder.GetContentsTable(0)
! except pythoncom.com_error, details:
# We will ignore *all* such errors for the time
# being, but warn for results we don't know about.
! if not IsNotFoundCOMException(details):
print "WARNING: Unexpected MAPI error opening folder"
! print GetCOMExceptionString(details)
return None
# Ensure we have a long-term ID.
***************
*** 251,260 ****
# Return a single message given either the ID, or an Outlook
# message representing the object.
! if hasattr(message_id, "EntryID"):
! # An Outlook object
! message_id = mapi.BinFromHex(message_id.Parent.StoreID), \
! mapi.BinFromHex(message_id.EntryID)
! else:
message_id = self.NormalizeID(message_id)
prop_ids = PR_PARENT_ENTRYID, PR_SEARCH_KEY, PR_MESSAGE_FLAGS
mapi_object = self._OpenEntry(message_id)
--- 268,286 ----
# Return a single message given either the ID, or an Outlook
# message representing the object.
! try:
! eid = mapi.BinFromHex(message_id.EntryID)
! sid = mapi.BinFromHex(message_id.Parent.StoreID)
! message_id = sid, eid
! except AttributeError:
! # No 'EntryID'/'StoreID' properties - a 'normal' ID
message_id = self.NormalizeID(message_id)
+ except pythoncom.com_error, details:
+ if IsNotFoundCOMException(details):
+ print "Unable to open message '%r'" \
+ "- the message was not found" % message_id
+ else:
+ print "Unexpected MAPI error opening message"
+ print GetCOMExceptionString(details)
+ return None
prop_ids = PR_PARENT_ENTRYID, PR_SEARCH_KEY, PR_MESSAGE_FLAGS
mapi_object = self._OpenEntry(message_id)
***************
*** 682,686 ****
def Save(self):
assert self.dirty, "asking me to save a clean message!"
! self.mapi_object.SaveChanges(mapi.KEEP_OPEN_READWRITE | USE_DEFERRED_ERRORS)
self.dirty = False
--- 708,718 ----
def Save(self):
assert self.dirty, "asking me to save a clean message!"
! try:
! self.mapi_object.SaveChanges(mapi.KEEP_OPEN_READWRITE | USE_DEFERRED_ERRORS)
! except pythoncom.com_error, details:
! # hotmail gives this error - not sure what code, but
! # we don't want to mask other errors.
! if details[0] != -2147164169: # 0x8004dff7
! raise
self.dirty = False
More information about the Spambayes-checkins
mailing list