From 5d8ea1861f1af3c9ddde3ba606d55cd28fb3cfd8 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Mon, 7 May 2012 12:36:08 +0200 Subject: [PATCH] sendmail: correctly parse From headers, if lookup of the sender fails, print the pre-parse value --- docbow_project/docbow/management/commands/sendmail.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/docbow_project/docbow/management/commands/sendmail.py b/docbow_project/docbow/management/commands/sendmail.py index 40b8a6c..8f832de 100644 --- a/docbow_project/docbow/management/commands/sendmail.py +++ b/docbow_project/docbow/management/commands/sendmail.py @@ -63,13 +63,12 @@ In case of failure the following return value is returned: if exit_code: sys.exit(exit_code) - def handle_mail(self, mail, mail_sender, mail_recipients, **options): content_errors = [] attachments = [] recipients = [] description = u'' - mail_from = mail.get('From') + mail_from = email.utils.parseaddr(mail.get('From'))[1] tos = mail.get_all('to', []) ccs = mail.get_all('cc', []) resent_tos = mail.get_all('resent-to', []) @@ -118,7 +117,7 @@ In case of failure the following return value is returned: try: sender = mail_sender or auth_models.User.objects.get(email=mail_from) except auth_models.User.DoesNotExist: - content_errors.appen('Unable to find an unique sender for the mail %s' % mail_from) + content_errors.append('Unable to find an unique sender for the mail %s' % mail.get('From')) if content_errors: msg = [ '7.7.1 The email sent contains many errors:' ] for error in content_errors: