diff options
author | Mark Longair <mhl@pobox.com> | 2013-05-15 14:52:24 +0100 |
---|---|---|
committer | Mark Longair <mhl@pobox.com> | 2013-05-16 09:06:27 +0100 |
commit | 2d5ddc2d37837cb9ee80931b09dff04cc1120bda (patch) | |
tree | cf54cab06dacf7e804d10f8b293222e4b1f14ce2 /app/models | |
parent | 95cf55aad1f0985d28c28beb61e122dc7465b039 (diff) |
Make efforts to ensure that we're usually dealing with UTF-8 strings
One of these changes is to make sure that the Mail backend,
like the TMail backend it replaces, will return text parts
encoded in UTF-8 if possible.
The other change is to ensure that when text attachments are
reloaded from disk, we attempt to convert them to UTF-8.
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/foi_attachment.rb | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/app/models/foi_attachment.rb b/app/models/foi_attachment.rb index fcde379e0..0340f2b83 100644 --- a/app/models/foi_attachment.rb +++ b/app/models/foi_attachment.rb @@ -71,7 +71,12 @@ class FoiAttachment < ActiveRecord::Base tries = 0 delay = 1 begin - @cached_body = File.open(self.filepath, "rb" ).read + binary_data = File.open(self.filepath, "rb" ).read + if self.content_type =~ /^text/ + @cached_body = convert_string_to_utf8_or_binary(binary_data, 'UTF-8') + else + @cached_body = binary_data + end rescue Errno::ENOENT # we've lost our cached attachments for some reason. Reparse them. if tries > BODY_MAX_TRIES |