diff options
author | francis <francis> | 2008-04-18 15:44:49 +0000 |
---|---|---|
committer | francis <francis> | 2008-04-18 15:44:49 +0000 |
commit | a61f1e27299d0c75f31232a34ff367b0a908bfba (patch) | |
tree | fbcc1b68b259494ccbc8aa3d383c654457d9799f | |
parent | ccc5bb1f44064cf723c4f12dd0ee5264a5ec52ca (diff) |
RTF support
-rw-r--r-- | app/models/incoming_message.rb | 52 | ||||
-rw-r--r-- | app/views/request/_bubble.rhtml | 2 | ||||
-rw-r--r-- | public/images/README.txt | 4 | ||||
-rw-r--r-- | public/images/icon_application_rtf_large.png | bin | 0 -> 2564 bytes | |||
-rw-r--r-- | todo.txt | 7 |
5 files changed, 39 insertions, 26 deletions
diff --git a/app/models/incoming_message.rb b/app/models/incoming_message.rb index b21a638c7..f03210c47 100644 --- a/app/models/incoming_message.rb +++ b/app/models/incoming_message.rb @@ -17,7 +17,7 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: incoming_message.rb,v 1.79 2008-04-18 08:54:36 francis Exp $ +# $Id: incoming_message.rb,v 1.80 2008-04-18 15:44:49 francis Exp $ # TODO @@ -56,6 +56,8 @@ class FOIAttachment "attachment.pdf" elsif @content_type == 'application/msword' "attachment.doc" + elsif @content_type == 'application/rtf' + "attachment.rtf" elsif @content_type == 'application/msexcel' "attachment.xls" else @@ -342,6 +344,8 @@ class IncomingMessage < ActiveRecord::Base attachment.content_type = 'application/pdf' elsif attachment.filename.match(/\.doc$/) attachment.content_type = 'application/msword' + elsif attachment.filename.match(/\.rtf$/) + attachment.content_type = 'application/rtf' elsif attachment.filename.match(/\.xls$/) attachment.content_type = 'application/msexcel' else @@ -430,32 +434,30 @@ class IncomingMessage < ActiveRecord::Base for attachment in attachments if attachment.content_type == 'text/plain' text += attachment.body + "\n\n" - elsif attachment.content_type == 'application/msword' - tempfile = Tempfile.new('foidoc') - tempfile.print attachment.body - tempfile.flush - system("/usr/bin/wvText " + tempfile.path + " " + tempfile.path + ".txt") - text += File.read(tempfile.path + ".txt") + "\n\n" - File.unlink(tempfile.path + ".txt") - tempfile.close - elsif attachment.content_type == 'application/msexcel' - # Bit crazy using strings - but xls2csv, xlhtml and py_xls2txt - # only extract text from cells, not from floating notes. catdoc - # may be fooled by weird character sets, but will probably do for - # UK FOI requests. - tempfile = Tempfile.new('foixls') - tempfile.print attachment.body - tempfile.flush - IO.popen("/usr/bin/strings " + tempfile.path, "r") do |child| - text += child.read() + "\n\n" - end - tempfile.close - elsif attachment.content_type == 'application/pdf' - tempfile = Tempfile.new('foipdf') + else + tempfile = Tempfile.new('foiextract') tempfile.print attachment.body tempfile.flush - IO.popen("/usr/bin/pdftotext " + tempfile.path + " -", "r") do |child| - text += child.read() + "\n\n" + if attachment.content_type == 'application/msword' + system("/usr/bin/wvText " + tempfile.path + " " + tempfile.path + ".txt") + text += File.read(tempfile.path + ".txt") + "\n\n" + File.unlink(tempfile.path + ".txt") + elsif attachment.content_type == 'application/rtf' + IO.popen("/usr/bin/catdoc " + tempfile.path, "r") do |child| + text += child.read() + "\n\n" + end + elsif attachment.content_type == 'application/msexcel' + # Bit crazy using strings - but xls2csv, xlhtml and py_xls2txt + # only extract text from cells, not from floating notes. catdoc + # may be fooled by weird character sets, but will probably do for + # UK FOI requests. + IO.popen("/usr/bin/strings " + tempfile.path, "r") do |child| + text += child.read() + "\n\n" + end + elsif attachment.content_type == 'application/pdf' + IO.popen("/usr/bin/pdftotext " + tempfile.path + " -", "r") do |child| + text += child.read() + "\n\n" + end end tempfile.close end diff --git a/app/views/request/_bubble.rhtml b/app/views/request/_bubble.rhtml index 862b1058c..0327f4b91 100644 --- a/app/views/request/_bubble.rhtml +++ b/app/views/request/_bubble.rhtml @@ -7,7 +7,7 @@ <p> <% attachments.each do |a| %> <% attachment_url = get_attachment_url(:id => incoming_message.info_request_id, :incoming_message_id => incoming_message.id, :part => a.url_part_number, :file_name => a.display_filename) %> - <% if ['application/pdf', 'application/msword', 'application/msexcel', 'text/plain', 'image/tiff', 'image/gif'].include?(a.content_type) %> + <% if ['application/pdf', 'application/msword', 'application/rtf', 'application/msexcel', 'text/plain', 'image/tiff', 'image/gif'].include?(a.content_type) %> <a href="<%=attachment_url%>"><img class="attachment_image" alt="Attachment" src="/images/icon_<%=a.content_type.sub('/', '_')%>_large.png"></a> <% else %> Attachment: diff --git a/public/images/README.txt b/public/images/README.txt new file mode 100644 index 000000000..fa20c3b97 --- /dev/null +++ b/public/images/README.txt @@ -0,0 +1,4 @@ +The mime type icons are copied from the following directory on an Ubuntu +desktop machine. Look there for new ones... + +/usr/share/icons/Rodent/48x48/mimetypes diff --git a/public/images/icon_application_rtf_large.png b/public/images/icon_application_rtf_large.png Binary files differnew file mode 100644 index 000000000..2ad990608 --- /dev/null +++ b/public/images/icon_application_rtf_large.png @@ -1,3 +1,6 @@ +Watch this one: +http://www.whatdotheyknow.com/request/crime_statistics_for_2007_champi + FOI requests to use to test it ============================== @@ -28,10 +31,14 @@ BAILII - relationship with law courts, robots.txt ? Next ==== +Group requests by response +Make it totally awesome like in Tommy's screenshot + Things to track: - new requests - new requests with keyword - successful responses +described_at is needed for Users and Public Bodies for RSS Fix search to deal with overdue message query that Tomski asks for |