Results 1 to 9 of 9

Thread: Migration from Maildir File Format to Zimbra SUCCESS!

  1. #1
    Tekify is offline New Member
    Join Date
    Sep 2009
    Posts
    3
    Rep Power
    5

    Default Migration from Maildir File Format to Zimbra SUCCESS!

    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.

  2. #2
    yogesh2tech is offline Active Member
    Join Date
    Sep 2009
    Location
    India
    Posts
    45
    Rep Power
    5

    Default

    Hi Dear
    This is very important script to migrate mail from old system to newly zimbra server, but u dont think it still need some modification. Because i am using this script to migrate my mail account but after migrating all mails it shows all mail as read while i have lots of unread mails. pls provide the solution to get rid off the problem.
    Thanks

  3. #3
    Tekify is offline New Member
    Join Date
    Sep 2009
    Posts
    3
    Rep Power
    5

    Default

    Hello,

    Yes, it would be nice if it were able to retain the read/unread settings. However, the original script that I found online did not do this either. I didn't add the feature, I just made this script reliable so it works every time.

    In my case, having all old mail imported and marked as read was acceptable.

  4. #4
    yogesh2tech is offline Active Member
    Join Date
    Sep 2009
    Location
    India
    Posts
    45
    Rep Power
    5

    Default

    can you please edit this feature to me?
    because i am not expert in scripting as you.
    pls help me.
    Thanks in advance

  5. #5
    drwho18 is offline Senior Member
    Join Date
    May 2007
    Posts
    63
    Rep Power
    7

    Default

    Yep, I wrote/posted the original script, it worked but I quit on it because of the flag issue, and very little interest in the script a the time.

  6. #6
    tribear is offline Senior Member
    Join Date
    Oct 2009
    Location
    North Carolina, USA
    Posts
    58
    Rep Power
    5

    Question Migrating home/usr/maildir folder "cur" to Zimbra - questions.

    Can you help me understand that if I use this script I can move my old user mail folders having this layout to Zimbra?

    /Home/User/Maildir
    >cur
    >new
    >tmp
    .Archives
    .Drafts
    .Sent
    .Trash

    So if I try your script I can see where to change the domain. But when I copy mail to a working folder do I need to include the folders /home/user/maildir ...... and subfolder "cur" or just /user/maildir/cur?

    Steven

  7. #7
    dansomers is offline Starter Member
    Join Date
    Sep 2011
    Posts
    1
    Rep Power
    3

    Default This worked for me 3 months ago, now it seems broken

    I get a failure on line 7 of the script --> shopt: not found

    My default shell is bash, so this should work. shopt -s extglob works fine from the terminal but not in the script. Any ideas?

    I am attempting to import maildirs into Zimbra on Ubuntu Lucid.

  8. #8
    Tekify is offline New Member
    Join Date
    Sep 2009
    Posts
    3
    Rep Power
    5

    Default

    Try changing line 7 to reflect the full path to shopt. I'm not sure what it is off hand, so you'll need to find it.

  9. #9
    hpfs74 is offline Starter Member
    Join Date
    Oct 2011
    Posts
    1
    Rep Power
    3

    Default Updated Script

    I've been in need to import also subfolders so i've changed a little your script.

    Maybe it's useful for someone
    Code:
    #!/bin/bash
    #
    # Maildir to Zimbra import
    # Drop in your user root and run as superuser.
    #
    
    
    
    ZMM="/opt/zimbra/bin/zmmailbox"
    
    domain="domain.com" # change to your domain!
    defaultpass="xxxxyyyy"
    
    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 "LINE2 $line2"
          #echo "FOLDER $folder"
          if [ "$folder" = "cur" ]
          then
              $ZMM -z -m $user@$domain addMessage Inbox $PWD/$user/Maildir/cur
              $ZMM -z -m $user@$domain addMessage Inbox $PWD/$user/Maildir/new
          else
              if [ "$folder" != "Sent" ] && [ "$folder" != "Drafts" ] && [ "$folder" != "Junk" ] && [ "$folder" != "Trash" ]
              then
    
                  echo $folder | tr '\.' '\n' > /tmp/qq
    
                  folder=""
                  while read x;
                  do
                      folder="$folder/$x"
    
                      if [ $($ZMM -z -m $user@$domain gaf | grep "$folder" | wc -l) == 0 ]; then
                          $ZMM -z -m $user@$domain createFolder "$folder"
                      fi
                  done < /tmp/qq
              else
                  folder="/$folder"
              fi
    
              $ZMM -z -m $user@$domain addMessage "$folder" "${PWD}/${line}"
              $ZMM -z -m $user@$domain addMessage "$folder" "${PWD}/${line2}"
          fi
    
      done
    
    done

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] parts_decode_ext error
    By jsabater in forum Administrators
    Replies: 7
    Last Post: 10-13-2008, 07:24 AM
  2. zimbra install with perpetually broken logger/stats
    By jptech in forum Installation
    Replies: 8
    Last Post: 09-29-2008, 02:33 PM
  3. Replies: 12
    Last Post: 02-25-2008, 07:28 PM
  4. [SOLVED] Clamav problem ? What's happening ?
    By aNt1X in forum Installation
    Replies: 23
    Last Post: 02-14-2008, 05:43 AM
  5. Replies: 8
    Last Post: 02-27-2007, 04:10 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •