Corrigindo o bug do .tmda (messages not moving to maildir) no vpopmail

De Wiki Hackstore

Crie um script que renomeie automaticamente os arquivos de msgs do anti-spam do vpopmail (.tmda):

#!/bin/bash

#set -x

mysql vpopmail -e "select pw_domain from vpopmail"|sort|uniq|grep -v "pw_domain" > /tmp/domains.txt

> /tmp/all.txt

while read dominio;do
        DOMAIN=`echo $dominio | sed 's/_/./g'`
        mysql -h 127.0.0.1 vpopmail -e "select pw_name from vpopmail where pw_domain='${DOMAIN}'"|grep -v "pw_name" | egrep -v "^$|[#;]"  |awk '{print $1 "@'${DOMAIN}'"}' >> /tmp/all.txt

        while IFS=@ read mail;do
                USER=$(echo $mail |cut -d'@' -f1)
                DIR="/var/qmail/vpopmail/domains/${DOMAIN}/${USER}/.tmda/pending/"

                if [ -d ${DIR} ]; then
                        # Altera nome do arquivo em "pending" para *.msg
                        for i in $(find ${DIR} -type f |grep '.msg:3'); do echo mv "\"$i\" \"$(echo $i |sed s,':3\,R',,g|sed s,':3\,C',,g)\"";done > /tmp/script
                        bash /tmp/script
                fi
        done < /tmp/all.txt
done < /tmp/domains.txt