lib/logstash/inputs/imap.rb in logstash-input-imap-3.0.1 vs lib/logstash/inputs/imap.rb in logstash-input-imap-3.0.2

- old
+ new

@@ -25,11 +25,13 @@ config :folder, :validate => :string, :default => 'INBOX' config :fetch_count, :validate => :number, :default => 50 config :lowercase_headers, :validate => :boolean, :default => true config :check_interval, :validate => :number, :default => 300 config :delete, :validate => :boolean, :default => false - + config :expunge, :validate => :boolean, :default => false + config :strip_attachments, :validate => :boolean, :default => false + # For multipart messages, use the first part that has this # content-type as the event message. config :content_type, :validate => :string, :default => "text/plain" def register @@ -78,13 +80,26 @@ ids.each_slice(@fetch_count) do |id_set| items = imap.fetch(id_set, "RFC822") items.each do |item| next unless item.attr.has_key?("RFC822") mail = Mail.read_from_string(item.attr["RFC822"]) - queue << parse_mail(mail) + if @strip_attachments + queue << parse_mail(mail.without_attachments!) + else + queue << parse_mail(mail) + end end imap.store(id_set, '+FLAGS', @delete ? :Deleted : :Seen) + + end + + # Enable an 'expunge' IMAP command after the items.each loop + if @expunge + # Force messages to be marked as "Deleted", the above may or may not be working as expected. "Seen" means nothing if you are going to + # delete a message after processing. + imap.store(id_set, '+FLAGS', [:Deleted]) + imap.expunge() end imap.close imap.disconnect end