From 80ff9b8403f6af0708d5483050c281d4ab5e1400 Mon Sep 17 00:00:00 2001 From: scrat Date: Sat, 12 Jul 2008 13:45:47 +0000 Subject: [PATCH] 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 --- agent/crawl/outlook.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/agent/crawl/outlook.py b/agent/crawl/outlook.py index 3a5f389..a14f054 100644 --- a/agent/crawl/outlook.py +++ b/agent/crawl/outlook.py @@ -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,