#!/usr/bin/bash export TTY if [ $# -lt 1 ]; then echo "$0: usage: $0 " exit fi if [ -z "$migratedir" ]; then echo "$0: must be run by the wrapper script or \$migratedir must be defined." exit fi if [ -z "$sourcedir" -o -z "$destdir" ]; then if [ -f ${migratedir}/parameters ]; then source ${migratedir}/parameters else echo "$0: no parameters set and ${migratedir}/parameters doesn't exist." exit fi fi i=$1 cd $sourcedir suserd=${sourcedir}/${i} duserd=${destdir}/${i} smaild=${suserd}/Mail dmaild=${duserd}/Maildir echo "Finding and migrating: $suserd -> $dmaild" if [ -f ${smaild}/.subscriptions -a -f ${suserd}/.mailboxlist ]; then echo "Both .mailboxlist and .subscriptions files found, merging and migrating." cat ${suserd}/.mailboxlist ${smaild}/.subscriptions | sed -e 's?^Mail/??g' | sed -e 's?^mail/??g'| sort | uniq > ${dmaild}/subscriptions elif [ -f ${smaild}/.subscriptions ]; then echo "Using existing subscriptions file." cp ${smaild}/.subscriptions ${dmaild}/subscriptions elif [ -f ${suserd}/.mailboxlist ]; then echo "Migrating existing .mailboxlist file." sed -e 's?^Mail/??g' < ${suserd}/.mailboxlist | sed -e 's?^mail/??g'| sort | uniq > ${dmaild}/subscriptions fi if [ ! -d $smaild ]; then echo "User's Mail is not a directory." ls -ld $smaild fi echo -n "Searching for mbox mailboxes not in the Mail subdirectory... " gfind -H ${suserd} -maxdepth 5 -type f | gegrep -v "${suserd}/(mail|Mail)" | grep -v "/\." > ${duserd}/filelist ${migratedir}/findmailfiles < ${duserd}/filelist > ${duserd}/mailfiles echo "done." echo "Migrating mailboxes found:" while read j do echo "$j" maildir=${dmaild}/.`echo $j | sed -e "s?${suserd}\/??" | sed -e 's/\//./g'` mb2md -s "${j}" -d "${maildir}" 2> /dev/null > /dev/null < /dev/null done < ${duserd}/mailfiles rm ${duserd}/mailfiles ${duserd}/filelist echo echo -n "Migrating mailboxes found in Mail subdirectory... " mb2md -R -s ${smaild} -d ${dmaild} 2> /dev/null > /dev/null < /dev/null echo "done."