[Dovecot] MBOX to MAILDIR conversion
Stephen Usher
Stephen.Usher at earth.ox.ac.uk
Mon Mar 5 15:11:29 EET 2007
Well, I'm in the process of doing this, along with moving to a new mail server
and consolidating all messages, including inboxes, into a single set of
directories per user.
I'm moving e-mail from a remote server mounted /mnt/inboxes (the remote
server's /var/mail directory) and /mnt/users (the remote server's /home/users
directory) and converting them and -lacing them under /home/users/<username>
with the mailfolders being within a directory "Maildir" below the virtual
home directory.
The scripts I'm attaching are more complex due to historical reasons where we
used the UW IMAP server and some users didn't set a "Mail/" prefix in their
client settings so I'm having to search their whole home directory space for
mail folders!
Steve
--
---------------------------------------------------------------------------
Computer Systems Administrator, E-Mail:-steve at earth.ox.ac.uk
Department of Earth Sciences, Tel:- +44 (0)1865 282110
University of Oxford, Parks Road, Oxford, UK. Fax:- +44 (0)1865 272072
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mb2md
Type: application/x-perl
Size: 53779 bytes
Desc: Slightly modified version of mb2md which gives saner filenames.
Url : http://dovecot.org/pipermail/dovecot/attachments/20070305/bd4a00d5/attachment-0004.bin
-------------- next part --------------
#!/usr/bin/bash
export TTY
if [ $# -lt 1 ]; then
echo "$0: usage: $0 <username>"
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."
-------------- next part --------------
#!/usr/bin/bash
export TTY
if [ $# -lt 1 ]; then
echo "$0: usage: $0 <username>"
exit
fi
if [ -z "$migratedir" ]; then
echo "$0: must be run by the wrapper script or \$migratedir must be defined."
exit
fi
if [ -z "$inboxdir" -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 $destdir
sfile=${inboxdir}/${i}
duserd=${destdir}/${i}/Maildir
echo -n "Migrating inbox: $sfile... "
mb2md -s $sfile -d $duserd 2> /dev/null < /dev/null > /dev/null
echo "done."
-------------- next part --------------
#!/usr/bin/bash
migratedir=/usr/local/admin/migration
sourcedir=/mnt/users
inboxdir=/mnt/inboxes
destdir=/home/users
PATH=/usr/local/bin:$PATH
TTY=/dev/null
export PATH TTY migratedir sourcedir inboxdir destdir
quota="3000000000"
cd $sourcedir
for i in `${migratedir}/findusers`
do
echo "Migrating $i"
suserd=${sourcedir}/${i}
duserd=${destdir}/${i}
smaild=${suserd}/Mail
dmaild=${duserd}/Maildir
if [ ! -d $dmaild ]; then
gmkdir -p $dmaild
fi
echo "${quota}S" > ${dmaild}/maildirsize
touch ${dmaild}/maildirfolder
${migratedir}/migrate-home $i
${migratedir}/migrate-inbox $i
gchown -R ${i}.misc $duserd
gchmod -R 700 $dmaild
echo
done
-------------- next part --------------
A non-text attachment was scrubbed...
Name: findmailfiles
Type: application/x-perl
Size: 209 bytes
Desc: not available
Url : http://dovecot.org/pipermail/dovecot/attachments/20070305/bd4a00d5/attachment-0005.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: findusers
Type: application/x-perl
Size: 256 bytes
Desc: not available
Url : http://dovecot.org/pipermail/dovecot/attachments/20070305/bd4a00d5/attachment-0006.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mb2md.patch
Type: text/x-diff
Size: 506 bytes
Desc: not available
Url : http://dovecot.org/pipermail/dovecot/attachments/20070305/bd4a00d5/attachment-0007.bin
More information about the dovecot
mailing list