Maildir to zmmailbox with bash

Revision as of 02:17, 25 April 2009 by Gettyless (talk | contribs)
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Place this script in your /home directory (/home NOT /home/USER/ !!!) and run. Script will import all emails from "cur" and "new" directories from /home/*/Maildir/ (and all subdirectories) into /Import IMAP folder.

#!/bin/bash

#
# Maildir to Zimbra import
#
# Created by Jarosław Czarniak on 26-10-2008
#

clear
chown -R zimbra:zimbra *

domain="jarsat.pl" # change to your domain!
IMPORT="/Import"


for user in `ls -d1 */|sed s/\\\///`
do
    echo
    echo "User $user"
    echo
    echo "createFolder $IMPORT" > /tmp/tmp.txt
    /opt/zimbra/bin/zmmailbox -z -m $user@$domain < /tmp/tmp.txt

    #
    # CUR
    #
    for sciezka in `find $user -maxdepth 10 -type d -name cur`
    do
    echo
    echo "Directory $sciezka"
    echo

    nazwa=`echo $sciezka|cut -f3 -d"/"|sed s/\\\.//`
    if [ "$nazwa" = "cur" ]
        then
            echo "addMessage ${IMPORT} $PWD/$user/Maildir/cur" > /tmp/tmp.txt
            /opt/zimbra/bin/zmmailbox -z -m $user@$domain < /tmp/tmp.txt
        else
            echo "createFolder ${IMPORT}/$nazwa" > /tmp/tmp.txt
            /opt/zimbra/bin/zmmailbox -z -m $user@$domain < /tmp/tmp.txt
            echo "addMessage ${IMPORT}/$nazwa ${PWD}/${sciezka}" > /tmp/tmp.txt
            /opt/zimbra/bin/zmmailbox -z -m $user@$domain < /tmp/tmp.txt
    fi
    done

    #
    # NEW
    #
    for sciezka in `find $user -maxdepth 10 -type d -name new`
    do
    echo
    echo "Directory $sciezka"
    echo
    nazwa=`echo $sciezka|cut -f3 -d"/"|sed s/\\\.//`
    if [ "$nazwa" = "new" ]
        then
            echo "addMessage ${IMPORT} $PWD/$user/Maildir/new" > /tmp/tmp.txt
            /opt/zimbra/bin/zmmailbox -z -m $user@$domain < /tmp/tmp.txt
        else
            echo "createFolder ${IMPORT}/$nazwa" > /tmp/tmp.txt
            /opt/zimbra/bin/zmmailbox -z -m $user@$domain < /tmp/tmp.txt
            echo "addMessage ${IMPORT}/$nazwa ${PWD}/${sciezka}" > /tmp/tmp.txt
            /opt/zimbra/bin/zmmailbox -z -m $user@$domain < /tmp/tmp.txt
    fi
    done
done
Jump to: navigation, search