def render_PUT(self, request):
        content_dict = json.loads(request.content.read())
        _mail = InputMail.from_dict(content_dict)
        draft_id = content_dict.get("ident")

        def defer_response(deferred):
            deferred.addCallback(lambda pixelated_mail: respond_json_deferred({"ident": pixelated_mail.ident}, request))

        if draft_id:
            deferred_check = self._mail_service.mail_exists(draft_id)

            def handleDuplicatedDraftException(error):
                respond_json_deferred("", request, status_code=422)

            def return422otherwise(mail_exists):
                if not mail_exists:
                    respond_json_deferred("", request, status_code=422)
                else:
                    new_draft = self._draft_service.update_draft(draft_id, _mail)
                    new_draft.addErrback(handleDuplicatedDraftException)
                    defer_response(new_draft)

            deferred_check.addCallback(return422otherwise)
        else:
            defer_response(self._draft_service.create_draft(_mail))

        return server.NOT_DONE_YET
Example #2
0
    def render_PUT(self, request):
        content_dict = json.loads(request.content.read())
        _mail = InputMail.from_dict(content_dict)
        draft_id = content_dict.get('ident')

        def defer_response(deferred):
            deferred.addCallback(lambda pixelated_mail: respond_json_deferred(
                {'ident': pixelated_mail.ident}, request))

        if draft_id:
            deferred_check = self._mail_service.mail_exists(draft_id)

            def return422otherwise(mail_exists):
                if not mail_exists:
                    respond_json_deferred("", request, status_code=422)
                else:
                    defer_response(
                        self._draft_service.update_draft(draft_id, _mail))

            deferred_check.addCallback(return422otherwise)
        else:
            print '\nCreating draft\n'
            defer_response(self._draft_service.create_draft(_mail))

        return server.NOT_DONE_YET
    def send_mail(self, content_dict):
        mail = InputMail.from_dict(content_dict)
        draft_id = content_dict.get('ident')

        yield self.mail_sender.sendmail(mail)
        sent_mail = yield self.move_to_sent(draft_id, mail)
        defer.returnValue(sent_mail)
Example #4
0
    def test_sendmail(self):
        when(reactor).connectTCP('localhost', 4650, any()).thenReturn(None)
        input_mail = InputMail.from_dict(mail_dict())
        mail_sender = MailSender('*****@*****.**',
                                 self.ensure_smtp_is_running_cb)

        return self._succeed(mail_sender.sendmail(input_mail))
    def send_mail(self, content_dict):
        mail = InputMail.from_dict(content_dict, self.account_email)
        draft_id = content_dict.get('ident')
        yield self.mail_sender.sendmail(mail)

        sent_mail = yield self.move_to_sent(draft_id, mail)
        defer.returnValue(sent_mail)
    def test_update_draft(self):
        mail = InputMail.from_dict(test_helper.mail_dict())
        when(self.mail_store).add_mail("DRAFTS", mail.raw).thenReturn(defer.succeed(LeapMail("id", "DRAFTS")))

        self.draft_service.update_draft(mail.ident, mail)

        inorder.verify(self.mail_store).add_mail("DRAFTS", mail.raw)
        inorder.verify(self.mail_store).delete_mail(mail.ident)
Example #7
0
    def test_to_mime_multipart_handles_alternative_bodies(self):
        mime_multipart = InputMail.from_dict(multipart_mail_dict()).to_mime_multipart()

        part_one = 'Content-Type: text/plain; charset="us-ascii"\nMIME-Version: 1.0\nContent-Transfer-Encoding: 7bit\n\nHello world!'
        part_two = 'Content-Type: text/html; charset="us-ascii"\nMIME-Version: 1.0\nContent-Transfer-Encoding: 7bit\n\n<p>Hello html world!</p>'

        self.assertRegexpMatches(mime_multipart.as_string(), part_one)
        self.assertRegexpMatches(mime_multipart.as_string(), part_two)
    def test_if_recipient_doubled_in_fields_send_only_in_bcc(self):
        mail = InputMail.from_dict(duplicates_in_fields_mail_dict(), from_address='pixelated@org')

        yield self.mail_service._deduplicate_recipients(mail)

        self.assertIn('*****@*****.**', mail.to)
        self.assertNotIn('*****@*****.**', mail.to)
        self.assertIn('*****@*****.**', mail.bcc)
    def test_if_deduplicates_when_recipient_repeated_in_field(self):
        mail = InputMail.from_dict(duplicates_in_fields_mail_dict(), from_address='pixelated@org')

        yield self.mail_service._deduplicate_recipients(mail)

        self.assertItemsEqual(['*****@*****.**', '*****@*****.**'], mail.bcc)
        self.assertItemsEqual(['*****@*****.**', '*****@*****.**'], mail.to)
        self.assertItemsEqual(['*****@*****.**'], mail.cc)
Example #10
0
    def test_update_draft(self):
        mail = InputMail.from_dict(test_helper.mail_dict())
        when(self.drafts_mailbox).add(mail).thenReturn(mail)

        self.draft_service.update_draft(mail.ident, mail)

        inorder.verify(self.drafts_mailbox).add(mail)
        inorder.verify(self.drafts_mailbox).remove(mail.ident)
    def send_mail(self, content_dict):
        mail = InputMail.from_dict(content_dict, self.account_email)
        draft_id = content_dict.get('ident')
        self._deduplicate_recipients(mail)
        yield self.mail_sender.sendmail(mail)

        sent_mail = yield self.move_to_sent(draft_id, mail)
        defer.returnValue(sent_mail)
Example #12
0
    def test_to_mime_multipart_handles_alternative_bodies(self):
        mime_multipart = InputMail.from_dict(multipart_mail_dict()).to_mime_multipart()

        part_one = 'Content-Type: text/plain; charset="us-ascii"\nMIME-Version: 1.0\nContent-Transfer-Encoding: 7bit\n\nHello world!'
        part_two = 'Content-Type: text/html; charset="us-ascii"\nMIME-Version: 1.0\nContent-Transfer-Encoding: 7bit\n\n<p>Hello html world!</p>'

        self.assertRegexpMatches(mime_multipart.as_string(), part_one)
        self.assertRegexpMatches(mime_multipart.as_string(), part_two)
    def test_update_draft(self):
        mail = InputMail.from_dict(test_helper.mail_dict())
        when(self.drafts_mailbox).add(mail).thenReturn(mail)

        self.draft_service.update_draft(mail.ident, mail)

        inorder.verify(self.drafts_mailbox).add(mail)
        inorder.verify(self.drafts_mailbox).remove(mail.ident)
    def test_update_draft(self):
        mail = InputMail.from_dict(test_helper.mail_dict(), from_address='pixelated@org')
        when(self.mail_store).delete_mail(mail.ident).thenReturn(defer.succeed(True))
        when(self.mail_store).add_mail('DRAFTS', mail.raw).thenReturn(defer.succeed(LeapMail('id', 'DRAFTS')))

        self.draft_service.update_draft(mail.ident, mail)

        inorder.verify(self.mail_store).delete_mail(mail.ident)
        inorder.verify(self.mail_store).add_mail('DRAFTS', mail.raw)
Example #15
0
    def test_single_recipient(self):
        mail_single_recipient = {
            "body": "",
            "header": {"to": ["*****@*****.**"], "cc": [""], "bcc": [""], "subject": "Oi"},
        }

        result = InputMail.from_dict(mail_single_recipient).raw

        self.assertRegexpMatches(result, "To: [email protected]")
Example #16
0
    def test_to_mime_multipart_with_special_chars(self):
        mail_dict = simple_mail_dict()
        mail_dict['header']['to'] = u'"Älbert Übrö \xF0\x9F\x92\xA9" <äüö@example.mail>'
        pixelated.support.date.mail_date_now = lambda: 'date now'

        mime_multipart = InputMail.from_dict(mail_dict).to_mime_multipart()

        expected_part_of_encoded_to = 'Iiwgw4QsIGwsIGIsIGUsIHIsIHQsICAsIMOcLCBiLCByLCDDtiwgICwgw7As'
        self.assertRegexpMatches(mime_multipart.as_string(), expected_part_of_encoded_to)
    def test_iterates_over_recipients(self):
        input_mail = InputMail.from_dict(mail_dict(), from_address='pixelated@org')

        when(OutgoingMail).send_message(any(), any()).thenReturn(defer.succeed(None))

        yield self.sender.sendmail(input_mail)

        for recipient in flatten([input_mail.to, input_mail.cc, input_mail.bcc]):
            verify(OutgoingMail).send_message(any(), TwistedSmtpUserCapture(recipient))
