lib/fluent/plugin/out_mail.rb in fluent-plugin-mail-0.1.0 vs lib/fluent/plugin/out_mail.rb in fluent-plugin-mail-0.1.1

- old
+ new

@@ -29,10 +29,11 @@ def initialize super require 'net/smtp' require 'kconv' + require 'string/scrub' if RUBY_VERSION.to_f < 2.1 end def configure(conf) super @@ -134,10 +135,22 @@ else record[key].to_s end end - (@message % values).gsub(/\\n/, "\n") + message = (@message % values) + with_scrub(message) {|str| str.gsub(/\\n/, "\n") } + end + + def with_scrub(string) + begin + return yield(string) + rescue ArgumentError => e + raise e unless e.message.index("invalid byte sequence in") == 0 + log.info "out_mail: invalid byte sequence is replaced in #{string}" + string.scrub!('?') + retry + end end def create_formatted_subject(tag, time, record) values = []