diff options
author | Louise Crow <louise.crow@gmail.com> | 2015-06-09 16:59:44 +0100 |
---|---|---|
committer | Louise Crow <louise.crow@gmail.com> | 2015-06-22 17:43:20 +0100 |
commit | d359f76233787533c973a1f30c3f6439d5919783 (patch) | |
tree | ed14f72c729df0314d7247f7b68de3dae4eb85da /app/models | |
parent | 4440d11fb662c57428a2aba622209d6d1ddc0a59 (diff) |
Clearly separate text attachments and binary.
Text type attachments will always have a UTF-8 body (even if it has
to be scrubbed).
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/foi_attachment.rb | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/app/models/foi_attachment.rb b/app/models/foi_attachment.rb index 0af47b26e..eb6e27dd4 100644 --- a/app/models/foi_attachment.rb +++ b/app/models/foi_attachment.rb @@ -70,8 +70,8 @@ class FoiAttachment < ActiveRecord::Base delay = 1 begin binary_data = File.open(self.filepath, "rb" ){ |file| file.read } - if self.content_type =~ /^text/ - @cached_body = convert_string_to_utf8_or_binary(binary_data, 'UTF-8') + if text_type? + @cached_body = convert_string_to_utf8(binary_data, 'UTF-8') else @cached_body = binary_data end @@ -93,6 +93,7 @@ class FoiAttachment < ActiveRecord::Base return @cached_body end + # List of DSN codes taken from RFC 3463 # http://tools.ietf.org/html/rfc3463 DsnToMessage = { @@ -294,5 +295,11 @@ class FoiAttachment < ActiveRecord::Base AttachmentToHTML.to_html(self, to_html_opts) end + private + + def text_type? + AlaveteliTextMasker::TextMask.include?(content_type) + end + end |