Deleting old maildir messages, is what I'm doing OK?

Chris Green cl at isbd.net
Mon Feb 15 18:00:47 UTC 2021


On Mon, Feb 15, 2021 at 05:39:26PM +0000, Sam Kuper wrote:
> On Mon, Feb 15, 2021 at 04:21:11PM +0000, Chris Green wrote:
> > This isn't specifically mutt but it's definitely to do with managing
> > mail and there's lots of knowledgeable people here.
> > 
> > I currently have the following two lines in my crontab to delete old
> > mails in my junk catching directories, is it OK/safe to do it like
> > this? 
> > 
> >     20 02 * * * find /home/chris/mail/Ju/*/cur -type f -mtime +7 -exec rm {} \;
> >     30 02 * * * find /home/chris/mail/Ju/*/new -type f -mtime +7 -exec rm {} \;
> 
> If you have software expecting to be able to read or write to the files
> affected by the above commands, then if that software is not able to
> handle the sudden disappearance of those files, it may throw errors or
> otherwise misbehave.  Software designed to work with Maildirs should
> not have problems, though.
> 
Almost certainly only me using mutt to read them, and that's pretty
unlikely since they're in my junk directory. I might occasionally look
in there to check something but it's very rare, if ever.


> Also, unless I am mistaken, `find ... -exec rm () \;` is not atomic, so
> a race condition exists: `find` could find a matching file, but then
> some other piece of software could delete or rename it before `rm` does.
> 
> (If I am mistaken, someone please correct me!)
> 
Yes, true, but all that will happen is that I'll get an error sent to
me so it's not really a problem.


> Finally, I suppose that to be technically correct, you perhaps ought to
> first move the files from "new" to "cur", and then delete them from
> "cur".  A true mail guru may be able to shed light on this.
> 
I suppose deleting a file sort of counts as reading it.


> IMO, the likelihood is low that any of these issues will bite you.
> 
Yes, thank you, I *thought* this was so but just wanted to make sure I
wasn't doing something very obviously wrong/risky.


It's odd that none of the "maildir works like this" descriptions I
could find had anything about deleting mails.

-- 
Chris Green (chris at halon.org.uk)


More information about the Mutt-users mailing list