diff options
-rwxr-xr-x | localmb2md | 77 |
1 files changed, 58 insertions, 19 deletions
@@ -1,34 +1,73 @@ #!/bin/sh +# +# /usr/local/sbin/adduser.local +# Copyright 2005-2006 Jonas Smedegaard <dr@jones.dk> +# +# $Id: localmb2md,v 1.4 2006-01-18 11:25:34 jonas Exp $ +# +# Convert user account from mailboxes below /var/mail/ and ~/mail/ to +# maildirs below ~/Maildir/ . +# +# If from a different account, execute it like this: +# +# su -s /bin/sh -c localmb2md - <user> +# +# FIXME: Make sure no MUAs or pop/imap daemons are running +# TODO: Add --help (and perhaps --force) options +# set -e -if [ ! -f /usr/bin/mb2md ]; then - echo 'ERROR: mb2md not installed!' - exit 1 -fi +for prg in mb2md procmail mail-lock mail-touchlock mail-unlock; do + if [ ! -f "/usr/bin/$prg" ]; then + echo "ERROR: $prg not installed!" + exit 1 + fi +done -if [ -f ~/.procmailrc ]; then - echo 'ERROR: ~/.procmailrc exists - must be handled manually...!' +# 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 fi -echo 'DEFAULT=$HOME/Maildir/' > ~/.procmailrc -# Convert secondary mailboxes first -# (reduces risk of clashing with new incoming mail) -mv ~/mail ~/mail.abandoned -mb2md -s mail.abandoned +# Avoid incoming mail while messing with INBOX +mail-lock +mail-touchlock & +# Save the PID of the mail-touchlock process +BADGER="$!" -#FIXME: check spool file lock before reading the spool file -if [ -f "/var/mail/$USER" ]; then +# Convert INBOX and purge 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 + +# Allow incoming mail again +kill "${BADGER}" +mail-unlock -# Grab dovecot subscriptions -if [ -f ~/mail/.subscriptions ]; then - mv ~/mail/.subscriptions ~/Maildir/.subscriptions -# ...or UW-imap ones -elif [ -f ~/.mailboxlist ]; then - mv ~/.mailboxlist ~/Maildir/.subscriptions +# Convert secondary mailboxes +if [ -d ~/mail ]; then + mv ~/mail ~/mail.abandoned + mb2md -s mail.abandoned + # Grab dovecot subscriptions + if [ -f ~/mail/.subscriptions ]; then + mv ~/mail/.subscriptions ~/Maildir/.subscriptions + # ...or UW-imap ones + elif [ -f ~/.mailboxlist ]; then + mv ~/.mailboxlist ~/Maildir/.subscriptions + fi fi |