From 450f796b3c1e7d8b3f7db0c2b24419a67cb9c20f Mon Sep 17 00:00:00 2001 From: Jonas Smedegaard Date: Tue, 25 Apr 2006 19:09:38 +0000 Subject: Purge INBOX after creating procmailrc. Support configuration file. Change .subscriptions -> subscriptions (for newer Dovecot). Fix overwriting custom procmailrc containing Maildir rule with simple rule. --- localmb2md | 65 ++++++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 44 insertions(+), 21 deletions(-) (limited to 'localmb2md') diff --git a/localmb2md b/localmb2md index b5864c4..0979ef5 100755 --- a/localmb2md +++ b/localmb2md @@ -3,7 +3,7 @@ # /usr/local/sbin/adduser.local # Copyright 2005-2006 Jonas Smedegaard # -# $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 < "/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 -- cgit v1.2.3