Cheap VPS & Xen Server

Residential Proxy Network - Hourly & Monthly Packages

ISPConfig 2.x: How To Add A “Move to SPAM”-Option To Your ISPConfig Installation


This document describes the steps needed to add a third spam filter strategy to your ISPConfig 2.x installation. It will allow you and your users to select, wether they want to drop spam, allow spam or move it to the corresponding IMAP junk mail folder.

This howto was inspired by the forum thread from ‘grant’ ( who described exchanged the drop strategy with moving. By following the steps below you won’t replace the drop method but gain a third one.


In this howto I will assume you are using the following or a similar configuration:
ISPConfig (v2.2.23 or later)
At least one domain with a mailbox set up and running
IMAP is using Maildir format (this will not work with mbox!)

Step 1 – Changing Forms

The first step is to log into your ISPConfig Panel with the Admin account. Then enter the Administration tab and open the Form Designer with Edit Form. Search for isp – ISP User and click edit.
You should now see the complete form description of that particular form. Look out for spam_strategy and hit edit again.
Now change the Value list of that form element by inserting a line for our future move option so it shows:


and save that form. Your mail user options in your domain should now show that new option in the spam strategy dropdown box – even though it has no function yet. Now for the console part: Let’s edit some ISPConfig files, to breathe life into the new option.

Step 2 – Editing ISPConfig Source Files

Now we have to edit a bunch of files. I’ll just write them down and explain later:

vi /root/ispconfig/scripts/lib/classes/ispconfig_procmail.lib.php
(around line 109):

“.$web_path.”/user/”.$user_username.”/Maildir &> /dev/null”, “maildirmake
“.$web_path.”/user/”.$user_username.”/Maildir &> /dev/null”, __LINE__);
// ADD: create IMAP subfolders
“.$web_path.”/user/”.$user_username.”/Maildir/.Drafts &> /dev/null”,
“maildirmake “.$web_path.”/user/”.$user_username.”/Maildir/.Drafts &>
/dev/null”, __LINE__);
“.$web_path.”/user/”.$user_username.”/Maildir/.Junk &> /dev/null”,
“maildirmake “.$web_path.”/user/”.$user_username.”/Maildir/.Junk &>
/dev/null”, __LINE__);
“.$web_path.”/user/”.$user_username.”/Maildir/.Sent &> /dev/null”,
“maildirmake “.$web_path.”/user/”.$user_username.”/Maildir/.Sent &>
/dev/null”, __LINE__);
“.$web_path.”/user/”.$user_username.”/Maildir/.Trash &> /dev/null”,
“maildirmake “.$web_path.”/user/”.$user_username.”/Maildir/.Trash &>
/dev/null”, __LINE__);

0700), “create “.$web_path.”/user/”.$user_username.”/Maildir”, $this->FILE,

// ADD: create IMAP subfolders
0700), “create “.$web_path.”/user/”.$user_username.”/Maildir/.Drafts”,
$this->FILE, __LINE__);
0700), “create “.$web_path.”/user/”.$user_username.”/Maildir/.Junk”,
$this->FILE, __LINE__);
0700), “create “.$web_path.”/user/”.$user_username.”/Maildir/.Sent”,
$this->FILE, __LINE__);
0700), “create “.$web_path.”/user/”.$user_username.”/Maildir/.Trash”,
$this->FILE, __LINE__);

