[Spambayes-checkins] spambayes/Outlook2000 msgstore.py,1.70,1.71
Mark Hammond
mhammond at users.sourceforge.net
Mon Sep 1 01:29:50 EDT 2003
Update of /cvsroot/spambayes/spambayes/Outlook2000
In directory sc8-pr-cvs1:/tmp/cvs-serv21408
Modified Files:
msgstore.py
Log Message:
Handle MAPI failures fetching the message when trying to get a field value.
New RTF->HTML code - however, it won't actually extract HTML until you
upgrade your win32all to a version that is yet to be released.
Index: msgstore.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/Outlook2000/msgstore.py,v
retrieving revision 1.70
retrieving revision 1.71
diff -C2 -d -r1.70 -r1.71
*** msgstore.py 31 Aug 2003 05:38:52 -0000 1.70
--- msgstore.py 1 Sep 2003 07:29:48 -0000 1.71
***************
*** 424,427 ****
--- 424,454 ----
return ret
+ # Some nasty stuff for getting RTF out of the message
+ _have_complained_about_missing_rtf = False
+ def GetHTMLFromRTFProperty(mapi_object, prop_tag = PR_RTF_COMPRESSED):
+ global _have_complained_about_missing_rtf
+ try:
+ rtf_stream = mapi_object.OpenProperty(prop_tag, pythoncom.IID_IStream,
+ 0, 0)
+ except pythoncom.com_error, details:
+ if not IsNotFoundCOMException(details):
+ print "ERROR getting RTF body", details
+ return ""
+ try:
+ html_stream = mapi.WrapCompressedRTFStream(rtf_stream, 0)
+ except AttributeError:
+ if not _have_complained_about_missing_rtf:
+ print "*" * 50
+ print "Sorry, but you need to update to a new win32all (158 or "
+ print "later), so we correctly get the HTML from messages."
+ print "See http://starship.python.net/crew/mhammond/win32"
+ print "*" * 50
+ _have_complained_about_missing_rtf = True
+ return ""
+ html = mapi.RTFStreamToHTML(html_stream)
+ # html may be None if not RTF originally from HTML, but here we
+ # always want a string
+ return html or ''
+
class MAPIMsgStoreFolder(MsgStoreMsg):
def __init__(self, msgstore, id, name, count):
***************
*** 705,709 ****
def _GetMessageTextParts(self):
! # This is finally reliable. The only messages this now fails for
# are for "forwarded" messages, where the forwards are actually
# in an attachment. Later.
--- 732,736 ----
def _GetMessageTextParts(self):
! # This is almost reliable :). The only messages this now fails for
# are for "forwarded" messages, where the forwards are actually
# in an attachment. Later.
***************
*** 720,723 ****
--- 747,753 ----
html = self._GetPotentiallyLargeStringProp(prop_ids[1], data[1])
headers = self._GetPotentiallyLargeStringProp(prop_ids[2], data[2])
+ # xxx - not sure what to do if we have both.
+ if not html:
+ html = GetHTMLFromRTFProperty(self.mapi_object)
# Some Outlooks deliver a strange notion of headers, including
***************
*** 937,941 ****
def GetField(self, prop, raise_errors = False):
! self._EnsureObject()
if type(prop) != type(0):
props = ( (mapi.PS_PUBLIC_STRINGS, prop), )
--- 967,977 ----
def GetField(self, prop, raise_errors = False):
! try:
! self._EnsureObject()
! except pythoncom.com_error, details:
! if not IsNotFoundCOMException(details):
! print "ERROR: Could not open an object to fetch a field"
! print details
! return None
if type(prop) != type(0):
props = ( (mapi.PS_PUBLIC_STRINGS, prop), )
More information about the Spambayes-checkins
mailing list