Created
February 8, 2012 04:18
-
-
Save akishin/1765406 to your computer and use it in GitHub Desktop.
Ruby 1.9 + tmail-1.2.7 環境での Encoding::CompatibilityError 対策用。
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
# encoding: utf-8 | |
# Ruby 1.9 + tmail-1.2.7 環境での | |
#「Encoding::CompatibilityError (incompatible encoding regexp match (ASCII-8BIT regexp with ISO-2022-JP string))」 | |
# エラー対策。 | |
# Rails の場合 config/initializers 以下に配置する。 | |
# | |
module TMail | |
class Encoder | |
def phrase( str ) | |
str = normalize_encoding(str) | |
enc = str.encoding | |
str.force_encoding(Encoding::ASCII_8BIT) | |
if CONTROL_CHAR === str | |
scanadd str | |
else | |
add_text quote_phrase(str) | |
end | |
str.force_encoding(enc) | |
end | |
end | |
end | |
class StringOutput#:nodoc: | |
def <<( str ) | |
enc = str.encoding | |
str.force_encoding(Encoding::ASCII_8BIT) | |
stream_check! | |
@dest << str.to_s | |
str.force_encoding(enc) | |
self | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment