[Dovecot] Problems with BEFORE searches.
Ok, I am trying to modify some code given to me by the author of the dspam plugin for dovecot (sorry the name eludes me). I am modifying it to handle UNSEEN differently than SEEN.
Below is the python code. I am not a python programmer, but I get the basic idea.
ok, uids = conn.search(None, 'BEFORE', unreadsentbefore, 'SEEN')
"11-May-2007 06:18:29 -0600" is the value of unreadsentbefore.
However, this doesn't match any emails even though they are all dated as 5/10 and they have all been read for several hours (the time was the current to figure out why it isn't working).
Is there a problem with BEFORE and SEEN together? Is there a BEFORE bug in the system? Some of the messages are -500 and others, I am not sure.
Thanks, Trever Adams
On Fri, 2007-05-11 at 06:22 -0600, Trever L. Adams wrote:
ok, uids = conn.search(None, 'BEFORE', unreadsentbefore, 'SEEN')
"11-May-2007 06:18:29 -0600" is the value of unreadsentbefore.
From IMAP RFC:
search-key = "ALL" / "ANSWERED" / "BCC" SP astring / "BEFORE" SP date / "BODY" SP astring / .. date = date-text / DQUOTE date-text DQUOTE date-text = date-day "-" date-month "-" date-year
So you'll need to use "11-May-2007". It doesn't support time.
Timo Sirainen wrote:
From IMAP RFC:
search-key = "ALL" / "ANSWERED" / "BCC" SP astring / "BEFORE" SP date / "BODY" SP astring / .. date = date-text / DQUOTE date-text DQUOTE date-text = date-day "-" date-month "-" date-year
So you'll need to use "11-May-2007". It doesn't support time.
Tim, thank you. I am afraid I do not understand if the date is only allowed as such why does python's imaplib convert the date as such?!? Anyway, I understand that is a question for some place else. I hope python has something like strtok or similar where I can tokenize the first part out to be used.
Thank you very much.
Trever
On Fri, 2007-05-11 at 08:54 -0600, Trever Adams wrote:
So you'll need to use "11-May-2007". It doesn't support time.
Tim, thank you. I am afraid I do not understand if the date is only allowed as such why does python's imaplib convert the date as such?!?
Interesting. I just noticed another bug too, it pads with spaces: " 1-May-07 ..."
Try this in my script:
# this line is already there sentbefore = imaplib.Time2Internaldate(time.time() - float(sys.argv[1]) * 24 * 60 * 60)
# add these lines sentbefore = sentbefore.split('"')[1].split()[0] sentbefore = '"%s"' % sentbefore
Or maybe just replace it all with:
sentbefore = time.strftime("%d-%b-%Y", time.localtime(time.time() - float(sys.argv[1]) * 24 * 60 * 60))
johannes
On Fri, 2007-05-11 at 17:08 +0200, Johannes Berg wrote:
Interesting. I just noticed another bug too, it pads with spaces: " 1-May-07 ..."
Yes, I caught this too.
Or maybe just replace it all with:
sentbefore = time.strftime("%d-%b-%Y", time.localtime(time.time() - float(sys.argv[1]) * 24 * 60 * 60))
johannes
I like this last version better. I will use it instead of my version of your other version. It is much cleaner.
However, your code still lacks conn.expunge(). My testing shows this is necessary (at least if you are using Maildir, I imagine it is even more necessary with mbox).
I suggest you add it before you close the connection.
Thanks for your help Timo and Johannes.
Trever
If it's there and you can see it, it's REAL If it's there and you can't see it, it's TRANSPARENT If it's not there and you can see it, it's VIRTUAL If it's not there and you can't see it, it's GONE! -- Unknown
On Fri, 2007-05-11 at 16:16 -0600, Trever L. Adams wrote:
I like this last version better. I will use it instead of my version of your other version. It is much cleaner.
Yeah, I thought using the imaplib would be good but apparently not :)
However, your code still lacks conn.expunge(). My testing shows this is necessary (at least if you are using Maildir, I imagine it is even more necessary with mbox).
I think I had a reason not to do it. I forgot about that reason and just do it manually once a while. Heh.
johannes
On Fri, 2007-05-11 at 16:16 -0600, Trever L. Adams wrote:
I suggest you add it before you close the connection.
I've changed my script to take options:
johannes@sipsolutions:~$ cleanspam Usage: cleanspam [--expunge] days --expunge: expunge mail after marking older ones deleted --seen: delete only mail marked as seen (read) days: mark mails older than <days> deleted (can be fractional)
The old URL is still valid, maybe I'll link it from my projects page too.
johannes
participants (4)
-
Johannes Berg
-
Timo Sirainen
-
Trever Adams
-
Trever L. Adams