Skip to content
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
2 changes: 1 addition & 1 deletion lib/RubySpamAssassin/report_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class RubySpamAssassin::ReportParser
def self.parse(report_text)
last_part = report_text.split(LINE_REGEXP)[1].sub(/^[\n\r]/,'').chomp.chomp
pts_rules = last_part.gsub(RULE_REGEXP).collect { |sub| sub.chomp(' ') }
rule_texts = last_part.split(RULE_REGEXP).collect { |text| text.delete("\n").squeeze.chomp(' ').sub(/^\s/, '') }
rule_texts = last_part.split(RULE_REGEXP).collect { |text| text.delete("\n").squeeze(' ').strip }

rules = []
pts_rules.each_with_index do |pts_rule, i|
Expand Down
14 changes: 9 additions & 5 deletions spec/RubySpamAssassin/report_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@
it "should parse the report text into an informative hash" do
spam = File.read('spec/data/spam_test1.txt')
result = RubySpamAssassin::ReportParser.parse(spam)
result.length.equal?(6)
expect(result.length).to eq(6)

# Check contents of first one to make sure text/points are formatted correctly
result[0][:pts].equal?(0.5)
result[0][:rule].equal?('DATE_IN_PAST_24_48')
result[0][:text].equal?('Date: is 24 to 48 hours before Received: date')
# Check contents of some rules to make sure text/points are formatted correctly
expect(result[0][:pts]).to eq(0.5)
expect(result[0][:rule]).to eq('DATE_IN_PAST_24_48')
expect(result[0][:text]).to eq('Date: is 24 to 48 hours before Received: date')

expect(result[4][:pts]).to eq(1.2)
expect(result[4][:rule]).to eq('INVALID_MSGID')
expect(result[4][:text]).to eq('Message-Id is not valid, according to RFC 2822')
end
end