• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

QMail: Move Spam into IMAP Spam Folder

Gene Steinberg

Regular Pleskian
Is there a way to have SpamAssassin and/or QMail automatically redirect messages labeled Spam into the Spam folders on my various email accounts?

I've tried to find a way within the Plesk 9 interface, and do not see one. We could do this easily enough in cPanel.

I'm rather mediocre at my command line skills, so step-by-step please.

My server uses CentOS 5.2 if that helps.
 
You could also run your repair script through the Event Manager, that way the folders and .qmail changes would happen the moment the account was created or modified.
 
I tried your scripts and it seems that all incoming mail is held back in the queue. No mail gets processed or delivered though procmail.

procmail worked fine on Plesk 8.2, 8.3 and 8.6 but seems not to work at all on Plesk 9.0.1
Any ideas?
 
@atomicturtle
That's a great idea. I wasn't aware of the event manager's capabilities. I'll definitely look into that because it's an elegant solution.

@Trampelpfad
Interesting...
I unfortunately still have 8.6 on my systems and haven't had a chance to play on 9 yet. I'm willing to take a stab though...
Are you using qmail or postfix?
Also, please paste a .qmail file of a user on your system. If it's qmail it should be in /var/qmail/mailnames/<yourdomain>/<username>/.qmail .
I'm wondering if it's something to do with deliverquota and different usage in 9?
 
atomicturtle,

I've updated that post, thanks for that. Do you know of a (not too complex) way to detect via these events if the mailbox has been disabled?

The solution is 99% automated except for when you disable a mailbox, this isn't written into the .qmail file. Detecting mailbox changes would enable a great way to solve that....
 
Hi netweblogic,

I've adapted your scripts and they work fine under plesk 9 with qmail.
 
Nothing really, all works fine, only added some procmail logging lines.

I am testing first on two domains before going server wide.

I didn't test your .qmail-repair script yet, but by looking at it, should work fine too. Will let you know once I ran it.
 
Yep Scott,

When going server-wide will do through event manager, nice solution, thanks.

Timon
 
That improves on the solution I made, but the limitation it originally had still remains.

The problem is that when you create/update an account, my script changes the usual PLESK directive in all user .qmail files to send the mail to quota, so that it goes via procmail for the spam folder filtering.

When deactivating a mailbox, PLESK looks for the line it created and deletes it, which is not there anymore due to my script and therefore it assumes it's OK.

The problem is now that PLESK shows that mail isn't being delivered to the mailbox when actually .qmail has a line that instructs it to do just that. When I duplicate this error, errors start getting thrown by procmail and failure notices are returned to the sender...

If there was a trigger somewhere when mailboxes were disabled a script could be run to remove the line in that specific .qmail file.

Thanks,
Marcus
 
Are you using qmail or postfix?
I am using qmail
Also, please paste a .qmail file of a user on your system. If it's qmail it should be in /var/qmail/mailnames/<yourdomain>/<username>/.qmail .
I'm wondering if it's something to do with deliverquota and different usage in 9?
| true
| /usr/bin/deliverquota ./Maildir

This is the .qmail originally set up by Plesk
I also tried the variant below, I found somewhere on the web - unfortunately this didn't work at all. All mails were kept in the queue and were not delivered until I switched back to the previous version

| true
| preline /usr/bin/procmail -m -o .procmailrc

The funny thing is, with previous versions of plesk, my .procmailrc worked absolutely fine without fiddling in the .qmail at all. I use procmail to save mime attachments coming from a specified sender into a dedicated folder for further processing.

Any advise is highly appreciated.
Thanks
 
Hi netweblogic,

I just was wondering... since back then.. I'm about to put this technique server-wide. The only thing that is missing really is a way to auto-create all the Spam folders in the mail root as they are not there by default.

What is your view on this and how did you solve that on your production servers?

I was thinking if it was maybe possible to add to the maintenance qmail script that is triggered by the event manager in plesk.

Thanks
 
What truly annoys me about all this is the fact that cPanel has a lot of this stuff.

It includes, as part of the standard installation, an easy way to add ClamAV, and, once installed, it'll automatically scan your email. No special settings required. Also, you can configure each account so junk mail is automatically funneled to the Junk folder in your email accounts, because it supports email rules.

None of this can be done with the regular regular Plesk 9 layout. Unfortunate.

Peace,
Gene
 
Hi netweblogic,

I just was wondering... since back then.. I'm about to put this technique server-wide. The only thing that is missing really is a way to auto-create all the Spam folders in the mail root as they are not there by default.

What is your view on this and how did you solve that on your production servers?

I was thinking if it was maybe possible to add to the maintenance qmail script that is triggered by the event manager in plesk.

Thanks

Nevermind, it should auto create the spam folder on receiving the spam mail..

But to create it on forehand, just put this line in the qmail-repair script:

maildirmake -f Spam $1/Maildir
chown popuser:popuser $1/Maildir/.Spam
spamdir=$1/Maildir/.Spam
for i2 in $( ls -1 $spamdir); do
chown popuser:popuser $spamdir/$i2
done

Code:
#!/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
	
	maildirmake -f Spam $1/Maildir
	chown popuser:popuser $1/Maildir/.Spam
	spamdir=$1/Maildir/.Spam
	for i2 in $( ls -1 $spamdir); do
		chown popuser:popuser $spamdir/$i2
	done
}

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
 
Last edited by a moderator:
Back
Top