aboutsummaryrefslogtreecommitdiffstats
path: root/app/controllers/api_controller.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers/api_controller.rb')
-rw-r--r--app/controllers/api_controller.rb32
1 files changed, 23 insertions, 9 deletions
diff --git a/app/controllers/api_controller.rb b/app/controllers/api_controller.rb
index 15fb4f5f9..424f0444d 100644
--- a/app/controllers/api_controller.rb
+++ b/app/controllers/api_controller.rb
@@ -83,7 +83,7 @@ class ApiController < ApplicationController
direction = json["direction"]
body = json["body"]
- sent_at_str = json["sent_at"]
+ sent_at = json["sent_at"]
errors = []
@@ -107,12 +107,6 @@ class ApiController < ApplicationController
errors << "The 'body' is empty"
end
- begin
- sent_at = Time.iso8601(sent_at_str)
- rescue ArgumentError
- errors << "Failed to parse 'sent_at' field as ISO8601 time: #{sent_at_str}"
- end
-
if direction == "request" && !attachments.nil?
errors << "You cannot attach files to messages in the 'request' direction"
end
@@ -154,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 => {