Skip to content

Commit d80ef02

Browse files
author
Piers Lauder
committed
added GET/SETANNOTATION methods
1 parent a0abb24 commit d80ef02

2 files changed

Lines changed: 46 additions & 9 deletions

File tree

Doc/lib/libimaplib.tex

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,11 @@ \subsection{IMAP4 Objects \label{imap4-objects}}
222222
The method is non-standard, but is supported by the \samp{Cyrus} server.
223223
\end{methoddesc}
224224

225+
\begin{methoddesc}{getannotation}{mailbox, entry, attribute}
226+
Retrieve the specified \samp{ANNOTATION}s for \var{mailbox}.
227+
The method is non-standard, but is supported by the \samp{Cyrus} server.
228+
\end{methoddesc}
229+
225230
\begin{methoddesc}{getquota}{root}
226231
Get the \samp{quota} \var{root}'s resource usage and limits.
227232
This method is part of the IMAP4 QUOTA extension defined in rfc2087.
@@ -357,6 +362,11 @@ \subsection{IMAP4 Objects \label{imap4-objects}}
357362
The method is non-standard, but is supported by the \samp{Cyrus} server.
358363
\end{methoddesc}
359364

365+
\begin{methoddesc}{setannotation}{mailbox, entry, attribute\optional{, ...}}
366+
Set \samp{ANNOTATION}s for \var{mailbox}.
367+
The method is non-standard, but is supported by the \samp{Cyrus} server.
368+
\end{methoddesc}
369+
360370
\begin{methoddesc}{setquota}{root, limits}
361371
Set the \samp{quota} \var{root}'s resource \var{limits}.
362372
This method is part of the IMAP4 QUOTA extension defined in rfc2087.

Lib/imaplib.py

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818
# IMAP4_SSL contributed by Tino Lange <Tino.Lange@isg.de> March 2002.
1919
# GET/SETQUOTA contributed by Andreas Zeidler <az@kreativkombinat.de> June 2002.
2020
# PROXYAUTH contributed by Rick Holbert <holbert.13@osu.edu> November 2002.
21+
# GET/SETANNOTATION contributed by Tomas Lindroos <skitta@abo.fi> June 2005.
2122

22-
__version__ = "2.55"
23+
__version__ = "2.56"
2324

2425
import binascii, os, random, re, socket, sys, time
2526

@@ -51,6 +52,7 @@
5152
'EXPUNGE': ('SELECTED',),
5253
'FETCH': ('SELECTED',),
5354
'GETACL': ('AUTH', 'SELECTED'),
55+
'GETANNOTATION':('AUTH', 'SELECTED'),
5456
'GETQUOTA': ('AUTH', 'SELECTED'),
5557
'GETQUOTAROOT': ('AUTH', 'SELECTED'),
5658
'MYRIGHTS': ('AUTH', 'SELECTED'),
@@ -66,6 +68,7 @@
6668
'SEARCH': ('SELECTED',),
6769
'SELECT': ('AUTH', 'SELECTED'),
6870
'SETACL': ('AUTH', 'SELECTED'),
71+
'SETANNOTATION':('AUTH', 'SELECTED'),
6972
'SETQUOTA': ('AUTH', 'SELECTED'),
7073
'SORT': ('SELECTED',),
7174
'STATUS': ('AUTH', 'SELECTED'),
@@ -133,10 +136,10 @@ class IMAP4:
133136
the command re-tried.
134137
"readonly" exceptions imply the command should be re-tried.
135138
136-
Note: to use this module, you must read the RFCs pertaining
137-
to the IMAP4 protocol, as the semantics of the arguments to
138-
each IMAP4 command are left to the invoker, not to mention
139-
the results.
139+
Note: to use this module, you must read the RFCs pertaining to the
140+
IMAP4 protocol, as the semantics of the arguments to each IMAP4
141+
command are left to the invoker, not to mention the results. Also,
142+
most IMAP servers implement a sub-set of the commands available here.
140143
"""
141144

142145
class error(Exception): pass # Logical errors - debug required
@@ -186,11 +189,10 @@ def __init__(self, host = '', port = IMAP4_PORT):
186189
else:
187190
raise self.error(self.welcome)
188191

189-
cap = 'CAPABILITY'
190-
self._simple_command(cap)
191-
if not cap in self.untagged_responses:
192+
typ, dat = self.capability()
193+
if dat == [None]:
192194
raise self.error('no CAPABILITY response from server')
193-
self.capabilities = tuple(self.untagged_responses[cap][-1].upper().split())
195+
self.capabilities = tuple(dat[-1].upper().split())
194196

195197
if __debug__:
196198
if self.debug >= 3:
@@ -345,6 +347,15 @@ def authenticate(self, mechanism, authobject):
345347
return typ, dat
346348

347349

350+
def capability(self):
351+
"""(typ, [data]) = <instance>.capability()
352+
Fetch capabilities list from server."""
353+
354+
name = 'CAPABILITY'
355+
typ, dat = self._simple_command(name)
356+
return self._untagged_response(typ, dat, name)
357+
358+
348359
def check(self):
349360
"""Checkpoint mailbox on server.
350361
@@ -436,6 +447,14 @@ def getacl(self, mailbox):
436447
return self._untagged_response(typ, dat, 'ACL')
437448

438449

450+
def getannotation(self, mailbox, entry, attribute):
451+
"""(typ, [data]) = <instance>.getannotation(mailbox, entry, attribute)
452+
Retrieve ANNOTATIONs."""
453+
454+
typ, dat = self._simple_command('GETANNOTATION', mailbox, entry, attribute)
455+
return self._untagged_response(typ, dat, 'ANNOTATION')
456+
457+
439458
def getquota(self, root):
440459
"""Get the quota root's resource usage and limits.
441460
@@ -643,6 +662,14 @@ def setacl(self, mailbox, who, what):
643662
return self._simple_command('SETACL', mailbox, who, what)
644663

645664

665+
def setannotation(self, *args):
666+
"""(typ, [data]) = <instance>.setannotation(mailbox[, entry, attribute]+)
667+
Set ANNOTATIONs."""
668+
669+
typ, dat = self._simple_command('SETANNOTATION', *args)
670+
return self._untagged_response(typ, dat, 'ANNOTATION')
671+
672+
646673
def setquota(self, root, limits):
647674
"""Set the quota root's resource limits.
648675

0 commit comments

Comments
 (0)