Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b8cd3e4

Browse files
committed
#21804: Add RFC 6856 (UTF8) support to poplib.
Patch by Milan Oberkirch.
1 parent 8eb1f07 commit b8cd3e4

5 files changed

Lines changed: 41 additions & 0 deletions

File tree

Doc/library/poplib.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,15 @@ An :class:`POP3` instance has the following methods:
194194
the unique id for that message in the form ``'response mesgnum uid``, otherwise
195195
result is list ``(response, ['mesgnum uid', ...], octets)``.
196196

197+
198+
.. method:: POP3.utf8()
199+
200+
Try to switch to UTF-8 mode. Returns the server response if sucessful,
201+
raises :class:`error_proto` if not. Specified in :RFC:`6856`.
202+
203+
.. versionadded:: 3.5
204+
205+
197206
.. method:: POP3.stls(context=None)
198207

199208
Start a TLS session on the active connection as specified in :rfc:`2595`.

Doc/whatsnew/3.5.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,13 @@ pickle
452452
classes) now are supported with pickle protocols < 4.
453453
(Contributed by Serhiy Storchaka in :issue:`23611`.)
454454

455+
poplib
456+
------
457+
458+
* A new command :meth:`~poplib.POP3.utf8` enables :rfc:`6856`
459+
(internationalized email) support if the POP server supports it. (Contributed
460+
by Milan OberKirch in :issue:`21804`.)
461+
455462
re
456463
--
457464

Lib/poplib.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ class POP3:
7171
UIDL [msg] uidl(msg = None)
7272
CAPA capa()
7373
STLS stls()
74+
UTF8 utf8()
7475
7576
Raises one exception: 'error_proto'.
7677
@@ -348,6 +349,12 @@ def uidl(self, which=None):
348349
return self._longcmd('UIDL')
349350

350351

352+
def utf8(self):
353+
"""Try to enter UTF-8 mode (see RFC 6856). Returns server response.
354+
"""
355+
return self._shortcmd('UTF8')
356+
357+
351358
def capa(self):
352359
"""Return server capabilities (RFC 2449) as a dictionary
353360
>>> c=poplib.POP3('localhost')

Lib/test/test_poplib.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
class DummyPOP3Handler(asynchat.async_chat):
4545

4646
CAPAS = {'UIDL': [], 'IMPLEMENTATION': ['python-testlib-pop-server']}
47+
enable_UTF8 = False
4748

4849
def __init__(self, conn):
4950
asynchat.async_chat.__init__(self, conn)
@@ -142,6 +143,11 @@ def cmd_capa(self, arg):
142143
self.push(' '.join(_ln))
143144
self.push('.')
144145

146+
def cmd_utf8(self, arg):
147+
self.push('+OK I know RFC6856'
148+
if self.enable_UTF8
149+
else '-ERR What is UTF8?!')
150+
145151
if SUPPORTS_SSL:
146152

147153
def cmd_stls(self, arg):
@@ -309,6 +315,16 @@ def test_uidl(self):
309315
self.client.uidl()
310316
self.client.uidl('foo')
311317

318+
def test_utf8_raises_if_unsupported(self):
319+
self.server.handler.enable_UTF8 = False
320+
self.assertRaises(poplib.error_proto, self.client.utf8)
321+
322+
def test_utf8(self):
323+
self.server.handler.enable_UTF8 = True
324+
expected = b'+OK I know RFC6856'
325+
result = self.client.utf8()
326+
self.assertEqual(result, expected)
327+
312328
def test_capa(self):
313329
capa = self.client.capa()
314330
self.assertTrue('IMPLEMENTATION' in capa.keys())

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ Core and Builtins
4747
Library
4848
-------
4949

50+
- Issue #21804: poplib now supports RFC 6856 (UTF8).
51+
5052
- Issue #18682: Optimized pprint functions for builtin scalar types.
5153

5254
- Issue #22027: smtplib now supports RFC 6531 (SMTPUTF8).

0 commit comments

Comments
 (0)