classification
Title: Python 3.10 email returns invalid Date: header unchanged.
Type: Stage: resolved
Components: email Versions: Python 3.10
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: barry, msapiro, r.david.murray
Priority: normal Keywords: 3.10regression

Created on 2021-12-08 04:32 by msapiro, last changed 2021-12-09 14:58 by r.david.murray.

Messages (3)
msg407997 - (view) Author: Mark Sapiro (msapiro) * (Python triager) Date: 2021-12-08 04:32
Here is an interactive Python session
```
Python 3.10.1 (main, Dec  7 2021, 15:44:39) [GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from email import message_from_bytes, policy
>>> msg_raw = b"""Return-Path: <owner-mailman-users@python.org>
... Delivered-To: mailman-users@dinsdale.python.org
... From: user@example.com
... Message-Id: <msg1>
... Date: Tue, 30 Nov 1999 23:56:33 -3000 (CST)
... To: mailman-users@python.org
... 
... msg1
... """
>>> message = message_from_bytes(msg_raw, policy=policy.default)
>>> message.get('date')
'Tue, 30 Nov 1999 23:56:33 -3000 (CST)'
>>> message.defects
[]
>>> 
```
The same session in Python 3.9 throws ValueError: offset must be a timedelta strictly between -timedelta(hours=24) and timedelta(hours=24), not datetime.timedelta(days=-2, seconds=64800).

At first I thought this was related to https://bugs.python.org/issue30681 but that seems to not be the case as utils.parsedate_to_datetime('Tue, 30 Nov 1999 23:56:33 -3000 (CST)') throws the same exception In Python 3.10.1.

I think getting the Date: header which has an invalid timezone should either throw the exception as before or return None, but not return the invalid date header.
msg408048 - (view) Author: Mark Sapiro (msapiro) * (Python triager) Date: 2021-12-08 22:14
Upon further research I realized this is related to https://bugs.python.org/issue30681 and that while there are no message.defects the Date: header does have the InvalidDateDefect and its datetime attribute is None so I consider this resolved.
msg408130 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2021-12-09 14:58
Yeah, I think there may be a general issue with getting header defects reflected somehow in message.defects, but that's a separate issue :)
History
Date User Action Args
2021-12-09 14:58:06r.david.murraysetmessages: + msg408130
2021-12-08 22:14:39msapirosetmessages: + msg408048
stage: resolved
2021-12-08 04:32:57msapirocreate