From f5e3c101564cffe407af1ddf79d7bf89796c813a Mon Sep 17 00:00:00 2001 From: Clemens Wolff Date: Wed, 22 Jan 2020 00:24:29 -0500 Subject: [PATCH] Implement email deletion in webapp (#291) --- opwen_email_server/integration/webapp.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/opwen_email_server/integration/webapp.py b/opwen_email_server/integration/webapp.py index cb3da120..2850adba 100644 --- a/opwen_email_server/integration/webapp.py +++ b/opwen_email_server/integration/webapp.py @@ -24,6 +24,7 @@ from opwen_email_server.services.storage import AzureObjectStorage from opwen_email_server.utils.collections import chunks from opwen_email_server.utils.email_parser import get_domain +from opwen_email_server.utils.email_parser import get_recipients class AzureRole: @@ -212,7 +213,20 @@ def num_pending(self) -> int: return 0 def _delete(self, email_address: str, uids: Iterable[str]): - pass + for uid in uids: + email = self.get(uid) + if not email: + continue + + if email_address == email.get('from'): + folder = mailbox.SENT_FOLDER + elif email_address in get_recipients(email): + folder = mailbox.RECEIVED_FOLDER + else: + continue + + self._mailbox_storage.delete(f"{email_address}/{folder}/{email['sent_at']}/{uid}") + self._email_storage.delete(uid) def _mark_sent(self, uids: Iterable[str]): pass