Categories
Plesk Technology

Plesk Default Settings Script for qmail and procmail

As you may or may not know, Plesk likes to overwrite the .qmail file in each mail folder whenever you make changes. And as of this writing, Plesk 8.2 does not offer any .qmail template files in order for you to control it’s behavior.

Here’s a handy script that will generate a .qmail and a .procmailrc file for each mailbox on the entire server. You can place this script anywhere you want and run this as a higher authority such as root.

The .qmail file that is produced will send all mail to procmail in order to move spam mail into junk folders. Another interesting line in the .qmail file is the following:


#delete spam mail older than 15 days
|find ./Maildir/.Junk/cur -mtime +15 -exec rm {} \;

This line will delete all spam mail that is older than 15 days from the .Junk folder.


#!/bin/sh

IFS="
"

create_qmail()
{
file=$1/.qmail
cat > $file << EOF
|/usr/local/psa/bin/psa-spamc accept
#run procmail to move spam
|preline /usr/bin/procmail -m .procmailrc
#delete spam mail older than 15 days
|find ./Maildir/.Junk/cur -mtime +15 -exec rm {} \;
EOF
chmod 600 $file
chown popuser:popuser $file
echo created $file
}

create_procmail()
{
file=$1/.procmailrc
cat > $file << EOF
# Move spam to the .Junk folder
:0:
* ^X-Spam-Status: Yes.*
./Maildir/.Junk/

# Let other mail go through
:0:
*
./Maildir/ 
EOF

chmod 600 $file
chown popuser:popuser $file
echo created $file
}


dir=/var/qmail/mailnames

        for i in $( ls -1 $dir); do
                for x in $( ls -1 $dir/$i); do
                        cd $dir/$i/$x
                        create_qmail $dir/$i/$x
                        create_procmail $dir/$i/$x
                done
        done

2 replies on “Plesk Default Settings Script for qmail and procmail”

The .Junk folder is not created by default and one will usually be made by whatever mail client is used. Also the mail client may generate a different folder name such as .Spam.

You could use a script to create the .Junk folder in each mailbox if one does not exist.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.