akishin999の日記

調べた事などを書いて行きます。

tmail-1.2.7 で Encoding::CompatibilityError

Ruby 1.9.3 で Rails 2.3.12 アプリケーションを動かしてみたところ、iso-2022-jp でメールを送信している箇所で以下のようなエラーが発生しました。

incompatible encoding regexp match (ASCII-8BIT regexp with ISO-2022-JP string)
  /var/rails_apps/example_app/vendor/rails/actionmailer/lib/action_mailer/vendor/tmail-1.2.7/tmail/encode.rb:319:in `==='
  /var/rails_apps/example_app/vendor/rails/actionmailer/lib/action_mailer/vendor/tmail-1.2.7/tmail/encode.rb:319:in `phrase'
  /var/rails_apps/example_app/vendor/rails/actionmailer/lib/action_mailer/vendor/tmail-1.2.7/tmail/address.rb:277:in `accept'
  /var/rails_apps/example_app/vendor/rails/actionmailer/lib/action_mailer/vendor/tmail-1.2.7/tmail/header.rb:322:in `block in do_accept'
  /var/rails_apps/example_app/vendor/rails/actionmailer/lib/action_mailer/vendor/tmail-1.2.7/tmail/header.rb:315:in `each'
  /var/rails_apps/example_app/vendor/rails/actionmailer/lib/action_mailer/vendor/tmail-1.2.7/tmail/header.rb:315:in `do_accept'
  /var/rails_apps/example_app/vendor/rails/actionmailer/lib/action_mailer/vendor/tmail-1.2.7/tmail/header.rb:165:in `accept'
  /var/rails_apps/example_app/vendor/rails/actionmailer/lib/action_mailer/vendor/tmail-1.2.7/tmail/mail.rb:174:in `block (2 levels) in accept'
  /var/rails_apps/example_app/vendor/rails/actionmailer/lib/action_mailer/vendor/tmail-1.2.7/tmail/mail.rb:344:in `block (2 levels) in ordered_each'
  /var/rails_apps/example_app/vendor/rails/actionmailer/lib/action_mailer/vendor/tmail-1.2.7/tmail/mail.rb:344:in `each'
  /var/rails_apps/example_app/vendor/rails/actionmailer/lib/action_mailer/vendor/tmail-1.2.7/tmail/mail.rb:344:in `block in ordered_each'
  /var/rails_apps/example_app/vendor/rails/actionmailer/lib/action_mailer/vendor/tmail-1.2.7/tmail/mail.rb:342:in `each'
  /var/rails_apps/example_app/vendor/rails/actionmailer/lib/action_mailer/vendor/tmail-1.2.7/tmail/mail.rb:342:in `ordered_each'
  /var/rails_apps/example_app/vendor/rails/actionmailer/lib/action_mailer/vendor/tmail-1.2.7/tmail/mail.rb:171:in `block in accept'
  /var/rails_apps/example_app/vendor/rails/actionmailer/lib/action_mailer/vendor/tmail-1.2.7/tmail/mail.rb:192:in `with_multipart_encoding'
  /var/rails_apps/example_app/vendor/rails/actionmailer/lib/action_mailer/vendor/tmail-1.2.7/tmail/mail.rb:170:in `accept'
  /var/rails_apps/example_app/vendor/rails/actionmailer/lib/action_mailer/vendor/tmail-1.2.7/tmail/encode.rb:98:in `accept_strategy'
  /var/rails_apps/example_app/vendor/rails/actionmailer/lib/action_mailer/vendor/tmail-1.2.7/tmail/encode.rb:74:in `encoded'
  /var/rails_apps/example_app/vendor/rails/actionmailer/lib/action_mailer/base.rb:552:in `deliver!'
  /var/rails_apps/example_app/vendor/rails/actionmailer/lib/action_mailer/base.rb:428:in `method_missing'
  /var/rails_apps/example_app/app/controllers/application_controller.rb:18:in `rescue_action_in_public'

ActionMailer が使用している tmail 1.2.7 の Ruby 1.9 対応の問題の模様。

取り合えず、以下のパッチを config/initializers 以下に配置したところ、正常にメールが送信できるようになりました。


参考

Migrating TMail to 1.9 (1) - Regexp encoding problem - Ruby Forum
http://www.ruby-forum.com/topic/148160