Spostamento di una gerarchia Maildir sotto un'altro account
Script per rename di tutta una mailbox
TODO: fix per cartelle con spazi nei nomi
#!/bin/bash
if [ -z $1 ]
then
echo "Usage: rename_maildir newPrefix"
exit 1
fi
PRF="$1"
mkdir .$PRF
mv cur .${PRF}/
mv new .$PRF/
mv tmp .$PRF/
mv dovecot* .$PRF/
mv courier* .$PRF/
for MBX in .[[:alnum:]]*
do
mv ${MBX} .${PRF}${MBX}
done
Script per rename e spostamento
Questo script sposta tutta la posta dell'account sorgente in una sottocartella dell'account destinazione.
Uso:
sudo /tmp/sposta_maildir src_account dst_account
cat > /tmp/sposta_maildir <<'EOFile'
#!/bin/bash
SRC="$1"
DST="$2"
SRC_CLEAN=$(echo $SRC | tr . _)
if [ "$(id -u)" -ne "0" ]
then
echo You must be root to run this script. Aborting.
exit 127
fi
if [ -z "$1" -o -z "$2" ]
then
echo Usage: sposta_maildir src_account dst_account
exit 127
fi
if [ ! -e /home/${SRC}/Maildir ]
then
echo /home/${SRC}/Maildir does not exist. Aborting
exit 127
fi
if [ ! -e /home/${DST}/Maildir ]
then
echo /home/${DST}/Maildir does not exist. Aborting
exit 127
fi
echo Moving /home/${SRC}/Maildir to /home/${DST}/Maildir/.${SRC_CLEAN}
cd /home/${SRC}/Maildir
for VAR in .*
do
if [[ "$VAR" != "." && "$VAR" != ".." ]]
then
set -x
mv "$VAR" ".${SRC_CLEAN}$VAR"
set +x
fi
done
#set -x
mkdir .${SRC_CLEAN}
mv cur .${SRC_CLEAN}
mv new .${SRC_CLEAN}
mv tmp .${SRC_CLEAN}
mv .${SRC_CLEAN}* /home/${DST}/Maildir
#set +x
chown -R ${DST}: /home/${DST}/Maildir
EOFile
chmod +x /tmp/sposta_maildir