Utils: Finish ParsedEmail --> EmailAddress conversion

Within an EmailAddress (previously ParsedEmail object), properties
now match Python 3.6 email.headerregistry.Address naming:

* .email --> .addr_spec
* .name --> .display_name
* .localpart --> .username

(Completes work started in 386668908423d1d4eade90cf7a21a546a1e96514;
this updates remaining uses of old names and removes them.)
This commit is contained in:
medmunds
2017-10-27 17:53:13 -07:00
parent bb68f3dd6d
commit 9acf6501b5
10 changed files with 40 additions and 56 deletions

View File

@@ -64,7 +64,7 @@ class EmailBackend(AnymailRequestsBackend):
# SendGrid v3 doesn't provide any information in the response for a successful send,
# so simulate a per-recipient status of "queued":
status = AnymailRecipientStatus(message_id=payload.message_id, status="queued")
return {recipient.email: status for recipient in payload.all_recipients}
return {recipient.addr_spec: status for recipient in payload.all_recipients}
class SendGridPayload(RequestsPayload):
@@ -199,17 +199,17 @@ class SendGridPayload(RequestsPayload):
@staticmethod
def email_object(email, workaround_name_quote_bug=False):
"""Converts ParsedEmail to SendGrid API {email, name} dict"""
obj = {"email": email.email}
if email.name:
"""Converts EmailAddress to SendGrid API {email, name} dict"""
obj = {"email": email.addr_spec}
if email.display_name:
# Work around SendGrid API bug: v3 fails to properly quote display-names
# containing commas or semicolons in personalizations (but not in from_email
# or reply_to). See https://github.com/sendgrid/sendgrid-python/issues/291.
# We can work around the problem by quoting the name for SendGrid.
if workaround_name_quote_bug:
obj["name"] = '"%s"' % rfc822_quote(email.name)
obj["name"] = '"%s"' % rfc822_quote(email.display_name)
else:
obj["name"] = email.name
obj["name"] = email.display_name
return obj
def set_from_email(self, email):