Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

fix handling of more than 2 repetitions of same mail header #1144

Merged
merged 1 commit into from

3 participants

@colinsurprenant

No description provided.

@electrical
Owner

LGTM

@jordansissel jordansissel commented on the diff
lib/logstash/inputs/imap.rb
@@ -118,7 +118,7 @@ def parse_mail(mail)
# promote string to array if a header appears multiple times
# (like 'received')
when String; event[name] = [event[name], value]
- when Array; event[name].is_a?(Array)
+ when Array; event[name] << value
@jordansissel Owner

oof I just realized.

This should be += value, not << value.

@jordansissel Owner

Ignore me, I totally misread the code here. This looks correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@jordansissel jordansissel merged commit 5ed9c5e into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 27 additions and 1 deletion.
  1. +1 −1  lib/logstash/inputs/imap.rb
  2. +26 −0 spec/inputs/imap.rb
View
2  lib/logstash/inputs/imap.rb
@@ -118,7 +118,7 @@ def parse_mail(mail)
# promote string to array if a header appears multiple times
# (like 'received')
when String; event[name] = [event[name], value]
- when Array; event[name].is_a?(Array)
+ when Array; event[name] << value
@jordansissel Owner

oof I just realized.

This should be += value, not << value.

@jordansissel Owner

Ignore me, I totally misread the code here. This looks correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
when nil; event[name] = value
end
end # mail.header_fields.each
View
26 spec/inputs/imap.rb
@@ -57,4 +57,30 @@
end
end
+ context "with multiple values for same header" do
+ it "should add 2 values as array in event" do
+ msg.received = "test1"
+ msg.received = "test2"
+
+ config = {"type" => "imap", "host" => "localhost",
+ "user" => "#{user}", "password" => "#{password}"}
+
+ input = LogStash::Inputs::IMAP.new config
+ input.register
+ event = input.parse_mail(msg)
+ insist { event["received"] } == ["test1", "test2"]
+ end
+
+ it "should add more than 2 values as array in event" do
+ msg.received = "test3"
+
+ config = {"type" => "imap", "host" => "localhost",
+ "user" => "#{user}", "password" => "#{password}"}
+
+ input = LogStash::Inputs::IMAP.new config
+ input.register
+ event = input.parse_mail(msg)
+ insist { event["received"] } == ["test1", "test2", "test3"]
+ end
+ end
end
Something went wrong with that request. Please try again.