Spostamento di una gerarchia Maildir sotto un'altro account: Difference between revisions

From RVM Wiki
Jump to navigation Jump to search
m New page: {{Stub}} Usare lo script: <pre> #!/bin/bash cd /home/dmarcotti/Maildir for VAR in .* do if "$VAR" != "." && "$VAR" != ".." then mv "$VAR" ".dmarcot...
 
mNo edit summary
 
(9 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{Stub}}
==Script per rename di tutta una mailbox==


Usare lo script:
Questo script crea una gerarchia Maildir che parte dalla cartella .NewPrefix a partire da una Maildir completa.
 
Lo script va lanciato da una cartella che si chiama Maildir che contenga i folder cur new tmp e i sottofolder.
 
<pre>
#!/bin/bash
if [ -z $1 ]
then
        echo "Usage: rename_maildir newPrefix"
        exit 1
fi
 
PRF="$1"     
 
# Move subfolders
 
if [ "$(basename $(pwd))" = "Maildir" ]
then
        find . -name ".[[:alnum:]]*" -printf '%f\n' | \
        while read MBX; do
                mv "${MBX}" ".${PRF}${MBX}"
        done
else
        echo "You must run this command from a directory named Maildir. Aborting."
        exit 1
fi
 
# Move inbox
mkdir .$PRF
mv cur .${PRF}/
mv new .$PRF/
mv tmp .$PRF/
 
mv dovecot* .$PRF/ > /dev/null 2>&1
mv courier* .$PRF/ > /dev/null 2>&1
</pre>
 
==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


<pre>
<pre>
cat > /tmp/sposta_maildir <<'EOFile'
#!/bin/bash
#!/bin/bash
cd /home/dmarcotti/Maildir
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 .*
for VAR in .*
do
do
         if  [[ "$VAR" != "." && "$VAR" != ".." ]]
         if  [[ "$VAR" != "." && "$VAR" != ".." ]]
         then
         then
                 mv "$VAR" ".dmarcotti$VAR"
                set -x
                 mv "$VAR" ".${SRC_CLEAN}$VAR"
                set +x
         fi
         fi
done
done
#set -x
mkdir  .${SRC_CLEAN}
mv cur .${SRC_CLEAN}
mv new .${SRC_CLEAN}
mv tmp .${SRC_CLEAN}


mkdir  .dmarcotti
mv .${SRC_CLEAN}* /home/${DST}/Maildir
mv cur .dmarcotti
#set +x
mv new .dmarcotti
chown -R ${DST}: /home/${DST}/Maildir
mv tmp .dmarcotti
EOFile
</pre>


mv .dmarcotti* /home/info/Maildir
chmod +x /tmp/sposta_maildir
chown -R info: /home/info/Maildi
</pre>

Latest revision as of 09:06, 4 September 2012

Script per rename di tutta una mailbox

Questo script crea una gerarchia Maildir che parte dalla cartella .NewPrefix a partire da una Maildir completa.

Lo script va lanciato da una cartella che si chiama Maildir che contenga i folder cur new tmp e i sottofolder.

#!/bin/bash
if [ -z $1 ]
then
        echo "Usage: rename_maildir newPrefix"
        exit 1
fi

PRF="$1"      

# Move subfolders

if [ "$(basename $(pwd))" = "Maildir" ]
then
        find . -name ".[[:alnum:]]*" -printf '%f\n' | \
        while read MBX; do
                mv "${MBX}" ".${PRF}${MBX}"
        done
else
        echo "You must run this command from a directory named Maildir. Aborting."
        exit 1
fi

# Move inbox
mkdir .$PRF
mv cur .${PRF}/
mv new .$PRF/
mv tmp .$PRF/

mv dovecot* .$PRF/ > /dev/null 2>&1
mv courier* .$PRF/ > /dev/null 2>&1

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