def _store_inbound_email(self, email_id: str, email: dict): email['_uid'] = email_id self._email_storage.store_object(email_id, email) for domain in get_domains(email): pending_storage = self._pending_factory(domain) pending_storage.store_text(email_id, 'pending')
def test_gets_domains_with_cc_and_bcc(self): email = {'to': ['*****@*****.**'], 'cc': ['*****@*****.**'], 'bcc': ['foo@com']} domains = email_parser.get_domains(email) self.assertSetEqual(domains, {'bar.com', 'com'})
def _store_inbound_email(self, email: dict) -> str: ensure_has_sent_at(email) email_id = new_email_id(email) email['_uid'] = email_id self._email_storage.store_object(email_id, email) for domain in get_domains(email): if domain.endswith(mailbox.MAILBOX_DOMAIN): self._pending_storage.store_text(f'{domain}/{email_id}', 'pending') return email_id
def test_gets_domains(self): email = {'to': ['*****@*****.**', '*****@*****.**', 'foo@com']} domains = email_parser.get_domains(email) self.assertSetEqual(set(domains), {'bar.com', 'com'})
tables={ constants.TABLE_DOMAIN: get_domains, constants.TABLE_TO: lambda _: _.get('to') or [], constants.TABLE_CC: lambda _: _.get('cc') or [], constants.TABLE_BCC: lambda _: _.get('bcc') or [], constants.TABLE_FROM: lambda _: to_iterable(_.get('from')), constants.TABLE_DOMAIN_X_DELIVERED: lambda _: ('{domain}_{delivered}'.format(domain=domain, delivered=_.get('_delivered') or False) for domain in get_domains(_) if domain.endswith('lokole.ca')), }) def fetch_email(email_id: str) -> dict: serialized = STORAGE.fetch_text(email_id) email = loads(serialized) return email def fetch_pending_emails(domain: str) -> Iterable[dict]: partition = '{domain}_{delivered}'.format(domain=domain, delivered=False) email_ids = INDEX.query(constants.TABLE_DOMAIN_X_DELIVERED, partition) for email_id in email_ids: yield fetch_email(email_id)