def __init__(self, context_function): self.attachments = [] self.content_txt = "" self.content_html = "" parameters, contexts = context_function() hosts = set([]) for context in contexts: context.update(parameters) utils.html_escape_context(context) extend_context(context) txt, html, att = construct_content(context) self.content_txt += txt self.content_html += html self.attachments += att hosts.add(context["HOSTNAME"]) last_context = contexts[-1] self.mailto = last_context[ 'CONTACTEMAIL'] # Assume the same in each context # Use the single context subject in case there is only one context in the bulk self.subject = (utils.get_bulk_notification_subject(contexts, hosts) if len(contexts) > 1 else last_context['SUBJECT']) # TODO: cleanup duplicate code with SingleEmailContent # TODO: the context is only needed because of SMPT settings used in send_mail self.from_address = last_context.get( "PARAMETER_FROM") or default_from_address() self.reply_to = last_context.get("PARAMETER_REPLY_TO") self.context = last_context
def __init__(self, context_function): # gather all options from env context = context_function() escaped_context = utils.html_escape_context(context) extend_context(escaped_context) content_txt, content_html, attachments = construct_content(escaped_context) # TODO: cleanup duplicate code with BulkEmailContent # TODO: the context is only needed because of SMPT settings used in send_mail super().__init__( context=escaped_context, mailto=escaped_context["CONTACTEMAIL"], subject=escaped_context["SUBJECT"], from_address=utils.format_address( escaped_context.get("PARAMETER_FROM_DISPLAY_NAME", ""), escaped_context.get("PARAMETER_FROM_ADDRESS", utils.default_from_address()), ), reply_to=utils.format_address( escaped_context.get("PARAMETER_REPLY_TO_DISPLAY_NAME", ""), escaped_context.get("PARAMETER_REPLY_TO_ADDRESS", ""), ), content_txt=content_txt, content_html=content_html, attachments=attachments, )
def __init__(self, context_function): # gather all options from env context = context_function() utils.html_escape_context(context) content_txt, content_html, attachments = construct_content(context) self.content_txt = content_txt self.content_html = content_html self.attachments = attachments self.mailto = context['CONTACTEMAIL'] self.subject = context['SUBJECT'] # TODO: cleanup duplicate code with BulkEmailContent # TODO: the context is only needed because of SMPT settings used in send_mail self.from_address = context.get("PARAMETER_FROM") or default_from_address() self.reply_to = context.get("PARAMETER_REPLY_TO") self.context = context
def __init__(self, context_function): attachments = [] content_txt = "" content_html = "" parameters, contexts = context_function() context = contexts[-1] hosts = set([]) for i, c in enumerate(contexts, 1): c.update(parameters) utils.html_escape_context(c) extend_context(c) txt, html, att = construct_content(c, is_bulk=True, notification_number=i) content_txt += txt content_html += html attachments += att hosts.add(c["HOSTNAME"]) # TODO: cleanup duplicate code with SingleEmailContent # TODO: the context is only needed because of SMPT settings used in send_mail super(BulkEmailContent, self).__init__( context=context, # Assume the same in each context mailto=context['CONTACTEMAIL'], # Use the single context subject in case there is only one context in the bulk subject=(utils.get_bulk_notification_subject(contexts, hosts) if len(contexts) > 1 else context['SUBJECT']), from_address=utils.format_address( context.get("PARAMETER_FROM_DISPLAY_NAME", u""), # TODO: Correct context parameter??? context.get("PARAMETER_FROM_ADDRESS", utils.default_from_address())), reply_to=utils.format_address( context.get("PARAMETER_REPLY_TO_DISPLAY_NAME", u""), context.get("PARAMETER_REPLY_TO", u"")), content_txt=content_txt, content_html=content_html, attachments=attachments, )
def test_escape_context(input_context, expected_context): utils.html_escape_context(input_context) assert input_context == expected_context