summaryrefslogtreecommitdiffstats
path: root/Lib/poplib.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2012-11-23 19:07:39 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2012-11-23 19:07:39 (GMT)
commit25cee19beb3117f834100cf29cff625c98d0da29 (patch)
tree327c7f85c59825754afd328915afd57072439f5d /Lib/poplib.py
parentd89824b0e2fa9a44b56394a5185de737a6527ea7 (diff)
downloadcpython-25cee19beb3117f834100cf29cff625c98d0da29.zip
cpython-25cee19beb3117f834100cf29cff625c98d0da29.tar.gz
cpython-25cee19beb3117f834100cf29cff625c98d0da29.tar.bz2
Issue #4473: Add a POP3.capa() method to query the capabilities advertised by the POP3 server.
Patch by Lorenzo Catucci.
Diffstat (limited to 'Lib/poplib.py')
-rw-r--r--Lib/poplib.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/Lib/poplib.py b/Lib/poplib.py
index 094aaa1..ccb28e5 100644
--- a/Lib/poplib.py
+++ b/Lib/poplib.py
@@ -55,6 +55,7 @@ class POP3:
APOP name digest apop(name, digest)
TOP msg n top(msg, n)
UIDL [msg] uidl(msg = None)
+ CAPA capa()
Raises one exception: 'error_proto'.
@@ -322,6 +323,35 @@ class POP3:
return self._shortcmd('UIDL %s' % which)
return self._longcmd('UIDL')
+
+ def capa(self):
+ """Return server capabilities (RFC 2449) as a dictionary
+ >>> c=poplib.POP3('localhost')
+ >>> c.capa()
+ {'IMPLEMENTATION': ['Cyrus', 'POP3', 'server', 'v2.2.12'],
+ 'TOP': [], 'LOGIN-DELAY': ['0'], 'AUTH-RESP-CODE': [],
+ 'EXPIRE': ['NEVER'], 'USER': [], 'STLS': [], 'PIPELINING': [],
+ 'UIDL': [], 'RESP-CODES': []}
+ >>>
+
+ Really, according to RFC 2449, the cyrus folks should avoid
+ having the implementation splitted into multiple arguments...
+ """
+ def _parsecap(line):
+ lst = line.decode('ascii').split()
+ return lst[0], lst[1:]
+
+ caps = {}
+ try:
+ resp = self._longcmd('CAPA')
+ rawcaps = resp[1]
+ for capline in rawcaps:
+ capnm, capargs = _parsecap(capline)
+ caps[capnm] = capargs
+ except error_proto as _err:
+ raise error_proto('-ERR CAPA not supported by server')
+ return caps
+
try:
import ssl
except ImportError: