From ac022b7ee6fc38371ce7b4bb31665ccd38bd0cfa Mon Sep 17 00:00:00 2001 From: Clemens Wolff Date: Thu, 30 Jan 2020 22:48:43 -0500 Subject: [PATCH] Sync emails sent from webapp to Lokole (#311) * Sync emails sent from webapp to Lokole * Remove hidden form token from email persistence --- opwen_email_server/integration/webapp.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/opwen_email_server/integration/webapp.py b/opwen_email_server/integration/webapp.py index cbd60c24..27b67cc2 100644 --- a/opwen_email_server/integration/webapp.py +++ b/opwen_email_server/integration/webapp.py @@ -19,6 +19,7 @@ from opwen_email_server.constants import mailbox from opwen_email_server.integration.azure import get_email_storage from opwen_email_server.integration.azure import get_mailbox_storage +from opwen_email_server.integration.azure import get_pending_storage from opwen_email_server.integration.azure import get_user_storage from opwen_email_server.integration.celery import index_received_email_for_mailbox from opwen_email_server.integration.celery import index_sent_email_for_mailbox @@ -127,10 +128,11 @@ def _path_for(cls, email: str) -> str: class AzureEmailStore(EmailStore): def __init__(self, email_storage: AzureObjectStorage, mailbox_storage: AzureTextStorage, - send_email: Callable[[str], None]): + pending_storage: AzureTextStorage, send_email: Callable[[str], None]): super().__init__(restricted=None) self._email_storage = email_storage self._mailbox_storage = mailbox_storage + self._pending_storage = pending_storage self._send_email = send_email def _create(self, emails_or_attachments: Iterable[dict]): @@ -138,11 +140,17 @@ def _create(self, emails_or_attachments: Iterable[dict]): if email.get('_type') == 'attachment': raise NotImplementedError + domain = get_domain(email.get('from', '')) + if not domain.endswith(mailbox.MAILBOX_DOMAIN): + continue + if not email.get('sent_at'): email['sent_at'] = datetime.utcnow().strftime('%Y-%m-%d %H:%M') + email.pop('csrf_token', None) email_id = email['_uid'] self._email_storage.store_object(email_id, email) + self._pending_storage.store_text(f'{domain}/{email_id}', 'pending') self._send_email(email_id) def get(self, uid: str) -> Optional[dict]: @@ -250,6 +258,7 @@ def email_store(self): return AzureEmailStore( email_storage=get_email_storage(), mailbox_storage=get_mailbox_storage(), + pending_storage=get_pending_storage(), send_email=_send_email, )