After searching high and low to find a way to import mail from an old server to Zimbra, I've settled on this Maildir to Zimbra method. I began with Imapsync, but found it to be unreliable. It would complete, but Zimbra would still be missing lots of emails.
This solution is a modified version of a script found elsewhere on these forums. I made a few upgrades so that:
- Subfolders import correctly! The original scripts would make each folder show up at the root level with this syntax: "Folder1.Subfolder1.Sub-Subfolder1" instead of the intended hierarchical format.
- It runs successfully! I've moved GB's worth of email over already, and it hasn't had an issue so far.
I've found this to be the most reliable solution so far. I suggest you give it a try if you're looking to migrate mail.
Here's what you'll need to do:
1. Begin by adding the users to Zimbra in advance. The user accounts *must* match what you're importing. The only exception is if you import the mail below, and rename the folders to whatever account name you set up in this step.
2. Start with a "scratchpad" folder on your Zimbra system. This is a workplace where the Maildir files can sit while you're transferring them.
3. Copy the user mail folders from your old server. The result should be multiple folders inside this work area, such as user1, user2, user3, etc.
4. Make a file called run.sh in this work area. Copy the code below into it. Make sure you update the domain name in the script. Close it and CHMOD 777 it.
5. Now, run the script. Type ./run.sh. It will run for a while. You'll know it's complete when you are returned to a command prompt.
Code:
#!/bin/bash
#
# Maildir to Zimbra import
# Drop in your user root and run as superuser.
#
shopt -s extglob
domain="domain.com" # change to your domain!
for user in `ls -d1 */|sed s/\\\///`
do
echo
echo "User $user"
echo
#
#
find $user -maxdepth 10 -type d -name cur | awk '{ print length($0),$0 | "sort -n"}' | while read line;
do
line=`echo $line | sed -e 's/^[0123456789]*[[:space:]]//'`
#echo "PARSED LINE: " $line
folder=`echo ${line}|cut -f3 -d"/"|sed s/\\\.//`
# replace _ with a space (IMPORTANT! This makes the imported subfolders come out correctly!)
newfolder=$( echo $folder|sed 's/[.]/\//g')
line2=`echo ${line/%cur/new}`
echo "FOLDER $folder"
if [ "$folder" = "cur" ]
then
echo "Transferring inbox..."
/opt/zimbra/bin/zmmailbox -z -m $user@$domain addMessage "Inbox" "$PWD/$user/Maildir/cur"
/opt/zimbra/bin/zmmailbox -z -m $user@$domain addMessage "Inbox" "$PWD/$user/Maildir/new"
echo "Finished transferring inbox."
else
if [ "$folder" != "Sent" ] && [ "$folder" != "Drafts" ] && [ "$folder" != "Junk" ] && [ "$folder" != "Trash" ]
then
echo "Creating folder '/$newfolder'..."
/opt/zimbra/bin/zmmailbox -z -m $user@$domain createFolder /"$newfolder"
echo "Finished creating folder."
fi
/opt/zimbra/bin/zmmailbox -z -m $user@$domain addMessage "/$newfolder" "${PWD}/${line}"
/opt/zimbra/bin/zmmailbox -z -m $user@$domain addMessage "/$newfolder" "${PWD}/${line2}"
fi
done
done I hope this helps someone down the road! I know I could have used it. It would have saved a LOT of time.