Batch mailbox creation

Anders Norrbring lists at
Thu Sep 7 09:05:56 EDT 2006

Anthony Tibbs skrev:
> This isn't thoroughly tested or anything, but you could use something 
> like the following to generate a "command list" to be fed to cyradm, no?
> It doesn't check for things like the user already having a Spam 
> mailboox, but... that wouldn't be hard to add.  Is "-c" appropriate to 
> prevent mailbox deletions by the user?
> --- snip ~/mkmailboxes ---
> #!/bin/sh
> pushd /var/spool/imap/domain >/dev/nul
> for domLtr in *; do
>   pushd $domLtr >/dev/nul
>   for domain in *; do
>      pushd $domain >/dev/nul
>      for usrltr in *; do
>         pushd $usrltr/user >/dev/nul
>         for email in *; do
>            echo cm user.$email@$domain.Spam
>            echo sam user.$email@$domain.Spam cyrus a
>            echo sam user.$email@$domain.Spam anyone p
>            echo sam user.$email@$domain.Spam $email@$domain -c
>            echo -n "\n"
>         done
>         popd >/dev/nul
>      done
>      popd >/dev/nul
>   done
>   popd >/dev/nul
> done
> popd >/dev/nul
> --- Snip ---

Thanks Anthony.
Finally someone who could spare the sarcasm and actually push me in the 
right direction, it's much appreciated!

I made some trial and error, and came up with a modified version that 
will create the correct commands. My virtual domains are all converted 
to one local domain name, so I only need to list one dir, therefor I 
came up with this:

pushd /var/spool/imap/user >/dev/nul
     for acct in *; do
         for email in *; do
            echo cm  user.$email.SPAM
            echo sam user.$email.SPAM cyrus all
            echo sam user.$email.SPAM anyone p
            echo sam user.$email.SPAM $email lrswipcd
popd >/dev/nul

The create command doesn't give any rights, so the parameters are a bit 
different than your suggestion.

I'll try to find a way to feed the result into cyradm as well. :)


Anders Norrbring
Norrbring Consulting

More information about the Info-cyrus mailing list