Kaydet (Commit) 8a324a3b authored tarafından Ariel Constenla-Haile's avatar Ariel Constenla-Haile Kaydeden (comit) Caolán McNamara

i118814 - Allow set connection timeout in Mail API

Conflicts:
	scripting/source/pyprov/mailmerge.py

Change-Id: I7a3eb3b29f41eed154abd45e1aa5be824983f5de
üst a5cefd40
...@@ -41,6 +41,7 @@ from email.header import Header ...@@ -41,6 +41,7 @@ from email.header import Header
from email.mime.multipart import MIMEMultipart from email.mime.multipart import MIMEMultipart
from email.utils import formatdate from email.utils import formatdate
from email.utils import parseaddr from email.utils import parseaddr
from socket import _GLOBAL_DEFAULT_TIMEOUT
import sys, smtplib, imaplib, poplib import sys, smtplib, imaplib, poplib
dbg = False dbg = False
...@@ -80,20 +81,29 @@ class PyMailSMTPService(unohelper.Base, XSmtpService): ...@@ -80,20 +81,29 @@ class PyMailSMTPService(unohelper.Base, XSmtpService):
print("PyMailSMTPService connect", file=dbgout) print("PyMailSMTPService connect", file=dbgout)
server = xConnectionContext.getValueByName("ServerName") server = xConnectionContext.getValueByName("ServerName")
if dbg: if dbg:
print(server, file=dbgout) print("ServerName: " + server, file=dbgout)
port = int(xConnectionContext.getValueByName("Port")) port = int(xConnectionContext.getValueByName("Port"))
if dbg: if dbg:
print(port, file=dbgout) print("Port: " + str(port), file=dbgout)
self.server = smtplib.SMTP(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 = smtplib.SMTP(server, port,timeout=tout)
#stderr not available for us under windows, but #stderr not available for us under windows, but
#set_debuglevel outputs there, and so throw #set_debuglevel outputs there, and so throw
#an exception under windows on debugging mode #an exception under windows on debugging mode
#with this enabled #with this enabled
if dbg and os.name != 'nt': if dbg and os.name != 'nt':
self.server.set_debuglevel(1) self.server.set_debuglevel(1)
connectiontype = xConnectionContext.getValueByName("ConnectionType") connectiontype = xConnectionContext.getValueByName("ConnectionType")
if dbg: if dbg:
print(connectiontype, file=dbgout) print("ConnectionType: " + connectiontype, file=dbgout)
if connectiontype.upper() == 'SSL': if connectiontype.upper() == 'SSL':
self.server.ehlo() self.server.ehlo()
self.server.starttls() self.server.starttls()
...@@ -228,7 +238,6 @@ class PyMailSMTPService(unohelper.Base, XSmtpService): ...@@ -228,7 +238,6 @@ class PyMailSMTPService(unohelper.Base, XSmtpService):
filename=fname) filename=fname)
msg.attach(msgattachment) msg.attach(msgattachment)
uniquer = {} uniquer = {}
for key in recipients: for key in recipients:
uniquer[key] = True uniquer[key] = True
...@@ -357,7 +366,14 @@ class PyMailPOP3Service(unohelper.Base, XMailService): ...@@ -357,7 +366,14 @@ class PyMailPOP3Service(unohelper.Base, XMailService):
if connectiontype.upper() == 'SSL': if connectiontype.upper() == 'SSL':
self.server = poplib.POP3_SSL(server, port) self.server = poplib.POP3_SSL(server, port)
else: 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) print("AFTER", file=dbgout)
user = xAuthenticator.getUserName() user = xAuthenticator.getUserName()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment