473,385 Members | 1,353 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

imaplib: support for more cyrus extension : expire

setacl and getacl look to be already "Cyrus" specific (according the
why not to extend imaplib a little bit more ?

Here are some code I wrote and tested to support cyrus "expire" that
manage how long a message
can stay into a mailbox.
This is usefull for NEWS server !

The code is preceded by lot of sample.
I wrote the 2 generic functions getannotation and setannotation that
coul be used with any IMAP server.
And use them to access the Cyrus extensions !
I tried to use http://www.potaroo.net/ietf/all-ids/draft-daboo-imap-
but used a lot TCPDUMP to compare with cyradm :-)

Any chances to see this small part of me into the official python
release ?

"""IMAP4 Client

Extend default python imaplib to include ANNOTATION as described in

This extention is used by cyrus imap, for exemple to manage
removale of expired mail based on '/vendor/cmu/cyrus-imapd/expir'

Some usage
>>i.getannotation('user/al***********@asxnet.loc', '"*"', '"value.shared"')
i.getannotation('user/al***********@asxnet.loc', '/vendor/cmu/cyrus-imapd/expire', '"value.shared"')
('OK', ['"user/al***********@asxnet.loc" "/vendor/cmu/cyrus-imapd/
expire" ("value.shared" "44")'])
>>i.getannotation('user/al***********@asxnet.loc', '/vendor/cmu/cyrus-imapd/expire', '("value.shared")')
('OK', ['"user/al***********@asxnet.loc" "/vendor/cmu/cyrus-imapd/
expire" ("value.shared" "44")'])
>>i.getannotation('user/al***********@asxnet.loc', '/vendor/cmu/cyrus-imapd/expire', '("*")')
('OK', ['"user/al***********@asxnet.loc" "/vendor/cmu/cyrus-imapd/
expire" ("value.shared" "44" "content-type.shared" "text/plain"
"size.shared" "2" "modifiedsince.shared" "1156264470")'])
>>i.getannotation('user/al***********@asxnet.loc', '/vendor/cmu/cyrus-imapd/expire', '("value.shared" "content-type.shared")')
('OK', ['"user/al***********@asxnet.loc" "/vendor/cmu/cyrus-imapd/
expire" ("value.shared" "44" "content-type.shared" "text/plain")'])
>>i.setannotation('user/al***********@asxnet.loc', '/vendor/cmu/cyrus-imapd/expire', '("value.shared" "44")')
('OK', [None])
>>i.setannotation('user/al***********@asxnet.loc', '/vendor/cmu/cyrus-imapd/expire', '("value.shared" NIL)')
('OK', [None])
>>i.getannotation('user/al***********@asxnet.loc', '/vendor/cmu/cyrus-imapd/expire', '("value.shared")')
('OK', [None])

some more
i.login('manager', 'password')
('OK', ['User logged in'])
('OK', 0)
>>i.setcyrusexpire("user/al***********@asxnet.loc", 88)
('OK', [None])
('OK', 88)
>>i.setcyrusexpire("user/al***********@asxnet.loc", None)
('OK', [None])
('OK', 0)
import imaplib


class CYRUSIMAP4(imaplib.IMAP4):

def getannotation(self, root, entry, attrib):
"""Get annotation

(typ, [data]) = <instance>.getannotation(self, root, entry,
typ, dat = self._simple_command('GETANNOTATION', root, entry,
return self._untagged_response(typ, dat, 'ANNOTATION')

def setannotation(self, root, entry, value):
"""Set annotation value.

(typ, [data]) = <instance>.setannotation(root, limits)
typ, dat = self._simple_command('SETANNOTATION', root, entry,
return self._untagged_response(typ, dat, 'ANNOTATION')

def getcyrusexpire(self, root):
"""Get cyrus 'expire' annotation value.

(typ, [data]) = <instance>.getcyrusexpire(root)

typ, dat=self.getannotation(root, '/vendor/cmu/cyrus-imapd/
expire', '("value.shared")')
if typ!='OK':
return typ, dat

if dat[0]==None:
return typ, 0

# ['"user/al***********@asxnet.loc" "/vendor/cmu/cyrus-imapd/
expire" ("value.shared" "44")'])
return typ, v

def setcyrusexpire(self, root, value):
"""Get cyrus 'expire' annotation value.

(typ, [data]) = <instance>.setcyrusexpire(root, value)
if value==None or value==0:
v='"%d"' % (value,)

return self.setannotation(root, '/vendor/cmu/cyrus-imapd/
expire', '("value.shared" %s)'%(v,))

Feb 1 '07 #1
0 1515

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Bill Sneddon | last post by:
Anyone have an example they are willing to share that shows how to use the store command in imaplib? store( message_set, command, flag_list) Alters flag dispositions for messages in mailbox. ...
by: Mr. Magoo | last post by:
I'm working with imaplib. I'm trying to flag (or move or copy - anything that takes a message_set as an argument) a bunch of messages with one command and am having trouble. === def...
by: Colin Brown | last post by:
The Python 2.3 documentation in imaplib says: Internaldate2tuple( datestr) Converts an IMAP4 INTERNALDATE string to Coordinated Universal Time. Returns a time module tuple. Time2Internaldate(...
by: Max M | last post by:
I am using the fetch command from the imaplib to fetch messages. I get a result, but I am a bit uncertain as to how I should interpret it. The result is described at...
by: Raghul | last post by:
Is it posssible to read only the new messages or unread messages using imaplib in python? If it is possible pls specify the module or give a sample code. Thanks in advance
by: Wolfgang Kohnen | last post by:
Hello out there! I am new to python and so far I like it a lot. Now I want to create some IMAP mailboxes on my cyrus imapd, with quotas and each user should be subscribed to her/his own spam...
by: Antoon Pardon | last post by:
This little program gives IMO a strange result. import imaplib user = "cpapen" cyr = imaplib.IMAP4("imap.vub.ac.be") cyr.login("cyrus", "cOn-A1r") rc, lst = cyr.list('""', "user/%s/*" %...
by: aspineux | last post by:
imaplib use exception to report errors, but some problems must be detected by checking the return value ! For example, when trying to append into a mailbox with wrong ACL, imaplib return 'NO',...
by: gregpinero | last post by:
I'm trying to get a list of messages from GMAIL using it's new IMAP access. So far I've tried running this command but it just hangs. Any ideas? I figured that's the first line to run from...
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.