Example #18
0
    def test_if_recipient_doubled_in_fields_send_only_in_bcc(self):
        mail = InputMail.from_dict(duplicates_in_fields_mail_dict(),
                                   from_address='pixelated@org')

        yield self.mail_service._deduplicate_recipients(mail)

        self.assertIn('*****@*****.**', mail.to)
        self.assertNotIn('*****@*****.**', mail.to)
        self.assertIn('*****@*****.**', mail.bcc)
    def test_update_draft(self):
        mail = InputMail.from_dict(test_helper.mail_dict(), from_address='pixelated@org')
        when(self.mail_store).delete_mail(mail.ident).thenReturn(defer.succeed(True))
        when(self.mail_store).add_mail('DRAFTS', mail.raw).thenReturn(defer.succeed(LeapMail('id', 'DRAFTS')))

        self.draft_service.update_draft(mail.ident, mail)

        inorder.verify(self.mail_store).delete_mail(mail.ident)
        inorder.verify(self.mail_store).add_mail('DRAFTS', mail.raw)
    def test_iterates_over_recipients_and_send_whitout_bcc_field(self):
        input_mail = InputMail.from_dict(mail_dict())
        bccs = input_mail.bcc

        when(OutgoingMail).send_message(any(), any()).thenReturn(defer.succeed(None))

        yield self.sender.sendmail(input_mail)

        for recipient in flatten([input_mail.to, input_mail.cc, input_mail.bcc]):
            verify(OutgoingMail).send_message(MailToSmtpFormatCapture(recipient, bccs), TwistedSmtpUserCapture(recipient))
    def send_mail(self, content_dict):
        mail = InputMail.from_dict(content_dict)
        draft_id = content_dict.get('ident')

        def move_to_sent(_):
            return self.move_to_sent(draft_id, mail)

        deferred = self.mail_sender.sendmail(mail)
        deferred.addCallback(move_to_sent)
        return deferred
Example #22
0
    def send_mail(self, content_dict):
        mail = InputMail.from_dict(content_dict)
        draft_id = content_dict.get('ident')

        def move_to_sent(_):
            return self.move_to_sent(draft_id, mail)

        deferred = self.mail_sender.sendmail(mail)
        deferred.addCallback(move_to_sent)
        return deferred
    def test_iterates_over_recipients(self):
        sender = MailSender(self._smtp_config, self._keymanager_mock)
        input_mail = InputMail.from_dict(mail_dict())

        when(OutgoingMail).send_message(any(), any()).thenAnswer(lambda: defer.succeed(None))

        yield sender.sendmail(input_mail)

        for recipient in flatten([input_mail.to, input_mail.cc, input_mail.bcc]):
            verify(OutgoingMail).send_message(any(), TwistedSmtpUserCapture(recipient))
Example #24
0
    def test_to_mime_multipart(self):
        pixelated.support.date.mail_date_now = lambda: 'date now'

        mime_multipart = InputMail.from_dict(simple_mail_dict()).to_mime_multipart()

        self.assertRegexpMatches(mime_multipart.as_string(), "\nTo: [email protected], [email protected]\n")
        self.assertRegexpMatches(mime_multipart.as_string(), "\nCc: [email protected], [email protected]\n")
        self.assertRegexpMatches(mime_multipart.as_string(), "\nBcc: [email protected], [email protected]\n")
        self.assertRegexpMatches(mime_multipart.as_string(), "\nDate: date now\n")
        self.assertRegexpMatches(mime_multipart.as_string(), "\nSubject: Oi\n")
        self.assertRegexpMatches(mime_multipart.as_string(), base64.b64encode(simple_mail_dict()['body']))
    def test_senmail_returns_deffered(self):
        when(reactor).connectTCP('localhost', 4650, any()).thenReturn(None)
        input_mail = InputMail.from_dict(mail_dict())
        mail_sender = MailSender('*****@*****.**', self.smtp)

        deferred = mail_sender.sendmail(input_mail)

        self.assertIsNotNone(deferred)
        self.assertTrue(isinstance(deferred, Deferred))

        return self._succeed(deferred)
