Created
January 13, 2011 13:05
-
-
Save kakutani/777828 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
module Iso2022jpEnforcer | |
extend ActiveSupport::Concern | |
included do | |
default :charset => 'iso-2022-jp' | |
alias_method_chain :mail, :iso_2022_jp | |
end | |
module ClassMethods | |
# taken from http://wiki.fdiary.net/rails/?ActionMailer | |
def base64(text, charset="iso-2022-jp", convert=true) | |
if convert | |
if charset == "iso-2022-jp" | |
text = NKF.nkf('-j -m0', text) | |
end | |
end | |
text = [text].pack('m').delete("\r\n") | |
"=?#{charset}?B?#{text}?=" | |
end | |
end | |
module InstanceMethods | |
def mail_with_iso_2022_jp(headers, &block) | |
mail = mail_without_iso_2022_jp(headers, &block) | |
mail.subject = base64(mail.subject) | |
mail.body.charset = 'iso-2022-jp' | |
mail.body.encoding = '7bit' | |
mail.body = NKF::nkf('-j', mail.body.to_s) | |
end | |
private | |
def base64(text, charset="iso-2022-jp", convert=true) | |
self.class.base64(text, charset, convert) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment