Outlook dialog handle added

git-svn-id: svn://svn.cy55.de/Zope3/src/loops/trunk@2067 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
tschmid 2007-09-23 18:12:34 +00:00
parent 46a1638edd
commit e5eeb2d502

View file

@ -12,6 +12,14 @@ import win32com.client
import re
from email.mime.multipart import MIMEMultipart
from threading import Thread
# imports for handling the outlook dialog
import ctypes
import win32api, win32process, win32con
from watsup.winGuiAuto import findTopWindow, findControl, findControls, clickButton, \
getComboboxItems, selectComboboxItem, setCheckBox
from twisted.internet.defer import Deferred
from twisted.internet.task import coiterate
from zope.interface import implements
@ -59,7 +67,7 @@ class CrawlingJob(BaseCrawlingJob):
if not outlookFound:
return
# fetch the params
criteria = self.params
self.keys = criteria.get('keys')
@ -74,6 +82,10 @@ class CrawlingJob(BaseCrawlingJob):
if DEBUG_WRITELINE:
print 'MSOutlook.loadInbox() ===> starting'
# try to handle the Outlook dialog
handle = HandleOutlookDialog()
handle.start()
# catch Inbox folder
onMAPI = oOutlookApp.GetNamespace("MAPI")
@ -175,6 +187,12 @@ class CrawlingJob(BaseCrawlingJob):
else:
sender = str(emails['SenderName'].encode('utf-8'))
msg['From'] = sender
# CC
#msg['CC'] = str(emails['CC'].encode('utf-8'))
# ReceivedTime
#msg['Date'] = str(emails['ReceivedTime'])
#recipients
recipients = []
@ -191,7 +209,104 @@ class CrawlingJob(BaseCrawlingJob):
msg.preamble = emails['Body'].encode('utf-8')
return msg
def handleOutlookDialog(self):
"""
This function handles the outlook dialog, which appears if someone
tries to access to MS Outlook.
"""
hwnd = None
while True:
hwnd = ctypes.windll.user32.FindWindowExA(None, hwnd, None, None)
print 'searching....'
if hwnd == None:
break
else:
val = u"\0" * 1024
ctypes.windll.user32.GetWindowTextW(hwnd, val, len(val))
val = val.replace(u"\000", u"")
if val and repr(val) == "u'Microsoft Office Outlook'":
print repr(val)
print '===> MSOutlook dialog box found'
#tid, pid = win32process.GetWindowThreadProcessId(hwnd)
# get a handle
#handle = win32api.OpenProcess(win32con.PROCESS_TERMINATE, 0, pid)
# terminate the process by the handle
#win32api.TerminateProcess(handle, 0)
# close the handle - thankyou
#win32api.CloseHandle(handle)
# get the Main Control
form = findTopWindow(wantedText='Microsoft Office Outlook')
controls = findControls(form)
# get the check box
checkBox = findControl(form, wantedText='Zugriff')
setCheckBox(checkBox, 1)
# get the combo box
comboBox = findControl(form, wantedClass='ComboBox')
items = getComboboxItems(comboBox)
selectComboboxItem(comboBox, items[3])#'10 Minuten'
# finally get the button and click it
button = findControl(form, wantedText = 'Erteilen')
clickButton(button)
print '-> dialog found and handled'
break
class HandleOutlookDialog(Thread):
def __init_(self):
Thread.__init__(self)
def run(self):
hwnd = None
while True:
hwnd = ctypes.windll.user32.FindWindowExA(None, hwnd, None, None)
#print 'searching....'
if hwnd == None:
break
else:
val = u"\0" * 1024
ctypes.windll.user32.GetWindowTextW(hwnd, val, len(val))
val = val.replace(u"\000", u"")
if val and repr(val) == "u'Microsoft Office Outlook'":
print repr(val)
print '===> MSOutlook dialog box found'
# get the Main Control
form = findTopWindow(wantedText='Microsoft Office Outlook')
#print 'Control', form
controls = findControls(form)
#print 'Controls', str(controls)
# get the check box
checkBox = findControl(form, wantedText='Zugriff')
#print 'CheckBox', checkBox
setCheckBox(checkBox, 1)
# get the combo box
comboBox = findControl(form, wantedClass='ComboBox')
#print 'ComboBox', comboBox
items = getComboboxItems(comboBox)
#print 'ComboBox-Items', str(items)
selectComboboxItem(comboBox, items[1])#'10 Minuten'
# finally get the button and click it
button = findControl(form, wantedText = 'Erteilen')
print 'Erteilen Button', button
clickButton(button)
print '-> dialog found and handled'
break
class OutlookResource(object):