aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrancis Irving <francis@mysociety.org>2010-02-06 03:30:14 +0000
committerFrancis Irving <francis@mysociety.org>2010-02-06 03:30:14 +0000
commit2a324c3f17bbf0013bb021bbff2c1f2578d8f81c (patch)
treec7c7cb2cba47b6155ec9a8f7b6fed968d162d76b
parentb9676fcc0da3eb684b1063dda4b5431cda746049 (diff)
View as HTML link for text files
-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