#NEWLINE# def send_review_mail( user , review_request , subject , in_reply_to , to_field , cc_field , text_template_name , html_template_name , context = None , extra_headers = None ) : #NEWLINE# #INDENT# "Format and send an e-mail out.\n\n    Args:\n        user (django.contrib.auth.models.User):\n            The user who is sending the e-mail.\n\n        review_request (reviewboard.reviews.models.ReviewRequest):\n            The review request that the e-mail is about.\n\n        subject (unicode):\n            The subject of the e-mail address.\n\n        in_reply_to (unicode):\n            The e-mail message ID for threading.\n\n        to_field (list):\n            The recipients to send the e-mail to. This should be a list of\n            :py:class:`Users <django.contrib.auth.models.User>` and\n            :py:class:`Groups <reviewboard.reviews.models.Group>`.\n\n        cc_field (list):\n            The addresses to be CC'ed on the e-mail. This should be a list of\n            :py:class:`Users <django.contrib.auth.models.User>` and\n            :py:class:`Groups <reviewboard.reviews.models.Group>`.\n\n        text_template_name (unicode):\n            The name for the text e-mail template.\n\n        html_template_name (unicode):\n            The name for the HTML e-mail template.\n\n        context (dict):\n            Optional extra context to provide to the template.\n\n        extra_headers (dict):\n            Either a dict or\n            :py:class:`~django.utils.datastructures.MultiValueDict` providing\n            additional headers to send with the e-mail.\n\n    Returns:\n        unicode: The resulting e-mail message ID.\n    " #NEWLINE# current_site = Site . objects . get_current ( ) #NEWLINE# local_site = review_request . local_site #NEWLINE# from_email = get_email_address_for_user ( user ) #NEWLINE# to_field = recipients_to_addresses ( to_field , review_request . id ) #NEWLINE# cc_field = ( recipients_to_addresses ( cc_field , review_request . id ) - to_field ) #NEWLINE# if ( not user . should_send_own_updates ( ) ) : #NEWLINE# #INDENT# user_email = get_email_address_for_user ( user ) #NEWLINE# to_field . discard ( user_email ) #NEWLINE# cc_field . discard ( user_email ) #NEWLINE# #UNINDENT# if ( ( not to_field ) and ( not cc_field ) ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# siteconfig = current_site . config . get ( ) #NEWLINE# domain_method = siteconfig . get ( 'site_domain_method' ) #NEWLINE# if ( not context ) : #NEWLINE# #INDENT# context = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# context [ 'user' ] = user #NEWLINE# context [ 'domain' ] = current_site . domain #NEWLINE# context [ 'domain_method' ] = domain_method #NEWLINE# context [ 'review_request' ] = review_request #NEWLINE# if review_request . local_site : #NEWLINE# #INDENT# context [ 'local_site_name' ] = review_request . local_site . name #NEWLINE# #UNINDENT# text_body = render_to_string ( text_template_name , context ) #NEWLINE# html_body = render_to_string ( html_template_name , context ) #NEWLINE# base_url = get_server_url ( local_site = local_site ) #NEWLINE# headers = MultiValueDict ( { #NEWLINE# #INDENT# 'X-ReviewBoard-URL' : [ base_url ] , #NEWLINE# 'X-ReviewRequest-URL' : [ urljoin ( base_url , review_request . get_absolute_url ( ) ) ] , #NEWLINE# 'X-ReviewGroup' : [ ', ' . join ( ( group . name for group in review_request . target_groups . all ( ) ) ) ] , #NEWLINE# #UNINDENT# } ) #NEWLINE# if extra_headers : #NEWLINE# #INDENT# if ( not isinstance ( extra_headers , MultiValueDict ) ) : #NEWLINE# #INDENT# extra_headers = MultiValueDict ( ( ( key , [ value ] ) for ( key , value ) in six . iteritems ( extra_headers ) ) ) #NEWLINE# #UNINDENT# headers . update ( extra_headers ) #NEWLINE# #UNINDENT# if review_request . repository : #NEWLINE# #INDENT# headers [ 'X-ReviewRequest-Repository' ] = review_request . repository . name #NEWLINE# #UNINDENT# latest_diffset = review_request . get_latest_diffset ( ) #NEWLINE# if latest_diffset : #NEWLINE# #INDENT# modified_files = set ( ) #NEWLINE# for filediff in latest_diffset . files . all ( ) : #NEWLINE# #INDENT# if ( filediff . deleted or filediff . copied or filediff . moved ) : #NEWLINE# #INDENT# modified_files . add ( filediff . source_file ) #NEWLINE# #UNINDENT# if ( filediff . is_new or filediff . copied or filediff . moved ) : #NEWLINE# #INDENT# modified_files . add ( filediff . dest_file ) #NEWLINE# #UNINDENT# #UNINDENT# for filename in modified_files : #NEWLINE# #INDENT# headers . appendlist ( 'X-ReviewBoard-Diff-For' , filename ) #NEWLINE# #UNINDENT# #UNINDENT# sender = None #NEWLINE# if settings . DEFAULT_FROM_EMAIL : #NEWLINE# #INDENT# sender = build_email_address ( user . get_full_name ( ) , settings . DEFAULT_FROM_EMAIL ) #NEWLINE# if ( user == from_email ) : #NEWLINE# #INDENT# sender = None #NEWLINE# #UNINDENT# #UNINDENT# message = EmailMessage ( subject . strip ( ) , text_body . encode ( 'utf-8' ) , html_body . encode ( 'utf-8' ) , from_email , sender , list ( to_field ) , list ( cc_field ) , in_reply_to , headers ) #NEWLINE# try : #NEWLINE# #INDENT# message . send ( ) #NEWLINE# #UNINDENT# except Exception : #NEWLINE# #INDENT# logging . exception ( "Error sending e-mail notification with subject '%s' on behalf of '%s' to '%s'" , subject . strip ( ) , from_email , ',' . join ( ( list ( to_field ) + list ( cc_field ) ) ) ) #NEWLINE# #UNINDENT# return message . message_id