fix: validate email id before passing to formataddr

This commit is contained in:
Saurabh 2020-10-16 14:09:35 +05:30
parent b720726207
commit 9219db4c2a

View file

@ -66,9 +66,14 @@ def get_email_address(user=None):
def get_formatted_email(user, mail=None):
"""get Email Address of user formatted as: `John Doe <johndoe@example.com>`"""
fullname = get_fullname(user)
if not mail:
mail = get_email_address(user)
return cstr(make_header(decode_header(formataddr((fullname, mail)))))
mail = get_email_address(user) or validate_email_address(user)
if not mail:
return ''
else:
return cstr(make_header(decode_header(formataddr((fullname, mail)))))
def extract_email_id(email):
"""fetch only the email part of the Email Address"""