Exemplo n.º 1
0
    def __call__(self, filename, title, description, content_type, data,
                 portal_type):
        """Quickupload description inputs are hidden in gever
        therefore we skip the description.
        """
        if self.is_email_upload(filename):
            command = CreateEmailCommand(
                self.context,
                filename,
                data,
                message_source=MESSAGE_SOURCE_DRAG_DROP_UPLOAD)
        else:
            command = CreateDocumentCommand(self.context, filename, data)

        try:
            obj = command.execute()
        except ForbiddenByQuota as exc:
            # this is an error, we must not commit
            transaction.abort()
            return {
                'error': translate(exc.message, context=self.context.REQUEST),
                'success': None
            }

        result = {'success': obj}
        return result
    def test_download_copy_delivers_msg_if_available(self, browser):
        msg_data = 'mock-msg-body'

        dossier = create(Builder('dossier'))

        class MockMsg2MimeTransform(object):

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

        command = CreateEmailCommand(dossier,
                                     'testm\xc3\xa4il.msg',
                                     msg_data,
                                     transform=MockMsg2MimeTransform())
        mail = command.execute()
        transaction.commit()

        DownloadConfirmationHelper(mail).deactivate()
        browser.login().visit(mail, view='tabbedview_view-overview')
        browser.find('Download copy').click()

        self.assertDictContainsSubset({
            'status': '200 Ok',
            'content-length': str(len(browser.contents)),
            'content-type': 'application/vnd.ms-outlook',
            'content-disposition': 'attachment; filename="testm\xc3\xa4il.msg"',
            },
            browser.headers)

        self.assertEquals(msg_data, browser.contents)
Exemplo n.º 3
0
    def test_download_copy_delivers_msg_if_available(self, browser):
        msg_data = 'mock-msg-body'

        dossier = create(Builder('dossier'))

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

        command = CreateEmailCommand(dossier,
                                     'testm\xc3\xa4il.msg',
                                     msg_data,
                                     transform=MockMsg2MimeTransform())
        mail = command.execute()
        transaction.commit()

        DownloadConfirmationHelper(mail).deactivate()
        browser.login().visit(mail, view='tabbedview_view-overview')
        browser.find('Download copy').click()

        self.assertDictContainsSubset(
            {
                'status':
                '200 Ok',
                'content-length':
                str(len(browser.contents)),
                'content-type':
                'application/vnd.ms-outlook',
                'content-disposition':
                'attachment; filename="testm\xc3\xa4il.msg"',
            }, browser.headers)

        self.assertEquals(msg_data, browser.contents)
Exemplo n.º 4
0
    def create_mail(self, message):
        """Use `CreateEmailCommand` to create the mailed-in mail."""

        self.check_permission()
        self.check_addable_types()

        command = CreateEmailCommand(self.context, 'message.eml', message,
                                     message_source=MESSAGE_SOURCE_MAILIN)
        return command.execute()
Exemplo n.º 5
0
    def test_converted_msg_is_created_correctly(self):
        self.login(self.regular_user)
        command = CreateEmailCommand(
            self.dossier, 'testm\xc3\xa4il.msg', 'mock-msg-body',
            transform=MockMsg2MimeTransform())
        mail = command.execute()

        self.assertEqual('message/rfc822', mail.message.contentType)
        self.assertEqual('no-subject.eml', mail.message.filename)

        self.assertEqual(u'testm\xe4il.msg', mail.original_message.filename)
        self.assertEqual('mock-msg-body', mail.original_message.data)
Exemplo n.º 6
0
    def test_converted_msg_is_created_correctly(self):
        command = CreateEmailCommand(self.dossier,
                                     'testm\xc3\xa4il.msg',
                                     'mock-msg-body',
                                     transform=MockMsg2MimeTransform())
        mail = command.execute()

        self.assertEqual('message/rfc822', mail.message.contentType)
        self.assertEqual('no-subject.eml', mail.message.filename)

        self.assertEqual(u'testm\xe4il.msg', mail.original_message.filename)
        self.assertEqual('mock-msg-body', mail.original_message.data)
Exemplo n.º 7
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())
Exemplo n.º 8
0
    def __call__(self,
                 filename,
                 title,
                 description,
                 content_type,
                 data, portal_type):

        if self.is_email_upload(filename):
            command = CreateEmailCommand(
                self.context, filename, data, description=description)
        else:
            command = CreateDocumentCommand(
                self.context, filename, data, description=description)

        obj = command.execute()

        result = {'success': obj}
        return result
Exemplo n.º 9
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()
Exemplo n.º 10
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
Exemplo n.º 11
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
Exemplo n.º 12
0
    def __call__(self, filename, title, description, content_type,
                 data, portal_type):
        """Quickupload description inputs are hidden in gever
        therefore we skip the description.
        """
        if self.is_email_upload(filename):
            command = CreateEmailCommand(
                self.context, filename, data,
                message_source=MESSAGE_SOURCE_DRAG_DROP_UPLOAD)
        else:
            command = CreateDocumentCommand(self.context, filename, data)

        try:
            obj = command.execute()
        except ForbiddenByQuota as exc:
            # this is an error, we must not commit
            transaction.abort()
            return {'error': translate(exc.message,
                                       context=self.context.REQUEST),
                    'success': None}

        result = {'success': obj}
        return result