[Dovecot] deleting maildir files

Kirill Miazine km at krot.org
Tue Jul 17 11:02:25 EEST 2007


* Don Russell [2007-07-16 10:23]:
>> Can we delete maildir files directly from the file system?
[...]
>> And if we cannot delete files with the 'rm' command, whats the
>> best/proper way to delete these older files.
>
> My opinion has always been that the data structure should not be replied 
> upon.... if you want to do things with your mail items, then use the 
> APIs/imap commands to do it. That protects you from any internal stuff you 
> didn't know about, or changed from one server to another, or one version to 
> another.

Maildir is a sort of a standard with some sort of an API, isn't it? The
"standard" (<http://cr.yp.to/proto/maildir.html>) says following:

     An MUA can read and delete messages while new mail is being
     delivered: each message is stored in a separate file with a
     unique name, so it isn't affected by operations on other messages.

> For example, I have the beginnings of a script to handle my "mail retention 
> policies". It connects to Dovecot/imap to get the list of mail for specific 
> folders, then uses the imap delete (or copy) API to delete mail older than 
> n days, or to keep only the most recent n messages. That sort of thing.

With Maildir it's trivial to do this sort of things with a shell script.

> The benefit is my script then doesn't care how Dovecot (or whichever 
> server) stores things.... and if a mailbox changes from mbox to maildir 
> format, or similar change.. no worries... my script just doesn't care... it 
> always uses the APIs to manipulate mail.
>
> Safe, but admittedly not as fast. I favor reliability over speed in these 
> sorts of cases.  :-)

That's a valid point. It's much easier to shoot one's own leg pretty
ugly, when deleting/renaming/whatevert the files in the Maildir
directly. IMAP SEARCH is IMHO a bit easier to understand than find(1).

Best wishes,
Kirill

-- 
#!/usr/bin/perl -w
print(&{sub{eval(qq(q(@_)))}}((join(''=>map{ord=~m(^106)?uc:lc}($[=>
map{chr}(97..122))[map{int}grep{length}split(/(\d\d)/,'10211920011'.
qq(41520080518190907140120211805))]))=~m(\A(\w{4})(\S+)(s\D+)$)),$/)



More information about the dovecot mailing list