forked from elastic/logstash
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[imap] configurable content-type selection for multipart messages
User can now select which content-type in multipart messages should be used as the event message. Default behavior for multipart messages is still to select first part with text/plain content-type.
- Loading branch information
Showing
2 changed files
with
54 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
require "logstash/inputs/imap" | ||
require "mail" | ||
|
||
describe LogStash::Inputs::IMAP do | ||
user = "logstash" | ||
password = "secret" | ||
msg_time = Time.new | ||
msg_text = "foo\nbar\nbaz" | ||
msg_html = "<p>a paragraph</p>\n\n" | ||
|
||
msg = Mail.new do | ||
from "[email protected]" | ||
to "[email protected]" | ||
subject "logstash imap input test" | ||
date msg_time | ||
body msg_text | ||
add_file :filename => "some.html", :content => msg_html | ||
end | ||
|
||
context "with both text and html parts" do | ||
context "when no content-type selected" do | ||
it "should select text/plain part" do | ||
config = {"type" => "imap", "host" => "localhost", | ||
"user" => "#{user}", "password" => "#{password}"} | ||
|
||
input = LogStash::Inputs::IMAP.new config | ||
input.register | ||
event = input.parse_mail(msg) | ||
insist { event["message"] } == msg_text | ||
end | ||
end | ||
|
||
context "when text/html content-type selected" do | ||
it "should select text/html part" do | ||
config = {"type" => "imap", "host" => "localhost", | ||
"user" => "#{user}", "password" => "#{password}", | ||
"content_type" => "text/html"} | ||
|
||
input = LogStash::Inputs::IMAP.new config | ||
input.register | ||
event = input.parse_mail(msg) | ||
insist { event["message"] } == msg_html | ||
end | ||
end | ||
end | ||
|
||
end |