email: Set List-Unsubscribe headers where we have unsubscribe links.

Since we have a convention of using `unsubscribe_link` as the context
variable name, this will apply to all of our emails with confirmation
links.
This commit is contained in:
Tim Abbott
2021-04-27 16:10:00 -07:00
committed by Tim Abbott
parent 84db1e9737
commit f52005b638

View File

@@ -164,6 +164,16 @@ def build_email(
if len(sanitize_address(extra_headers["From"], "utf-8")) > 320:
extra_headers["From"] = str(Address(addr_spec=from_address))
# If we have an unsubscribe link for this email, configure it for
# "Unsubscribe" buttons in email clients via the List-Unsubscribe header.
#
# Note that Microsoft ignores URLs in List-Unsubscribe headers, as
# they only support the alternative `mailto:` format, which we
# have not implemented.
if "unsubscribe_link" in context:
extra_headers["List-Unsubscribe"] = f"<{context['unsubscribe_link']}>"
extra_headers["List-Unsubscribe-Post"] = "List-Unsubscribe=One-Click"
reply_to = None
if reply_to_email is not None:
reply_to = [reply_to_email]