def test_descending_timestamp_order_by_day(self):
        january_1st = '2020-01-01 22:09'
        january_2nd = '2020-01-02 22:09'

        january_1_timestamp = email_parser.descending_timestamp(january_1st)
        january_2_timestamp = email_parser.descending_timestamp(january_2nd)

        timestamp_ordering = sorted([january_1_timestamp, january_2_timestamp])
        self.assertEqual(timestamp_ordering, [january_2_timestamp, january_1_timestamp])
    def test_descending_timestamp_order_by_minute(self):
        january_1st_22h09m = '2020-01-01 22:09'
        january_1st_22h11m = '2020-01-01 22:11'

        january_22h09m_timestamp = email_parser.descending_timestamp(january_1st_22h09m)
        january_22h11m_timestamp = email_parser.descending_timestamp(january_1st_22h11m)

        timestamp_ordering = sorted([january_22h09m_timestamp, january_22h11m_timestamp])
        self.assertEqual(timestamp_ordering, [january_22h11m_timestamp, january_22h09m_timestamp])
    def test_descending_timestamp_order_by_month(self):
        january = '2020-01-01 22:09'
        february = '2020-02-02 22:09'

        january_timestamp = email_parser.descending_timestamp(january)
        february_timestamp = email_parser.descending_timestamp(february)

        timestamp_ordering = sorted([january_timestamp, february_timestamp])
        self.assertEqual(timestamp_ordering, [february_timestamp, january_timestamp])
    def test_descending_timestamp_order_by_year(self):
        january_2020 = '2020-01-01 22:09'
        january_2021 = '2021-01-01 22:09'

        january_2020_timestamp = email_parser.descending_timestamp(january_2020)
        january_2021_timestamp = email_parser.descending_timestamp(january_2021)

        timestamp_ordering = sorted([january_2020_timestamp, january_2021_timestamp])
        self.assertEqual(timestamp_ordering, [january_2021_timestamp, january_2020_timestamp])
Exemple #5
0
    def _action(self, resource_id):  # type: ignore
        email = self._email_storage.fetch_object(resource_id)

        for email_address in self._get_pivot(email):
            domain = get_domain(email_address)
            desc_prefix = descending_timestamp(email['sent_at'])
            if domain.endswith(mailbox.MAILBOX_DOMAIN):
                index = f"{domain}/{email_address}/{self._folder}/{desc_prefix}/{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
Exemple #6
0
    def _delete(self, email_address: str, uids: Iterable[str]):
        domain = get_domain(email_address)

        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

            desc_prefix = descending_timestamp(email['sent_at'])

            self._mailbox_storage.delete(
                f"{domain}/{email_address}/{folder}/{desc_prefix}/{uid}")
    def test_descending_timestamp_correct(self):
        sent_at = '2020-02-01 21:09'

        sent_at_timestamp = email_parser.descending_timestamp(sent_at)

        self.assertEqual(sent_at_timestamp, '519408660')