diff options
| author | Louise Crow <louise.crow@gmail.com> | 2015-05-28 10:57:19 +0100 |
|---|---|---|
| committer | Louise Crow <louise.crow@gmail.com> | 2015-05-28 10:57:19 +0100 |
| commit | e936b687a7df62dc69d1cc0493492346bd8e300a (patch) | |
| tree | 61206adc9f66b7bfc691174c9f93c92ccea1ffe9 /lib | |
| parent | c6e8e298fd0861cd822f23f370a01ccbc21cb9d3 (diff) | |
| parent | 495f82365ccd374d5b33339abce356f3a3662295 (diff) | |
Merge branch 'force-filenames-to-utf8' into rails-3-develop
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/mail_handler/backends/mail_backend.rb | 7 | ||||
| -rw-r--r-- | lib/normalize_string.rb | 14 |
2 files changed, 20 insertions, 1 deletions
diff --git a/lib/mail_handler/backends/mail_backend.rb b/lib/mail_handler/backends/mail_backend.rb index 5a7e0ef65..9e3fbc008 100644 --- a/lib/mail_handler/backends/mail_backend.rb +++ b/lib/mail_handler/backends/mail_backend.rb @@ -65,7 +65,12 @@ module MailHandler # Return a copy of the file name for the mail part def get_part_file_name(part) part_file_name = part.filename - part_file_name.nil? ? nil : part_file_name.dup + part_file_name = part_file_name.nil? ? nil : part_file_name.dup + if part_file_name + part_file_name = CGI.unescape(part_file_name) + part_file_name = convert_string_to_utf8(part_file_name, part.charset) + end + part_file_name end # Get the body of a mail part diff --git a/lib/normalize_string.rb b/lib/normalize_string.rb index 409262b8e..d850d7e05 100644 --- a/lib/normalize_string.rb +++ b/lib/normalize_string.rb @@ -73,6 +73,20 @@ def convert_string_to_utf8_or_binary(s, suggested_character_encoding=nil) result end +def convert_string_to_utf8(s, suggested_character_encoding=nil) + begin + result = normalize_string_to_utf8 s, suggested_character_encoding + rescue EncodingNormalizationError + result = s + if String.method_defined?(:encode) + result = s.force_encoding("utf-8").encode("utf-8", :invalid => :replace, + :undef => :replace, + :replace => "") + end + end + result +end + def log_text_details(message, text) if String.method_defined?(:encode) STDERR.puts "#{message}, we have text: #{text}, of class #{text.class} and encoding #{text.encoding}" |
