aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/api_controller.rb11
-rw-r--r--app/models/foi_attachment.rb23
m---------commonlib0
-rwxr-xr-xscript/load-exim-logs5
4 files changed, 21 insertions, 18 deletions
diff --git a/app/controllers/api_controller.rb b/app/controllers/api_controller.rb
index a7853c787..718c31e6f 100644
--- a/app/controllers/api_controller.rb
+++ b/app/controllers/api_controller.rb
@@ -71,18 +71,10 @@ class ApiController < ApplicationController
end
- def _get_attachments_from_params(params)
- attachments = []
- params.each_pair do |k, v|
- attachments << v if v.is_a? Tempfile
- end
- return attachments
- end
-
def add_correspondence
request = InfoRequest.find(params[:id])
json = ActiveSupport::JSON.decode(params[:correspondence_json])
- attachments = _get_attachments_from_params(params)
+ attachments = params[:attachments]
direction = json["direction"]
body = json["body"]
@@ -155,6 +147,7 @@ class ApiController < ApplicationController
:filename => filename
)
end
+
mail = RequestMailer.create_external_response(request, body, sent_at, attachment_hashes)
request.receive(mail, mail.encoded, true)
end
diff --git a/app/models/foi_attachment.rb b/app/models/foi_attachment.rb
index 9bbf0988f..a40898aef 100644
--- a/app/models/foi_attachment.rb
+++ b/app/models/foi_attachment.rb
@@ -1,3 +1,5 @@
+# encoding: UTF-8
+
# == Schema Information
# Schema version: 114
#
@@ -14,8 +16,6 @@
# hexdigest :string(32)
#
-# encoding: UTF-8
-
# models/foi_attachment.rb:
# An attachment to an email (IncomingMessage)
#
@@ -315,14 +315,21 @@ class FoiAttachment < ActiveRecord::Base
tempfile.print self.body
tempfile.flush
+ html = nil
if self.content_type == 'application/pdf'
- html = AlaveteliExternalCommand.run("pdftohtml", "-nodrm", "-zoom", "1.0", "-stdout", "-enc", "UTF-8", "-noframes", tempfile.path)
+ # We set a timeout here, because pdftohtml can spiral out of control
+ # on some PDF files and we don’t want to crash the whole server.
+ html = AlaveteliExternalCommand.run("pdftohtml", "-nodrm", "-zoom", "1.0", "-stdout", "-enc", "UTF-8", "-noframes", tempfile.path, :timeout => 30)
elsif self.content_type == 'application/rtf'
- html = AlaveteliExternalCommand.run("unrtf", "--html", tempfile.path)
- elsif self.has_google_docs_viewer?
- html = '' # force error and using Google docs viewer
- else
- raise "No HTML conversion available for type " + self.content_type
+ html = AlaveteliExternalCommand.run("unrtf", "--html", tempfile.path, :timeout => 120)
+ end
+
+ if html.nil?
+ if self.has_google_docs_viewer?
+ html = '' # force error and using Google docs viewer
+ else
+ raise "No HTML conversion available for type " + self.content_type
+ end
end
tempfile.close
diff --git a/commonlib b/commonlib
-Subproject 9e1d29721b9dba232c251ef4b8b79f8505422de
+Subproject 131375c752c02aa20f1644240fe69720275da42
diff --git a/script/load-exim-logs b/script/load-exim-logs
index 5ca0c66f8..00b6b9825 100755
--- a/script/load-exim-logs
+++ b/script/load-exim-logs
@@ -5,7 +5,10 @@ LOC=`dirname "$0"`
# Specific file if specified
if [ x$1 != x ]
then
- f=`abspath "$1"`
+ case "$1" in
+ /*) f=$1 ;;
+ *) f=$(pwd)/$1 ;;
+ esac
cd "$LOC"
bundle exec ./runner 'EximLog.load_file("'$f'")'
exit