Skip to content

imaplib Time2Internaldate crashing with time.struct_time supplied from datetime.timetuple() #86165

Closed

Description

@sajicek
mannequin
BPO 41999
Nosy @sajicek

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = None
created_at = <Date 2020-10-10.14:40:53.737>
labels = ['type-bug', '3.8', '3.9', '3.10', '3.7', 'library']
title = 'imaplib Time2Internaldate crashing with time.struct_time supplied from datetime.timetuple()'
updated_at = <Date 2020-10-10.14:40:53.737>
user = 'https://github.com/sajicek'

bugs.python.org fields:

activity = <Date 2020-10-10.14:40:53.737>
actor = 'sajicek'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Library (Lib)']
creation = <Date 2020-10-10.14:40:53.737>
creator = 'sajicek'
dependencies = []
files = []
hgrepos = []
issue_num = 41999
keywords = []
message_count = 1.0
messages = ['378409']
nosy_count = 1.0
nosy_names = ['sajicek']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue41999'
versions = ['Python 3.5', 'Python 3.6', 'Python 3.7', 'Python 3.8', 'Python 3.9', 'Python 3.10']

Linked PRs

Activity

  1. sajicek commented on Oct 10, 2020

    sajicekmannequin
    MannequinAuthor

    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:

    1. inside Time2Internaldate: surround the delta with try and except - in except make the delta = 0
    2. inside Time2Internaldate: check the gmtoff for None and if yes, then change it to 0
    3. 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

  2. added
    stdlibStandard Library Python modules in the Lib/ directory
    type-bugAn unexpected behavior, bug, or error
    on Oct 10, 2020
  3. transferred this issue fromon Apr 10, 2022
  4. added a commit that references this issue on Jul 2, 2026
  5. added 3 commits that reference this issue on Jul 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytopic-emailtype-bugAn unexpected behavior, bug, or error

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions