From 02f40ec0a2aabd55aad14c0c679b018c58cdbf6a Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Oct 03 2018 08:54:42 +0000 Subject: Fix the From header in notification emails Fixes https://pagure.io/pagure/issue/3793 Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure/lib/notify.py b/pagure/lib/notify.py index 500c384..20b8eea 100644 --- a/pagure/lib/notify.py +++ b/pagure/lib/notify.py @@ -310,7 +310,7 @@ def send_email( from_email = from_email.decode("utf-8") if user_from: header = Header(user_from, "utf-8") - from_email = "%s <%s>" % (header, from_email) + from_email = "%s <%s>" % (header.encode(), from_email) if project_name is not None: subject_tag = project_name diff --git a/tests/test_pagure_lib_notify.py b/tests/test_pagure_lib_notify.py index 8d7a914..ff77501 100644 --- a/tests/test_pagure_lib_notify.py +++ b/tests/test_pagure_lib_notify.py @@ -424,7 +424,9 @@ class PagureLibNotifytests(tests.Modeltests): # Due to differences in the way Python2 and Python3 encode non-ascii # email headers, we compare the From and To headers separately from the # rest of the message. - self.assertEqual(email["From"], "Zöé ") + self.assertEqual( + email["From"], + "=?utf-8?b?WsO2w6k=?= ") self.assertEqual(email["To"], "zöé@foo.net") del email["From"] del email["To"] @@ -456,7 +458,9 @@ RW1haWwgY29udGVudA== project_name='namespace/project', user_from='Zöé', ) - self.assertEqual(email["From"], "Zöé ") + self.assertEqual( + email["From"], + "=?utf-8?b?WsO2w6k=?= ") self.assertEqual(email["To"], "zöé@foo.net") del email["From"] del email["To"] @@ -508,7 +512,9 @@ RW1haWwgY29udGVudA== # Due to differences in the way Python2 and Python3 encode non-ascii # email headers, we compare the From and To headers separately from the # rest of the message. - self.assertEqual(email["From"], "Zöé ") + self.assertEqual( + email["From"], + "=?utf-8?b?WsO2w6k=?= ") self.assertEqual(email["To"], "zöé@foo.net") del email["From"] del email["To"]