# HG changeset patch # User Goffi # Date 1308930322 -7200 # Node ID 68cdaf6d78e322fd87a4b80211b7ee25b98e35b3 # Parent e83d0c21d64d7e33477982bc26092a55094e061f plugin smtp: fixed email address parsing and invalid unicode message diff -r e83d0c21d64d -r 68cdaf6d78e3 src/plugins/plugin_misc_smtp.py --- 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)