From 9ed58715616f5c6341d32c9b0316933d3f2b4a3e Mon Sep 17 00:00:00 2001 From: Folker Bernitt Date: Mon, 10 Aug 2015 19:23:18 +0200 Subject: Added test to ensure mail with same content can be added. - as long as each one has a unique message id --- service/pixelated/adapter/mailstore/leap_mailstore.py | 2 +- service/test/integration/test_leap_mailstore.py | 13 +++++++++++++ service/test/support/integration/util.py | 7 ++++++- 3 files changed, 20 insertions(+), 2 deletions(-) (limited to 'service') diff --git a/service/pixelated/adapter/mailstore/leap_mailstore.py b/service/pixelated/adapter/mailstore/leap_mailstore.py index a641c35b..1bcab036 100644 --- a/service/pixelated/adapter/mailstore/leap_mailstore.py +++ b/service/pixelated/adapter/mailstore/leap_mailstore.py @@ -159,7 +159,7 @@ class LeapMailStore(MailStore): message = SoledadMailAdaptor().get_msg_from_string(Message, raw_msg) message.get_wrapper().set_mbox_uuid(mailbox.uuid) - yield message.get_wrapper().create(self.soledad) + yield SoledadMailAdaptor().create_msg(self.soledad, message) # add behavious from insert_mdoc_id from mail.py mail = yield self._leap_message_to_leap_mail(message.get_wrapper().mdoc.doc_id, message, include_body=True) # TODO test that asserts include_body diff --git a/service/test/integration/test_leap_mailstore.py b/service/test/integration/test_leap_mailstore.py index 61bb3e42..48764194 100644 --- a/service/test/integration/test_leap_mailstore.py +++ b/service/test/integration/test_leap_mailstore.py @@ -69,6 +69,19 @@ class LeapMailStoreTest(SoledadTestBase): self.assertIsNone(deleted_msg) + @defer.inlineCallbacks + def test_add_add_mail_twice(self): + yield self.adaptor.initialize_store(self.soledad) + mail = load_mail_from_file('mbox00000000', enforceUniqueMessageId=True) + mail2 = load_mail_from_file('mbox00000000', enforceUniqueMessageId=True) + yield self.mail_store.add_mailbox('INBOX') + + msg1 = yield self.mail_store.add_mail('INBOX', mail.as_string()) + msg2 = yield self.mail_store.add_mail('INBOX', mail2.as_string()) + + self.assertIsNotNone(msg1.ident) + self.assertIsNotNone(msg2.ident) + @defer.inlineCallbacks def test_get_mailbox_mail_ids(self): mail = load_mail_from_file('mbox00000000') diff --git a/service/test/support/integration/util.py b/service/test/support/integration/util.py index 2049105d..302edeaa 100644 --- a/service/test/support/integration/util.py +++ b/service/test/support/integration/util.py @@ -14,13 +14,18 @@ # You should have received a copy of the GNU Affero General Public License # along with Pixelated. If not, see . from email.parser import Parser +from email.utils import make_msgid import os import pkg_resources -def load_mail_from_file(mail_file): +def load_mail_from_file(mail_file, enforceUniqueMessageId=False): mailset_dir = pkg_resources.resource_filename('test.unit.fixtures', 'mailset') mail_file = os.path.join(mailset_dir, 'new', mail_file) with open(mail_file) as f: mail = Parser().parse(f) + + if enforceUniqueMessageId: + mail.add_header('Message-Id', make_msgid()) + return mail -- cgit v1.2.3