diff --git a/README.rdoc b/README.rdoc index 7763315..28ce115 100644 --- a/README.rdoc +++ b/README.rdoc @@ -7,15 +7,26 @@ Now you just need to: include RubySpamAssassin spam_client = SpamClient.new("host_running_spamd", "port_spamd_is_listening_on", timeout) - # MyMailer is your ActionMailer - # check will also accept a string, if you're into that kind of thing - report = spam_client.check(MyMailer.my_email.to_s) + message = File.read("/path/to/email.eml") + + report = spam_client.check(message) p report.inspect Wasn't that easy? Cucumber and rspec tests are on their way. +== Using TELL command + +To learn a message as spam: + spam_client.tell(message, message_class: "spam", set: "local") +To learn a message as ham: + spam_client.tell(message, message_class: "ham", set: "local") +To forget a learned message: + spam_client.tell(message, remove: "local") +You can also set username of the user on whose behalf this scan is being performed: + spam_client.tell(message, message_class: "spam", set: "local", user: "johndoe") + == Contributing to RubySpamAssassin * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet @@ -29,4 +40,3 @@ Cucumber and rspec tests are on their way. == Copyright Copyright (c) 2011 Kevin Poorman. See LICENSE.txt for further details. - diff --git a/lib/RubySpamAssassin/spam_client.rb b/lib/RubySpamAssassin/spam_client.rb index 3571408..f10ffde 100644 --- a/lib/RubySpamAssassin/spam_client.rb +++ b/lib/RubySpamAssassin/spam_client.rb @@ -17,6 +17,16 @@ def check(message) result = process_headers protocol_response[0...2] end + def tell(message, headers={}) + h = [] + h << "Message-class: #{headers[:message_class]}" if headers[:message_class] + h << "Set: #{headers[:set]}" if headers[:set] + h << "Remove: #{headers[:remove]}" if headers[:remove] + h << "User: #{headers[:user]}" if headers[:user] + protocol_response = send_message("TELL", message, h) + result = process_headers protocol_response[0...2] + end + def report(message) protocol_response = send_message("REPORT", message) result = process_headers protocol_response[0...2] @@ -41,10 +51,14 @@ def ping alias :process :report private - def send_message(command, message = "") + + def send_message(command, message="", headers=[]) length = message.bytesize @connection_pool.with do |socket| socket.write(command + " SPAMC/1.2\r\n") + headers.each do |h| + socket.write(h + "\r\n") + end socket.write("Content-length: " + length.to_s + "\r\n\r\n") socket.write(message) socket.shutdown(1) #have to shutdown sending side to get response