Created
April 19, 2011 13:19
-
-
Save arika/927633 to your computer and use it in GitHub Desktop.
milter-bsfilter.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # メモ: | |
| # * libmilter-client-ruby1.8_1.6.7-1を前提に作成。 | |
| # * ごく簡単に動作確認をした。 | |
| # * 実際には使用していない。 | |
| require 'tempfile' | |
| require 'milter/client' | |
| load '/usr/bin/bsfilter' | |
| class Bsfilter | |
| attr_accessor :milter | |
| def insert_header!(buf, header, content) | |
| @milter.instance_eval do | |
| add_header header, content | |
| end | |
| end | |
| end | |
| class MilterBsfilter < Milter::ClientSession | |
| def initialize(context, opts) | |
| super(context) | |
| @bsfilter_opts = opts | |
| @bsfilter_probability = nil | |
| @tempfile = Tempfile.new("milter-bsfilter.") | |
| end | |
| attr_accessor :bsfilter_probability | |
| def header(name, value) | |
| @tempfile.print "#{name}: #{value}\n" | |
| end | |
| def end_of_header | |
| @tempfile.print "\n\n" | |
| end | |
| def body(chunk) | |
| @tempfile.print chunk | |
| end | |
| def end_of_message | |
| @tempfile.close | |
| bsfilter = Bsfilter.new | |
| bsfilter.setup(@bsfilter_opts) | |
| bsfilter.milter = self | |
| bsfilter.run(@tempfile.path) | |
| if bsfilter.token_dbs.last.probability >= 1.0 | |
| #reject | |
| end | |
| end | |
| end | |
| opts = [ | |
| '--insert-revision', | |
| '--insert-flag', | |
| '--insert-probability', | |
| '--header-prefix', 'Bsfilter', | |
| '--quiet', | |
| ] | |
| command_line = Milter::Client::CommandLine.new | |
| command_line.run do |client, _options| | |
| client.register(MilterBsfilter, opts) | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment