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

gh-77508: Add imaplib.IMAP4.move method by serhiy-storchaka · Pull Request #153121 · python/cpython · GitHub

/ cpython Public
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
9 changes: 9 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 @@ -450,6 +450,15 @@ An :class:`IMAP4` instance has the following methods:
Returned data are tuples of message part envelope and data.


.. method:: IMAP4.move(message_set, new_mailbox)

Move *message_set* messages onto end of *new_mailbox*.

The server must support the ``MOVE`` capability (:rfc:`6851`).

.. versionadded:: next


.. method:: IMAP4.myrights(mailbox)

Show my ACLs for a mailbox (i.e. the rights that I have on mailbox).
Expand Down
8 changes: 8 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 @@ -228,6 +228,14 @@ io
(Contributed by Marcel Martin in :gh:`90533`.)


imaplib
-------

* Add the :meth:`~imaplib.IMAP4.move` method,
a wrapper for the ``MOVE`` command (:rfc:`6851`).
(Contributed by Serhiy Storchaka in :gh:`77508`.)


logging
-------

Expand Down
10 changes: 9 additions & 1 deletion 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 @@ -787,6 +787,14 @@ def lsub(self, directory='', pattern='*'):
self._list_mailbox(pattern))
return self._untagged_response(typ, dat, name)

def move(self, message_set, new_mailbox):
"""Move 'message_set' messages onto end of 'new_mailbox'.

(typ, [data]) = <instance>.move(message_set, new_mailbox)
"""
return self._simple_command('MOVE', self._sequence_set(message_set),
self._astring(new_mailbox))

def myrights(self, mailbox):
"""Show my ACLs for a mailbox (i.e. the rights that I have on mailbox).

Expand Down Expand Up @@ -1029,7 +1037,7 @@ def uid(self, command, *args):
(command, self.state,
', '.join(Commands[command])))
name = 'UID'
if command == 'COPY':
if command in ('COPY', 'MOVE'):
message_set, new_mailbox = args
args = (self._sequence_set(message_set),
self._astring(new_mailbox))
Expand Down
29 changes: 29 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 @@ -1173,6 +1173,35 @@ def test_uid_copy(self):
self.assertEqual(data, [None])
self.assertEqual(server.args, ['COPY', '4827313:4828442', '"New folder"'])

def test_move(self):
client, server = self._setup(make_simple_handler('MOVE'))
client.login('user', 'pass')
client.select()
typ, data = client.move('2:4', 'MEETING')
self.assertEqual(typ, 'OK')
self.assertEqual(data, [b'MOVE completed'])
self.assertEqual(server.args, ['2:4', 'MEETING'])

typ, data = client.move('2:4', 'New folder')
self.assertEqual(typ, 'OK')
self.assertEqual(data, [b'MOVE completed'])
self.assertEqual(server.args, ['2:4', '"New folder"'])

def test_uid_move(self):
client, server = self._setup(make_simple_handler('UID',
completed='UID MOVE completed'))
client.login('user', 'pass')
client.select()
typ, data = client.uid('move', '4827313:4828442', 'MEETING')
self.assertEqual(typ, 'OK')
self.assertEqual(data, [None])
self.assertEqual(server.args, ['MOVE', '4827313:4828442', 'MEETING'])

typ, data = client.uid('move', '4827313:4828442', 'New folder')
self.assertEqual(typ, 'OK')
self.assertEqual(data, [None])
self.assertEqual(server.args, ['MOVE', '4827313:4828442', '"New folder"'])

def test_store(self):
client, server = self._setup(make_simple_handler('STORE', [
r'* 2 FETCH (FLAGS (\Deleted \Seen))',
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.move`, a wrapper for the IMAP ``MOVE`` command
(:rfc:`6851`), analogous to :meth:`~imaplib.IMAP4.copy`.
Loading

Back | FazBrowse Home | New Git URL