Example #26
0
    def test_if_deduplicates_when_recipient_repeated_in_field(self):
        mail = InputMail.from_dict(duplicates_in_fields_mail_dict(),
                                   from_address='pixelated@org')

        yield self.mail_service._deduplicate_recipients(mail)

        self.assertItemsEqual(['*****@*****.**', '*****@*****.**'],
                              mail.bcc)
        self.assertItemsEqual(['*****@*****.**', '*****@*****.**'],
                              mail.to)
        self.assertItemsEqual(['*****@*****.**'], mail.cc)
Example #27
0
    def test_to_mime_multipart_with_special_chars(self):
        mail_dict = simple_mail_dict()
        mail_dict['header'][
            'to'] = u'"Älbert Übrö \xF0\x9F\x92\xA9" <äüö@example.mail>'
        pixelated.support.date.mail_date_now = lambda: 'date now'

        mime_multipart = InputMail.from_dict(mail_dict).to_mime_multipart()

        expected_part_of_encoded_to = 'Iiwgw4QsIGwsIGIsIGUsIHIsIHQsICAsIMOcLCBiLCByLCDDtiwgICwgw7As'
        self.assertRegexpMatches(mime_multipart.as_string(),
                                 expected_part_of_encoded_to)
    def test_problem_with_email_raises_exception(self):
        input_mail = InputMail.from_dict(mail_dict(), from_address='pixelated@org')

        when(OutgoingMail).send_message(any(), any()).thenReturn(defer.fail(Exception('pretend something went wrong')))

        try:
            yield self.sender.sendmail(input_mail)
            self.fail('Exception expected!')
        except MailSenderException, e:
            for recipient in flatten([input_mail.to, input_mail.cc, input_mail.bcc]):
                self.assertTrue(recipient in e.email_error_map)
