summaryrefslogtreecommitdiff
path: root/localmb2md
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2006-04-25 19:09:38 +0000
committerJonas Smedegaard <dr@jones.dk>2006-04-25 19:09:38 +0000
commit450f796b3c1e7d8b3f7db0c2b24419a67cb9c20f (patch)
treefe7e5122d172b60dec2a6870a5282aaa5b370b79 /localmb2md
parent195bd42079bb05cb455bcf221f16f903b440bc46 (diff)
Purge INBOX after creating procmailrc. Support configuration file. Change .subscriptions -> subscriptions (for newer Dovecot). Fix overwriting custom procmailrc containing Maildir rule with simple rule.
Diffstat (limited to 'localmb2md')
-rwxr-xr-xlocalmb2md65
1 files changed, 44 insertions, 21 deletions
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 <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