From 1a0084e46f72624bc25a4f78e3e60eaf7ac39461 Mon Sep 17 00:00:00 2001 From: helmutm Date: Wed, 16 Apr 2008 16:01:39 +0000 Subject: [PATCH] work in progress: outlook crawler: make dummy implementation work git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@2528 fd906abe-77d9-0310-91a1-e0d9ade77398 --- agent/crawl/outlook.py | 19 ++++++++---- agent/crawl/outlook.txt | 4 +-- agent/testing/winapi.py | 65 ++++++++++++++++++++++++++--------------- 3 files changed, 56 insertions(+), 32 deletions(-) diff --git a/agent/crawl/outlook.py b/agent/crawl/outlook.py index 7837f8d..2e0b65a 100644 --- a/agent/crawl/outlook.py +++ b/agent/crawl/outlook.py @@ -54,17 +54,21 @@ class OutlookCrawler(MailCrawler): pattern = "" def collect(self, filter=None): - self.collected = [] + self.result = [] self.d = defer.Deferred() self.oOutlookApp = None if self.findOutlook(): self.fetchCriteria() - coiterate(self.crawlFolders()).addCallback(self.finished) + coiterate(self.crawlFolders()).addCallback(self.finished).addErrback(self.error) else: pass #self.d.addErrback([]) return self.d + def error(self, reason): + print '***** error', + print reason + def finished(self, result): self.d.callback(self.result) @@ -83,19 +87,22 @@ class OutlookCrawler(MailCrawler): onMAPI.GetDefaultFolder(api.client.constants.olFolderInbox) # fetch mails from inbox if self.inbox: - self.loadMailsFromFolder(ofInbox) + for m in self.loadMailsFromFolder(ofInbox): + yield None # fetch mails of inbox subfolders if self.subfolders and self.pattern is None: lInboxSubfolders = getattr(ofInbox, 'Folders') for of in range(lInboxSubfolders.__len__()): # get a MAPI-subfolder object and load its emails - yield self.loadMailsFromFolder(lInboxSubfolders.Item(of + 1)) + for m in self.loadMailsFromFolder(lInboxSubfolders.Item(of + 1)): + yield None elif self.subfolders and self.pattern: lInboxSubfolders = getattr(ofInbox, 'Folders') for of in range(lInboxSubfolders.__len__()): # get specified MAPI-subfolder object and load its emails if self.pattern.match(getattr(lInboxSubfolders.Item(of + 1), 'Name')): - yield self.loadMailsFromFolder(lInboxSubfolders.Item(of + 1)) + for m in self.loadMailsFromFolder(lInboxSubfolders.Item(of + 1)): + yield None def loadMailsFromFolder(self, folder): # get items of the folder @@ -164,7 +171,7 @@ class OutlookCrawler(MailCrawler): def createEmailMime(self, emails): # Create the container (outer) email message. - msg = MIMEMultipart() + msg = MIMEMultipart.MIMEMultipart() msg['Subject'] = emails['Subject'].encode('utf-8') if emails.has_key('SenderEmailAddress'): sender = str(emails['SenderEmailAddress'].encode('utf-8')) diff --git a/agent/crawl/outlook.txt b/agent/crawl/outlook.txt index 1f45de8..970d843 100644 --- a/agent/crawl/outlook.txt +++ b/agent/crawl/outlook.txt @@ -35,7 +35,7 @@ dlls". In the next step we request the start of a job, again via the controller. - >>> controller.enterJob('sample', 'sample02') + >>> controller.enterJob('sample', 'sample02', params=dict(inbox=True)) The job is not executed immediately - we have to hand over control to the twisted reactor first. @@ -46,4 +46,4 @@ the twisted reactor first. Namespace MAPI retrieved retrieving Outlook default folder collecting Mails from folder - Job 00001 completed; result: []; + Job 00001 completed; result: [...]; diff --git a/agent/testing/winapi.py b/agent/testing/winapi.py index bc40268..ede2a30 100644 --- a/agent/testing/winapi.py +++ b/agent/testing/winapi.py @@ -25,38 +25,55 @@ $Id$ client = ctypes = win32api = win32process = win32con = None class Mail(object): - + #this is just a guess what a Outlook Mail Object Probably returns - Class = None + #Class = client.constants.olMail def __init__(self): - Class = self.__class__ - + self.Class = client.constants.olMail + self.Subject = 'dummy' + self.SenderName = 'dummy' + self.To = 'dummy' + self.Body = 'dummy' + + @property def _prop_map_get_(self): #here it is necessary of what attributes (called keys in outlok.py) #an Outlook Mail typically has # should return a tuple () - pass - + return ('Subject', 'SenderName', 'To', 'Body') + + +class Items(object): + + def __init__(self): + self.data = {} + self.data[0] = Mail() + self.data[1] = Mail() + self.data[2] = Mail() + + def Item(self, idx): + return self.data[idx-1] + + def __len__(self): + return len(self.data) + class OutlookFolder(object): - - Items = {} + # Folders defines in Outlook the sub folders under the "Main" Folder Folders = None - + def __init__(self): print "collecting Mails from folder" - self.Items[0] = Mail() - self.Items[1] = Mail() - self.Items[2] = Mail() + self.Items = Items() class OutlookNamespace(object): - + def __init__(self): pass - + def GetDefaultFolder(self, message=""): print "retrieving Outlook default folder" folder = OutlookFolder() @@ -64,10 +81,10 @@ class OutlookNamespace(object): class OutlookApp(object): - + def __init__(self): pass - + def GetNamespace(self, message=""): print "Namespace " + message + " retrieved" oNamespace = OutlookNamespace() @@ -75,17 +92,17 @@ class OutlookApp(object): class Message(object): - + olFolderInbox = None # esp. for olMail, for further dummy implementations it is necessary # to find out, what class is expected. Meaning what type of object has # to be faked and what attributes it has. see outlook.py # loadMailsfromFolder - olMail = Mail() - + olMail = Mail + def __init__(self): pass - + def EnsureDispatch(self, message=""): print message + " retrieved" oApp = OutlookApp() @@ -93,14 +110,14 @@ class Message(object): class client(object): - + gencache = Message() constants = Message() - + def __init__(self): pass - + class ctypes(object): - + def __init__(self): pass \ No newline at end of file