diff options
-rwxr-xr-x | localmb2md | 65 |
1 files changed, 44 insertions, 21 deletions
@@ -3,7 +3,7 @@ # /usr/local/sbin/adduser.local # Copyright 2005-2006 Jonas Smedegaard <dr@jones.dk> # -# $Id: localmb2md,v 1.7 2006-03-24 14:03:00 jonas Exp $ +# $Id: localmb2md,v 1.8 2006-04-25 19:09:38 jonas Exp $ # # Convert user account from mailboxes below /var/mail/ and ~/mail/ to # maildirs below ~/Maildir/ . @@ -18,22 +18,42 @@ set -e -for prg in mb2md procmail mail-lock mail-touchlock mail-unlock; do - if [ ! -f "/usr/bin/$prg" ]; then +helpers="/usr/bin/mb2md /usr/bin/mail-lock /usr/bin/mail-touchlock /usr/bin/mail-unlock" + +# Unset these if the MDA delivers to Maildir without being told explicitly +mkprocmailrc="yes" +helpers="$helpers /usr/bin/procmail" + +# Change this to ".subscriptions" if using pre-1.xx Dovecot +subscriptions="subscriptions" + +if [ -e /etc/local/mb2md.conf ]; then + . /etc/local/mb2md.conf +fi + +# Make sure all required tools are available +for prg in $helpers; do + if [ ! -x "$prg" ]; then echo "ERROR: $prg not installed!" exit 1 fi done -# Make sure Maildir is used if procmailrc exists already -if [ -f ~/.procmailrc ] && egrep -v -q '^DEFAULT=\$HOME/Maildir/$' ~/.procmailrc; then - echo 'ERROR: non-Maildir-aware ~/.procmailrc exists already.' - echo ' Please edit manually to include the following line:' - echo - echo ' DEFAULT=$HOME/Maildir/' - echo - echo ' Make sure other rules use Maildirs too, if needed.' - exit 1 +# Bail out if custom procmailrc is in the way +if [ -n "$mkprocmailrc" ] && [ -f ~/.procmailrc ]; then + if egrep -v -q '^DEFAULT=\$HOME/Maildir/$' ~/.procmailrc; then + cat <<EOF +ERROR: non-Maildir-aware ~/.procmailrc exists already. + Please edit manually to include the following line: + + DEFAULT=$HOME/Maildir/ + + Make sure other rules use Maildirs too, if needed. +EOF + exit 1 + else + mkprocmailrc="" + fi fi # Avoid incoming mail while messing with INBOX @@ -44,17 +64,20 @@ if [ -e "/var/mail/$USER" ]; then # Save the PID of the mail-touchlock process BADGER="$!" - # Convert INBOX and purge if not empty + # Create Maildir for INBOX if not there already + mkdir -p ~/Maildir/cur ~/Maildir/new ~/Maildir/tmp + chmod -R u=rw,go=,u+X ~/Maildir + + # Convert INBOX if not empty if [ -s "/var/mail/$USER" ]; then mb2md -m - echo -n '' > "/var/mail/$USER" - else - # Create Maildir for INBOX if not there already - mkdir -p ~/Maildir/cur ~/Maildir/new ~/Maildir/tmp - chmod -R u=rw,go=,u+X ~/Maildir fi # Reroute future incoming mail to Maildir - echo 'DEFAULT=$HOME/Maildir/' > ~/.procmailrc + if [ -n "$mkprocmailrc" ]; then + echo 'DEFAULT=$HOME/Maildir/' > ~/.procmailrc + fi + # Purge old INBOX + echo -n '' > "/var/mail/$USER" # Allow incoming mail again kill "${BADGER}" @@ -68,9 +91,9 @@ if [ -d ~/mail ]; then mb2md -R -s mail.abandoned # Grab dovecot subscriptions if [ -f ~/mail/.subscriptions ]; then - mv ~/mail/.subscriptions ~/Maildir/.subscriptions + mv ~/mail/.subscriptions ~/Maildir/"$subscriptions" # ...or UW-imap ones elif [ -f ~/.mailboxlist ]; then - mv ~/.mailboxlist ~/Maildir/.subscriptions + mv ~/.mailboxlist ~/Maildir/"$subscriptions" fi fi |