FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-98092: Add imaplib.IMAP4.id method by serhiy-storchaka · Pull Request #153136 · python/cpython · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) .rst  (3) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
13 changes: 13 additions & 0 deletions Doc/library/imaplib.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,19 @@ An :class:`IMAP4` instance has the following methods:
of the IMAP4 QUOTA extension defined in rfc2087.


.. method:: IMAP4.id(fields=None)

Send client identification information to the server
and return the identification information sent back by the server
(the ``ID`` command, defined in :rfc:`2971`).
*fields* is a mapping of field names to values
(for example, ``{'name': 'myclient', 'version': '1.0'}``);
a value can be ``None``.
The server must support the ``ID`` capability.

.. versionadded:: next


.. method:: IMAP4.idle(duration=None)

Return an :class:`!Idler`: an iterable context manager implementing the
Expand Down
4 changes: 4 additions & 0 deletions Doc/whatsnew/3.16.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,10 @@ io
imaplib
-------

* Add the :meth:`~imaplib.IMAP4.id` method,
a wrapper for the ``ID`` command (:rfc:`2971`).
(Contributed by Serhiy Storchaka in :gh:`98092`.)

* Add the :meth:`~imaplib.IMAP4.move` method,
a wrapper for the ``MOVE`` command (:rfc:`6851`).
(Contributed by Serhiy Storchaka in :gh:`77508`.)
Expand Down
23 changes: 23 additions & 0 deletions Lib/imaplib.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
'GETANNOTATION':('AUTH', 'SELECTED'),
'GETQUOTA': ('AUTH', 'SELECTED'),
'GETQUOTAROOT': ('AUTH', 'SELECTED'),
'ID': ('NONAUTH', 'AUTH', 'SELECTED', 'LOGOUT'),
'IDLE': ('AUTH', 'SELECTED'),
'MYRIGHTS': ('AUTH', 'SELECTED'),
'LIST': ('AUTH', 'SELECTED'),
Expand Down Expand Up @@ -697,6 +698,28 @@ def getquotaroot(self, mailbox):
return typ, [quotaroot, quota]


def id(self, fields=None):
"""Send client identification information to the server.

(typ, [data]) = <instance>.id(fields)

'fields' is a mapping of field names to values; a value can be
None. 'data' is the identification information sent back by
the server, in the same parenthesized list form.
"""
name = 'ID'
if fields:
items = []
for field, value in fields.items():
items.append(self._quote(field))
items.append(b'NIL' if value is None else self._quote(value))
arg = b'(' + b' '.join(items) + b')'
else:
arg = 'NIL'
typ, dat = self._simple_command(name, arg)
return self._untagged_response(typ, dat, name)


def idle(self, duration=None):
"""Return an iterable IDLE context manager producing untagged responses.
If the argument is not None, limit iteration to 'duration' seconds.
Expand Down
18 changes: 18 additions & 0 deletions Lib/test/test_imaplib.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1701,6 +1701,24 @@ def test_getquotaroot(self):
self.assertEqual(typ, 'OK')
self.assertEqual(server.args, ['"New folder"'])

def test_id(self):
client, server = self._setup(make_simple_handler('ID',
['* ID ("name" "Cyrus" "version" "1.5")']))
typ, data = client.id({'name': 'imaplib', 'version': '3.16'})
self.assertEqual(typ, 'OK')
self.assertEqual(data, [b'("name" "Cyrus" "version" "1.5")'])
self.assertEqual(server.args, ['("name" "imaplib" "version" "3.16")'])

typ, data = client.id()
self.assertEqual(typ, 'OK')
self.assertEqual(server.args, ['NIL'])

# Fields and values are quoted strings; a None value is sent
# as NIL.
typ, data = client.id({'name': 'my "client"', 'os': None})
self.assertEqual(typ, 'OK')
self.assertEqual(server.args, [r'("name" "my \"client\"" "os" NIL)'])

def test_setquota(self):
client, server = self._setup(make_simple_handler('SETQUOTA',
['* QUOTA "" (STORAGE 512)']))
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add :meth:`imaplib.IMAP4.id`, a wrapper for the IMAP ``ID`` command
(:rfc:`2971`).
Loading

Back | FazBrowse Home | New Git URL