Difference between revisions of "Maildir to zmmailbox with bash"

(New page: 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)...)
 
Line 69: Line 69:
 
done
 
done
 
</pre>
 
</pre>
 +
 +
[[Category:Migration]]

Revision as of 02:17, 25 April 2009

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