plugin smtp: fixed email address parsing and invalid unicode message
This commit is contained in:
parent
e4586d5a07
commit
ee98769ddf
1 changed files with 9 additions and 3 deletions
|
|
@ -28,10 +28,11 @@ from twisted.cred import error as cred_error
|
|||
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 @@ class SatSmtpMessage:
|
|||
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)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue