diff options
Diffstat (limited to 'service')
4 files changed, 43 insertions, 3 deletions
diff --git a/service/pixelated/adapter/mailstore/__init__.py b/service/pixelated/adapter/mailstore/__init__.py index 47fd9869..6983194d 100644 --- a/service/pixelated/adapter/mailstore/__init__.py +++ b/service/pixelated/adapter/mailstore/__init__.py @@ -42,3 +42,7 @@ class MailStore(object): def get_mailbox_mail_ids(self, mailbox_name): pass + + +def underscore_uuid(uuid): + return uuid.replace('-', '_') diff --git a/service/pixelated/adapter/mailstore/leap_mailstore.py b/service/pixelated/adapter/mailstore/leap_mailstore.py index 238fcf86..ee40e03b 100644 --- a/service/pixelated/adapter/mailstore/leap_mailstore.py +++ b/service/pixelated/adapter/mailstore/leap_mailstore.py @@ -15,7 +15,7 @@ # along with Pixelated. If not, see <http://www.gnu.org/licenses/>. from leap.mail.adaptors.soledad import SoledadMailAdaptor from twisted.internet import defer -from pixelated.adapter.mailstore import MailStore +from pixelated.adapter.mailstore import MailStore, underscore_uuid from leap.mail.mail import Message from pixelated.adapter.model.mail import Mail @@ -97,7 +97,7 @@ class LeapMailStore(MailStore): def add_mail(self, mailbox_name, raw_msg): mailbox = yield self._get_or_create_mailbox(mailbox_name) message = SoledadMailAdaptor().get_msg_from_string(Message, raw_msg) - message.get_wrapper().set_mbox_uuid(mailbox.doc_id) + message.get_wrapper().set_mbox_uuid(mailbox.uuid) yield message.get_wrapper().create(self.soledad) # add behavious from insert_mdoc_id from mail.py @@ -110,6 +110,15 @@ class LeapMailStore(MailStore): yield message.get_wrapper().delete(self.soledad) @defer.inlineCallbacks + def get_mailbox_mail_ids(self, mailbox_name): + mailbox = yield self._get_or_create_mailbox(mailbox_name) + fdocs = yield self.soledad.get_from_index('by-type-and-mbox-uuid', 'flags', underscore_uuid(mailbox.uuid)) + + mail_ids = map(lambda doc: _fdoc_id_to_mdoc_id(doc.doc_id), fdocs) + + defer.returnValue(mail_ids) + + @defer.inlineCallbacks def _leap_message_to_leap_mail(self, mail_id, message, include_body): if include_body: body = (yield message._wrapper.get_body(self.soledad)).raw @@ -128,3 +137,7 @@ class LeapMailStore(MailStore): def _is_empty_message(message): return (message is None) or (message.get_wrapper().mdoc.doc_id is None) + + +def _fdoc_id_to_mdoc_id(fdoc_id): + return 'M' + fdoc_id[1:] diff --git a/service/test/integration/test_leap_mailstore.py b/service/test/integration/test_leap_mailstore.py index a71df74d..1cca6903 100644 --- a/service/test/integration/test_leap_mailstore.py +++ b/service/test/integration/test_leap_mailstore.py @@ -68,6 +68,16 @@ class LeapMailStoreTest(SoledadTestBase): self.assertIsNone(deleted_msg) @defer.inlineCallbacks + def test_get_mailbox_mail_ids(self): + mail = _load_mail_from_file('mbox00000000') + yield self.store.add_mailbox('INBOX') + yield self.store.add_mail('INBOX', mail.as_string()) + + mails = yield self.store.get_mailbox_mail_ids('INBOX') + + self.assertEqual(1, len(mails)) + + @defer.inlineCallbacks def _create_mail_in_soledad(self, mail): message = self._convert_mail_to_leap_message(mail) yield self.adaptor.initialize_store(self.soledad) diff --git a/service/test/unit/adapter/mailstore/test_leap_mailstore.py b/service/test/unit/adapter/mailstore/test_leap_mailstore.py index 3a862da7..f860455d 100644 --- a/service/test/unit/adapter/mailstore/test_leap_mailstore.py +++ b/service/test/unit/adapter/mailstore/test_leap_mailstore.py @@ -27,6 +27,7 @@ from mockito import mock, when, verify, any from leap.mail.adaptors.soledad import SoledadMailAdaptor, MailboxWrapper import pkg_resources from leap.mail.mail import Message +from pixelated.adapter.mailstore import underscore_uuid from pixelated.adapter.mailstore.leap_mailstore import LeapMailStore, LeapMail @@ -209,6 +210,18 @@ class TestLeapMailStore(TestCase): verify(self.soledad).delete_doc(self.doc_by_id[mdoc_id]) verify(self.soledad).delete_doc(self.doc_by_id[fdoc_id]) + @defer.inlineCallbacks + def test_get_mailbox_mail_ids(self): + mdoc_id, fdoc_id = self._add_mail_fixture_to_soledad('mbox00000000') + when(self.soledad).get_from_index('by-type-and-mbox-uuid', 'flags', underscore_uuid(self.mbox_uuid)).thenReturn(defer.succeed([self.doc_by_id[fdoc_id]])) + self._mock_get_mailbox('INBOX') + store = LeapMailStore(self.soledad) + + mail_ids = yield store.get_mailbox_mail_ids('INBOX') + + self.assertEqual(1, len(mail_ids)) + self.assertEqual(mdoc_id, mail_ids[0]) + def _assert_message_docs_created(self, expected_message, actual_message): wrapper = expected_message.get_wrapper() @@ -221,7 +234,7 @@ class TestLeapMailStore(TestCase): def _mock_get_mailbox(self, mailbox_name): when(self.soledad).list_indexes().thenReturn(defer.succeed(MAIL_INDEXES)).thenReturn( defer.succeed(MAIL_INDEXES)) - mbox = MailboxWrapper(doc_id=self.mbox_uuid, mbox=mailbox_name) + mbox = MailboxWrapper(doc_id=self.mbox_uuid, mbox=mailbox_name, uuid=self.mbox_uuid) soledad_doc = SoledadDocument(self.mbox_uuid, json=json.dumps(mbox.serialize())) when(self.soledad).get_from_index('by-type-and-mbox', 'mbox', mailbox_name).thenReturn(defer.succeed([soledad_doc])) |