exec(“chown -R “.$user_username.”:web”.$web_doc_id.”
exec(“chmod 700 “.$web_path.”/user/”.$user_username.”/Maildir”);

// ADD: create IMAP subfolders
exec(“chown -R “.$user_username.”:web”.$web_doc_id.”
exec(“chmod 700 “.$web_path.”/user/”.$user_username.”/Maildir/.Drafts”);
exec(“chown -R “.$user_username.”:web”.$web_doc_id.”
exec(“chmod 700 “.$web_path.”/user/”.$user_username.”/Maildir/.Junk”);
exec(“chown -R “.$user_username.”:web”.$web_doc_id.”
exec(“chmod 700 “.$web_path.”/user/”.$user_username.”/Maildir/.Sent”);
exec(“chown -R “.$user_username.”:web”.$web_doc_id.”
exec(“chmod 700 “.$web_path.”/user/”.$user_username.”/Maildir/.Trash”);

exec(“rm -f $web_path/Maildir &> /dev/null”);

$web_path.”/Maildir”), “symlink “.$web_path.”/Maildir”, $this->FILE,
(around line 300)

$mod->tpl->define( array(table => “spamassassin.rc.master”));

if(!isset($user[“spam_strategy”])) $user[“spam_strategy”] = “accept”;

if($user[“spam_strategy”] == “accept”){
$spam_comment = “#”;
$spam_command = “.Junk/”;
} else {
$spam_comment = “”;
if($user[“spam_strategy”] == “discard”){
$spam_command = “/dev/null”;
} else {
$spam_command = “.Junk/”;
(around line 330)
@@ -302,6 +333,7 @@
// Variablen zuweisen
$mod->tpl->assign( array(PREFS_FILE =>
SPAM_COMMENT => $spam_comment,
SPAM_COMMAND => $spam_command,
SPAMASSASSIN_PATH => $spamassassin_path,

This adds core functionality. The change adds users standard Maildir mailboxes like Trash, Sent, Junk and Drafts every time a mailuser is created, so we can move spam into the correpsonding junk folder.

Find and add the move string throughout the next files like shown:

vi /home/admispconfig/ispconfig/lib/classes/ispconfig_isp_user.lib.php
(around line 102)

$doc->deck[1]->elements[11]->visible = 0;
$doc->deck[2]->elements[2]->values[“accept”] =
$doc->deck[2]->elements[2]->values[“move”] =
$doc->deck[2]->elements[2]->values[“discard”] =
vi /home/admispconfig/ispconfig/web/mailuser/mail/table/user.table.php
(around line 135)

=> “”,
=> “”,
=> array( “accept” => $app->lng(“txt_accept”),

“move” =>

“discard” =>

$table[‘spam_hits’] = array(‘datatype’ => “VARCHAR”,
vi /home/admispconfig/ispconfig/web/mailuser/lib/lang/.lng
(example for en.lng, around line 33)

$wb[“txt_accept”] = “accept”;
$wb[“txt_move”] = “move”;
$wb[“txt_discard”] = “discard”;
vi /home/admispconfig/ispconfig/web/isp_manager/lib/lang/.lng
(example for en.lng, around line 268 and line 452)

$wb[“Spamfilter”] = ‘Spamfilter’;
$wb[“Antivirus”] = ‘Antivirus’;
$wb[“accept”] = ‘accept’;
$wb[“move”] = ‘move’;
$wb[“discard”] = ‘discard’;
$wb[“Spam Strategie”] = ‘Spam Strategy’;
$wb[“Spam Hits”] = ‘Spam Hits’;
$wb[“Keine Vorlage verwenden”] = “Individual Settings”;
$wb[“Keine Vorlage vorhanden”] = “No Hostingplan Available”;
$wb[“txt_accept”] = “accept”;
$wb[“txt_move”] = “move”;
$wb[“txt_discard”] = “discard”;
$wb[“Eigenschaften”] = “Properties”;
$wb[“ISP Datenbank”] = “ISP Database”;

vi /home/admispconfig/ispconfig/web/isp_kunde/lib/lang/.lng

(example for en.lng, around line 268 and line 449)

 $wb["Spamfilter"] = 'Spamfilter';
 $wb["Antivirus"] = 'Antivirus';
 $wb["accept"] = 'accept';
 $wb["move"] = 'move';
 $wb["discard"] = 'discard';
 $wb["Spam Strategie"] = 'Spam Strategy';
 $wb["Spam Hits"] = 'Spam Hits';
 $wb["Keine Vorlage verwenden"] = "Individual Settings";
 $wb["Keine Vorlage vorhanden"] = "No Hostingplan Available";
 $wb["txt_accept"] = "accept";
 $wb["txt_move"] = "move";
 $wb["txt_discard"] = "discard";
 $wb["Eigenschaften"] = "Properties";
 $wb["ISP Datenbank"] = "ISP Database";


The last three changes you have to do per language file or your interface will just show move instead of the corresponding term in your language. The three example snippets are from the en.lng files in those directories, edit other languages the same way (insert the move entries between the others).

Step 3 – Create Customized Templates

Now change to the /root/ispconfig/isp/conf directory and create a custom copy of spamassassin.rc.master:

cd /root/ispconfig/isp/conf
cp -pr spamassassin.rc.master ./customized_templates/ cd customized_templates

Now edit the custom template to reflect the needed changes:

# All mail tagged as spam (eg. with a score higher than the set threshold)
# is moved to "/dev/null".
{SPAM_COMMENT}* ^X-Spam-Status: Yes

Step 4 (optional) – Implement Cleaning of your trash and spam folders

This has already been adressed by MuisjeNL in the following HowTo: Automatic Cleaning Of Trash And/Or Junk Folders With ISPConfig (With Roundcube + Tmpreaper / Tmpwatch)

Step 5 (optional) – Implement some userfriendlyness and create status mails

This is under heavy developement as we’re using some pretty hacked perl code at the moment. I’ll try and clean that up or transfer it to a pretty little script.


So now you can add a mailuser (or change an existing) to use the new move method. I tested it with a user getting around 100-200 spam mails a day and changed his strategy to move. With a webmailer like roundcube or by connecting to the mailbox via IMAP I almost had immediate results as the first mails dropped into the junk folder rather than his inbox.

Make sure that you check this before actually running it on production servers.
This tutorials comes with no garantuee whatsoever. Be wise, test it!

As this is the first HowTo on Kreationnext for me (and I’m no native speaker), I hope you’ll have no problems in adapting it to your needs. Have fun with a great Software: ISPConfig!

Jens Groh for SANlutions Ltd.