Kaydet (Commit) 4166969f authored tarafından Ariel Constenla-Haile's avatar Ariel Constenla-Haile

i118736 - i118787 : fix XMailMessage implementation in mailmerge.py

üst 91a17ad2
...@@ -52,7 +52,7 @@ class PyMailSMTPService(unohelper.Base, XSmtpService): ...@@ -52,7 +52,7 @@ class PyMailSMTPService(unohelper.Base, XSmtpService):
self.supportedtypes = ('Insecure', 'Ssl') self.supportedtypes = ('Insecure', 'Ssl')
self.server = None self.server = None
self.connectioncontext = None self.connectioncontext = None
self.notify = EventObject() self.notify = EventObject(self)
if dbg: if dbg:
print >> sys.stderr, "PyMailSMPTService init" print >> sys.stderr, "PyMailSMPTService init"
def addConnectionListener(self, xListener): def addConnectionListener(self, xListener):
...@@ -83,7 +83,7 @@ class PyMailSMTPService(unohelper.Base, XSmtpService): ...@@ -83,7 +83,7 @@ class PyMailSMTPService(unohelper.Base, XSmtpService):
connectiontype = xConnectionContext.getValueByName("ConnectionType") connectiontype = xConnectionContext.getValueByName("ConnectionType")
if dbg: if dbg:
print >> sys.stderr, connectiontype print >> sys.stderr, connectiontype
if connectiontype == 'Ssl': if connectiontype.upper() == 'SSL':
self.server.ehlo() self.server.ehlo()
self.server.starttls() self.server.starttls()
self.server.ehlo() self.server.ehlo()
...@@ -180,7 +180,7 @@ class PyMailSMTPService(unohelper.Base, XSmtpService): ...@@ -180,7 +180,7 @@ class PyMailSMTPService(unohelper.Base, XSmtpService):
mailerstring = "OpenOffice.org 2.0 via Caolan's mailmerge component" mailerstring = "OpenOffice.org 2.0 via Caolan's mailmerge component"
try: try:
ctx = uno.getComponentContext() ctx = uno.getComponentContext()
aConfigProvider = ctx.ServiceManager.createInstance("com.sun.star.configuration.ConfigurationProvider") aConfigProvider = ctx.ServiceManager.createInstance("com.sun.star.configuration.ConfigurationProvider")
prop = uno.createUnoStruct('com.sun.star.beans.PropertyValue') prop = uno.createUnoStruct('com.sun.star.beans.PropertyValue')
prop.Name = "nodepath" prop.Name = "nodepath"
...@@ -191,7 +191,7 @@ class PyMailSMTPService(unohelper.Base, XSmtpService): ...@@ -191,7 +191,7 @@ class PyMailSMTPService(unohelper.Base, XSmtpService):
aSettings.getByName("ooSetupVersion") + " via Caolan's mailmerge component" aSettings.getByName("ooSetupVersion") + " via Caolan's mailmerge component"
except: except:
pass pass
msg['X-Mailer'] = mailerstring msg['X-Mailer'] = mailerstring
msg['Date'] = formatdate(localtime=True) msg['Date'] = formatdate(localtime=True)
...@@ -206,9 +206,10 @@ class PyMailSMTPService(unohelper.Base, XSmtpService): ...@@ -206,9 +206,10 @@ class PyMailSMTPService(unohelper.Base, XSmtpService):
msgattachment.set_payload(data) msgattachment.set_payload(data)
Encoders.encode_base64(msgattachment) Encoders.encode_base64(msgattachment)
msgattachment.add_header('Content-Disposition', 'attachment', \ msgattachment.add_header('Content-Disposition', 'attachment', \
filename=attachment.ReadableName) filename=('utf-8','',attachment.ReadableName.encode('utf-8')))
msg.attach(msgattachment) msg.attach(msgattachment)
uniquer = {} uniquer = {}
for key in recipients: for key in recipients:
uniquer[key] = True uniquer[key] = True
...@@ -232,6 +233,7 @@ class PyMailIMAPService(unohelper.Base, XMailService): ...@@ -232,6 +233,7 @@ class PyMailIMAPService(unohelper.Base, XMailService):
self.supportedtypes = ('Insecure', 'Ssl') self.supportedtypes = ('Insecure', 'Ssl')
self.server = None self.server = None
self.connectioncontext = None self.connectioncontext = None
self.notify = EventObject(self)
if dbg: if dbg:
print >> sys.stderr, "PyMailIMAPService init" print >> sys.stderr, "PyMailIMAPService init"
def addConnectionListener(self, xListener): def addConnectionListener(self, xListener):
...@@ -261,12 +263,12 @@ class PyMailIMAPService(unohelper.Base, XMailService): ...@@ -261,12 +263,12 @@ class PyMailIMAPService(unohelper.Base, XMailService):
if dbg: if dbg:
print >> sys.stderr, connectiontype print >> sys.stderr, connectiontype
print >> sys.stderr, "BEFORE" print >> sys.stderr, "BEFORE"
if connectiontype == 'Ssl': if connectiontype.upper() == 'SSL':
self.server = imaplib.IMAP4_SSL(server, port) self.server = imaplib.IMAP4_SSL(server, port)
else: else:
self.server = imaplib.IMAP4(server, port) self.server = imaplib.IMAP4(server, port)
print >> sys.stderr, "AFTER" print >> sys.stderr, "AFTER"
user = xAuthenticator.getUserName().encode('ascii') user = xAuthenticator.getUserName().encode('ascii')
password = xAuthenticator.getPassword().encode('ascii') password = xAuthenticator.getPassword().encode('ascii')
if user != '': if user != '':
...@@ -300,6 +302,7 @@ class PyMailPOP3Service(unohelper.Base, XMailService): ...@@ -300,6 +302,7 @@ class PyMailPOP3Service(unohelper.Base, XMailService):
self.supportedtypes = ('Insecure', 'Ssl') self.supportedtypes = ('Insecure', 'Ssl')
self.server = None self.server = None
self.connectioncontext = None self.connectioncontext = None
self.notify = EventObject(self)
if dbg: if dbg:
print >> sys.stderr, "PyMailPOP3Service init" print >> sys.stderr, "PyMailPOP3Service init"
def addConnectionListener(self, xListener): def addConnectionListener(self, xListener):
...@@ -329,18 +332,18 @@ class PyMailPOP3Service(unohelper.Base, XMailService): ...@@ -329,18 +332,18 @@ class PyMailPOP3Service(unohelper.Base, XMailService):
if dbg: if dbg:
print >> sys.stderr, connectiontype print >> sys.stderr, connectiontype
print >> sys.stderr, "BEFORE" print >> sys.stderr, "BEFORE"
if connectiontype == '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) self.server = poplib.POP3(server, port)
print >> sys.stderr, "AFTER" print >> sys.stderr, "AFTER"
user = xAuthenticator.getUserName().encode('ascii') user = xAuthenticator.getUserName().encode('ascii')
password = xAuthenticator.getPassword().encode('ascii') password = xAuthenticator.getPassword().encode('ascii')
if dbg: if dbg:
print >> sys.stderr, 'Logging in, username of', user print >> sys.stderr, 'Logging in, username of', user
self.server.user(user) self.server.user(user)
self.server.pass_(user, password) self.server.pass_(password)
for listener in self.listeners: for listener in self.listeners:
listener.connected(self.notify) listener.connected(self.notify)
...@@ -384,12 +387,12 @@ class PyMailMessage(unohelper.Base, XMailMessage): ...@@ -384,12 +387,12 @@ class PyMailMessage(unohelper.Base, XMailMessage):
print >> sys.stderr, "PyMailMessage init" print >> sys.stderr, "PyMailMessage init"
self.ctx = ctx self.ctx = ctx
self.recipients = sTo, self.recipients = [sTo]
self.ccrecipients = () self.ccrecipients = []
self.bccrecipients = () self.bccrecipients = []
self.aMailAttachments = () self.aMailAttachments = []
if aMailAttachment != None: if aMailAttachment != None:
self.aMailAttachments = aMailAttachment, self.aMailAttachments.append(aMailAttachment)
self.SenderName, self.SenderAddress = parseaddr(sFrom) self.SenderName, self.SenderAddress = parseaddr(sFrom)
self.ReplyToAddress = sFrom self.ReplyToAddress = sFrom
...@@ -400,35 +403,36 @@ class PyMailMessage(unohelper.Base, XMailMessage): ...@@ -400,35 +403,36 @@ class PyMailMessage(unohelper.Base, XMailMessage):
def addRecipient( self, recipient ): def addRecipient( self, recipient ):
if dbg: if dbg:
print >> sys.stderr, "PyMailMessage.addRecipient", recipient print >> sys.stderr, "PyMailMessage.addRecipient", recipient
self.recipients = self.recipients, recipient self.recipients.append(recipient)
def addCcRecipient( self, ccrecipient ): def addCcRecipient( self, ccrecipient ):
if dbg: if dbg:
print >> sys.stderr, "PyMailMessage.addCcRecipient", ccrecipient print >> sys.stderr, "PyMailMessage.addCcRecipient", ccrecipient
self.ccrecipients = self.ccrecipients, ccrecipient self.ccrecipients.append(ccrecipient)
def addBccRecipient( self, bccrecipient ): def addBccRecipient( self, bccrecipient ):
if dbg: if dbg:
print >> sys.stderr, "PyMailMessage.addBccRecipient", bccrecipient print >> sys.stderr, "PyMailMessage.addBccRecipient", bccrecipient
self.bccrecipients = self.bccrecipients, bccrecipient self.bccrecipients.append(bccrecipient)
def getRecipients( self ): def getRecipients( self ):
if dbg: if dbg:
print >> sys.stderr, "PyMailMessage.getRecipients", self.recipients print >> sys.stderr, "PyMailMessage.getRecipients", self.recipients
return self.recipients return tuple(self.recipients)
def getCcRecipients( self ): def getCcRecipients( self ):
if dbg: if dbg:
print >> sys.stderr, "PyMailMessage.getCcRecipients", self.ccrecipients print >> sys.stderr, "PyMailMessage.getCcRecipients", self.ccrecipients
return self.ccrecipients return tuple(self.ccrecipients)
def getBccRecipients( self ): def getBccRecipients( self ):
if dbg: if dbg:
print >> sys.stderr, "PyMailMessage.getBccRecipients", self.bccrecipients print >> sys.stderr, "PyMailMessage.getBccRecipients", self.bccrecipients
return self.bccrecipients return tuple(self.bccrecipients)
def addAttachment( self, aMailAttachment ): def addAttachment( self, aMailAttachment ):
if dbg: if dbg:
print >> sys.stderr, "PyMailMessage.addAttachment" print >> sys.stderr, "PyMailMessage.addAttachment"
self.aMailAttachments = self.aMailAttachments, aMailAttachment self.aMailAttachments.append(aMailAttachment)
def getAttachments( self ): def getAttachments( self ):
if dbg: if dbg:
print >> sys.stderr, "PyMailMessage.getAttachments" print >> sys.stderr, "PyMailMessage.getAttachments"
return self.aMailAttachments return tuple(self.aMailAttachments)
# pythonloader looks for a static g_ImplementationHelper variable # pythonloader looks for a static g_ImplementationHelper variable
g_ImplementationHelper = unohelper.ImplementationHelper() g_ImplementationHelper = unohelper.ImplementationHelper()
......
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