changeset 4:bf14f603f5e4 4.4 tip

Add From to email header issue6632 review40511002
author Cédric Krier <ced@b2ck.com>
date Fri, 28 Jul 2017 09:16:29 +0200
parents 2b29d5281b88
children
files notification.py tests/test_notification_email.py
diffstat 2 files changed, 6 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/notification.py	Wed Jul 26 18:59:14 2017 +0200
+++ b/notification.py	Fri Jul 28 09:16:29 2017 +0200
@@ -177,7 +177,7 @@
         else:
             return {self._get_language(value)}
 
-    def get_email(self, record, to, cc, bcc, languages):
+    def get_email(self, record, from_, to, cc, bcc, languages):
         pool = Pool()
         Attachment = pool.get('notification.email.attachment')
 
@@ -193,6 +193,7 @@
         else:
             msg = content
 
+        msg['From'] = from_
         msg['To'] = ', '.join(to)
         msg['Cc'] = ', '.join(cc)
         msg['Bcc'] = ', '.join(bcc)
@@ -248,7 +249,7 @@
                     languagues.update(self._get_languages(recipients_hidden))
                     bcc = self._get_addresses(recipients_hidden)
 
-            msg = self.get_email(record, to, cc, bcc, languagues)
+            msg = self.get_email(record, from_, to, cc, bcc, languagues)
             to_addrs = [e for _, e in getaddresses(to + cc + bcc)]
             if to_addrs:
                 sendmail_transactional(
--- a/tests/test_notification_email.py	Wed Jul 26 18:59:14 2017 +0200
+++ b/tests/test_notification_email.py	Fri Jul 28 09:16:29 2017 +0200
@@ -88,6 +88,7 @@
                 FROM, ['user@example.com'], ANY,
                 datamanager=ANY)
             _, _, msg = sendmail.call_args[0]
+            self.assertEqual(msg['From'], FROM)
             self.assertEqual(msg['Subject'], 'Notification Email')
             self.assertEqual(msg['To'], 'Administrator <user@example.com>')
             self.assertEqual(msg.get_content_type(), 'multipart/alternative')
@@ -152,8 +153,9 @@
         user, = User.create([{'name': "Michael Scott", 'login': "msc"}])
 
         msg = notification_email.get_email(
-            user, ['Administrator <user@example.com>'], [], [], ['en'])
+            user, FROM, ['Administrator <user@example.com>'], [], [], ['en'])
 
+        self.assertEqual(msg['From'], FROM)
         self.assertEqual(msg['Subject'], 'Notification Email')
         self.assertEqual(msg['To'], 'Administrator <user@example.com>')
         self.assertEqual(msg.get_content_type(), 'multipart/mixed')