diff options
author | Francis Irving <francis@mysociety.org> | 2010-02-06 03:19:49 +0000 |
---|---|---|
committer | Francis Irving <francis@mysociety.org> | 2010-02-06 03:19:49 +0000 |
commit | b9676fcc0da3eb684b1063dda4b5431cda746049 (patch) | |
tree | 2a8712983e4f6fcb2828bf5d4d36650774f9da66 | |
parent | ad5b58c3472f6e1564ecbc16c324f058c0d9fa2a (diff) |
View as HTML for RTF
-rw-r--r-- | app/models/incoming_message.rb | 10 | ||||
-rw-r--r-- | config/packages | 1 |
2 files changed, 11 insertions, 0 deletions
diff --git a/app/models/incoming_message.rb b/app/models/incoming_message.rb index 61edafaa2..a8ce78484 100644 --- a/app/models/incoming_message.rb +++ b/app/models/incoming_message.rb @@ -309,6 +309,8 @@ class FOIAttachment return true elsif self.content_type == 'application/pdf' return true + elsif self.content_type == 'application/rtf' + return true end return false end @@ -317,6 +319,9 @@ class FOIAttachment def body_as_html(dir) html = nil + # the extractions will also produce image files, which go in the + # current directory, so change to the directory the function caller + # wants everything in Dir.chdir(dir) do tempfile = Tempfile.new('foiextract', '.') tempfile.print self.body @@ -331,6 +336,10 @@ class FOIAttachment IO.popen("/usr/bin/pdftohtml -nodrm -zoom 1.0 -stdout -enc UTF-8 -noframes " + tempfile.path + "", "r") do |child| html = child.read() end + elsif self.content_type == 'application/rtf' + IO.popen("/usr/bin/unrtf --html " + tempfile.path + "", "r") do |child| + html = child.read() + end else raise "No HTML conversion available for type " + self.content_type end @@ -1107,6 +1116,7 @@ class IncomingMessage < ActiveRecord::Base File.unlink(tempfile.path + ".txt") end elsif content_type == 'application/rtf' + # catdoc on RTF prodcues less comments and extra bumf than --text option to unrtf IO.popen("/usr/bin/catdoc " + tempfile.path, "r") do |child| text += child.read() + "\n\n" end diff --git a/config/packages b/config/packages index 18243e567..0e1625e24 100644 --- a/config/packages +++ b/config/packages @@ -11,6 +11,7 @@ gs-gpl catdoc links lynx +unrtf libxapian-ruby1.8 gnuplot-nox ttf-bitstream-vera |