プロジェクト

全般

プロフィール

ベイジアンフィルタ(ベイズ推定学習フィルタ)

ベイジアンフィルタは、スパムメールをspam/hamに分類してスパム傾向をスコアで判断する
フィルタです。

が、日本語などの要デコード文字列に対応しておらず、各種エンコード状態の文字列で判断
するしかないため、英語環境以外での効果はいま一つとなります。

逆に言うと(ある程度エンコード状態でも傾向は測れるとはいえ)正常に判断していない以上
誤検知のリスクもあるため、ここでは設定箇所を説明しつつ無効化していることを確認します。

設定(無効化の確認)

  • 要件
    ベイジアンフィルタにはRedisが必要になりますが、そのほかの機能でも使用するためベイジアン
    フィルタを使わない場合でもRedisは導入したままであることが望ましいです。
  • 設定箇所
    デフォルトでは以下のファイルで定義されています。
    # less /etc/rspamd/statistic.conf
    --------------------
    …(中略)…
    
    classifier "bayes" {
      # name = "custom";  # 'name' parameter must be set if multiple classifiers are defined
      tokenizer {
        name = "osb";
      }
      cache {
      }
      new_schema = true; # Always use new schema
      store_tokens = false; # Redefine if storing of tokens is desired
      signatures = false; # Store learn signatures
      #per_user = true; # Enable per user classifier
      min_tokens = 11;
      backend = "redis";
      min_learns = 200;
    
      statfile {
        symbol = "BAYES_HAM";
        spam = false;
      }
      statfile {
        symbol = "BAYES_SPAM";
        spam = true;
      }
      learn_condition = 'return require("lua_bayes_learn").can_learn';
    
      # Autolearn sample
      # autolearn {
      #  spam_threshold = 6.0; # When to learn spam (score >= threshold and action is reject)
      #  junk_threshold = 4.0; # When to learn spam (score >= threshold and action is rewrite subject or add header, and has two or more positive results)
      #  ham_threshold = -0.5; # When to learn ham (score <= threshold and action is no action, and score is negative or has three or more negative results)
      #  check_balance = true; # Check spam and ham balance
      #  min_balance = 0.9; # Keep diff for spam/ham learns for at least this value
      #}
    
      .include(try=true; priority=1) "$LOCAL_CONFDIR/local.d/classifier-bayes.conf" 
      .include(try=true; priority=10) "$LOCAL_CONFDIR/override.d/classifier-bayes.conf" 
    }
    
    …(中略)…
    

    自動学習となる「autolearn {}」はコメントアウトされています。つまり、定義されている
    spam/hamフォルダにメーラまたはWebUIで手動投入しなければ学習を行いません。
  • 設定変更箇所
    設定を追加する場合は「/etc/rspamd/local.d/statistic.conf」、よりプライオリティを高く
    設定を上書きする場合は「/etc/rspamd/override.d/statistic.conf」に同構造で設定を記載
    します。
    # vi /etc/rspamd/local.d/statistic.conf
    または
    # vi /etc/rspamd/override.d/statistic.conf
    
    • 注意
      WebUIで設定した場合はDBの値としてこれらの設定ファイルをさらにオーバーライドしてしまうので注意。
  • 完全に無効化する場合
    「min_learns」以上の数を学習していなければフィルタを実行しないので、自動学習を設定せずにこの数を
    引き上げるとフィルタは動作しません。
  • サービスを再読み込みします。
    # systemctl restart rspamd
    

手動学習

  • メーラで学習
    • spamの場合
      「BAYES_SPAM」フォルダにメールを投入、学習すると消えます
    • hamの場合
      「BAYES_HAM」フォルダにメールを投入、学習すると消えます
  • コマンドで学習
    • spamの場合
      # rspamc learn_spam < メールファイル.eml
      
    • hamの場合
      # rspamc learn_ham < メールファイル.eml
      
  • 学習状況の確認
    # rspamc stat