end
def self.convert_from body, charset
- charset = "utf-8" if charset =~ /UTF_?8/i
begin
raise MessageFormatError, "RubyMail decode returned a null body" unless body
return body unless charset
- Iconv.iconv($encoding + "//IGNORE", charset, body + " ").join[0 .. -2]
+ Iconv.easy_decode($encoding, charset, body)
rescue Errno::EINVAL, Iconv::InvalidEncoding, Iconv::IllegalSequence, MessageFormatError => e
Redwood::log "warning: error (#{e.class.name}) decoding message body from #{charset}: #{e.message}"
File.open(File.join(BASE_DIR,"unable-to-decode.txt"), "w") { |f| f.write body }
# WORD.
end
- charset = "utf-8" if charset =~ /UTF_?8/i
-
- # Convert:
- #
- # Remember - Iconv.open(to, from)!
begin
- text = Iconv.iconv(target + "//IGNORE", charset, text + " ").join[0 .. -2]
+ Iconv.easy_decode(target, charset, text)
rescue Iconv::InvalidCharacter
text
end
@m.synchronize { !@over && @over = true }
end
end
+
+class Iconv
+ def self.easy_decode target, charset, text
+ return text if charset =~ /^x-unknown$/i
+ charset = case charset
+ when /UTF[-_]?8/i: "utf-8"
+ when /(iso[-_])?latin[-_]?1$/i: "ISO-8859-1"
+ else charset
+ end
+
+ # Convert:
+ #
+ # Remember - Iconv.open(to, from)!
+ Iconv.iconv(target + "//IGNORE", charset, text + " ").join[0 .. -2]
+ end
+end