Miksus / red-box

Next generation email box manager

Home Page:https://red-box.readthedocs.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Exception on date retrieval

jaboto opened this issue · comments

Hey, thanks for this piece of software. Have been using in some of my scripts. However, today I run into an issue while extracting the information from one of the emails.

In [64]: msg = inbox.search(SUBJECT("XXXXX"))

In [65]: msg
Out[65]: 
[EmailMessage(session=<imaplib.IMAP4_SSL object at 0x7fdc08e69870>, uid=279, mailbox='INBOX'),
 EmailMessage(session=<imaplib.IMAP4_SSL object at 0x7fdc08e69870>, uid=280, mailbox='INBOX'),
 EmailMessage(session=<imaplib.IMAP4_SSL object at 0x7fdc08e69870>, uid=281, mailbox='INBOX')]

In [66]: msg[0]
Out[66]: EmailMessage(session=<imaplib.IMAP4_SSL object at 0x7fdc08e69870>, uid=279, mailbox='INBOX')

In [67]: msg[0].date
Out[67]: datetime.datetime(2024, 1, 16, 10, 57, 48, tzinfo=datetime.timezone.utc)

In [68]: msg[1].date
Out[68]: datetime.datetime(2023, 12, 19, 16, 27, 9, tzinfo=datetime.timezone.utc)

In [69]: msg[2].date
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-69-2efa661e9837> in <module>
----> 1 msg[2].date

~/.local/lib/python3.10/site-packages/redbox/models/message.py in date(self)
     82         headers = {k.lower(): v for k, v in self.headers.items()}
     83         date = headers['date']
---> 84         return datetime.datetime.strptime(date, "%a, %d %b %Y %H:%M:%S %z")
     85 
     86     def read(self):

/usr/lib/python3.10/_strptime.py in _strptime_datetime(cls, data_string, format)
    566     """Return a class cls instance based on the input string and the
    567     format string."""
--> 568     tt, fraction, gmtoff_fraction = _strptime(data_string, format)
    569     tzname, gmtoff = tt[-2:]
    570     args = tt[:6] + (fraction,)

/usr/lib/python3.10/_strptime.py in _strptime(data_string, format)
    347     found = format_regex.match(data_string)
    348     if not found:
--> 349         raise ValueError("time data %r does not match format %r" %
    350                          (data_string, format))
    351     if len(data_string) != found.end():

ValueError: time data '17 Jan 2024 21:34:20 +0000' does not match format '%a, %d %b %Y %H:%M:%S %z'

This email was automatically forwarded from one email provider to another one, not sure if that's what caused the issue. Fix seems to be an easy one, will try to PR eventually but wanted to put it here.