Skip to content

IMAP library lacks documentation about expected parameter types #68215

Description

@pmoleri
mannequin
BPO 24027
Nosy @warsaw, @mcepl, @bitdancer

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 2015-04-22.15:19:43.283>
labels = ['type-feature', 'expert-email', 'docs']
title = 'IMAP library lacks documentation about expected parameter types'
updated_at = <Date 2018-04-21.09:14:32.760>
user = 'https://bugs.python.org/pmoleri'

bugs.python.org fields:

activity = <Date 2018-04-21.09:14:32.760>
actor = 'mcepl'
assignee = 'docs@python'
closed = False
closed_date = None
closer = None
components = ['Documentation', 'email']
creation = <Date 2015-04-22.15:19:43.283>
creator = 'pmoleri'
dependencies = []
files = []
hgrepos = []
issue_num = 24027
keywords = []
message_count = 3.0
messages = ['241812', '241814', '315560']
nosy_count = 5.0
nosy_names = ['barry', 'mcepl', 'r.david.murray', 'docs@python', 'pmoleri']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue24027'
versions = ['Python 3.4', 'Python 3.5']

Activity

  1. pmoleri commented on Apr 22, 2015

    pmolerimannequin
    MannequinAuthor

    I used the IMAP library and I feel it lacks a lot of documentation regarding types and encoding.

    Example:
    IMAP4.list([directory[, pattern]]):
    It doesn't state if it expects the directory argument to be an string (unicode) or a imap_utf7 encoded string or bytes.
    It also expects names with spaces to be between double quotation marks and it doesn't state that it returns a bytes raw output.

    This is valid for every function that receives a directory or mailbox argument. Also for most return values.

    Documentation aside, I think it would be a nice improvement in the implementation to add an imap_utf7 convertion function, and check every directory or mailbox argument to see if it has characters outside the imap_utf7 charset and attempts to convert them automatically.

  2. added
    docsDocumentation in the Doc dir
    type-featureA feature request or enhancement
    on Apr 22, 2015
  3. bitdancer commented on Apr 22, 2015

    @bitdancer
    Member

    Documentation patches are welcome. imaplib has not seen much attention for quite some time (though there is currently someone interested in working on it, so that may change).

    Please open a separate issue for the utf7 enhancement proposal.

  4. mcepl commented on Apr 21, 2018

    mceplmannequin
    Mannequin
  5. transferred this issue fromon Apr 10, 2022
  6. vadmium commented on May 2, 2024

    @vadmium
    Member

    Regarding double-quoting, the general rule implied by https://docs.python.org/3/library/imaplib.html#imap4-objects for almost all command arguments is the command methods sometimes quote their arguments (e.g. if they contain spaces), but not if they already look like a quoted string or parenthesized list. However this quoting functionality was accidentally removed (Issue #92835). And the caller always had to do their own quoting anyway if the raw argument value happens to be enclosed in quotes or brackets.

    It might be worth specifying what IMAP syntax is required for directory and mailbox arguments (presumably the mailbox rule).

    Regarding return values, the general rule does say the data items are either bytes or tuples. It seems that each bytes item is based on an IMAP server response (tagged status or untagged data), while the tuples may be 2-tuples involving IMAP literal strings. The “header” seems to be based on the IMAP response that precedes the literal, including the {number} prefix of the literal, but excluding the CRLF. The tuple might be followed by more tuples, and then a final bytes item, all corresponding to one untagged server data response.

    It seems these returned items aren’t always pure raw IMAP protocol. FETCH responses seem to have the initial asterisk and trailing CRLF removed, as well as the FETCH atom and a space removed from the middle of the string. Here is a single FETCH response returned as two lines including a literal string. You can see how the first line doesn’t quite match the IMAP protocol from the raw debug log.

    >>> M.fetch('1', '(BODY.PEEK[HEADER.FIELDS (DATE)])')
      56:52.30 > b'NMFB14 FETCH 1 (BODY.PEEK[HEADER.FIELDS (DATE)])'
      56:52.68 < b'* 1 FETCH (BODY[HEADER.FIELDS (DATE)] {41}'
      56:52.68 read literal size 41
      56:52.68 < b')'
      56:52.68 < b'NMFB14 OK Success'
    ('OK',
     [(b'1 (BODY[HEADER.FIELDS (DATE)] {41}',
       b'Date: Fri, 17 Sep 2004 11:56:09 +1000\r\n\r\n'),
      b')'])

    Similarly, EXPUNGE responses seem to be just the message number from the protocol, with the asterisk, EXPUNGE and CRLF removed:

    >>> M.noop()
      15:50.85 > b'NMFB22 NOOP'
      15:51.18 < b'* 887 EXPUNGE'
      15:51.18 < b'* 886 EXISTS'
      15:51.18 < b'NMFB22 OK Success'
    ('OK', [b'Success'])
    >>> M.response('EXPUNGE')
    ('EXPUNGE', [b'887'])

    I’ve also seen the list [None] being returned as the data list, where I would expect an empty list. This might be hinted at in the response method documentation, but it is not clear enough, and doesn’t seem limited to that method.

    >>> NONEXISTENT_UID = '999999'
    >>> M.uid('FETCH', NONEXISTENT_UID, '(FLAGS)')
      40:06.75 > b'NMFB24 UID FETCH 999999 (FLAGS)'
      40:07.13 < b'NMFB24 OK Success'
    ('OK', [None])
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

    docsDocumentation in the Doc dirtopic-emailtype-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions