aboutsummaryrefslogtreecommitdiffstats
path: root/app/controllers/request_controller.rb
diff options
context:
space:
mode:
authorMatthew Landauer <matthew@openaustralia.org>2013-02-01 16:59:31 +1100
committerMatthew Landauer <matthew@openaustralia.org>2013-02-01 16:59:31 +1100
commitd05f4b605f21501e54d3576eae6f5f1af190ba18 (patch)
treef62e6f1fb1451c28a579a674a706870d622b9aa3 /app/controllers/request_controller.rb
parent2c00d9b1a4bf42bba92def1ee8e0f750db9b4905 (diff)
Another hack to manually stitch together a fake email using tmail
Diffstat (limited to 'app/controllers/request_controller.rb')
-rw-r--r--app/controllers/request_controller.rb28
1 files changed, 27 insertions, 1 deletions
diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb
index 500738b91..179c04e4e 100644
--- a/app/controllers/request_controller.rb
+++ b/app/controllers/request_controller.rb
@@ -853,7 +853,33 @@ class RequestController < ApplicationController
return
end
- mail = RequestMailer.create_fake_response(@info_request, @user, body, file_name, file_content)
+ # There is duplication of the email creation code in api_controller.rb
+ # TODO: Remove duplication
+ if MailHandler.backend == "TMail"
+ # Directly construct Tmail object using attachment_hashes
+ mail = TMail::Mail.new
+ mail.from = @user.name_and_email
+ mail.to = @info_request.incoming_name_and_email
+
+ b = TMail::Mail.new
+ b.body = body
+ b.set_content_type("text/plain")
+ b['Content-Disposition'] = "inline"
+ mail.parts << b
+
+ if !file_name.nil? && !file_content.nil?
+ content_type = AlaveteliFileTypes.filename_to_mimetype(file_name) || 'application/octet-stream'
+
+ attachment = TMail::Mail.new
+ attachment.body = Base64.encode64(file_content)
+ attachment.transfer_encoding = "base64"
+ attachment['Content-Type'] = "#{content_type}; name=\"#{file_name}\""
+ attachment['Content-Disposition'] = "attachment; filename=#{file_name}"
+ mail.parts << attachment
+ end
+ else
+ mail = RequestMailer.create_fake_response(@info_request, @user, body, file_name, file_content)
+ end
@info_request.receive(mail, mail.encoded, true)
flash[:notice] = _("Thank you for responding to this FOI request! Your response has been published below, and a link to your response has been emailed to ") + CGI.escapeHTML(@info_request.user.name) + "."
redirect_to request_url(@info_request)