1. Please take a little time for this simple survey! Thank you for participating!
    Dismiss Notice
  2. Dear Pleskians, please read this carefully! New attachments and other rules Thank you!
    Dismiss Notice
  3. Dear Pleskians, I really hope that you will share your opinion in this Special topic for chatter about Plesk in the Clouds. Thank you!
    Dismiss Notice

QMail: Move Spam into IMAP Spam Folder

Discussion in 'Plesk 9.x for Linux Issues, Fixes, How-To' started by Gene Steinberg, Dec 13, 2008.

  1. Gene Steinberg

    Gene Steinberg Regular Pleskian

    25
    57%
    Joined:
    Dec 9, 2008
    Messages:
    119
    Likes Received:
    0
    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.
     
  2. netweblogic

    netweblogic Guest

    0
     
  3. atomicturtle

    atomicturtle Golden Pleskian

    29
     
    Joined:
    Nov 20, 2002
    Messages:
    2,110
    Likes Received:
    7
    Location:
    Washington, DC
    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.
     
  4. Trampelpfad

    Trampelpfad Guest

    0
     
    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?
     
  5. netweblogic

    netweblogic Guest

    0
     
    @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?
     
  6. netweblogic

    netweblogic Guest

    0
     
    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....
     
  7. Xploreweb.com

    Xploreweb.com Guest

    0
     
    Hi netweblogic,

    I've adapted your scripts and they work fine under plesk 9 with qmail.
     
  8. netweblogic

    netweblogic Guest

    0
     
    Nice to know!

    Was there a lot to modify?
     
  9. Xploreweb.com

    Xploreweb.com Guest

    0
     
    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.
     
  10. atomicturtle

    atomicturtle Golden Pleskian

    29
     
    Joined:
    Nov 20, 2002
    Messages:
    2,110
    Likes Received:
    7
    Location:
    Washington, DC
    You can run events on mailbox creates, updates, and deletes. Would that get you need?
     
  11. Xploreweb.com

    Xploreweb.com Guest

    0
     
    Yep Scott,

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

    Timon
     
  12. netweblogic

    netweblogic Guest

    0
     
    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
     
  13. Markus_Eyrich

    Markus_Eyrich Basic Pleskian

    24
    23%
    Joined:
    Dec 11, 2008
    Messages:
    93
    Likes Received:
    0
    How can i run events on mailbox create, update, delete ? I don't see an option for this?!
     
  14. Trampelpfad

    Trampelpfad Guest

    0
     
    I am using qmail
    | 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
     
  15. Xploreweb.com

    Xploreweb.com Guest

    0
     
    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
     
  16. Gene Steinberg

    Gene Steinberg Regular Pleskian

    25
    57%
    Joined:
    Dec 9, 2008
    Messages:
    119
    Likes Received:
    0
    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
     
  17. Xploreweb.com

    Xploreweb.com Guest

    0
     
    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: May 26, 2009
Loading...