You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
imaplib Time2Internaldate crashing with time.struct_time supplied from datetime.timetuple() #86165
Hello
first of all, I couldn't find any issue related to this, so sorry if it has been solved before.
There seems to be an issue with IMAPLIB in all versions I've checked, when using the Time2Internaldate function with time.struct_time created by datetime.timetuple() extracted from an EmailMessage object (using the email.utils.parsedate_to_datetime function), and even when created with datetime.now() the function crashes the app with
"TypeError: unsupported type for timedelta seconds component: NoneType"
on line 1530 in current master on GH. (delta = timedelta(seconds=gmtoff))
Crash happens because the "date_time.tm_gmtoff" from which the gmtoff variable is constructed, seems to default to None in all instances of time.struct_time object created by datetime.timetuple(), which still passes the try, except clausule on 1520, because it's not an AttributeError. The time.localtime() metioned in the docs asigns the correct value into tm_gmtoff, but the datetime.timetuple() does not.
Possible solutions I've found:
inside Time2Internaldate: surround the delta with try and except - in except make the delta = 0
inside Time2Internaldate: check the gmtoff for None and if yes, then change it to 0
change the default of tm_gmtoff in timetuple from None to 0 (or to a current timezone offset)
or just say in the docs, that time.struct_time created this way (using the datetime.timetuple()) is unsupported
PS: when writing this issue, I've started thinking this might be a datetime lib issue too
Activity
sajicek commentedon Oct 10, 2020
Hello
first of all, I couldn't find any issue related to this, so sorry if it has been solved before.
There seems to be an issue with IMAPLIB in all versions I've checked, when using the Time2Internaldate function with time.struct_time created by datetime.timetuple() extracted from an EmailMessage object (using the email.utils.parsedate_to_datetime function), and even when created with datetime.now() the function crashes the app with
"TypeError: unsupported type for timedelta seconds component: NoneType"
on line 1530 in current master on GH. (delta = timedelta(seconds=gmtoff))
Crash happens because the "date_time.tm_gmtoff" from which the gmtoff variable is constructed, seems to default to None in all instances of time.struct_time object created by datetime.timetuple(), which still passes the try, except clausule on 1520, because it's not an AttributeError. The time.localtime() metioned in the docs asigns the correct value into tm_gmtoff, but the datetime.timetuple() does not.
Possible solutions I've found:
or just say in the docs, that time.struct_time created this way (using the datetime.timetuple()) is unsupported
PS: when writing this issue, I've started thinking this might be a datetime lib issue too
gh-86165: Fix Time2Internaldate with datetime timetuple (GH-151844)
[3.13] gh-86165: Fix Time2Internaldate with datetime timetuple (GH-15…
[3.14] gh-86165: Fix Time2Internaldate with datetime timetuple (GH-15…
[3.15] gh-86165: Fix Time2Internaldate with datetime timetuple (GH-15…