local0.warn と言われてたのに、local1.warn で出してました。 そりゃ届かんはずですよ。まぁ届いたら届いたでまずいことになってたんですが。 もう一回行っとかないとダメな予感。
なんとなく Rails っぽく書くとこんな感じなのかなぁ。
== init.rb ==
require "converter"
ActionMailer::Base.class_eval do
include ActionMailer::Converter
end
== lib/converter.rb ==
module ActionMailer
module Converter
def self.append_features(base)
super
base.extend(ClassMethods)
base.send(:include, InstanceMethods)
end
module ClassMethods
def converters
@converters ||= []
end
def converter(*converter)
converters.concat(converter.flatten)
end
end
module InstanceMethods
def self.append_features(base)
super
base.class_eval do
alias_method :create_mail_without_convert, :create_mail
alias_method :create_mail, :create_mail_with_convert
end
end
def create_mail_with_convert
create_mail_without_convert
self.class.converters.each do |converter|
send(converter)
end
@mail
end
end
end
end
class Mail < ActionMailer::Base
converter :convert_subject, :convert_body
def mail
from "nov@example.jp"
subject "サブジェクト"
recipients "nov@example.com"
sent_on Time.now
end
private
def convert_subject
@mail.subject = NKF.nkf("-j", @mail.subject)
end
def convert_body
if @mail.multipart?
body = @mail.parts.find{|part| part.content_type == "text/plain"}
else
body = @mail.content_type == "text/plain" ? @mail : nil
end
if body
body.body = NKF.nkf("-j", body.body)
body.set_content_type("text", "plain", "charset" => "iso-2022-jp")
body.content_transfer_encoding = "7bit"
end
end
end
とか?結局全部書かないとダメなので、あんまりうれしくないなぁ。
とりあえず再発明再確認ということで。