ISPConfig 2.x: How To Add A "Move to SPAM"-Option To Your ISPConfig Installation
|
Submitted by Grey (Contact Author) (Forums) on Mon, 2008-09-22 18:18. :: Anti-Spam/Virus | Linux | Control Panels | Email
ISPConfig 2.x: How To Add a "Move to SPAM"-Option To Your ISPConfig Installation
Version 1.0b Overview: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' (http://www.howtoforge.com/forums/showthread.php?t=15704) 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. Prerequisites:In this howto I will assume you are using the following or a similar configuration:
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. accept,accept; move,move; discard,discard;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 FilesNow 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):
if(!is_dir($web_path."/user/".$user_username."/Maildir"))
$mod->log->caselog("maildirmake
".$web_path."/user/".$user_username."/Maildir &> /dev/null", "maildirmake
".$web_path."/user/".$user_username."/Maildir &> /dev/null", __LINE__);
// ADD: create IMAP subfolders
if(!is_dir($web_path."/user/".$user_username."/Maildir/.Drafts"))
$mod->log->caselog("maildirmake
".$web_path."/user/".$user_username."/Maildir/.Drafts &> /dev/null",
"maildirmake ".$web_path."/user/".$user_username."/Maildir/.Drafts &>
/dev/null", __LINE__);
if(!is_dir($web_path."/user/".$user_username."/Maildir/.Junk"))
$mod->log->caselog("maildirmake
".$web_path."/user/".$user_username."/Maildir/.Junk &> /dev/null",
"maildirmake ".$web_path."/user/".$user_username."/Maildir/.Junk &>
/dev/null", __LINE__);
if(!is_dir($web_path."/user/".$user_username."/Maildir/.Sent"))
$mod->log->caselog("maildirmake
".$web_path."/user/".$user_username."/Maildir/.Sent &> /dev/null",
"maildirmake ".$web_path."/user/".$user_username."/Maildir/.Sent &>
/dev/null", __LINE__);
if(!is_dir($web_path."/user/".$user_username."/Maildir/.Trash"))
$mod->log->caselog("maildirmake
".$web_path."/user/".$user_username."/Maildir/.Trash &> /dev/null",
"maildirmake ".$web_path."/user/".$user_username."/Maildir/.Trash &>
/dev/null", __LINE__);
if(!is_dir($web_path."/user/".$user_username."/Maildir"))
$mod->log->phpcaselog(mkdir($web_path."/user/".$user_username."/Maildir",
0700), "create ".$web_path."/user/".$user_username."/Maildir", $this->FILE,
__LINE__);
// ADD: create IMAP subfolders
if(!is_dir($web_path."/user/".$user_username."/Maildir/.Drafts"))
$mod->log->phpcaselog(mkdir($web_path."/user/".$user_username."/Maildir/.Drafts",
0700), "create ".$web_path."/user/".$user_username."/Maildir/.Drafts",
$this->FILE, __LINE__);
if(!is_dir($web_path."/user/".$user_username."/Maildir/.Junk"))
$mod->log->phpcaselog(mkdir($web_path."/user/".$user_username."/Maildir/.Junk",
0700), "create ".$web_path."/user/".$user_username."/Maildir/.Junk",
$this->FILE, __LINE__);
if(!is_dir($web_path."/user/".$user_username."/Maildir/.Sent"))
$mod->log->phpcaselog(mkdir($web_path."/user/".$user_username."/Maildir/.Sent",
0700), "create ".$web_path."/user/".$user_username."/Maildir/.Sent",
$this->FILE, __LINE__);
if(!is_dir($web_path."/user/".$user_username."/Maildir/.Trash"))
$mod->log->phpcaselog(mkdir($web_path."/user/".$user_username."/Maildir/.Trash",
0700), "create ".$web_path."/user/".$user_username."/Maildir/.Trash",
$this->FILE, __LINE__);
exec("chown -R ".$user_username.":web".$web_doc_id."
".$web_path."/user/".$user_username."/Maildir");
exec("chmod 700 ".$web_path."/user/".$user_username."/Maildir");
// ADD: create IMAP subfolders
exec("chown -R ".$user_username.":web".$web_doc_id."
".$web_path."/user/".$user_username."/Maildir/.Drafts");
exec("chmod 700 ".$web_path."/user/".$user_username."/Maildir/.Drafts");
exec("chown -R ".$user_username.":web".$web_doc_id."
".$web_path."/user/".$user_username."/Maildir/.Junk");
exec("chmod 700 ".$web_path."/user/".$user_username."/Maildir/.Junk");
exec("chown -R ".$user_username.":web".$web_doc_id."
".$web_path."/user/".$user_username."/Maildir/.Sent");
exec("chmod 700 ".$web_path."/user/".$user_username."/Maildir/.Sent");
exec("chown -R ".$user_username.":web".$web_doc_id."
".$web_path."/user/".$user_username."/Maildir/.Trash");
exec("chmod 700 ".$web_path."/user/".$user_username."/Maildir/.Trash");
if($user["user_admin"]){
exec("rm -f $web_path/Maildir &> /dev/null");
$mod->log->phpcaselog(@symlink($web_path."/user/".$user_username."/Maildir",
$web_path."/Maildir"), "symlink ".$web_path."/Maildir", $this->FILE,
__LINE__);
(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)
if(is_file('/home/admispconfig/ispconfig/tools/spamassassin/usr/local/bin/spamassassin')){
@@ -302,6 +333,7 @@
// Variablen zuweisen
$mod->tpl->assign( array(PREFS_FILE =>
$web_path."/user/".$user_username."/.user_prefs",
SPAM_COMMENT => $spam_comment,
SPAM_COMMAND => $spam_command,
SPAMASSASSIN_PATH => $spamassassin_path,
USERNAME =>
$user_username));
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"] =
$go_api->lng("txt_accept");
$doc->deck[2]->elements[2]->values["move"] =
$go_api->lng("txt_move");
$doc->deck[2]->elements[2]->values["discard"] =
$go_api->lng("txt_discard");
}
vi /home/admispconfig/ispconfig/web/mailuser/mail/table/user.table.php (around line 135)
'regex'
=> "",
'errmsg'
=> "",
'value'
=> array( "accept" => $app->lng("txt_accept"),
"move" =>
$app->lng("txt_move"),
"discard" =>
$app->lng("txt_discard")));
$table['spam_hits'] = array('datatype' => "VARCHAR",
vi
/home/admispconfig/ispconfig/web/mailuser/lib/lang/ $wb["txt_accept"] = "accept"; $wb["txt_move"] = "move"; $wb["txt_discard"] = "discard"; vi
/home/admispconfig/ispconfig/web/isp_manager/lib/lang/ $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/ $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 TemplatesNow change to the /root/ispconfig/isp/conf directory and create a custom copy of spamassassin.rc.master:
cd /root/ispconfig/isp/conf 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}:0:
{SPAM_COMMENT}* ^X-Spam-Status: Yes
{SPAM_COMMENT}{SPAM_COMMAND}
Step 4 (optional) - Implement Cleaning of your trash and spam foldersThis 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 mailsThis 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. Conclusion
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. As this is the first HowTo on HowtoForge 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.
|






Recent comments
11 min 28 sec ago
1 hour 26 min ago
2 hours 8 min ago
2 hours 36 min ago
10 hours 3 min ago
13 hours 33 min ago
16 hours 23 min ago
20 hours 59 min ago
21 hours 39 min ago
23 hours 17 min ago