Example #29
0
    def test_to_mime_multipart(self):
        pixelated.support.date.iso_now = lambda: 'date now'

        mime_multipart = InputMail.from_dict(simple_mail_dict()).to_mime_multipart()

        self.assertRegexpMatches(mime_multipart.as_string(), "\nTo: [email protected], [email protected]\n")
        self.assertRegexpMatches(mime_multipart.as_string(), "\nCc: [email protected], [email protected]\n")
        self.assertRegexpMatches(mime_multipart.as_string(), "\nBcc: [email protected], [email protected]\n")
        self.assertRegexpMatches(mime_multipart.as_string(), "\nDate: date now\n")
        self.assertRegexpMatches(mime_multipart.as_string(), "\nSubject: Oi\n")
        self.assertRegexpMatches(mime_multipart.as_string(), base64.b64encode(simple_mail_dict()['body']))
    def test_senmail_returns_deffered(self):
        when(reactor).connectTCP('localhost', 4650, any()).thenReturn(None)
        input_mail = InputMail.from_dict(mail_dict())
        mail_sender = MailSender('*****@*****.**', self.smtp)

        deferred = mail_sender.sendmail(input_mail)

        self.assertIsNotNone(deferred)
        self.assertTrue(isinstance(deferred, Deferred))

        return self._succeed(deferred)
    def test_problem_with_email_raises_exception(self):
        sender = MailSender(self._smtp_config, self._keymanager_mock)
        input_mail = InputMail.from_dict(mail_dict())

        when(OutgoingMail).send_message(any(), any()).thenAnswer(lambda: defer.fail(Exception('pretend something went wrong')))

        try:
            yield sender.sendmail(input_mail)
            self.fail('Exception expected!')
        except MailSenderException, e:
            for recipient in flatten([input_mail.to, input_mail.cc, input_mail.bcc]):
                self.assertTrue(recipient in e.email_error_map)
    def test_send_leaves_mail_in_tact(self):
        input_mail_dict = mail_dict()
        input_mail = InputMail.from_dict(input_mail_dict, from_address='pixelated@org')

        when(OutgoingMail).send_message(any(), any()).thenReturn(defer.succeed(None))

        yield self.sender.sendmail(input_mail)

        self.assertEqual(input_mail.to, input_mail_dict["header"]["to"])
        self.assertEqual(input_mail.cc, input_mail_dict["header"]["cc"])
        self.assertEqual(input_mail.bcc, input_mail_dict["header"]["bcc"])
        self.assertEqual(input_mail.subject, input_mail_dict["header"]["subject"])
    def test_sendmail_uses_twisted(self):
        when(reactor).connectTCP('localhost', 4650, any()).thenReturn(None)

        input_mail = InputMail.from_dict(mail_dict())

        mail_sender = MailSender('*****@*****.**', self.smtp)

        sent_deferred = mail_sender.sendmail(input_mail)

        verify(reactor).connectTCP('localhost', 4650, any())

        return self._succeed(sent_deferred)
    def test_sendmail_uses_twisted(self):
        when(reactor).connectTCP('localhost', 4650, any()).thenReturn(None)

        input_mail = InputMail.from_dict(mail_dict())

        mail_sender = MailSender('*****@*****.**', self.smtp)

        sent_deferred = mail_sender.sendmail(input_mail)

        verify(reactor).connectTCP('localhost', 4650, any())

        return self._succeed(sent_deferred)
    def render_PUT(self, request):
        content_dict = json.loads(request.content.read())
        _mail = InputMail.from_dict(content_dict)
        draft_id = content_dict.get('ident')

        if draft_id:
            if not self._mail_service.mail_exists(draft_id):
                return respond_json("", request, status_code=422)
            pixelated_mail = self._draft_service.update_draft(draft_id, _mail)
        else:
            pixelated_mail = self._draft_service.create_draft(_mail)

        return respond_json({'ident': pixelated_mail.ident}, request)
    def test_raw_with_attachment_data(self):
        input_mail = InputMail.from_dict(with_attachment_mail_dict(), from_address='pixelated@org')

        attachment = MIMENonMultipart('text', 'plain', Content_Disposition='attachment; filename=ayoyo.txt')
        attachment.set_payload('Hello World')
        mail = MIMEMultipart()
        mail.attach(attachment)

        part_one = 'Content-Type: text/plain\nMIME-Version: 1.0\nContent-Disposition: attachment; filename="ayoyo.txt"\nContent-Transfer-Encoding: base64\n\n'
        part_two = 'Content-Type: text/html\nMIME-Version: 1.0\nContent-Disposition: attachment; filename="hello.html"\nContent-Transfer-Encoding: base64\n\n'

        self.assertRegexpMatches(input_mail.raw, part_one)
        self.assertRegexpMatches(input_mail.raw, part_two)
    def test_iterates_over_recipients(self):
        input_mail = InputMail.from_dict(mail_dict(),
                                         from_address='pixelated@org')

        when(OutgoingMail).send_message(any(),
                                        any()).thenReturn(defer.succeed(None))

        yield self.sender.sendmail(input_mail)

        for recipient in flatten(
            [input_mail.to, input_mail.cc, input_mail.bcc]):
            verify(OutgoingMail).send_message(
                any(), TwistedSmtpUserCapture(recipient))
