Extract two methods from recipient_for_emails.

We now have these methods:
    user_profiles_from_unvalidated_emails
    recipient_for_user_profiles
This commit is contained in:
Steve Howell 2017-08-17 19:57:48 -04:00 committed by Tim Abbott
parent 30d37d1270
commit 32f18f77d4
1 changed files with 16 additions and 0 deletions

View File

@ -1163,6 +1163,17 @@ def recipient_for_emails(emails, not_forged_mirror_message,
forwarder_user_profile, sender):
# type: (Iterable[Text], bool, Optional[UserProfile], UserProfile) -> Recipient
user_profiles = user_profiles_from_unvalidated_emails(emails)
return recipient_for_user_profiles(
user_profiles=user_profiles,
not_forged_mirror_message=not_forged_mirror_message,
forwarder_user_profile=forwarder_user_profile,
sender=sender
)
def user_profiles_from_unvalidated_emails(emails):
# type: (Iterable[Text]) -> List[UserProfile]
user_profiles = [] # type: List[UserProfile]
for email in emails:
try:
@ -1170,6 +1181,11 @@ def recipient_for_emails(emails, not_forged_mirror_message,
except UserProfile.DoesNotExist:
raise ValidationError(_("Invalid email '%s'") % (email,))
user_profiles.append(user_profile)
return user_profiles
def recipient_for_user_profiles(user_profiles, not_forged_mirror_message,
forwarder_user_profile, sender):
# type: (List[UserProfile], bool, Optional[UserProfile], UserProfile) -> Recipient
recipient_profile_ids = validate_recipient_user_profiles(user_profiles, sender)