#!/bin/sh SPAMASSASSIN_BASE_DIR=/usr/local/debug/mail/spamassassin [ -f ${SPAMASSASSIN_BASE_DIR}/rc.conf.sa.default ] && . ${SPAMASSASSIN_BASE_DIR}/rc.conf.sa.default [ -f ${SPAMASSASSIN_BASE_DIR}/rc.conf.sa ] && . ${SPAMASSASSIN_BASE_DIR}/rc.conf.sa [ ! -z "${DEBUG}" ] && echo "distribute messages for SpamAssassin learning" [ -z "${DEBUG}" ] || echo "> cd ${BASE_MAILDIR}" cd ${BASE_MAILDIR} for flag in spam ham ; do for subdir in cur new ; do [ ! -z "${DEBUG}" ] && echo "check source folder ${BASE_MAILDIR}/${DISTRIBUTE_PREFIX}sa-learn-${flag}/${subdir}/" if [ ! -z "`ls ${DISTRIBUTE_PREFIX}sa-learn-${flag}/${subdir}/* 2>/dev/null | head -n 2`" ] ; then [ ! -z "${DEBUG}" ] && echo "process folder ${BASE_MAILDIR}/${DISTRIBUTE_PREFIX}sa-learn-${flag}/${subdir}/" TMP_FOLDER="/tmp/sa-distribute-"${flag}"-"`date +"%Y%m%d-%H%M%S"` [ ! -z "${DEBUG}" ] && echo "temporary folder ${TMP_FOLDER}" [ -d ${TMP_FOLDER} ] || mkdir -p ${TMP_FOLDER} chmod 700 ${TMP_FOLDER} if [ "`uname`" = "Linux" ] ; then [ ! -z "${DEBUG}" ] && echo "> find ${DISTRIBUTE_PREFIX}sa-learn-${flag}/${subdir}/ -type f | xargs -l1 -ifile mv file ${TMP_FOLDER}" find ${DISTRIBUTE_PREFIX}sa-learn-${flag}/${subdir}/ -type f | xargs -l1 -ifile mv file ${TMP_FOLDER} else [ ! -z "${DEBUG}" ] && echo "> find ${DISTRIBUTE_PREFIX}sa-learn-${flag}/${subdir}/ -type f | xargs -L 1 -I file mv file ${TMP_FOLDER}" find ${DISTRIBUTE_PREFIX}sa-learn-${flag}/${subdir}/ -type f | xargs -L 1 -I file mv file ${TMP_FOLDER} fi for d in ${DISTRIBUTE_PREFIX}sa-learn-${flag}.* ; do if [ -d $d ] ; then [ ! -z "${DEBUG}" ] && echo "process destination folder ${BASE_MAILDIR}/$d" if [ "`uname`" = "Linux" ] ; then [ ! -z "${DEBUG}" ] && echo "> find ${TMP_FOLDER}/ -type f | xargs -l1 -ifile cp -p file ${d}/new/" find ${TMP_FOLDER}/ -type f | xargs -l1 -ifile cp -p file ${d}/new/ else [ ! -z "${DEBUG}" ] && echo "> find ${TMP_FOLDER}/ -type f | xargs -L 1 -I file cp -p file ${d}/new/" find ${TMP_FOLDER}/ -type f | xargs -L 1 -I file cp -p file ${d}/new/ fi [ ! -z "${DEBUG}" ] && echo "> chown -R ${MAILDIR_USER}:mail ${d}/new ${d}/cur" chown -R ${MAILDIR_USER}:mail ${d}/new ${d}/cur [ ! -z "${DEBUG}" ] && echo "> find ${d}/new/ -type f | xargs chmod 660" find ${d}/new/ -type f | xargs chmod 660 # в будущем заменить for mv на find | xargs mv for f in ${d}/new/*,W=* ; do [ -f $f ] && mv $f `echo $f | perl -p -e 's/,W=\d*//'` done fi done [ -z "${DEBUG}" ] || echo "> rm -rf ${TMP_FOLDER}/" rm -rf ${TMP_FOLDER}/ fi done done