Example #38
0
    def render_POST(self, request):
        content_dict = json.loads(request.content.read())
        _mail = InputMail.from_dict(content_dict)
        draft_id = content_dict.get('ident')

        self._mail_service.send(_mail)
        sent_mail = self._mail_service.move_to_send(draft_id, _mail)
        self._search_engine.index_mail(sent_mail)

        if draft_id:
            self._search_engine.remove_from_index(draft_id)

        return respond_json(sent_mail.as_dict(), request)
    def render_POST(self, request):
        try:
            content_dict = json.loads(request.content.read())
            _mail = InputMail.from_dict(content_dict)
            draft_id = content_dict.get('ident')
            if draft_id:
                self._search_engine.remove_from_index(draft_id)
            _mail = self._mail_service.send(draft_id, _mail)
            self._search_engine.index_mail(_mail)

            return respond_json(_mail.as_dict(), request)
        except Exception as error:
            return respond_json({'message': _format_exception(error)}, request, status_code=422)
    def render_PUT(self, request):
        content_dict = json.loads(request.content.read())
        _mail = InputMail.from_dict(content_dict)
        draft_id = content_dict.get('ident')

        if draft_id:
            if not self._mail_service.mail_exists(draft_id):
                return respond_json("", request, status_code=422)
            pixelated_mail = self._draft_service.update_draft(draft_id, _mail)
        else:
            pixelated_mail = self._draft_service.create_draft(_mail)

        return respond_json({'ident': pixelated_mail.ident}, request)
Example #41
0
    def test_iterates_over_recipients(self):
        sender = MailSender(self._smtp_config, self._keymanager_mock)
        input_mail = InputMail.from_dict(mail_dict())

        when(OutgoingMail).send_message(
            any(), any()).thenAnswer(lambda: defer.succeed(None))

        yield sender.sendmail(input_mail)

        for recipient in flatten(
            [input_mail.to, input_mail.cc, input_mail.bcc]):
            verify(OutgoingMail).send_message(
                any(), TwistedSmtpUserCapture(recipient))
Example #42
0
    def test_problem_with_email_raises_exception(self):
        sender = MailSender(self._smtp_config, self._keymanager_mock)
        input_mail = InputMail.from_dict(mail_dict())

        when(OutgoingMail).send_message(any(), any()).thenAnswer(
            lambda: defer.fail(Exception('pretend something went wrong')))

        try:
            yield sender.sendmail(input_mail)
            self.fail('Exception expected!')
        except MailSenderException, e:
            for recipient in flatten(
                [input_mail.to, input_mail.cc, input_mail.bcc]):
                self.assertTrue(recipient in e.email_error_map)
    def _handle_put(self, request):
        _draft_service = self.draft_service(request)
        _mail_service = self.mail_service(request)
        content_dict = json.loads(request.content.read())
        with_attachment_content = yield self._fetch_attachment_contents(content_dict, _mail_service)

        _mail = InputMail.from_dict(with_attachment_content, from_address=_mail_service.account_email)
        draft_id = content_dict.get('ident')
        pixelated_mail = yield _draft_service.process_draft(draft_id, _mail)

        if not pixelated_mail:
            respond_json_deferred("", request, status_code=422)
        else:
            respond_json_deferred({'ident': pixelated_mail.ident}, request)
    def test_problem_with_email_raises_exception(self):
        input_mail = InputMail.from_dict(mail_dict(),
                                         from_address='pixelated@org')

        when(OutgoingMail).send_message(any(), any()).thenReturn(
            defer.fail(Exception('pretend something went wrong')))

        try:
            yield self.sender.sendmail(input_mail)
            self.fail('Exception expected!')
        except MailSenderException, e:
            for recipient in flatten(
                [input_mail.to, input_mail.cc, input_mail.bcc]):
                self.assertTrue(recipient in e.email_error_map)
    def _handle_put(self, request):
        _draft_service = self.draft_service(request)
        _mail_service = self.mail_service(request)
        content_dict = json.loads(request.content.read())
        with_attachment_content = yield self._fetch_attachment_contents(content_dict, _mail_service)

        _mail = InputMail.from_dict(with_attachment_content, from_address=_mail_service.account_email)
        draft_id = content_dict.get('ident')
        pixelated_mail = yield _draft_service.process_draft(draft_id, _mail)

        if not pixelated_mail:
            respond_json_deferred("", request, status_code=422)
        else:
            respond_json_deferred({'ident': pixelated_mail.ident}, request)
Example #46
0
    def test_single_recipient(self):
        mail_single_recipient = {
            'body': '',
            'header': {
                'to': ['*****@*****.**'],
                'cc': [''],
                'bcc': [''],
                'subject': 'Oi'
            }
        }

        result = InputMail.from_dict(mail_single_recipient).raw

        self.assertRegexpMatches(result, 'To: [email protected]')
