Updated outlook.py to support writing also the mail text data to a temporary file with mkstemp. Also changed some details in saving the attachments which has been wrong up to now.

git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@2756 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
scrat 2008-07-12 13:45:47 +00:00
parent 66faec4a38
commit 80ff9b8403

View file

@ -167,6 +167,7 @@ class OutlookCrawler(MailCrawler):
enc = None
textType = "application/octet-stream"
attachments = []
mailContent = ""
ident = None
if (hasattr(mail, 'BodyFormat')):
value = getattr(mail, 'BodyFormat')
@ -186,14 +187,14 @@ class OutlookCrawler(MailCrawler):
mailContent = getattr(mail, 'HTMLBody')
textType = "text/html"
else:
mailContent = "Could not retrieve HTMLBody of mail"
mailContent = ""
textType = "text/html"
else:
#Could not determine BodyFormat. Try to retrieve plain text
if hasattr(mail, 'Body'):
mailContent = getattr(mail, 'Body')
else:
mailContent = "Could not retrieve mail body"
mailContent = ""
if hasattr(mail, 'InternetCodepage'):
Codepage = getattr(mail, 'InternetCodepage')
if codepages.has_key(Codepage):
@ -205,17 +206,21 @@ class OutlookCrawler(MailCrawler):
for item in range(1, len(attachedElems)+1):
fileHandle, filePath = tempfile.mkstemp(prefix="outlook")
attachedItem = attachedElems.Item(item)
attachedItem.SaveAsFile(fileHandle)
attachedItem.SaveAsFile(filePath)
os.close(fileHandle)
metadat = self.createMetadata(dict(filename=filePath))
fileRes = FileResource(data=None,
path=filePath,
metadata=metadat)
attachments.append(fileRes)
fileHandle, filePath = tempfile.mkstemp(prefix="olmail")
filePointer = os.fdopen(fileHandle, "w")
filePointer.write(mailContent)
filePointer.close()
resource = MailResource(data=mailContent,
contentType=textType,
encoding=enc,
path=None,
path=filePath,
application='outlook',
identifier=ident,
metadata=metadata,