Skip to content

Added support for TELL command #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -29,4 +40,3 @@ Cucumber and rspec tests are on their way.
== Copyright

Copyright (c) 2011 Kevin Poorman. See LICENSE.txt for further details.

16 changes: 15 additions & 1 deletion lib/RubySpamAssassin/spam_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Expand Down