def _get_source_address(course_id, course_title, truncate=True):
 course_title_no_quotes = re.sub('"', '', course_title)
 course_name = re.sub('[^\\w.-]', '_', course_id.course)
 from_addr_format = u'"{course_title}" Course Staff <{course_name}-{from_email}>'
 def format_address(course_title_no_quotes):
  '\n        Partial function for formatting the from_addr. Since\n        `course_title_no_quotes` may be truncated to make sure the returned\n        string has fewer than 320 characters, we define this function to make\n        it easy to determine quickly what the max length is for\n        `course_title_no_quotes`.\n        '
  return from_addr_format.format(course_title=course_title_no_quotes, course_name=course_name, from_email=configuration_helpers.get_value('email_from_address', settings.BULK_EMAIL_DEFAULT_FROM_EMAIL))
 from_addr = format_address(course_title_no_quotes)
 (__, encoded_from_addr) = forbid_multi_line_headers('from', from_addr, 'utf-8')
 escaped_encoded_from_addr = escape(encoded_from_addr)
 if ((len(escaped_encoded_from_addr) >= 320) and truncate):
  from_addr = format_address(course_name)
 return from_addr

def _get_source_address ( course_id , course_title , truncate = True ) : course_title_no_quotes = re . sub ( '"' , '' , course_title ) course_name = re . sub ( '[^\\w.-]' , '_' , course_id . course ) from_addr_format = u'"{course_title}" Course Staff <{course_name}-{from_email}>' def format_address ( course_title_no_quotes ) : return from_addr_format . format ( course_title = course_title_no_quotes , course_name = course_name , from_email = configuration_helpers . get_value ( 'email_from_address' , settings . BULK_EMAIL_DEFAULT_FROM_EMAIL ) ) from_addr = format_address ( course_title_no_quotes ) ( __ , encoded_from_addr ) = forbid_multi_line_headers ( 'from' , from_addr , 'utf-8' ) escaped_encoded_from_addr = escape ( encoded_from_addr ) if ( ( len ( escaped_encoded_from_addr ) >= 320 ) and truncate ) : from_addr = format_address ( course_name ) return from_addr
calculates an email address to be used as the from-address for sent emails .