Results 1 to 1 of 1

Thread: Howto: Thunderbird local folders to zimbra desktop local folders

Hybrid View

  1. #1
    Join Date
    Jul 2010
    Rep Power

    Default Howto: Thunderbird local folders to zimbra desktop local folders

    EDIT: Please see this post for a much better and cleaner solution:

    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
    • 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 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:
      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:
      mb2md -R -s /home/myuser/zimbraimport/mbox -d /home/myuser/zimbraimport/maildir
    3. Save the following script as /home/myuser/zimbraimport/
      # 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() {
      	echo "This script will attempt to transform a maildir to an importable"
      	echo "zimbra directory structure containing .eml files."
      	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 "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() {
      	if [ ! -d "$dir" ]; then echo "ignoring non dir $1"; return 0; fi
      	if [[ "$dir" == *_msf/ ]]; then echo "ignoring _msf dir $1"; return 0; fi
      	IFS="." dirs=($dir)
      	for (( i=0; i<${#dirs[@]}; i++ )); do
                     if [ ! -z "${dirs[$i]}" ]; then outdir="$outdir"/"${dirs[$i]}"; fi
      	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"
      main() {
      	# treat in_dir, then its subdirs
      	treat_dir "$1" "$2"
      	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
      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:
      mkdir /home/myuser/zimbraimport/targzdir
      cd /home/myuser/zimbraimport
      chmod 700
      # you MUST specify full paths in the next line
      ./ /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

Similar Threads

  1. Issues after upgrading from 6.0.10 to 7
    By rhorist in forum Administrators
    Replies: 8
    Last Post: 02-25-2011, 07:38 AM
  2. Replies: 12
    Last Post: 02-25-2008, 06:28 PM
  3. /tmp filling
    By Nutz in forum Administrators
    Replies: 8
    Last Post: 02-22-2008, 01:00 AM
  4. Replies: 8
    Last Post: 02-27-2007, 03:10 AM
  5. dspam logrotate errors
    By michaeln in forum Users
    Replies: 7
    Last Post: 02-19-2007, 11:45 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