Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allows users to submit rfc822 formatted email addresses #348

Merged
merged 10 commits into from
Oct 23, 2017
32 changes: 25 additions & 7 deletions sendgrid/helpers/mail/mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,13 +260,15 @@ def add_custom_arg(self, custom_arg):
class Email(object):

def __init__(self, email=None, name=None):
self._name = None
self._email = None

if email is not None:
self.email = email
if name is not None:
self.name = name
if not name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be if not name:

# allows passing emails as "dude Fella <example@example.com>"
self.parse_email(email)
else:
#allows backwards compatibility for Email(email, name)
if email is not None:
self.email = email
if name is not None:
self.name = name

@property
def name(self):
Expand All @@ -293,6 +295,22 @@ def get(self):
email["email"] = self.email
return email

def parse_email(self, email_info):
try:
import rfc822
except ImportError:
import email.utils as rfc822

name, email = rfc822.parseaddr(email_info)
if not name:
name = None

if not email:
email = None

self.name(name)
self.email(email)
return name, email

class Content(object):

Expand Down