示例#1
0
    def test_unique(self):
        id1 = unique.new_email_id({'from': 'foo'})
        id2 = unique.new_email_id({'from': 'bar'})
        id3 = unique.new_email_id({'from': 'foo'})

        self.assertNotEqual(id1, id2)
        self.assertNotEqual(id2, id3)
        self.assertEqual(id1, id3)
示例#2
0
    def _action(self, resource_id):  # type: ignore
        try:
            mime_email = self._raw_email_storage.fetch_text(resource_id)
        except ObjectDoesNotExistError:
            self.log_warning('Inbound email %s does not exist', resource_id)
            return 'skipped', 202

        email = self._email_parser(mime_email)

        for address in email.get('to', []):
            try:
                mailer_service = self._registry[address]
            except KeyError:
                self.log_warning('Skipping unknown mailer service: %s', address)
                continue

            formatted_email = mailer_service(email)

            formatted_email_id = new_email_id(formatted_email)
            formatted_email['_uid'] = formatted_email_id

            self._email_storage.store_object(formatted_email_id, formatted_email)

            self._next_task(formatted_email_id)

        self._raw_email_storage.delete(resource_id)
        self.log_event(events.EMAILS_FORMATTED_FOR_CLIENT)  # noqa: E501  # yapf: disable
        return 'OK', 200
示例#3
0
    def _store_inbound_email(self, email: dict):
        email_id = new_email_id(email)
        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')
示例#4
0
    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