<s> from __future__ import unicode_literals <EOL> from future . builtins import bytes , str <EOL> from django . contrib . auth . tokens import default_token_generator <EOL> from django . core . mail import EmailMultiAlternatives <EOL> from django . core . urlresolvers import reverse <EOL> from django . template import loader , Context <EOL> from django . utils . http import int_to_base36 <EOL> from mezzanine . conf import settings <EOL> from mezzanine . utils . urls import admin_url , next_url <EOL> from mezzanine . conf . context_processors import settings as context_settings <EOL> def split_addresses ( email_string_list ) : <EOL> """<STR_LIT>""" <EOL> return [ f for f in [ s . strip ( ) for s in email_string_list . split ( "<STR_LIT:U+002C>" ) ] if f ] <EOL> def subject_template ( template , context ) : <EOL> """<STR_LIT>""" <EOL> subject = loader . get_template ( template ) . render ( Context ( context ) ) <EOL> return "<STR_LIT:U+0020>" . join ( subject . splitlines ( ) ) . strip ( ) <EOL> def send_mail_template ( subject , template , addr_from , addr_to , context = None , <EOL> attachments = None , fail_silently = None , addr_bcc = None , <EOL> headers = None ) : <EOL> """<STR_LIT>""" <EOL> if context is None : <EOL> context = { } <EOL> if attachments is None : <EOL> attachments = [ ] <EOL> if fail_silently is None : <EOL> fail_silently = settings . EMAIL_FAIL_SILENTLY <EOL> context . update ( context_settings ( ) ) <EOL> if isinstance ( addr_to , str ) or isinstance ( addr_to , bytes ) : <EOL> addr_to = [ addr_to ] <EOL> if addr_bcc is not None and ( isinstance ( addr_bcc , str ) or <EOL> isinstance ( addr_bcc , bytes ) ) : <EOL> addr_bcc = [ addr_bcc ] <EOL> render = lambda type : loader . get_template ( "<STR_LIT>" % <EOL> ( template , type ) ) . render ( Context ( context ) ) <EOL> msg = EmailMultiAlternatives ( subject , render ( "<STR_LIT>" ) , <EOL> addr_from , addr_to , addr_bcc , <EOL> headers = headers ) <EOL> msg . attach_alternative ( render ( "<STR_LIT:html>" ) , "<STR_LIT>" ) <EOL> for attachment in attachments : <EOL> msg . attach ( * attachment ) <EOL> msg . send ( fail_silently = fail_silently ) <EOL> def send_verification_mail ( request , user , verification_type ) : <EOL> """<STR_LIT>""" <EOL> verify_url = reverse ( verification_type , kwargs = { <EOL> "<STR_LIT>" : int_to_base36 ( user . id ) , <EOL> "<STR_LIT>" : default_token_generator . make_token ( user ) , <EOL> } ) + "<STR_LIT>" + ( next_url ( request ) or "<STR_LIT:/>" ) <EOL> context = { <EOL> "<STR_LIT>" : request , <EOL> "<STR_LIT:user>" : user , <EOL> "<STR_LIT>" : verify_url , <EOL> } <EOL> subject_template_name = "<STR_LIT>" % verification_type <EOL> subject = subject_template ( subject_template_name , context ) <EOL> send_mail_template ( subject , "<STR_LIT>" % verification_type , <EOL> settings . DEFAULT_FROM_EMAIL , user . email , <EOL> context = context ) <EOL> def send_approve_mail ( request , user ) : <EOL> """<STR_LIT>""" <EOL> approval_emails = split_addresses ( settings . ACCOUNTS_APPROVAL_EMAILS ) <EOL> if not approval_emails : <EOL> return <EOL> context = { <EOL> "<STR_LIT>" : request , <EOL> "<STR_LIT:user>" : user , <EOL> "<STR_LIT>" : admin_url ( user . __class__ , "<STR_LIT>" , user . id ) , <EOL> } <EOL> subject = subject_template ( "<STR_LIT>" , context ) <EOL> send_mail_template ( subject , "<STR_LIT>" , <EOL> settings . DEFAULT_FROM_EMAIL , approval_emails , <EOL> context = context ) <EOL> def send_approved_mail ( request , user ) : <EOL> """<STR_LIT>""" <EOL> context = { "<STR_LIT>" : request , "<STR_LIT:user>" : user } <EOL> subject = subject_template ( "<STR_LIT>" , context ) <EOL> send_mail_template ( subject , "<STR_LIT>" , <EOL> settings . DEFAULT_FROM_EMAIL , user . email , <EOL> context = context ) </s>
