#!/bin/sh # # /usr/local/sbin/adduser.local # Copyright 2005-2006 Jonas Smedegaard # # $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 - # # 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 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 # 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