blob: 0e9fe5e97259f5f4157225d8c05dc3914923a3ab (
plain)
- #!/bin/sh
- #
- # /usr/local/sbin/adduser.local
- # Copyright 2005-2006 Jonas Smedegaard <dr@jones.dk>
- #
- # $Id: localmb2md,v 1.6 2006-03-24 13:54:46 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
- 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
- # 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
- # Avoid incoming mail while messing with INBOX
- if [ -e "/var/mail/$USER" ]; then
- mail-lock
- mail-touchlock &
- # Save the PID of the mail-touchlock process
- BADGER="$!"
- # 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
- fi
- # Convert secondary mailboxes
- if [ -d ~/mail ]; then
- mv ~/mail ~/mail.abandoned
- mb2md -R -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
|