lib/fluent/plugin/out_mail.rb in fluent-plugin-mail-0.0.2 vs lib/fluent/plugin/out_mail.rb in fluent-plugin-mail-0.0.3

- old
+ new

@@ -12,13 +12,16 @@ config_param :domain, :string, :default => 'localdomain' config_param :user, :string, :default => nil config_param :password, :string, :default => nil config_param :from, :string, :default => 'localhost@localdomain' config_param :to, :string, :default => '' + config_param :cc, :string, :default => '' + config_param :bcc, :string, :default => '' config_param :subject, :string, :default => 'Fluent::MailOutput plugin' config_param :subject_out_keys, :string, :default => "" config_param :enable_starttls_auto, :bool, :default => false + config_param :time_locale, :default => nil def initialize super require 'net/smtp' require 'kconv' @@ -159,20 +162,40 @@ end subject = subject.force_encoding('binary') body = msg.force_encoding('binary') - smtp.send_mail(<<EOS, @from, @to.split(/,/)) -Date: #{Time::now.strftime("%a, %d %b %Y %X")} + if time_local + date = Time::now.timezone(time_local) + else + date = Time::now + end + + smtp.send_mail(<<EOS, @from, @to.split(/,/), @cc.split(/,/), @bcc.split(/,/)) +Date: #{date.strftime("%a, %d %b %Y %X %z")} From: #{@from} To: #{@to} +Cc: #{@cc} +Bcc: #{@bcc} Subject: #{subject} Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 #{body} EOS smtp.finish end end + +class Time + def timezone(timezone = 'UTC') + old = ENV['TZ'] + utc = self.dup.utc + ENV['TZ'] = timezone + output = utc.localtime + ENV['TZ'] = old + output + end +end +