Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jreyesr committed Jul 2, 2022
1 parent 2de0776 commit 37a474b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/logstash/inputs/imap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def parse_mail(mail)

@codec.decode(message) do |event|
# Use the 'Date' field as the timestamp
event.timestamp = LogStash::Timestamp.new(mail.date.to_time)
event.timestamp = LogStash::Timestamp.new(mail.date&.to_time)

process_headers(mail, event) if @headers_target

Expand Down
12 changes: 12 additions & 0 deletions spec/inputs/imap_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,18 @@
end
end

context "missing date" do
before do
mail.date = nil
end

it "should not cause an exception" do
event = input.parse_mail(mail)
expect( event.include?('Date') ).to be false
expect( event.timestamp ).not_to be nil
end
end

context "headers_target => ''" do
let(:config) { super().merge("headers_target" => '') }

Expand Down

0 comments on commit 37a474b

Please sign in to comment.