Skip to content

Fixes LOGSTASH-2245 #7

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: main
Choose a base branch
from
Open
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
16 changes: 12 additions & 4 deletions lib/logstash/inputs/imap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,14 @@ def parse_mail(mail)
# No multipart message, just use the body as the event text
message = mail.body.decoded
else
# Multipart message; use the first text/plain part we find
part = mail.parts.find { |p| p.content_type.match @content_type_re } || mail.parts.first
if mail.parts.map { |p| p.content_type.match Regexp.new("^multipart/alternative") }
part = mail.html_part || mail.text_part
else
part = mail.parts.map { |p| p.content_type.match @content_type_re } || mail.parts.map { |p| p.content_type.match Regexp.new("^text/plain") } || mail.parts.first
end

message = part.decoded
end
end || mi

@codec.decode(message) do |event|
# event = LogStash::Event.new("message" => message)
Expand All @@ -123,7 +127,11 @@ def parse_mail(mail)
# Details at:
# https://github.com/mikel/mail/blob/master/README.md#encodings
# http://tools.ietf.org/html/rfc2047#section-2
value = transcode_to_utf8(header.decoded.to_s)
if header.decoded != nil
value = transcode_to_utf8(header.decoded.to_s)
else
value = false
end

# Assume we already processed the 'date' above.
next if name == "Date"
Expand Down