def construct_digest(self, messages):
        # render message body
        template = self.template.__of__(aq_inner(self.context))
        template.context = self.context
        now = datetime.now()
        date = now.strftime('%B %d, %Y')
        timestamp = "%d.%d" % (now.toordinal(), now.microsecond)
        extra_context = {
            'mailinglist': self.context,
            'messages': messages,
            'date': date,
            'constructor': self,
        }
        msghtml = template.pt_render(extra_context=extra_context)
        #XXX for some reason the template renders an empty string without this
        # hack
        # no idea why ... caching?
        # possible exception the first time through but not the next and the
        # template swalows it and returns an empty string?
        if not msghtml:
            try:
                template()
            except:
                pass
            msghtml = template.pt_render(extra_context=extra_context)

        msgtext = render(msghtml)

        # construct message object
        list_title = self.context.title
        subject = '[%s] Digest, %s' % (list_title, date)
        mailto = self.context.getValueFor('mailto')
        returnpath = self.context.getValueFor('returnpath') \
                     or self.context.manager_email
        listsub = self.context.getValueFor('subscribe')
        listsub = '<mailto:%s?subject=%s>' % (mailto, listsub)
        listunsub = self.context.getValueFor('unsubscribe')
        listunsub = '<mailto:%s?subject=%s>' % (mailto, listunsub)
        boundary = '----=_Part_%s' % timestamp
        msg_map = {
            'title': list_title,
            'subject': subject,
            'mailto': mailto,
            'xmailer': self.context.getValueFor('xmailer'),
            'returnpath': returnpath,
            'listsub': listsub,
            'listunsub': listunsub,
            'boundary': boundary,
            'msghtml': msghtml,
            'msgtext': msgtext,
        }
        for key, value in msg_map.items():
            if type(value) is unicode:
                msg_map[key] = value.encode('utf-8')
        msg_str = msg_tmpl % msg_map
        msg = email.message_from_string(msg_str)
        return msg
Example #2
0
    def construct_digest(self, messages):
        # render message body
        template = self.template.__of__(aq_inner(self.context))
        template.context = self.context
        now = datetime.now()
        date = now.strftime('%B %d, %Y')
        timestamp = "%d.%d" % (now.toordinal(), now.microsecond)
        extra_context = {'mailinglist': self.context,
                         'messages': messages,
                         'date': date,
                         'constructor': self,
                         }
        msghtml = template.pt_render(extra_context=extra_context)
        #XXX for some reason the template renders an empty string without this
        # hack
        # no idea why ... caching?
        # possible exception the first time through but not the next and the
        # template swalows it and returns an empty string?
        if not msghtml:
            try:
                template()
            except:
                pass
            msghtml = template.pt_render(extra_context=extra_context)

        msgtext = render(msghtml)

        # construct message object
        list_title = self.context.title
        subject = '[%s] Digest, %s' % (list_title, date)
        mailto = self.context.getValueFor('mailto')
        returnpath = self.context.getValueFor('returnpath') \
                     or self.context.manager_email
        listsub = self.context.getValueFor('subscribe')
        listsub = '<mailto:%s?subject=%s>' % (mailto, listsub)
        listunsub = self.context.getValueFor('unsubscribe')
        listunsub = '<mailto:%s?subject=%s>' % (mailto, listunsub)
        boundary = '----=_Part_%s' % timestamp
        msg_map = {'title': list_title,
                   'subject': subject,
                   'mailto': mailto,
                   'xmailer': self.context.getValueFor('xmailer'),
                   'returnpath': returnpath,
                   'listsub': listsub,
                   'listunsub': listunsub,
                   'boundary': boundary,
                   'msghtml': msghtml,
                   'msgtext': msgtext,
                   }
        for key, value in msg_map.items():
            if type(value) is unicode:
                msg_map[key] = value.encode('utf-8')
        msg_str = msg_tmpl % msg_map
        msg = email.message_from_string(msg_str)
        return msg
Example #3
0
 def unpack_message(self, message):
     msgstr = message.as_string()
     text_body, content_type, html_body, attachments = unpackMail(msgstr)
     if text_body:
         body = convertWebIntelligentPlainTextToHtml(text_body).strip()
     else:
         # we only have an html body; convert it to text and then
         # back to different html rendering
         body = render(html_body)
         body = convertWebIntelligentPlainTextToHtml(body).strip()
     return {'body': body, 'attachments': attachments}
 def unpack_message(self, message):
     msgstr = message.as_string()
     text_body, content_type, html_body, attachments = unpackMail(msgstr)
     if text_body:
         body = convertWebIntelligentPlainTextToHtml(text_body).strip()
     else:
         # we only have an html body; convert it to text and then
         # back to different html rendering
         body = render(html_body)
         body = convertWebIntelligentPlainTextToHtml(body).strip()
     return {'body': body, 'attachments': attachments}