<<< Date Index >>>     <<< Thread Index >>>

Re: wish: file/directory funtions for maildir etc (was: Re: New IMAP function: rename-mailbox)



Re: Charles Cazabon in <20050222150644.GA12372@xxxxxxxxxxxxxxxxxxxx>
> > rmdir %s/cur %s/tmp %s/new %s
> 
> That still has the problem that it can leave an invalid maildir behind;
> consider the case of a maildir with no new messages in it, for example.

        rmdir %s/cur %s/new %s/tmp %s || mkdir %s/cur %s/new %s/tmp

(The exit code is coincidentally >0 unless creating tmp fails, which
is unlikely.)

> The only truly safe way to do this is to stop any processes which could
> deliver mail to the maildir in question, then do something like:

We could rename the maildir first, but this isn't 100% safe, too.

>   [ ! -f %s/cur/* -a ! -f %s/tmp/* -a ! -f %s/new/* ] && rm -rf %s

-a isn't POSIX, one should use [ ... ] && [ ...] instead. And if the *
expands to > 1 file, this goes havoc. The easiest way to check if a
wildcard pattern expands I found was the following, which is still
ugly:

        set -- *
        if [ "$1" != "*" ] ; then...

Christoph
-- 
cb@xxxxxxxx | http://www.df7cb.de/

Attachment: signature.asc
Description: Digital signature