From 3a16017679691804f39c32187a02e6d20f22ed3d Mon Sep 17 00:00:00 2001 From: Karsten Hopp Date: Jun 13 2018 14:11:57 +0000 Subject: [PATCH 1/3] skip Reply-To or Mail-Followup-To when mail_id is unset Fixes https://pagure.io/pagure/issue/3289 --- diff --git a/pagure/lib/notify.py b/pagure/lib/notify.py index d46bfb1..d79d774 100644 --- a/pagure/lib/notify.py +++ b/pagure/lib/notify.py @@ -329,16 +329,17 @@ def send_email(text, subject, to_mail, if salt and not isinstance(salt, bytes): salt = salt.encode('utf-8') - key = (b'<' + mail_id.encode("utf-8") + b'>' + salt - + mailto.encode("utf-8")) - if isinstance(key, six.text_type): - key = key.encode('utf-8') - mhash = hashlib.sha512(key) - - msg['Reply-To'] = 'reply+%s@%s' % ( - mhash.hexdigest(), - pagure_config['DOMAIN_EMAIL_NOTIFICATIONS']) - msg['Mail-Followup-To'] = msg['Reply-To'] + if mail_id: + key = (b'<' + mail_id.encode("utf-8") + b'>' + salt + + mailto.encode("utf-8")) + if isinstance(key, six.text_type): + key = key.encode('utf-8') + mhash = hashlib.sha512(key) + + msg['Reply-To'] = 'reply+%s@%s' % ( + mhash.hexdigest(), + pagure_config['DOMAIN_EMAIL_NOTIFICATIONS']) + msg['Mail-Followup-To'] = msg['Reply-To'] if not pagure_config.get('EMAIL_SEND', True): _log.debug('******EMAIL******') _log.debug('From: %s', from_email) From f6ca9b09c9acb0b038176caeffa5111e6e58c696 Mon Sep 17 00:00:00 2001 From: Karsten Hopp Date: Jun 13 2018 18:29:38 +0000 Subject: [PATCH 2/3] add testcase for https://pagure.io/pagure/issue/3289 --- diff --git a/tests/test_pagure_lib_notify.py b/tests/test_pagure_lib_notify.py index 1b94d75..c62c97c 100644 --- a/tests/test_pagure_lib_notify.py +++ b/tests/test_pagure_lib_notify.py @@ -390,6 +390,31 @@ RW1haWwgY29udGVudA== del email["From"] del email["To"] self.assertEqual(email.as_string(), exp) + exp = '''Content-Type: text/plain; charset="utf-8" +MIME-Version: 1.0 +Content-Transfer-Encoding: base64 +Subject: =?utf-8?b?W25hbWVzcGFjZS9wcm9qZWN0XSBFbWFpbCDigJxTdWJqZWN04oCc?= +In-Reply-To: +X-Auto-Response-Suppress: All +X-pagure: http://localhost.localdomain/ +X-pagure-project: namespace/project +List-ID: namespace/project +List-Archive: http://localhost.localdomain/namespace/project + +RW1haWwgY29udGVudA== +''' + email = pagure.lib.notify.send_email( + 'Email content', + 'Email “Subject“', + 'foo@bar.com,zöé@foo.net', + mail_id=None, + in_reply_to='test-pull-request-2edbf96ebe644f4bb31b94605e', + project_name='namespace/project', + user_from='Zöé', + ) + del email["From"] + del email["To"] + self.assertEqual(email.as_string(), exp) if __name__ == '__main__': From 8f18fd13ce009619e52c9ea7dd2925ab3ce649e1 Mon Sep 17 00:00:00 2001 From: Karsten Hopp Date: Jun 14 2018 10:03:42 +0000 Subject: [PATCH 3/3] fix whitespace --- diff --git a/pagure/lib/notify.py b/pagure/lib/notify.py index d79d774..0e2dc9c 100644 --- a/pagure/lib/notify.py +++ b/pagure/lib/notify.py @@ -335,7 +335,7 @@ def send_email(text, subject, to_mail, if isinstance(key, six.text_type): key = key.encode('utf-8') mhash = hashlib.sha512(key) - + msg['Reply-To'] = 'reply+%s@%s' % ( mhash.hexdigest(), pagure_config['DOMAIN_EMAIL_NOTIFICATIONS'])