Zimbra offers Open Source email server software and shared calendar for Linux and the Mac
Go Back   Zimbra :: Forums > Zimbra Collaboration Suite > Migration

Welcome to the Zimbra :: Forums!
Welcome, if you would like to post a comment please register. We also encourage you to explore all things Zimbra with our team and members of the community.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-29-2008, 07:29 PM
Senior Member
 
Posts: 57
Default Maildir to Zimbra

This is a modification of the Maildir import script on the Wiki. It copies the messages to the correct folder on Zimbra, it also will copy folder names with spaces in them, and I've joined the cur/new folder stuff into one loop, rather then two. I've also exempted creation of certain mailboxes that exist within zimbra by default to avoid zmmailbox error delay's.

I'm not a proficient bash coder, so if there is major issues with it please let me know. I've migrated about 300GB with it, without issue.

One thing that it doesn't do is set the flags, I haven't quite figured out how to do that with zmmailbox/zimbra yet. I know I can do it with imapsync, but I'd rather do it from the same script.


#!/bin/bash

#
# Maildir to Zimbra import
# Drop in your user root and run as superuser.
#

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 | while read line;
do
folder=`echo ${line}|cut -f3 -d"/"|sed s/\\\.//`
line2=`echo ${line/%cur/new}`
echo "FOLDER $folder"
if [ "$folder" = "cur" ]
then
/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
else
if [ "$folder" != "Sent" ] && [ "$folder" != "Drafts" ] && [ "$folder" != "Junk" ] && [ "$folder" != "Trash" ]
then
/opt/zimbra/bin/zmmailbox -z -m $user@$domain createFolder "/$folder"
fi
/opt/zimbra/bin/zmmailbox -z -m $user@$domain addMessage "/$folder" "${PWD}/${line}"
/opt/zimbra/bin/zmmailbox -z -m $user@$domain addMessage "/$folder" "${PWD}/${line2}"
fi
done

done

Last edited by drwho18; 11-30-2008 at 05:35 AM..
Reply With Quote
  #2 (permalink)  
Old 11-30-2008, 12:21 AM
Zimbra Consultant & Moderator
 
Posts: 19,633
Default

Thanks for your work on this. Would you mind adding this to the wiki article (so it's all kept in one place)? You'll need to create an account on the wiki to modify the pages.
__________________
Regards


Bill
Reply With Quote
  #3 (permalink)  
Old 11-30-2008, 05:34 AM
Senior Member
 
Posts: 57
Default

Well, I'm not entirely finished, that's why I was looking for feedback and further optimizations. I also trying to figure out how to handle the message flags within the same script, with minimal configuration on the part of the user.
Reply With Quote
  #4 (permalink)  
Old 06-10-2009, 01:36 PM
Starter Member
 
Posts: 2
Default

Thanks for the script. It works except that the unread flag is lost on messages after importing.
Is there any way to keep message flags?
Reply With Quote
  #5 (permalink)  
Old 05-11-2010, 04:43 AM
Starter Member
 
Posts: 1
Default Plesk Maildir to Zimbra

Thanks for the script. I have modified the script to restore mails from Plesk (Qmail) server to zimbra server.

HTML Code:
#!/bin/bash
#
# Maildir to Zimbra import
# Drop in your user root and run as superuser.
#

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 | while read line;
do
folder=`echo ${line}|cut -f3 -d"/"|sed s/\\\.//`
line2=`echo ${line/%cur/new}`
echo "FOLDER $folder"
if [ "$folder" = "cur" ]
then
/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
else
if [ "$folder" != "Sent" ] && [ "$folder" != "Drafts" ] && [ "$folder" != "Junk" ] && [ "$folder" != "Trash" ]
then
/opt/zimbra/bin/zmmailbox -z -m $user@$domain createFolder "/$folder"
fi
/opt/zimbra/bin/zmmailbox -z -m $user@$domain addMessage "/$folder" "${PWD}/${line}"
/opt/zimbra/bin/zmmailbox -z -m $user@$domain addMessage "/$folder" "${PWD}/${line2}"
fi
done

done
I have tested (Zimbra Release 6.0.6 in Fedora 7 box) and It's working fine for me.

Last edited by diadem; 05-11-2010 at 04:50 AM..
Reply With Quote
  #6 (permalink)  
Old 05-12-2010, 02:03 AM
Junior Member
 
Posts: 5
Default

Great, I finish the mail moving use this scripts, but I remove the "Maildir/" from the scripts before run it.

Thanks
Reply With Quote
  #7 (permalink)  
Old 05-12-2010, 05:14 AM
Junior Member
 
Posts: 5
Question

Oops.
Some email cannot be imported, get a RFC822 mailformat error:
ERROR: zclient.CLIENT_ERROR (***skipped email file name*** does not contain a valid RFC 822 message)

Wonder whether anyone have suggestion on this issue?
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads

Why Join?

Registering let's you ask questions, makes it easier to search, displays any files attached to posts, and notifies you about replies.

blog.zimbra.com




 

SEO by vBSEO ©2011, Crawlability, Inc.