mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
Issue #4473: Add a POP3.capa() method to query the capabilities advertised by the POP3 server.
Patch by Lorenzo Catucci.
This commit is contained in:
parent
d89824b0e2
commit
25cee19beb
4 changed files with 57 additions and 0 deletions
|
@ -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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue