summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--service/pixelated/adapter/mail_service.py4
-rw-r--r--service/pixelated/adapter/search.py3
-rw-r--r--service/pixelated/adapter/soledad_querier.py4
-rw-r--r--service/pixelated/controllers/mails_controller.py8
-rw-r--r--service/test/integration/delete_mail_test.py8
-rw-r--r--service/test/support/integration_helper.py4
6 files changed, 25 insertions, 6 deletions
diff --git a/service/pixelated/adapter/mail_service.py b/service/pixelated/adapter/mail_service.py
index cc03ab3a..6c093b6d 100644
--- a/service/pixelated/adapter/mail_service.py
+++ b/service/pixelated/adapter/mail_service.py
@@ -68,6 +68,10 @@ class MailService:
def delete_mail(self, mail_id):
return self.mailboxes.move_to_trash(mail_id)
+ def delete_permanent(self, mail_id):
+ mail = self.mail(mail_id)
+ self.querier.remove_mail(mail)
+
def save_draft(self, draft):
raise NotImplementedError()
diff --git a/service/pixelated/adapter/search.py b/service/pixelated/adapter/search.py
index 71b72dba..559e8a99 100644
--- a/service/pixelated/adapter/search.py
+++ b/service/pixelated/adapter/search.py
@@ -99,7 +99,8 @@ class SearchEngine(object):
body=TEXT(stored=False),
tag=KEYWORD(stored=True, commas=True),
flags=KEYWORD(stored=True, commas=True),
- raw=TEXT(stored=False))
+ raw=TEXT(stored=False),
+ deleted=BOOLEAN(stored=False))
def _create_index(self):
return whoosh.index.create_in(self.INDEX_FOLDER, self._mail_schema(), indexname='mails')
diff --git a/service/pixelated/adapter/soledad_querier.py b/service/pixelated/adapter/soledad_querier.py
index 318e1539..42af6d2b 100644
--- a/service/pixelated/adapter/soledad_querier.py
+++ b/service/pixelated/adapter/soledad_querier.py
@@ -67,9 +67,9 @@ class SoledadQuerier:
def remove_mail(self, mail):
_mail = self.mail(mail.ident)
# FIX-ME: Must go through all the part_map phash to delete all the cdocs
- self.soledad.delete_doc(_mail.bdoc)
- self.soledad.delete_doc(_mail.hdoc)
self.soledad.delete_doc(_mail.fdoc)
+ self.soledad.delete_doc(_mail.hdoc)
+ self.soledad.delete_doc(_mail.bdoc)
def idents_by_mailbox(self, mailbox_name):
return set(doc.content['chash'] for doc in self.soledad.get_from_index('by-type-and-mbox-and-deleted', 'flags', mailbox_name, '0'))
diff --git a/service/pixelated/controllers/mails_controller.py b/service/pixelated/controllers/mails_controller.py
index b039495f..e85d338d 100644
--- a/service/pixelated/controllers/mails_controller.py
+++ b/service/pixelated/controllers/mails_controller.py
@@ -70,8 +70,12 @@ class MailsController:
return ""
def delete_mail(self, mail_id):
- trashed_mail = self._mail_service.delete_mail(mail_id)
- self._search_engine.index_mail(trashed_mail)
+ mail = self._mail_service.mail(mail_id)
+ if mail.mailbox_name == 'TRASH':
+ self._mail_service.delete_permanent(mail_id)
+ else:
+ trashed_mail = self._mail_service.delete_mail(mail_id)
+ self._search_engine.index_mail(trashed_mail)
return respond_json(None)
def delete_mails(self):
diff --git a/service/test/integration/delete_mail_test.py b/service/test/integration/delete_mail_test.py
index 894f84bf..10c09e7a 100644
--- a/service/test/integration/delete_mail_test.py
+++ b/service/test/integration/delete_mail_test.py
@@ -39,3 +39,11 @@ class DeleteMailTest(unittest.TestCase, SoledadTestBase):
self.assertEquals(0, len(inbox_mails))
trash_mails = self.get_mails_by_tag('trash')
self.assertEquals(1, len(trash_mails))
+
+ def test_delete_mail_when_trashing_mail_from_trash_mailbox(self):
+ mails = self.add_multiple_to_mailbox(1, 'trash')
+ self.delete_mail(mails[0].ident)
+
+ trash_mails = self.get_mails_by_tag('trash')
+
+ self.assertEqual(0, len(trash_mails))
diff --git a/service/test/support/integration_helper.py b/service/test/support/integration_helper.py
index 3667001f..e71da443 100644
--- a/service/test/support/integration_helper.py
+++ b/service/test/support/integration_helper.py
@@ -220,12 +220,14 @@ class SoledadTestBase:
self.search_engine.index_mail(mail)
def add_multiple_to_mailbox(self, num, mailbox='', flags=[], tags=[]):
+ mails = []
for _ in range(num):
input_mail = MailBuilder().with_status(flags).with_tags(tags).build_input_mail()
mail = self.mailboxes._create_or_get(mailbox).add(input_mail)
+ mails.append(mail)
mail.update_tags(input_mail.tags)
self.search_engine.index_mail(mail)
-
+ return mails
class ResponseMail:
def __init__(self, mail_dict):