Colin Watson has proposed merging ~cjwatson/launchpad:dmarc-for-merges-and-code
into launchpad:master.
Commit message:
Use DMARC-compliant From addresses in code review emails
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
Related bugs:
Bug #1879740 in Launchpad itself: "Make Launchpad Code Review / Merge Review
/ Code Notices DMARC Compliant"
https://bugs.launchpad.net/launchpad/+bug/1879740
For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/406528
Most of this work is by Thomas Ward; I just tidied a few things up and fixed
the tests.
--
Your team Launchpad code reviewers is requested to review the proposed merge of
~cjwatson/launchpad:dmarc-for-merges-and-code into launchpad:master.
diff --git a/lib/lp/code/doc/branch-merge-proposal-notifications.txt b/lib/lp/code/doc/branch-merge-proposal-notifications.txt
index 70d15f0..e7134c2 100644
--- a/lib/lp/code/doc/branch-merge-proposal-notifications.txt
+++ b/lib/lp/code/doc/branch-merge-proposal-notifications.txt
@@ -129,7 +129,7 @@ An email is sent to subscribers of either branch and the default reviewer.
>>> notification = notifications[0]
>>> print(notification['From'])
-Eric
+Eric
>>> print(notification['Subject'])
[Merge] lp://dev/~person-name... into lp://dev/~person-name...
>>> print(notification['X-Launchpad-Project'])
diff --git a/lib/lp/code/doc/codereviewcomment.txt b/lib/lp/code/doc/codereviewcomment.txt
index 8023afd..263f73e 100644
--- a/lib/lp/code/doc/codereviewcomment.txt
+++ b/lib/lp/code/doc/codereviewcomment.txt
@@ -86,7 +86,7 @@ Now run the pending job to send the email.
>>> notifications = [email for email in notifications if
... email['X-Launchpad-Message-Rationale'] == 'Owner']
>>> print_emails(include_reply_to=True, notifications=notifications)
-From: Sender Person
+From: Sender Person
To: ...
Reply-To: mp+...@code.launchpad.test
Subject: Please merge
diff --git a/lib/lp/code/mail/branchmergeproposal.py b/lib/lp/code/mail/branchmergeproposal.py
index 9566ae8..d876ad5 100644
--- a/lib/lp/code/mail/branchmergeproposal.py
+++ b/lib/lp/code/mail/branchmergeproposal.py
@@ -8,9 +8,9 @@ __metaclass__ = type
from lp.code.enums import CodeReviewNotificationLevel
from lp.code.mail.branch import BranchMailer
-from lp.services.config import config
from lp.services.mail.basemailer import BaseMailer
from lp.services.mail.sendmail import (
+format_address,
format_address_for_person,
get_msgid,
)
@@ -52,9 +52,8 @@ class BMPMailer(BranchMailer):
recipients = merge_proposal.getNotificationRecipients(
CodeReviewNotificationLevel.STATUS)
-assert from_user.preferredemail is not None, (
-'The sender must have an email address.')
-from_address = format_address_for_person(from_user)
+from_address = format_address(
+from_user.display_name, merge_proposal.address)
return cls(
'%(proposal_title)s',
@@ -74,11 +73,10 @@ class BMPMailer(BranchMailer):
recipients = merge_proposal.getNotificationRecipients(
CodeReviewNotificationLevel.STATUS)
if from_user is not None:
-assert from_user.preferredemail is not None, (
-'The sender must have an email address.')
-from_address = format_address_for_person(from_user)
+from_address = format_address(
+from_user.display_name, merge_proposal.address)
else:
-from_address = config.canonical.noreply_from_address
+from_address = merge_proposal.address
return cls(
'%(proposal_title)s',
'branch-merge-proposal-updated.txt', recipients,
@@ -88,7 +86,8 @@ class BMPMailer(BranchMailer):
@classmethod
def forReviewRequest(cls, reason, merge_proposal, from_user):
"""Return a mailer for a request to review a BranchMergeProposal."""
-from_address = format_address_for_person(from_user)
+from_address = format_address(
+from_user.display_name, merge_proposal.address)
recipients = {reason.subscriber: reason}
return cls(
'%(proposal_title)s',
diff --git a/lib/lp/code/mail/codereviewcomment.py b/lib/lp/code/mail/codereviewcomment.py
index 0a885d2..f9e882f 100644
--- a/lib/lp/code/mail/codereviewcomment.py
+++ b/lib/lp/code/mail/codereviewcomment.py
@@ -44,7 +44,8 @@ class CodeReviewCommentMailer(BMPMailer):
self.message = code_review_comment.message
from_person = self.message.owner
from_address = format_address(
-from_person.displayname, from_person.preferredemail.email)
+from_person.display_name,
+code_review_comment.branch_merge_proposal.address)
merge_proposal = code_review_comment.branch_merge_proposal
BMPMailer.__init__(