Zimbra offers Open Source email server software and shared calendar for Linux and the Mac
Go Back   Zimbra :: Forums > Zimbra Desktop > General Questions

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 10-31-2011, 07:20 AM
Member
 
Posts: 12
Default Howto: Thunderbird local folders to zimbra desktop local folders

EDIT: Please see this post for a much better and cleaner solution: Script: (Thunberbird) mbox tree to (zimbra desktop) importable .eml tree

Hi there,

I wanted to share a solution I found to migrate local mbox mail folders to zimbra desktop local folders.

Please note that I take no responsibility if the guide below somehow results in any damage or lost files. Use at your own risk. You have been warned.

Also note that I'm aware that this is far from perfect and could be cleaned up/enhanced/scripted/etc. For example, the procedure will result in the creationg of unneeded subfolders. Maybe I'll update the script late. Feel free to do so yourself and share your solution with us...

What you need:
  • A linux box
  • mb2md (this is a simple perl script. If it's not in one of your package repos, look here http://dovecot.org/tools/mb2md.pl)
  • perl (for md2md)
  • grep, sed, cut, touch, tar and gzip commands (for the bash script)

How it works:
  • In the first step, mb2md will transform the mbox files that thunderbird uses to store local mail into the maildir format. In maildir, each message is a single file.
  • Then, the script md2zimport.sh will transform the maildir generated by mb2md to an importable .tgz file. The .tgz is simply a gzipped tar archive containing directories (mail folders) and .eml files (the actual e-mails). In order to have the correct "received dates", the script will set the modification date of all .eml files to the value found in the mail's "Date:" header.
  • Once the tgz file was created, you can import it into zimbra desktop.

How to do it:
Let's assume that our working directory is /home/myuser/zimbraimport
  1. Copy the local folders from thunderbird to a working directory on your linux box. If you don't know where the local folders are, see Profile folder - Thunderbird - MozillaZine Knowledge Base. Example:
    Code:
    mkdir -p /home/myuser/zimbraimport/mbox
    cp -R "/home/myuser/.thunderbird/abcdefgh.default/Mail/Local Folders" /home/myuser/zimbraimport/mbox/
    (Of course you could also copy the files over from a windows box using a mounted smb share or something)
  2. Fire up mb2md like this:
    Code:
    mb2md -R -s /home/myuser/zimbraimport/mbox -d /home/myuser/zimbraimport/maildir
  3. Save the following script as /home/myuser/zimbraimport/md2zimport.sh:
    Code:
    #!/bin/bash
    # requires grep, sed, cut, tar, touch and gzip
    
    usage() {
    	echo "Usage: "$0" MAILDIR_ROOT ZIMBRA_DEST_DIR"
    	echo "To get help, type: "$0" help"
    }
    
    help() {
    	usage
    	echo
    	echo "This script will attempt to transform a maildir to an importable"
    	echo "zimbra directory structure containing .eml files."
    	echo
    	echo "Only one level of subdirs in MAILDIR_ROOT will be processed"
    	echo "If you need deeper subdirs, use dots in the name of the first"
    	echo "level subdirs to separate them. Example: firstlevel.secondlevel"
    	echo "The messages themselves must be inside a dir 'cur' inside"
    	echo "MAILDIR_ROOT or a dir 'cur' inside the subdirs."
    	echo "Note that the string '_sbd' will be removed from all names"
    	echo "when creating the zimbra directory structure."
    	echo "Also, subdirs with a trailing _msf will be ignored."
    	echo
    	echo "Example:"
    	echo "Say, we have the following file structure inside MAILDIR_ROOT:"
    	echo "cur/message1"
    	echo "cur/message2"
    	echo "adir_sdb/cur/message3"
    	echo "adir_sdb.anotherdir_sdb/cur/message4"
    	echo "This would be translated to the following zimbra dir structure"
    	echo "inside ZIMBRA_DEST_DIR:"
    	echo "message1.eml"
    	echo "message2.eml"
    	echo "adir/message3.eml"
    	echo "adir/anotherdir/message4.eml"
    	exit 0
    }
    
    checkargs() {
    	if [ -z "$2" ]; then usage; exit -1;  fi
    	if [ ! -d "$1" ]; then echo "$1 is not a directory"; exit -1; fi
    	if [ ! -d "$2" ]; then echo "$2 is not a directory"; exit -1; fi
    }
    
    treat_dir() {
    	dir="$1"
    
    	if [ ! -d "$dir" ]; then echo "ignoring non dir $1"; return 0; fi
    	if [[ "$dir" == *_msf/ ]]; then echo "ignoring _msf dir $1"; return 0; fi
    	outdir="$2"
    
    	OLDIFS=$IFS
    	IFS="." dirs=($dir)
    	IFS=$OLDIFS
    	for (( i=0; i<${#dirs[@]}; i++ )); do
                   if [ ! -z "${dirs[$i]}" ]; then outdir="$outdir"/"${dirs[$i]}"; fi
    	done
    	outdir="${outdir//_sbd/}"
    	mkdir -p "$outdir"
    	echo "mkdir $outdir"
    
    	for msg in `ls -1Ap "$dir/cur" 2>/dev/null`; do
    		echo "cp \"$dir/cur/$msg\" \"$outdir/$msg.eml\""
    		cp "$dir/cur/$msg" "$outdir/$msg.eml"
    	        d=`grep "^Date\:\ " "$outdir/$msg.eml"`
    	        # use the first Date occurrence
    	        datestring=`echo $d | sed -n '1p'`
    	        # remove the 'Date: ' prefix
    	        datestring=${datestring#*\ }
    		echo $datestring
    		touch -m -d $datestring "$outdir/$msg.eml"
    	done
    }
    
    main() {
    	# treat in_dir, then its subdirs
    	treat_dir "$1" "$2"
    
    	OLDIFS=$IFS
    	IFS=$(echo -en "\n\b")
    	test=$(ls -1Ap -I "new" "$1" | grep /\$)
    	for subdir in $(ls -1Ap -I "new" "$1" | grep /\$); do treat_dir "$1/$subdir" $2; done
    	IFS=$OLDIFS
    }
    
    if [ "$1" = "help" ]; then help; fi
    checkargs "$1" "$2"
    main "$1" "$2"
    tar -vzcf zimbraimport.tgz "$2"
  4. Use the bash script (see below) to create a tgz file:
    Code:
    mkdir /home/myuser/zimbraimport/targzdir
    cd /home/myuser/zimbraimport
    chmod 700 md2zimport.sh
    # you MUST specify full paths in the next line
    ./md2zimport.sh /home/myuser/zimbraimport/maildir /home/myuser/zimbraimport/targzdir
    The .tgz file should then be created at /home/myuser/zimbraimport/zimbraimport.tgz
  5. In Zimbra Desktop, go to Preferences -> Local folders -> Import/Export. Under Import, choose the tgz file e.g. /home/myuser/zimbraimport/zimbraimport.tgz. Change any options you want to chagne and click on Import.
  6. While the import runs, you may use zimbra desktop as normal. Notice the local folders that will appear on the "Mail" tab.
Note: if everything went ok, you'll see your local folders in zimbra desktop now. You'll find the full paths used above, e.g. /home/myuser/zimbraimport/, feel free to move your mail folders around once the import finishes

Last edited by fbongartz; 11-04-2011 at 12:57 AM.. Reason: Link to post with new python script
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.