# HG changeset patch # User "Lorenzo M. Catucci" # Date 1228211660 -3600 # Branch trunk # Node ID ee1a524888f12a9174e750716bcdf669bc0d334d # Parent 79b67d641688d87b8393027034d0456560a3dd7e Add CAPA command. * * * Blah... missing dot before _longcmd * * * Another Blah!!! experience... capnm is a variable!!!! diff --git a/Lib/poplib.py b/Lib/poplib.py --- a/Lib/poplib.py +++ b/Lib/poplib.py @@ -307,6 +307,34 @@ if which is not None: 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.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, val: + raise error_proto('-ERR CAPA not supported by server') + return caps try: import ssl