#!/bin/bash
##
# Convert every mbox file taken out from .pst file 
# and inject it into IMAP server. This script will
# also keep the directory structure inside pst.
#
# Be sure to change the SOURCE and BASEDEST vars.
# check also that PWD contain the mbox2imapfolder.pl script.
#
# Finally, just run the readpst -r out/ your.pst command to
# extract pst into multiple mbox files. Then filter out directory that
# you don't need (Calendar, Tasks, Notes) and finally, run this script
# with SOURCE var being the main folder of your PST.
##

SOURCE="/home/wildcat/pstconvert/out/Archive Folders"
BASEDEST="archives/mycompany"
CDIR=${PWD}

pushd > /dev/null 2>&1
cd "${SOURCE}"
find . -type d | while read line; do
 if [ -f "${line}/mbox" ]; then
  imapdir=`echo $line|cut -f 2- -d'/'|tr ' ' '_'`;
  echo "Injecting mail of ${line}/mbox to IMAP folder ${BASEDEST}/${imapdir}";
  ${CDIR}/mbox2imapfolder.pl "${line}/mbox" ${BASEDEST}/${imapdir}
 fi;
done;

popd > /dev/null 2>&1
