@@ -55,6 +55,7 @@ class POP3:
5555 APOP name digest apop(name, digest)
5656 TOP msg n top(msg, n)
5757 UIDL [msg] uidl(msg = None)
58+ CAPA capa()
5859
5960 Raises one exception: 'error_proto'.
6061
@@ -322,6 +323,35 @@ def uidl(self, which=None):
322323 return self ._shortcmd ('UIDL %s' % which )
323324 return self ._longcmd ('UIDL' )
324325
326+
327+ def capa (self ):
328+ """Return server capabilities (RFC 2449) as a dictionary
329+ >>> c=poplib.POP3('localhost')
330+ >>> c.capa()
331+ {'IMPLEMENTATION': ['Cyrus', 'POP3', 'server', 'v2.2.12'],
332+ 'TOP': [], 'LOGIN-DELAY': ['0'], 'AUTH-RESP-CODE': [],
333+ 'EXPIRE': ['NEVER'], 'USER': [], 'STLS': [], 'PIPELINING': [],
334+ 'UIDL': [], 'RESP-CODES': []}
335+ >>>
336+
337+ Really, according to RFC 2449, the cyrus folks should avoid
338+ having the implementation splitted into multiple arguments...
339+ """
340+ def _parsecap (line ):
341+ lst = line .decode ('ascii' ).split ()
342+ return lst [0 ], lst [1 :]
343+
344+ caps = {}
345+ try :
346+ resp = self ._longcmd ('CAPA' )
347+ rawcaps = resp [1 ]
348+ for capline in rawcaps :
349+ capnm , capargs = _parsecap (capline )
350+ caps [capnm ] = capargs
351+ except error_proto as _err :
352+ raise error_proto ('-ERR CAPA not supported by server' )
353+ return caps
354+
325355try :
326356 import ssl
327357except ImportError :
0 commit comments