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
This commit is contained in:
parent
1011f4b2eb
commit
1a0084e46f
3 changed files with 56 additions and 32 deletions
|
@ -54,17 +54,21 @@ class OutlookCrawler(MailCrawler):
|
||||||
pattern = ""
|
pattern = ""
|
||||||
|
|
||||||
def collect(self, filter=None):
|
def collect(self, filter=None):
|
||||||
self.collected = []
|
self.result = []
|
||||||
self.d = defer.Deferred()
|
self.d = defer.Deferred()
|
||||||
self.oOutlookApp = None
|
self.oOutlookApp = None
|
||||||
if self.findOutlook():
|
if self.findOutlook():
|
||||||
self.fetchCriteria()
|
self.fetchCriteria()
|
||||||
coiterate(self.crawlFolders()).addCallback(self.finished)
|
coiterate(self.crawlFolders()).addCallback(self.finished).addErrback(self.error)
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
#self.d.addErrback([])
|
#self.d.addErrback([])
|
||||||
return self.d
|
return self.d
|
||||||
|
|
||||||
|
def error(self, reason):
|
||||||
|
print '***** error',
|
||||||
|
print reason
|
||||||
|
|
||||||
def finished(self, result):
|
def finished(self, result):
|
||||||
self.d.callback(self.result)
|
self.d.callback(self.result)
|
||||||
|
|
||||||
|
@ -83,19 +87,22 @@ class OutlookCrawler(MailCrawler):
|
||||||
onMAPI.GetDefaultFolder(api.client.constants.olFolderInbox)
|
onMAPI.GetDefaultFolder(api.client.constants.olFolderInbox)
|
||||||
# fetch mails from inbox
|
# fetch mails from inbox
|
||||||
if self.inbox:
|
if self.inbox:
|
||||||
self.loadMailsFromFolder(ofInbox)
|
for m in self.loadMailsFromFolder(ofInbox):
|
||||||
|
yield None
|
||||||
# fetch mails of inbox subfolders
|
# fetch mails of inbox subfolders
|
||||||
if self.subfolders and self.pattern is None:
|
if self.subfolders and self.pattern is None:
|
||||||
lInboxSubfolders = getattr(ofInbox, 'Folders')
|
lInboxSubfolders = getattr(ofInbox, 'Folders')
|
||||||
for of in range(lInboxSubfolders.__len__()):
|
for of in range(lInboxSubfolders.__len__()):
|
||||||
# get a MAPI-subfolder object and load its emails
|
# 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:
|
elif self.subfolders and self.pattern:
|
||||||
lInboxSubfolders = getattr(ofInbox, 'Folders')
|
lInboxSubfolders = getattr(ofInbox, 'Folders')
|
||||||
for of in range(lInboxSubfolders.__len__()):
|
for of in range(lInboxSubfolders.__len__()):
|
||||||
# get specified MAPI-subfolder object and load its emails
|
# get specified MAPI-subfolder object and load its emails
|
||||||
if self.pattern.match(getattr(lInboxSubfolders.Item(of + 1), 'Name')):
|
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):
|
def loadMailsFromFolder(self, folder):
|
||||||
# get items of the folder
|
# get items of the folder
|
||||||
|
@ -164,7 +171,7 @@ class OutlookCrawler(MailCrawler):
|
||||||
|
|
||||||
def createEmailMime(self, emails):
|
def createEmailMime(self, emails):
|
||||||
# Create the container (outer) email message.
|
# Create the container (outer) email message.
|
||||||
msg = MIMEMultipart()
|
msg = MIMEMultipart.MIMEMultipart()
|
||||||
msg['Subject'] = emails['Subject'].encode('utf-8')
|
msg['Subject'] = emails['Subject'].encode('utf-8')
|
||||||
if emails.has_key('SenderEmailAddress'):
|
if emails.has_key('SenderEmailAddress'):
|
||||||
sender = str(emails['SenderEmailAddress'].encode('utf-8'))
|
sender = str(emails['SenderEmailAddress'].encode('utf-8'))
|
||||||
|
|
|
@ -35,7 +35,7 @@ dlls".
|
||||||
|
|
||||||
In the next step we request the start of a job, again via the controller.
|
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 job is not executed immediately - we have to hand over control to
|
||||||
the twisted reactor first.
|
the twisted reactor first.
|
||||||
|
@ -46,4 +46,4 @@ the twisted reactor first.
|
||||||
Namespace MAPI retrieved
|
Namespace MAPI retrieved
|
||||||
retrieving Outlook default folder
|
retrieving Outlook default folder
|
||||||
collecting Mails from folder
|
collecting Mails from folder
|
||||||
Job 00001 completed; result: [];
|
Job 00001 completed; result: [...];
|
||||||
|
|
|
@ -25,38 +25,55 @@ $Id$
|
||||||
client = ctypes = win32api = win32process = win32con = None
|
client = ctypes = win32api = win32process = win32con = None
|
||||||
|
|
||||||
class Mail(object):
|
class Mail(object):
|
||||||
|
|
||||||
#this is just a guess what a Outlook Mail Object Probably returns
|
#this is just a guess what a Outlook Mail Object Probably returns
|
||||||
Class = None
|
#Class = client.constants.olMail
|
||||||
|
|
||||||
def __init__(self):
|
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):
|
def _prop_map_get_(self):
|
||||||
#here it is necessary of what attributes (called keys in outlok.py)
|
#here it is necessary of what attributes (called keys in outlok.py)
|
||||||
#an Outlook Mail typically has
|
#an Outlook Mail typically has
|
||||||
# should return a tuple ()
|
# 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):
|
class OutlookFolder(object):
|
||||||
|
|
||||||
Items = {}
|
|
||||||
# Folders defines in Outlook the sub folders under the "Main" Folder
|
# Folders defines in Outlook the sub folders under the "Main" Folder
|
||||||
Folders = None
|
Folders = None
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
print "collecting Mails from folder"
|
print "collecting Mails from folder"
|
||||||
self.Items[0] = Mail()
|
self.Items = Items()
|
||||||
self.Items[1] = Mail()
|
|
||||||
self.Items[2] = Mail()
|
|
||||||
|
|
||||||
|
|
||||||
class OutlookNamespace(object):
|
class OutlookNamespace(object):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def GetDefaultFolder(self, message=""):
|
def GetDefaultFolder(self, message=""):
|
||||||
print "retrieving Outlook default folder"
|
print "retrieving Outlook default folder"
|
||||||
folder = OutlookFolder()
|
folder = OutlookFolder()
|
||||||
|
@ -64,10 +81,10 @@ class OutlookNamespace(object):
|
||||||
|
|
||||||
|
|
||||||
class OutlookApp(object):
|
class OutlookApp(object):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def GetNamespace(self, message=""):
|
def GetNamespace(self, message=""):
|
||||||
print "Namespace " + message + " retrieved"
|
print "Namespace " + message + " retrieved"
|
||||||
oNamespace = OutlookNamespace()
|
oNamespace = OutlookNamespace()
|
||||||
|
@ -75,17 +92,17 @@ class OutlookApp(object):
|
||||||
|
|
||||||
|
|
||||||
class Message(object):
|
class Message(object):
|
||||||
|
|
||||||
olFolderInbox = None
|
olFolderInbox = None
|
||||||
# esp. for olMail, for further dummy implementations it is necessary
|
# esp. for olMail, for further dummy implementations it is necessary
|
||||||
# to find out, what class is expected. Meaning what type of object has
|
# to find out, what class is expected. Meaning what type of object has
|
||||||
# to be faked and what attributes it has. see outlook.py
|
# to be faked and what attributes it has. see outlook.py
|
||||||
# loadMailsfromFolder
|
# loadMailsfromFolder
|
||||||
olMail = Mail()
|
olMail = Mail
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def EnsureDispatch(self, message=""):
|
def EnsureDispatch(self, message=""):
|
||||||
print message + " retrieved"
|
print message + " retrieved"
|
||||||
oApp = OutlookApp()
|
oApp = OutlookApp()
|
||||||
|
@ -93,14 +110,14 @@ class Message(object):
|
||||||
|
|
||||||
|
|
||||||
class client(object):
|
class client(object):
|
||||||
|
|
||||||
gencache = Message()
|
gencache = Message()
|
||||||
constants = Message()
|
constants = Message()
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class ctypes(object):
|
class ctypes(object):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
pass
|
pass
|
Loading…
Add table
Reference in a new issue