コード例 #1
0
    def test_to_mime_multipart_handles_alternative_bodies(self):
        mime_multipart = InputMail.from_dict(self.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)
コード例 #2
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)
コード例 #3
0
    def test_to_mime_multipart_handles_alternative_bodies(self):
        mime_multipart = InputMail.from_dict(
            self.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)
コード例 #4
0
    def update_draft(self):
        _mail = InputMail.from_dict(request.json)
        draft_id = request.json.get('ident')
        if draft_id:
            ident = self._draft_service.update_draft(draft_id, _mail).ident
            self._search_engine.remove_from_index(draft_id)
        else:
            ident = self._draft_service.create_draft(_mail).ident

        self._search_engine.index_mail(self._mail_service.mail(ident))
        return respond_json({'ident': ident})
コード例 #5
0
    def test_to_mime_multipart(self):
        pixelated.support.date.iso_now = lambda: 'date now'

        mime_multipart = InputMail.from_dict(self.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(), "\nEste \xe9 o corpo")
コード例 #6
0
    def send_mail(self, _request=request):
        try:
            _mail = InputMail.from_dict(_request.json)
            draft_id = _request.json.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())
        except Exception as error:
            return respond_json({'message': self._format_exception(error)}, status_code=422)
コード例 #7
0
    def send_mail(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': self._format_exception(error)}, request, status_code=422)
コード例 #8
0
    def update_draft(self, request):
        content_dict = json.loads(request.content.read())

        _mail = InputMail.from_dict(content_dict)
        draft_id = content_dict.get('ident')
        if draft_id:
            ident = self._draft_service.update_draft(draft_id, _mail).ident
            self._search_engine.remove_from_index(draft_id)
        else:
            ident = self._draft_service.create_draft(_mail).ident

        self._search_engine.index_mail(self._mail_service.mail(ident))
        return respond_json({'ident': ident}, request)
コード例 #9
0
    def send_mail(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': self._format_exception(error)}, request, status_code=422)
コード例 #10
0
    def update_draft(self, request):
        content_dict = json.loads(request.content.read())

        _mail = InputMail.from_dict(content_dict)
        draft_id = content_dict.get('ident')
        if draft_id:
            ident = self._draft_service.update_draft(draft_id, _mail).ident
            self._search_engine.remove_from_index(draft_id)
        else:
            ident = self._draft_service.create_draft(_mail).ident

        self._search_engine.index_mail(self._mail_service.mail(ident))
        return respond_json({'ident': ident}, request)
コード例 #11
0
    def test_to_mime_multipart_should_add_blank_fields(self):
        pixelated.support.date.iso_now = lambda: 'date now'

        mail_dict = self.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")
コード例 #12
0
    def test_to_mime_multipart_should_add_blank_fields(self):
        pixelated.support.date.iso_now = lambda: 'date now'

        mail_dict = self.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")
コード例 #13
0
    def test_to_mime_multipart(self):
        pixelated.support.date.iso_now = lambda: 'date now'

        mime_multipart = InputMail.from_dict(
            self.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(),
                                 "\nEste \xe9 o corpo")
コード例 #14
0
 def build_input_mail(self):
     return InputMail.from_dict(self.mail)
コード例 #15
0
    def test_smtp_format(self):
        InputMail.FROM_EMAIL_ADDRESS = 'pixelated@org'

        smtp_format = InputMail.from_dict(self.mail_dict()).to_smtp_format()

        self.assertRegexpMatches(smtp_format, "\nFrom: pixelated@org")
コード例 #16
0
def input_mail():
    mail = InputMail()
    mail.fdoc = TestDoc({})
    mail._chash = "123"
    mail.as_dict = lambda: None
    return mail
コード例 #17
0
    def test_smtp_format(self):
        InputMail.FROM_EMAIL_ADDRESS = 'pixelated@org'

        smtp_format = InputMail.from_dict(self.mail_dict()).to_smtp_format()

        self.assertRegexpMatches(smtp_format, "\nFrom: pixelated@org")
コード例 #18
0
    def test_add_draft(self):
        mail = InputMail()
        self.draft_service.create_draft(mail)

        verify(self.drafts_mailbox).add(mail)
コード例 #19
0
 def build_input_mail(self):
     return InputMail.from_dict(self.mail)
コード例 #20
0
def input_mail():
    mail = InputMail()
    mail.fdoc = TestDoc({})
    mail._chash = "123"
    mail.as_dict = lambda: None
    return mail