예제 #1
0
파일: models.py 프로젝트: daonb/froide
    def add_message_from_email(self, email, mail_string):
        message = FoiMessage(request=self)
        message.subject = email['subject']
        message.is_response = True
        message.sender_name = email['from'][0]
        message.sender_email = email['from'][1]
        message.sender_public_body = self.public_body
        message.timestamp = convert_to_local(*email['date'])
        message.recipient = self.secret_address
        # strip timezone, in case database can't handle it
        message.timestamp = message.timestamp.replace(tzinfo=None)
        message.plaintext = email['body']
        message.html = html2markdown(email['html'])
        message.original = mail_string
        message.save()
        self.last_message = message.timestamp
        self.save()

        for attachment in email['attachments']:
            att = FoiAttachment(belongs_to=message,
                    name=attachment.name,
                    size=attachment.size,
                    filetype=attachment.content_type)
            attachment._committed = False
            att.file = File(attachment)
            att.save()
        self.message_received.send(sender=self, message=message)
예제 #2
0
파일: models.py 프로젝트: MechanisM/froide
 def add_message_from_email(self, email, mail_string):
     message = FoiMessage(request=self)
     message.subject = email['subject']
     message.is_response = True
     message.sender_name = email['from'][0]
     message.sender_email = email['from'][1]
     message.sender_public_body = self.public_body
     message.timestamp = convert_to_local(*email['date'])
     message.recipient_email = self.secret_address
     message.recipient = self.user.get_profile().display_name()
     # strip timezone, in case database can't handle it
     message.timestamp = message.timestamp.replace(tzinfo=None)
     message.plaintext = email['body']
     message.html = html2markdown(email['html'])
     message.original = mail_string
     message.save()
     self.status = 'awaiting_classification'
     self.last_message = message.timestamp
     self.save()
     has_pdf = False
     for attachment in email['attachments']:
         att = FoiAttachment(belongs_to=message,
                 name=attachment.name,
                 size=attachment.size,
                 filetype=attachment.content_type)
         if att.name is None:
             att.name = _("attached_file")
         if att.name.endswith('pdf') or 'pdf' in att.filetype:
             has_pdf = True
         attachment._committed = False
         att.file = File(attachment)
         att.save()
     if (has_pdf and
             settings.FROIDE_CONFIG.get("mail_managers_on_pdf_attachment",
                 False)):
         mail_managers(_('Message contains PDF'),
                 self.get_absolute_domain_url())
     self.message_received.send(sender=self, message=message)