mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 14:47:19 -04:00
Merge pull request #790 from bfritz/imap-decode-header-values
[imap] decode header values in RFC 2047 encoded-word format
This commit is contained in:
commit
b43b3af480
2 changed files with 18 additions and 3 deletions
|
@ -105,9 +105,11 @@ class LogStash::Inputs::IMAP < LogStash::Inputs::Base
|
||||||
else
|
else
|
||||||
name = header.name.to_s
|
name = header.name.to_s
|
||||||
end
|
end
|
||||||
# Call .to_s on the value just in case it's some weird Mail:: object
|
# Call .decoded on the header in case it's in encoded-word form.
|
||||||
# thing.
|
# Details at:
|
||||||
value = header.value.to_s
|
# https://github.com/mikel/mail/blob/master/README.md#encodings
|
||||||
|
# http://tools.ietf.org/html/rfc2047#section-2
|
||||||
|
value = header.decoded
|
||||||
|
|
||||||
# Assume we already processed the 'date' above.
|
# Assume we already processed the 'date' above.
|
||||||
next if name == "Date"
|
next if name == "Date"
|
||||||
|
|
|
@ -44,4 +44,17 @@ describe LogStash::Inputs::IMAP do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "when subject is in RFC 2047 encoded-word format" do
|
||||||
|
it "should be decoded" do
|
||||||
|
msg.subject = "=?iso-8859-1?Q?foo_:_bar?="
|
||||||
|
config = {"type" => "imap", "host" => "localhost",
|
||||||
|
"user" => "#{user}", "password" => "#{password}"}
|
||||||
|
|
||||||
|
input = LogStash::Inputs::IMAP.new config
|
||||||
|
input.register
|
||||||
|
event = input.parse_mail(msg)
|
||||||
|
insist { event["subject"] } == "foo : bar"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue