Adding Anti-Spam

From PMWH2 - PHPMyWebHosting's official wiki
Revision as of 17:24, 13 February 2006 by Chris (talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

This describes howto add global and per domain anti-spam control.

Add SpamAssassin module to PMWH
Add menu entry:

  INSERT INTO `menu` VALUES ('_SA_ANTISPAM', 'act=email&what=sa_antispam', 0, 40, 20, 'N');        

Add the translations (ENGLISH):

  INSERT INTO `translations` VALUES ('english', '_SA_ACCEPTED_LANGUAGES', 'Accepted languages');
  INSERT INTO `translations` VALUES ('english', '_SA_ACCEPTED_LANGUAGES_DESCR', 'This option is used to specify which languages are considered                  
  OK for incoming mail.');
  INSERT INTO `translations` VALUES ('english', '_SA_ACCEPTED_LOCALES', 'Accepted locales');
  INSERT INTO `translations` VALUES ('english', '_SA_ACCEPTED_LOCALES_DESCR', 'This option is used to specify which locales (country codes) are         
  considered OK for incoming mail.');
  INSERT INTO `translations` VALUES ('english', '_SA_ANTISPAM', 'Anti Spam');
  INSERT INTO `translations` VALUES ('english', '_SA_BLACKLIST', 'Blacklist');
  INSERT INTO `translations` VALUES ('english', '_SA_BLACKLIST_DESCR', 'Used to specify addresses which send mail that is often tagged 
  (incorrectly) as non-spam.');
  INSERT INTO `translations` VALUES ('english', '_SA_FOLD_HEADERS', 'Fold headers');
  INSERT INTO `translations` VALUES ('english', '_SA_FOLD_HEADERS_DESCR', 'By default, headers added by SpamAssassin will be whitespace folded. 
  In other words, they will be\r\n broken up into multiple lines instead of one very long one and each other line will have a tabulator                 
  prepended to mark it as a continuation of the preceding one.');
  INSERT INTO `translations` VALUES ('english', '_SA_OVERVIEW', 'Anti Spam overview');
  INSERT INTO `translations` VALUES ('english', '_SA_REWRITE_SUBJECT_DESCR', 'By default, the subject lines of suspected spam will be tagged. 
  This can be enabled here.');
  INSERT INTO `translations` VALUES ('english', '_SA_SAVE_SETTINGS', 'Save Spam settings');
  INSERT INTO `translations` VALUES ('english', '_SA_SPAM_REPORTING', 'Spam report');
  INSERT INTO `translations` VALUES ('english', '_SA_SPAM_REPORTING_DESCR', 'How to display the original e-mail when it is marked as spam.');
  INSERT INTO `translations` VALUES ('english', '_SA_SPAM_SCORE', 'Spam score');
  INSERT INTO `translations` VALUES ('english', '_SA_SPAM_SCORE_DESCR', 'Set the number of hits required before a mail is considered spam.');
  INSERT INTO `translations` VALUES ('english', '_SA_SUBJECT_TAG', 'Spam subject tag');
  INSERT INTO `translations` VALUES ('english', '_SA_SUBJECT_TAG_DESCR', 'Text added to the Subject: line of mails that are considered spam, if 
  rewrite_subject is enabled.');
  INSERT INTO `translations` VALUES ('english', '_SA_USE_BAYESIAN_CLASSIFIER', 'Use Bayesian filter');
  INSERT INTO `translations` VALUES ('english', '_SA_USE_BAYESIAN_CLASSIFIER_DESCR', 'Whether to use the naive-Bayesian-style classifier built 
  into SpamAssassin.');
  INSERT INTO `translations` VALUES ('english', '_SA_WHITELIST', 'Whitelist');
  INSERT INTO `translations` VALUES ('english', '_SA_WHITELIST_DESCR', 'Used to specify addresses which send mail that is often tagged 
  (incorrectly) as spam.');
       

Add the following 3 files to includes/modules/email
- sa_antispam.php
- sa_change_domain.php
- sa_options.php

Add the following file to templates/{your_template}/modules/email
- sa_overview.tpl
- sa_show_domain.tpl

You can change the SpamAssassin options and tablename in sa_options.php.

Default it expects the following table:

   CREATE TABLE userpref (
     username varchar(100) default NOT NULL,
     preference varchar(30) default NOT NULL,
     value varchar(100) default NOT NULL,
     prefid int(11) NOT NULL auto_increment,
     PRIMARY KEY (prefid),
     INDEX (username)
   ) TYPE=MyISAM;

You can download the files sa_module.tar.gz.

Setting up SpamAssassin
Now we have to setup SpamAssassin to use per-user anti-spam settings. Under the documentation of FreeBSD 5.3 you can see how to do this from maildrop.

Run spamd with SQL support. Use the spamd with the following flags:

   /usr/local/bin/spamd -i 127.0.0.1 -u nobody -q -x -c -d -Q -r /var/tmp/spamd.pid

Configure SpamAssassin:

The configuration files with FreeBSD are in /usr/local/etc/mail/spamassassin, in Linux probably in /etc/mail/spamassassin.

Edit local.cf so that it contains:

   rewrite_header Subject *****SPAM*****
   report_safe 0
   add_header all Scanned by YOUR_NAME SPAM Scanner
   trusted_networks 127.0.0.
   lock_method flock
   dns_available yes
   use_bayes 1
   use_razor 1
   use_pyzor 1
   use_dcc 1
   user_scores_dsn DBI:mysql:database_name:localhost:3306
   user_scores_sql_username username
   user_scores_sql_password password
   user_scores_sql_custom_query SELECT preference, value FROM userpref WHERE username = _USERNAME_ OR username = '$GLOBAL' OR username =     
   CONCAT('%',_DOMAIN_) ORDER BY username ASC

Caution: make sure the user_scores_sql_custom_query is on 1 line!

That should be it.

If you have any questions or remarks, please post it on our forum!