コード例 #1
0
    def test_index_is_initialized_with_mail_tags_if_empty(self):
        mail_one = PixelatedMail.from_soledad(*test_helper.leap_mail(uid=0, extra_headers={'X-Tags': '["tag_1"]'}))
        mail_two = PixelatedMail.from_soledad(*test_helper.leap_mail(uid=1, extra_headers={'X-Tags': '["tag_2"]'}))
        mails = [mail_one, mail_two]

        self.tag_service.load_index(mails)

        self.assertEqual(self.tag_service.all_tags(), {Tag('sent'), Tag('inbox'), Tag('drafts'), Tag('trash'), Tag('tag_1'), Tag('tag_2')})
コード例 #2
0
 def test_update_tags_return_a_set_for_current_tags_and_a_set_for_removed(self):
     pixelated_mail = PixelatedMail.from_leap_mail(
         test_helper.leap_mail(leap_flags=[], extra_flags=["tag_custom_1", "tag_custom_2"])
     )
     current_tags, removed_tags = pixelated_mail.update_tags(set([Tag("custom_1"), Tag("custom_3")]))
     self.assertEquals(set([Tag("custom_3"), Tag("custom_1")]), current_tags)
     self.assertEquals(set([Tag("custom_2")]), removed_tags)
コード例 #3
0
    def test_remove_message_from_mailbox(self):
        mail = PixelatedMail.from_soledad(*test_helper.leap_mail(), soledad_querier=self.querier)
        when(self.querier).mail(1).thenReturn(mail)

        self.mailbox.remove(1)

        verify(self.querier).remove_mail(mail)
コード例 #4
0
    def test_to_mime_multipart(self):
        mail = PixelatedMail.from_dict(self.mail_dict)

        mime_multipart = mail.to_mime_multipart()

        self.assertRegexpMatches(mime_multipart.as_string(), "\nTo: [email protected]\n")
        self.assertRegexpMatches(mime_multipart.as_string(), "\nSubject: Oi\n")
        self.assertRegexpMatches(mime_multipart.as_string(), "\nEste \xe9 o corpo")
コード例 #5
0
    def _build_mails_from_fdocs(self, fdocs_chash):
        if len(fdocs_chash) == 0:
            return []

        fdocs_hdocs = [(f[0], self.soledad.get_from_index('by-type-and-contenthash', 'head', f[1])[0]) for f in fdocs_chash]
        fdocs_hdocs_phash = [(f[0], f[1], f[1].content.get('body')) for f in fdocs_hdocs]
        fdocs_hdocs_bdocs = [(f[0], f[1], self.soledad.get_from_index('by-type-and-payloadhash', 'cnt', f[2])[0]) for f in fdocs_hdocs_phash]
        return [PixelatedMail.from_soledad(*raw_mail, soledad_querier=self) for raw_mail in fdocs_hdocs_bdocs]
コード例 #6
0
    def test_parse_date_from_soledad_uses_date_header_if_available(self):
        leap_mail_date = 'Wed, 3 Sep 2014 12:36:17 -0300'
        leap_mail_date_in_iso_format = "2014-09-03T12:36:17-03:00"

        leap_mail = test_helper.leap_mail(headers={'date': leap_mail_date})

        mail = PixelatedMail.from_soledad(*leap_mail, soledad_querier=self.querier)

        self.assertEqual(str(mail.headers['Date']), leap_mail_date_in_iso_format)
コード例 #7
0
    def test_update_tags_notifies_tag_service(self):
        db_path = '/tmp/test_update_tags_notifies_tag_service'
        TagService.instance = TagService(TagIndex(db_path))

        mail = PixelatedMail.from_soledad(*test_helper.leap_mail(), soledad_querier=self.querier)

        mail.update_tags({'new_tag'})
        self.assertIn(Tag('new_tag'), mail.tag_service.all_tags())

        os.remove(db_path + '.db')
コード例 #8
0
    def test_parse_date_from_soledad_fallback_to_received_header_if_date_header_isnt_available(self):
        leap_mail_date = "Wed, 03 Sep 2014 13:11:15 -0300"
        leap_mail_date_in_iso_format = "2014-09-03T13:11:15-03:00"
        leap_mail_received_header = "by bitmask.local from 127.0.0.1 with ESMTP ;\n " + leap_mail_date

        leap_mail = test_helper.leap_mail(headers={'received': leap_mail_received_header})

        mail = PixelatedMail.from_soledad(*leap_mail, soledad_querier=self.querier)

        self.assertEqual(str(mail.headers['Date']), leap_mail_date_in_iso_format)
コード例 #9
0
    def test_from_dict(self):

        mail = PixelatedMail.from_dict(self.mail_dict)

        self.assertEqual(mail.headers["cc"], ["*****@*****.**"])
        self.assertEqual(mail.headers["to"], ["*****@*****.**"])
        self.assertEqual(mail.headers["bcc"], ["*****@*****.**"])
        self.assertEqual(mail.headers["subject"], "Oi")
        self.assertEqual(mail.ident, "")
        self.assertEqual(mail.tags, ["sent"])
        self.assertEqual(mail.body, "Este \xe9 o corpo")
