473,385 Members | 1,492 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
doc),
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-
annotatemore-00.txt
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
http://www.potaroo.net/ietf/all-ids/...atemore-00.txt

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

"""
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=cyrusimap.CYRUSIMAP4('localhost')
i.login('manager', 'password')
('OK', ['User logged in'])
>>i.getcyrusexpire("user/al***********@asxnet.loc")
('OK', 0)
>>i.setcyrusexpire("user/al***********@asxnet.loc", 88)
('OK', [None])
>>i.getcyrusexpire("user/al***********@asxnet.loc")
('OK', 88)
>>i.setcyrusexpire("user/al***********@asxnet.loc", None)
('OK', [None])
>>i.getcyrusexpire("user/al***********@asxnet.loc")
('OK', 0)
"""
import imaplib

imaplib.Commands.update(
{
'GETANNOTATION': ('AUTH', 'SELECTED'),
'SETANNOTATION': ('AUTH', 'SELECTED'),
})

class CYRUSIMAP4(imaplib.IMAP4):

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

(typ, [data]) = <instance>.getannotation(self, root, entry,
attrib)
"""
typ, dat = self._simple_command('GETANNOTATION', root, entry,
attrib)
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,
value)
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")'])
v=int(dat[0].split(None,2)[2].strip('()').split(None,1)
[1].strip('"'))
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='NIL'
else:
v='"%d"' % (value,)

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

Feb 1 '07 #1
0 1517

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

Similar topics

2
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. ...
0
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...
1
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(...
2
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...
1
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
0
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...
5
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/*" %...
1
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',...
4
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
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...
0
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...
0
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
0
BarryA
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.