procmail
[Top] [All Lists]

Re: removing mailboxes

2001-03-28 21:46:01
Glen asked,

| Procmail sorts through all of the messages and puts them in their
| respective places.  Fine and dandy.  But what if I want procmail to
| remove the mailboxes that have nothing in them after this sort?  Can
| this be done?

Why would those extra mailboxes be created in the first place?  If you start
with none and let procmail create those that it needs, you won't have any
extras.

If you absolutely must create them in advance and then find that some went
unused, how to remove them depends on whether they're files or directories.

If your "mailboxen" (far too vague a word for this question, unfortunately)
are plain files in a given directory, you can use try this shell script
(without the indentation, or at least without indentation on the #! line):

 #!/bin/sh
 # usage scriptname directory
 cd "${1+$HOME/Mail}" || exit

 set -- `find * \( -type d -prune \) -o \
  \( -type f ! -type l ! -name '*.lock' -size 0 -print \)`

 for folder
 do
   lockfile -r0 "$folder.lock" || continue
   if [ ! -s "$folder" ]
   then rm -f "$folder" "$folder.lock" ; echo "$folder" removed
   else rm -f "$folder.lock"
   fi
 done

If your "mailboxen" are directories, well, 

 rmdir $MAILDIR/*/ 2>/dev/null

will remove any empty directories without harming the non-empty ones.

But still, the situation should not arise.  Start with no mailboxes and let
procmail create those that it is going to save mail into; then you won't have
any empty leftovers to remove.

_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail

<Prev in Thread] Current Thread [Next in Thread>