#!/bin/sh # .qmail-repair can be used to change the .qmail files rewritten by plesk to call a systemwide .procmailrc file. This can be run in intervals to repair rewriten .qmail files # Written by Marcus Sykes @ blog.netweblogic.com create_qmail() { file=$1/.qmail tempfile=$1/.qmailtmp qmailfile= awk -v domain=$2 -v username=$3 '{ if ( match($0,"(\\.\\/Maildir|procmail)") == 0 ) { if( match($0, "preline /usr/bin/procmail") ){ already = 1 } print $0 } else { found = 1 } } END { if ( already != 1 && found == 1){ printf("| preline /usr/bin/procmail -m -o /var/qmail/.procmailrc %s %s\n", domain, username ) } }' $file > $tempfile cat $tempfile > $file rm -rf $tempfile chmod 600 $file chown popuser:popuser $file } dir=/var/qmail/mailnames for i in $( ls -1 $dir); do for x in $( ls -1 $dir/$i); do create_qmail $dir/$i/$x $i $x done done