diff options
-rw-r--r-- | app/controllers/request_controller.rb | 37 | ||||
-rw-r--r-- | app/models/incoming_message.rb | 4 | ||||
-rw-r--r-- | public/stylesheets/main.css | 16 | ||||
-rw-r--r-- | spec/controllers/request_controller_spec.rb | 8 |
4 files changed, 39 insertions, 26 deletions
diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb index 42d54a403..466c6d6ce 100644 --- a/app/controllers/request_controller.rb +++ b/app/controllers/request_controller.rb @@ -604,23 +604,29 @@ class RequestController < ApplicationController # special caching code so mime types are handled right around_filter :cache_attachments, :only => [ :get_attachment, :get_attachment_as_html ] def cache_attachments - key = params.merge(:only_path => true) - key_path = foi_fragment_cache_path(key) + if !params[:skip_cache].nil? + yield + else + key = params.merge(:only_path => true) + key_path = foi_fragment_cache_path(key) - if foi_fragment_cache_exists?(key_path) - cached = foi_fragment_cache_read(key_path) - response.content_type = AlaveteliFileTypes.filename_to_mimetype(params[:file_name].join("/")) || 'application/octet-stream' - render_for_text(cached) - return - end + if foi_fragment_cache_exists?(key_path) + cached = foi_fragment_cache_read(key_path) + response.content_type = AlaveteliFileTypes.filename_to_mimetype(params[:file_name].join("/")) || 'application/octet-stream' + render_for_text(cached) + return + end - yield + yield - # write it to the fileystem ourselves, so is just a plain file. (The - # various fragment cache functions using Ruby Marshall to write the file - # which adds a header, so isnt compatible with images that have been - # extracted elsewhere from PDFs) - foi_fragment_cache_write(key_path, response.body) + if params[:skip_cache].nil? + # write it to the fileystem ourselves, so is just a plain file. (The + # various fragment cache functions using Ruby Marshall to write the file + # which adds a header, so isnt compatible with images that have been + # extracted elsewhere from PDFs) + foi_fragment_cache_write(key_path, response.body) + end + end end def get_attachment @@ -649,7 +655,7 @@ class RequestController < ApplicationController view_html_stylesheet = render_to_string :partial => "request/view_html_stylesheet" html.sub!(/<head>/i, "<head>" + view_html_stylesheet) - html.sub!(/<body[^>]*>/i, '<body><prefix-here><div id="' + wrapper_id + '"><div id="view_html_content">') + html.sub!(/<body[^>]*>/i, '<body><prefix-here><div id="' + wrapper_id + '"><div id="view-html-content">') html.sub!(/<\/body[^>]*>/i, '</div></div></body>') view_html_prefix = render_to_string :partial => "request/view_html_prefix" @@ -657,7 +663,6 @@ class RequestController < ApplicationController html.sub!("<attachment-url-here>", CGI.escape(@attachment_url)) @incoming_message.html_mask_stuff!(html) - response.content_type = 'text/html' render :text => html end diff --git a/app/models/incoming_message.rb b/app/models/incoming_message.rb index b0b02fdda..16ae38b92 100644 --- a/app/models/incoming_message.rb +++ b/app/models/incoming_message.rb @@ -255,7 +255,8 @@ class FOIAttachment text = CGI.escapeHTML(text) text = MySociety::Format.make_clickable(text) html = text.gsub(/\n/, '<br>') - return "<html><head></head><body>" + html + "</body></html>", wrapper_id + return '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" + "http://www.w3.org/TR/html4/loose.dtd"><html><head><title></title></head><body>' + html + "</body></html>", wrapper_id end # the extractions will also produce image files, which go in the @@ -987,7 +988,6 @@ class IncomingMessage < ActiveRecord::Base attachment.filename = _get_censored_part_file_name(leaf) if leaf.within_rfc822_attachment attachment.within_rfc822_subject = leaf.within_rfc822_attachment.subject - # Test to see if we are in the first part of the attached # RFC822 message and it is text, if so add headers. # XXX should probably use hunting algorithm to find main text part, rather than diff --git a/public/stylesheets/main.css b/public/stylesheets/main.css index 8dfecd586..28b2762ab 100644 --- a/public/stylesheets/main.css +++ b/public/stylesheets/main.css @@ -273,24 +273,24 @@ body text-align: left; overflow: visible; } -#view_html_content table { +#view-html-content table { border-collapse: collapse; margin-bottom: 1em; } -#view_html_content td, th { +#view-html-content td, th { border: solid 1px #000000; } -#view_html_content td { +#view-html-content td { vertical-align: top } -#view_html_content td { +#view-html-content td { max-width: 30em; overflow: auto; } -#view_html_content tr:nth-child(odd) { +#view-html-content tr:nth-child(odd) { background-color: #bbbbbb; } -#view_html_content tr:nth-child(even) { +#view-html-content tr:nth-child(even) { background-color: #dddddd; } @@ -890,11 +890,11 @@ a img.attachment_image { /*------------------------------------------------ view attachment as HTML */ -.view_html_content { +.view-html-content { margin-left: 1em; margin-right: 1em; } -.view_html_content, img { +.view-html-content, img { max-width: 50em; } diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index a9315ddb2..f69cf414c 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -125,6 +125,14 @@ describe RequestController, "when showing one request" do response.should have_text(/First hello/) end + it "should generate valid HTML verson of plain text attachments " do + ir = info_requests(:fancy_dog_request) + receive_incoming_mail('incoming-request-two-same-name.email', ir.incoming_email) + get :get_attachment_as_html, :incoming_message_id => ir.incoming_messages[1].id, :id => ir.id, :part => 2, :file_name => ['hello.txt.html'], :skip_cache => 1 + response.content_type.should == "text/html" + response.should have_text(/Second hello/) + end + it "should treat attachments with unknown extensions as binary" do ir = info_requests(:fancy_dog_request) receive_incoming_mail('incoming-request-attachment-unknown-extension.email', ir.incoming_email) |