diff options
author | Ariel Constenla-Haile <arielch@apache.org> | 2012-01-25 07:36:38 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2013-01-15 14:58:05 +0000 |
commit | 8a324a3ba599bee03311e5f6ba6e1c83edc1e343 (patch) | |
tree | bf732dc4ee5ae3805ec391b9e9970a35aacf0217 /scripting | |
parent | a5cefd4007be4789f550ee559aa832ddb04c2dc3 (diff) |
i118814 - Allow set connection timeout in Mail API
Conflicts:
scripting/source/pyprov/mailmerge.py
Change-Id: I7a3eb3b29f41eed154abd45e1aa5be824983f5de
Diffstat (limited to 'scripting')
-rwxr-xr-x | scripting/source/pyprov/mailmerge.py | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/scripting/source/pyprov/mailmerge.py b/scripting/source/pyprov/mailmerge.py index 40a62f35a378..96bbd688bd12 100755 --- a/scripting/source/pyprov/mailmerge.py +++ b/scripting/source/pyprov/mailmerge.py @@ -41,6 +41,7 @@ from email.header import Header from email.mime.multipart import MIMEMultipart from email.utils import formatdate from email.utils import parseaddr +from socket import _GLOBAL_DEFAULT_TIMEOUT import sys, smtplib, imaplib, poplib dbg = False @@ -80,20 +81,29 @@ class PyMailSMTPService(unohelper.Base, XSmtpService): print("PyMailSMTPService connect", file=dbgout) server = xConnectionContext.getValueByName("ServerName") if dbg: - print(server, file=dbgout) + print("ServerName: " + server, file=dbgout) port = int(xConnectionContext.getValueByName("Port")) if dbg: - print(port, file=dbgout) - self.server = smtplib.SMTP(server, port) + print("Port: " + str(port), file=dbgout) + tout = xConnectionContext.getValueByName("Timeout") + if dbg: + print(isinstance(tout,int), file=dbgout) + if not isinstance(tout,int): + tout = _GLOBAL_DEFAULT_TIMEOUT + if dbg: + print("Timeout: " + str(tout), file=dbgout) + self.server = smtplib.SMTP(server, port,timeout=tout) + #stderr not available for us under windows, but #set_debuglevel outputs there, and so throw #an exception under windows on debugging mode #with this enabled if dbg and os.name != 'nt': self.server.set_debuglevel(1) + connectiontype = xConnectionContext.getValueByName("ConnectionType") if dbg: - print(connectiontype, file=dbgout) + print("ConnectionType: " + connectiontype, file=dbgout) if connectiontype.upper() == 'SSL': self.server.ehlo() self.server.starttls() @@ -228,7 +238,6 @@ class PyMailSMTPService(unohelper.Base, XSmtpService): filename=fname) msg.attach(msgattachment) - uniquer = {} for key in recipients: uniquer[key] = True @@ -357,7 +366,14 @@ class PyMailPOP3Service(unohelper.Base, XMailService): if connectiontype.upper() == 'SSL': self.server = poplib.POP3_SSL(server, port) else: - self.server = poplib.POP3(server, port) + tout = xConnectionContext.getValueByName("Timeout") + if dbg: + print(isinstance(tout,int), file=dbgout) + if not isinstance(tout,int): + tout = _GLOBAL_DEFAULT_TIMEOUT + if dbg: + print("Timeout: " + str(tout), file=dbgout) + self.server = poplib.POP3(server, port, timeout=tout) print("AFTER", file=dbgout) user = xAuthenticator.getUserName() |