From 783422369e60628d08a141cd274e2d0a17f7220f Mon Sep 17 00:00:00 2001 From: moson Date: Tue, 28 Nov 2023 09:33:02 +0100 Subject: [PATCH] feat: Set reply-to header for notifications to ML We can set the "reply-to" header to the "to" address for any mails that go out to the aur-requests mailing list. Signed-off-by: moson --- aurweb/scripts/notify.py | 13 ++++++++++++- test/test_notify.py | 7 +++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/aurweb/scripts/notify.py b/aurweb/scripts/notify.py index 0e548be4..5bb81e20 100755 --- a/aurweb/scripts/notify.py +++ b/aurweb/scripts/notify.py @@ -59,10 +59,13 @@ class Notification: body += "\n" + "[%d] %s" % (i + 1, ref) return body.rstrip() + def get_reply_to(self): + return aurweb.config.get("notifications", "reply-to") + def _send(self) -> None: sendmail = aurweb.config.get("notifications", "sendmail") sender = aurweb.config.get("notifications", "sender") - reply_to = aurweb.config.get("notifications", "reply-to") + reply_to = self.get_reply_to() reason = self.__class__.__name__ if reason.endswith("Notification"): reason = reason[: -len("Notification")] @@ -563,6 +566,7 @@ class RequestOpenNotification(Notification): ) self._to = aurweb.config.get("options", "aur_request_ml") + self._reply_to = self._to query = ( db.query(PackageRequest) @@ -599,6 +603,9 @@ class RequestOpenNotification(Notification): def get_recipients(self): return [(self._to, "en")] + def get_reply_to(self): + return self._reply_to + def get_cc(self): return self._cc @@ -654,6 +661,7 @@ class RequestCloseNotification(Notification): self._user = user.Username if user else None self._to = aurweb.config.get("options", "aur_request_ml") + self._reply_to = self._to query = ( db.query(PackageRequest) @@ -700,6 +708,9 @@ class RequestCloseNotification(Notification): def get_recipients(self): return [(self._to, "en")] + def get_reply_to(self): + return self._reply_to + def get_cc(self): return self._cc diff --git a/test/test_notify.py b/test/test_notify.py index 3d773bc2..bc6d878f 100644 --- a/test/test_notify.py +++ b/test/test_notify.py @@ -13,6 +13,7 @@ from aurweb.testing.smtp import FakeSMTP, FakeSMTP_SSL aur_location = config.get("options", "aur_location") aur_request_ml = config.get("options", "aur_request_ml") +aur_reply_to = config.get("notifications", "reply-to") @pytest.fixture(autouse=True) @@ -411,6 +412,7 @@ def test_open_close_request( email = Email(1).parse() assert email.headers.get("To") == aur_request_ml + assert email.headers.get("Reply-to") == aur_request_ml assert email.headers.get("Cc") == ", ".join([user.Email, user2.Email]) expected = f"[PRQ#{pkgreq.ID}] Orphan Request for {pkgbase.Name}" assert email.headers.get("Subject") == expected @@ -432,6 +434,7 @@ This is a request test comment. email = Email(2).parse() assert email.headers.get("To") == aur_request_ml + assert email.headers.get("Reply-to") == aur_request_ml assert email.headers.get("Cc") == ", ".join([user.Email, user2.Email]) expected = f"[PRQ#{pkgreq.ID}] Orphan Request for {pkgbase.Name} Rejected" assert email.headers.get("Subject") == expected @@ -450,6 +453,7 @@ Request #{pkgreq.ID} has been rejected by {user2.Username} [1]. email = Email(3).parse() assert email.headers.get("To") == aur_request_ml + assert email.headers.get("Reply-to") == aur_request_ml assert email.headers.get("Cc") == ", ".join([user.Email, user2.Email]) expected = f"[PRQ#{pkgreq.ID}] Orphan Request for " f"{pkgbase.Name} Accepted" assert email.headers.get("Subject") == expected @@ -476,6 +480,7 @@ def test_close_request_comaintainer_cc( email = Email(1).parse() assert email.headers.get("To") == aur_request_ml + assert email.headers.get("Reply-to") == aur_request_ml assert email.headers.get("Cc") == ", ".join([user.Email, user2.Email]) @@ -530,6 +535,7 @@ def test_close_request_closure_comment( email = Email(1).parse() assert email.headers.get("To") == aur_request_ml + assert email.headers.get("Reply-to") == aur_request_ml assert email.headers.get("Cc") == ", ".join([user.Email, user2.Email]) expected = f"[PRQ#{pkgreq.ID}] Orphan Request for {pkgbase.Name} Accepted" assert email.headers.get("Subject") == expected @@ -721,6 +727,7 @@ def test_notification_defaults(): assert notif.get_refs() == tuple() assert notif.get_headers() == dict() assert notif.get_cc() == list() + assert notif.get_reply_to() == aur_reply_to def test_notification_oserror(user: User, caplog: pytest.LogCaptureFixture):