コード例 #10
0
    def test_send_mail_sends_to_To_Cc_and_Bcc(self):
        headers = {
            'To': ['*****@*****.**', '*****@*****.**'],
            'Cc': ['*****@*****.**', '*****@*****.**'],
            'Bcc': ['*****@*****.**', '*****@*****.**']
        }

        mail = PixelatedMail.from_soledad(*test_helper.leap_mail(extra_headers=headers))
        mail.to_smtp_format = lambda: "mail as smtp string"

        self.mail_sender.sendmail(mail)

        expected_recipients = ['*****@*****.**', '*****@*****.**', '*****@*****.**',
                               '*****@*****.**',
                               '*****@*****.**', '*****@*****.**']

        verify(self.smtp_client).sendmail(self.mail_address, expected_recipients, "mail as smtp string")
コード例 #11
0
    def test_mark_as_not_recent(self):
        mail = PixelatedMail.from_soledad(*test_helper.leap_mail(flags=['\\Recent']), soledad_querier=self.querier)

        mail.mark_as_not_recent()

        self.assertEquals(mail.fdoc.content['flags'], [])
コード例 #12
0
    def mail(self, ident):
        fdoc = self.soledad.get_from_index('by-type-and-contenthash', 'flags', ident)[0]
        hdoc = self.soledad.get_from_index('by-type-and-contenthash', 'head', ident)[0]
        bdoc = self.soledad.get_from_index('by-type-and-payloadhash', 'cnt', hdoc.content['body'])[0]

        return PixelatedMail.from_soledad(fdoc, hdoc, bdoc, soledad_querier=self)
コード例 #13
0
 def test_custom_tags_containing_our_prefix_are_handled(self):
     pixelated_mail = PixelatedMail.from_leap_mail(test_helper.leap_mail(extra_flags=["tag_tag_work_tag_"]))
     self.assertIn(Tag("tag_work_tag_"), pixelated_mail.tags)
コード例 #14
0
 def test_non_tags_flags_are_ignored(self):
     pixelated_mail = PixelatedMail.from_leap_mail(
         test_helper.leap_mail(leap_flags=["\\Recent"], extra_flags=["this_is_not_a_tag", "tag_custom_tag"])
     )
     self.assertEquals(set([Tag("custom_tag"), Tag("inbox")]), pixelated_mail.tags)
コード例 #15
0
 def test_leap_draft_flag_is_translated_to_draft_tag(self):
     pixelated_mail = PixelatedMail.from_leap_mail(test_helper.leap_mail(leap_flags=["\\Draft"]))
     self.assertIn(Tag("drafts"), pixelated_mail.tags)
コード例 #16
0
 def test_leap_flags_that_are_custom_tags_are_handled(self):
     pixelated_mail = PixelatedMail.from_leap_mail(test_helper.leap_mail(extra_flags=["tag_work"]))
     self.assertIn(Tag("work"), pixelated_mail.tags)
コード例 #17
0
 def test_leap_deleted_flag_is_translated_to_trash_tag(self):
     pixelated_mail = PixelatedMail.from_leap_mail(test_helper.leap_mail(leap_flags=["\\Deleted"]))
     self.assertIn(Tag("trash"), pixelated_mail.tags)
コード例 #18
0
 def test_leap_recent_flag_is_translated_to_inbox_tag(self):
     pixelated_mail = PixelatedMail.from_leap_mail(test_helper.leap_mail(leap_flags=["\\Recent"]))
     self.assertIn(Tag("inbox"), pixelated_mail.tags)
コード例 #19
0
    def test_update_tags_return_a_set_with_the_current_tags(self):
        soledad_docs = test_helper.leap_mail(extra_headers={'X-tags': '["custom_1", "custom_2"]'})
        pixelated_mail = PixelatedMail.from_soledad(*soledad_docs, soledad_querier=self.querier)

        current_tags = pixelated_mail.update_tags({'custom_1', 'custom_3'})
        self.assertEquals({'custom_3', 'custom_1'}, current_tags)
コード例 #20
0
 def mails(self):
     mails = self.leap_mailbox.messages or []
     mails = [PixelatedMail.from_leap_mail(mail) for mail in mails]
     return mails
コード例 #21
0
 def mail(self, mail_id):
     for message in self.leap_mailbox.messages:
         if message.getUID() == int(mail_id):
             return PixelatedMail.from_leap_mail(message)
コード例 #22
0
    def test_smtp_format(self):
        mail = PixelatedMail.from_dict(self.mail_dict)

        smtp_format = mail.to_smtp_format(_from="pixelated@org")

        self.assertRegexpMatches(smtp_format, "\nFrom: pixelated@org")
コード例 #23
0
def send_mail():
    mail = PixelatedMail.from_dict(request.json)
    mail_service.send(mail)
    return respond_json(None)