Mercurial > libervia-backend
changeset 370:68cdaf6d78e3
plugin smtp: fixed email address parsing and invalid unicode message
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 24 Jun 2011 17:45:22 +0200 |
parents | e83d0c21d64d |
children | 3ea41a199b36 |
files | src/plugins/plugin_misc_smtp.py |
diffstat | 1 files changed, 9 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/src/plugins/plugin_misc_smtp.py Sun Jun 19 17:40:36 2011 +0200 +++ b/src/plugins/plugin_misc_smtp.py Fri Jun 24 17:45:22 2011 +0200 @@ -28,10 +28,11 @@ from twisted.mail import smtp from twisted.python import failure from email.parser import Parser +from email.utils import parseaddr from twisted.mail.imap4 import LOGINCredentials, PLAINCredentials import os,os.path from twisted.internet import reactor -import pdb +import sys from zope.interface import implements @@ -88,8 +89,13 @@ def eomReceived(self): """handle end of message""" mail = Parser().parsestr("\n".join(self.message)) - self.host.sendMessage(mail['to'].decode('utf-8'), mail.get_payload().decode('utf-8'), - subject=mail['subject'].decode('utf-8'), type='normal', profile_key=self.profile) + try: + self.host.sendMessage(parseaddr(mail['to'].decode('utf-8','replace'))[1], mail.get_payload().decode('utf-8','replace'), #TODO: manage other charsets + subject=mail['subject'].decode('utf-8','replace'), type='normal', profile_key=self.profile) + except: + exc_type, exc_value, exc_traceback = sys.exc_info() + error(_("Can't send message: %s") % exc_value) #The email is invalid or incorreclty parsed + return defer.fail() self.message=None return defer.succeed(None)