Example #47
0
    def test_single_recipient(self):
        mail_single_recipient = {
            'body': '',
            'header': {
                'to': ['*****@*****.**'],
                'cc': [''],
                'bcc': [''],
                'subject': 'Oi'
            }
        }

        result = InputMail.from_dict(mail_single_recipient).raw

        self.assertRegexpMatches(result, 'To: [email protected]')
    def test_send_leaves_mail_in_tact(self):
        input_mail_dict = mail_dict()
        input_mail = InputMail.from_dict(input_mail_dict,
                                         from_address='pixelated@org')

        when(OutgoingMail).send_message(any(),
                                        any()).thenReturn(defer.succeed(None))

        yield self.sender.sendmail(input_mail)

        self.assertEqual(input_mail.to, input_mail_dict["header"]["to"])
        self.assertEqual(input_mail.cc, input_mail_dict["header"]["cc"])
        self.assertEqual(input_mail.bcc, input_mail_dict["header"]["bcc"])
        self.assertEqual(input_mail.subject,
                         input_mail_dict["header"]["subject"])
Example #49
0
    def test_to_mime_multipart_should_add_blank_fields(self):
        pixelated.support.date.mail_date_now = lambda: 'date now'

        mail_dict = simple_mail_dict()
        mail_dict['header']['to'] = ''
        mail_dict['header']['bcc'] = ''
        mail_dict['header']['cc'] = ''
        mail_dict['header']['subject'] = ''

        mime_multipart = InputMail.from_dict(mail_dict).to_mime_multipart()

        self.assertNotRegexpMatches(mime_multipart.as_string(), "\nTo: \n")
        self.assertNotRegexpMatches(mime_multipart.as_string(), "\nBcc: \n")
        self.assertNotRegexpMatches(mime_multipart.as_string(), "\nCc: \n")
        self.assertNotRegexpMatches(mime_multipart.as_string(), "\nSubject: \n")
Example #50
0
    def test_to_mime_multipart_should_add_blank_fields(self):
        pixelated.support.date.iso_now = lambda: "date now"

        mail_dict = simple_mail_dict()
        mail_dict["header"]["to"] = ""
        mail_dict["header"]["bcc"] = ""
        mail_dict["header"]["cc"] = ""
        mail_dict["header"]["subject"] = ""

        mime_multipart = InputMail.from_dict(mail_dict).to_mime_multipart()

        self.assertNotRegexpMatches(mime_multipart.as_string(), "\nTo: \n")
        self.assertNotRegexpMatches(mime_multipart.as_string(), "\nBcc: \n")
        self.assertNotRegexpMatches(mime_multipart.as_string(), "\nCc: \n")
        self.assertNotRegexpMatches(mime_multipart.as_string(), "\nSubject: \n")
