Skip to content

Commit

Permalink
Always run indexing for sent mailbox (#321)
Browse files Browse the repository at this point in the history
* Always run all indexing code paths

* Only index emails of users in system
  • Loading branch information
c-w authored Feb 5, 2020
1 parent 63236a8 commit 027c230
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 19 deletions.
9 changes: 4 additions & 5 deletions opwen_email_server/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,9 @@ def _action(self, resource_id): # type: ignore

for email_address in self._get_pivot(email):
domain = get_domain(email_address)
index = f"{domain}/{email_address}/{self._folder}/{email['sent_at']}/{resource_id}"
self._mailbox_storage.store_text(index, 'indexed')
if domain.endswith(mailbox.MAILBOX_DOMAIN):
index = f"{domain}/{email_address}/{self._folder}/{email['sent_at']}/{resource_id}"
self._mailbox_storage.store_text(index, 'indexed')

self.log_event(events.MAILBOX_EMAIL_INDEXED, {'folder': self._folder}) # noqa: E501 # yapf: disable
return 'OK', 200
Expand All @@ -140,9 +141,7 @@ class IndexReceivedEmailForMailbox(_IndexEmailForMailbox):

def _get_pivot(self, email: dict) -> Iterable[str]:
for email_address in get_recipients(email):
domain = get_domain(email_address)
if domain.endswith(mailbox.MAILBOX_DOMAIN):
yield email_address
yield email_address


class IndexSentEmailForMailbox(_IndexEmailForMailbox):
Expand Down
5 changes: 3 additions & 2 deletions opwen_email_server/integration/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,10 @@ def inbound_store(resource_id: str) -> None:
action(resource_id)


def _send_email(resource_id: str) -> None:
def send_and_index_email(resource_id: str) -> None:
send.delay(resource_id)
index_sent_email_for_mailbox.delay(resource_id)
index_received_email_for_mailbox.delay(resource_id)


@celery.task(ignore_result=True)
Expand All @@ -84,7 +85,7 @@ def written_store(resource_id: str) -> None:
client_storage=get_client_storage(),
email_storage=get_email_storage(),
user_storage=get_user_storage(),
next_task=_send_email,
next_task=send_and_index_email,
)

action(resource_id)
Expand Down
12 changes: 2 additions & 10 deletions opwen_email_server/integration/webapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@
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
from opwen_email_server.integration.celery import send
from opwen_email_server.integration.celery import send_and_index_email
from opwen_email_server.services.storage import AzureObjectStorage
from opwen_email_server.services.storage import AzureTextStorage
from opwen_email_server.utils.collections import chunks
Expand Down Expand Up @@ -244,20 +242,14 @@ def download(self) -> Iterable:
return []


def _send_email(resource_id: str) -> None:
send.delay(resource_id)
index_sent_email_for_mailbox.delay(resource_id)
index_received_email_for_mailbox.delay(resource_id)


class AzureIoc:
@cached_property
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,
send_email=send_and_index_email,
)

@cached_property
Expand Down
5 changes: 3 additions & 2 deletions tests/opwen_email_server/test_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def test_200(self):
email_id = '123'
email = {
'to': ['1@bar.lokole.ca', 'foo@gmail.com'], 'cc': ['2@baz.lokole.ca'], 'sent_at': '2019-10-26 22:47',
'from': 'foo@foo'
'from': 'foo@foo.lokole.ca'
}

self.email_storage.fetch_object.return_value = email
Expand All @@ -185,7 +185,8 @@ def test_200(self):

self.assertEqual(status, 200)
self.email_storage.fetch_object.assert_called_once_with(email_id)
self.mailbox_storage.store_text.assert_called_once_with('foo/foo@foo/sent/2019-10-26 22:47/123', 'indexed')
self.mailbox_storage.store_text.assert_called_once_with(
'foo.lokole.ca/foo@foo.lokole.ca/sent/2019-10-26 22:47/123', 'indexed')

def _execute_action(self, *args, **kwargs):
action = actions.IndexSentEmailForMailbox(
Expand Down

0 comments on commit 027c230

Please sign in to comment.