aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/models/incoming_message.rb13
1 files changed, 12 insertions, 1 deletions
diff --git a/app/models/incoming_message.rb b/app/models/incoming_message.rb
index a8ce78484..2bffd3be8 100644
--- a/app/models/incoming_message.rb
+++ b/app/models/incoming_message.rb
@@ -305,12 +305,14 @@ class FOIAttachment
# Whether this type has a "View as HTML"
def has_body_as_html?
- if self.content_type == 'application/vnd.ms-word'
+ if self.content_type == 'text/plain'
return true
elsif self.content_type == 'application/pdf'
return true
elsif self.content_type == 'application/rtf'
return true
+ elsif self.content_type == 'application/vnd.ms-word'
+ return true
end
return false
end
@@ -319,6 +321,15 @@ class FOIAttachment
def body_as_html(dir)
html = nil
+ # simple cases, can never fail
+ if self.content_type == 'text/plain'
+ text = self.body.strip
+ text = CGI.escapeHTML(text)
+ text = MySociety::Format.make_clickable(text)
+ html = text.gsub(/\n/, '<br>')
+ return "<html><head></head><body>" + html + "</body></html>"
+ end
+
# the extractions will also produce image files, which go in the
# current directory, so change to the directory the function caller
# wants everything in