Example #51
0
    def test_to_mime_multipart_should_add_blank_fields(self):
        pixelated.support.date.iso_now = lambda: 'date now'

        mail_dict = simple_mail_dict()
        mail_dict['header']['to'] = ''
        mail_dict['header']['bcc'] = ''
        mail_dict['header']['cc'] = ''
        mail_dict['header']['subject'] = ''

        mime_multipart = InputMail.from_dict(mail_dict).to_mime_multipart()

        self.assertNotRegexpMatches(mime_multipart.as_string(), "\nTo: \n")
        self.assertNotRegexpMatches(mime_multipart.as_string(), "\nBcc: \n")
        self.assertNotRegexpMatches(mime_multipart.as_string(), "\nCc: \n")
        self.assertNotRegexpMatches(mime_multipart.as_string(), "\nSubject: \n")
    def setUp(self):
        self.drafts = mock()
        self.mail_store = mock()
        self.attachment_store = mock()
        self.mailboxes = mock()

        self.mailboxes.drafts = defer.succeed(self.drafts)

        self.mailboxes.trash = mock()
        self.mailboxes.sent = mock()

        self.mail_sender = mock()
        self.search_engine = mock()
        self.mail_service = MailService(self.mail_sender, self.mail_store, self.search_engine, 'acount@email', self.attachment_store)
        self.mail = InputMail.from_dict(duplicates_in_fields_mail_dict(), from_address='pixelated@org')
    def test_keymanager_encrypt_problem_raises_exception(self):
        input_mail = InputMail.from_dict(mail_dict(), from_address='pixelated@org')

        when(OutgoingMail)._maybe_attach_key(any(), any(), any()).thenReturn(
            defer.succeed(None))
        when(OutgoingMail)._fix_headers(any(), any(), any()).thenReturn(
            defer.succeed((None, mock())))
        when(self._keymanager_mock).encrypt(any(), any(), sign=any(),
                                            fetch_remote=any()).thenReturn(defer.fail(Exception('pretend key expired')))

        with patch('leap.bitmask.mail.outgoing.service.emit_async'):
            try:
                yield self.sender.sendmail(input_mail)
                self.fail('Exception expected!')
            except MailSenderException, e:
                for recipient in flatten([input_mail.to, input_mail.cc, input_mail.bcc]):
                    self.assertTrue(recipient in e.email_error_map)
    def test_raw_with_attachment_data(self):
        input_mail = InputMail.from_dict(with_attachment_mail_dict(),
                                         from_address='pixelated@org')

        attachment = MIMENonMultipart(
            'text',
            'plain',
            Content_Disposition='attachment; filename=ayoyo.txt')
        attachment.set_payload('Hello World')
        mail = MIMEMultipart()
        mail.attach(attachment)

        part_one = 'Content-Type: text/plain\nMIME-Version: 1.0\nContent-Disposition: attachment; filename="ayoyo.txt"\nContent-Transfer-Encoding: base64\n\n'
        part_two = 'Content-Type: text/html\nMIME-Version: 1.0\nContent-Disposition: attachment; filename="hello.html"\nContent-Transfer-Encoding: base64\n\n'

        self.assertRegexpMatches(input_mail.raw, part_one)
        self.assertRegexpMatches(input_mail.raw, part_two)
Example #55
0
    def setUp(self):
        self.drafts = mock()
        self.mail_store = mock()
        self.attachment_store = mock()
        self.mailboxes = mock()

        self.mailboxes.drafts = defer.succeed(self.drafts)

        self.mailboxes.trash = mock()
        self.mailboxes.sent = mock()

        self.mail_sender = mock()
        self.search_engine = mock()
        self.mail_service = MailService(self.mail_sender, self.mail_store,
                                        self.search_engine, 'acount@email',
                                        self.attachment_store)
        self.mail = InputMail.from_dict(duplicates_in_fields_mail_dict(),
                                        from_address='pixelated@org')
    def render_PUT(self, request):
        content_dict = json.loads(request.content.read())
        _mail = InputMail.from_dict(content_dict)
        draft_id = content_dict.get('ident')

        def defer_response(deferred):
            deferred.addCallback(lambda pixelated_mail: respond_json_deferred({'ident': pixelated_mail.ident}, request))

        if draft_id:
            deferred_check = self._mail_service.mail_exists(draft_id)

            def return422otherwise(mail_exists):
                if not mail_exists:
                    respond_json_deferred("", request, status_code=422)
                else:
                    defer_response(self._draft_service.update_draft(draft_id, _mail))
            deferred_check.addCallback(return422otherwise)
        else:
            print '\nCreating draft\n'
            defer_response(self._draft_service.create_draft(_mail))

        return server.NOT_DONE_YET
Example #57
0
 def build_input_mail(self):
     return InputMail.from_dict(self.mail, from_address='Formatted Sender <*****@*****.**>')
Example #58
0
    def test_smtp_format(self):
        InputMail.FROM_EMAIL_ADDRESS = 'pixelated@org'

        smtp_format = InputMail.from_dict(simple_mail_dict()).to_smtp_format()

        self.assertRegexpMatches(smtp_format, "\nFrom: pixelated@org")
    def test_smtp_format(self):
        smtp_format = InputMail.from_dict(
            simple_mail_dict(), from_address='pixelated@org').to_smtp_format()

        self.assertRegexpMatches(smtp_format, "\nFrom: pixelated@org")
Example #60
0
 def build_input_mail(self):
     return InputMail.from_dict(self.mail)