aboutsummaryrefslogtreecommitdiffstats
path: root/app/controllers/api_controller.rb
diff options
context:
space:
mode:
authorMatthew Landauer <matthew@openaustralia.org>2013-01-31 19:57:59 +1100
committerMatthew Landauer <matthew@openaustralia.org>2013-01-31 19:57:59 +1100
commit0983f28ff23564a8aebd1f88d19d8787a42dab55 (patch)
tree732f2c58dfc2c889ad78f03239de46a0ae123101 /app/controllers/api_controller.rb
parente9a8afc0458f0c23e1fdcc26791745827f9ad7c2 (diff)
Directly construct tmail object from body and attachments. Ugh. Because actionmailer uses mail under the hood
Diffstat (limited to 'app/controllers/api_controller.rb')
-rw-r--r--app/controllers/api_controller.rb24
1 files changed, 22 insertions, 2 deletions
diff --git a/app/controllers/api_controller.rb b/app/controllers/api_controller.rb
index 903ff648d..424f0444d 100644
--- a/app/controllers/api_controller.rb
+++ b/app/controllers/api_controller.rb
@@ -148,8 +148,28 @@ class ApiController < ApplicationController
:filename => filename
)
end
-
- mail = RequestMailer.create_external_response(request, body, sent_at, attachment_hashes)
+ if MailHandler.backend == "TMail"
+ # Directly construct Tmail object using attachment_hashes
+ mail = TMail::Mail.new
+ mail.body = body
+ blackhole_email = Configuration::blackhole_prefix+"@"+Configuration::incoming_email_domain
+ mail.from = blackhole_email
+ mail.to = request.incoming_name_and_email
+ mail.date = sent_at.dup.localtime
+ b = TMail::Mail.new
+ b.body = body
+ mail.parts << b
+ attachment_hashes.each do |attachment_hash|
+ attachment = TMail::Mail.new
+ attachment.body = Base64.encode64(attachment_hash[:body])
+ attachment.transfer_encoding = "Base64"
+ attachment.set_content_type(attachment_hash[:content_type])
+ attachment['Content-Disposition'] = "attachment; filename=#{attachment_hash[:filename]}"
+ mail.parts << attachment
+ end
+ else
+ mail = RequestMailer.create_external_response(request, body, sent_at, attachment_hashes)
+ end
request.receive(mail, mail.encoded, true)
end
render :json => {