|
18 | 18 | # IMAP4_SSL contributed by Tino Lange <Tino.Lange@isg.de> March 2002. |
19 | 19 | # GET/SETQUOTA contributed by Andreas Zeidler <az@kreativkombinat.de> June 2002. |
20 | 20 | # PROXYAUTH contributed by Rick Holbert <holbert.13@osu.edu> November 2002. |
| 21 | +# GET/SETANNOTATION contributed by Tomas Lindroos <skitta@abo.fi> June 2005. |
21 | 22 |
|
22 | | -__version__ = "2.55" |
| 23 | +__version__ = "2.56" |
23 | 24 |
|
24 | 25 | import binascii, os, random, re, socket, sys, time |
25 | 26 |
|
|
51 | 52 | 'EXPUNGE': ('SELECTED',), |
52 | 53 | 'FETCH': ('SELECTED',), |
53 | 54 | 'GETACL': ('AUTH', 'SELECTED'), |
| 55 | + 'GETANNOTATION':('AUTH', 'SELECTED'), |
54 | 56 | 'GETQUOTA': ('AUTH', 'SELECTED'), |
55 | 57 | 'GETQUOTAROOT': ('AUTH', 'SELECTED'), |
56 | 58 | 'MYRIGHTS': ('AUTH', 'SELECTED'), |
|
66 | 68 | 'SEARCH': ('SELECTED',), |
67 | 69 | 'SELECT': ('AUTH', 'SELECTED'), |
68 | 70 | 'SETACL': ('AUTH', 'SELECTED'), |
| 71 | + 'SETANNOTATION':('AUTH', 'SELECTED'), |
69 | 72 | 'SETQUOTA': ('AUTH', 'SELECTED'), |
70 | 73 | 'SORT': ('SELECTED',), |
71 | 74 | 'STATUS': ('AUTH', 'SELECTED'), |
@@ -133,10 +136,10 @@ class IMAP4: |
133 | 136 | the command re-tried. |
134 | 137 | "readonly" exceptions imply the command should be re-tried. |
135 | 138 |
|
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. |
140 | 143 | """ |
141 | 144 |
|
142 | 145 | class error(Exception): pass # Logical errors - debug required |
@@ -186,11 +189,10 @@ def __init__(self, host = '', port = IMAP4_PORT): |
186 | 189 | else: |
187 | 190 | raise self.error(self.welcome) |
188 | 191 |
|
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]: |
192 | 194 | 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()) |
194 | 196 |
|
195 | 197 | if __debug__: |
196 | 198 | if self.debug >= 3: |
@@ -345,6 +347,15 @@ def authenticate(self, mechanism, authobject): |
345 | 347 | return typ, dat |
346 | 348 |
|
347 | 349 |
|
| 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 | + |
348 | 359 | def check(self): |
349 | 360 | """Checkpoint mailbox on server. |
350 | 361 |
|
@@ -436,6 +447,14 @@ def getacl(self, mailbox): |
436 | 447 | return self._untagged_response(typ, dat, 'ACL') |
437 | 448 |
|
438 | 449 |
|
| 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 | + |
439 | 458 | def getquota(self, root): |
440 | 459 | """Get the quota root's resource usage and limits. |
441 | 460 |
|
@@ -643,6 +662,14 @@ def setacl(self, mailbox, who, what): |
643 | 662 | return self._simple_command('SETACL', mailbox, who, what) |
644 | 663 |
|
645 | 664 |
|
| 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 | + |
646 | 673 | def setquota(self, root, limits): |
647 | 674 | """Set the quota root's resource limits. |
648 | 675 |
|
|
0 commit comments