예제 #1
0
    def create_mail(self, message):
        """Use `CreateEmailCommand` to create the mailed-in mail."""

        self.check_permission()
        self.check_addable_types()

        # we don't set the content-type directly here but choose it with a
        # roundtrip via mimetype registry.
        if self.is_application_pkcs7_mime(message):
            filename = 'message.p7m'
        else:
            filename = 'message.eml'

        command = CreateEmailCommand(self.context,
                                     filename,
                                     message,
                                     message_source=MESSAGE_SOURCE_MAILIN)
        return command.execute()
예제 #2
0
    def create_emails(self):
        self.mail_eml = self.register(
            'mail_eml',
            create(
                Builder("mail").with_message(MAIL_DATA).within(self.dossier)))

        self.register('mail', self.mail_eml)

        class MockMsg2MimeTransform(object):
            def transform(self, data):
                return 'mock-eml-body'

        command = CreateEmailCommand(
            self.dossier,
            'testm\xc3\xa4il.msg',
            'mock-msg-body',
            transform=MockMsg2MimeTransform(),
        )

        self.mail_msg = self.register('mail_msg', command.execute())
예제 #3
0
    def extract_attachment_into_parent(self, position):
        """Extract one specified attachment into the mails parent dossier or
        inbox.

        Also add a reference from all attached documents (*not* mails) to self.

        Position must be an integer attachment positions. The position
        can be obtained from the attachment description returned by
        `get_attachments`.
        """
        parent = self.get_extraction_parent()
        if parent is None:
            raise RuntimeError("Could not find a parent dossier or inbox for "
                               "{}".format(self.absolute_url()))

        data, content_type, filename = self._get_attachment_data(position)
        title = os.path.splitext(filename)[0]

        if content_type == 'message/rfc822':
            doc = CreateEmailCommand(parent,
                                     filename,
                                     data,
                                     title=title,
                                     content_type=content_type,
                                     digitally_available=True).execute()
        else:
            doc = CreateDocumentCommand(parent,
                                        filename,
                                        data,
                                        title=title,
                                        content_type=content_type,
                                        digitally_available=True).execute()

            # add a reference from the attachment to the mail
            intids = getUtility(IIntIds)
            iid = intids.getId(self)

            IRelatedDocuments(doc).relatedItems = [RelationValue(iid)]
            doc.reindexObject()

        return doc