From 099afc86dc6a6c9f97e872a6404835ead9742066 Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Mon, 28 Jan 2013 16:01:24 +1100 Subject: Time doesn't need to be converted from string to time anymore --- app/controllers/api_controller.rb | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'app/controllers/api_controller.rb') diff --git a/app/controllers/api_controller.rb b/app/controllers/api_controller.rb index 15fb4f5f9..903ff648d 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 -- cgit v1.2.3 From 0983f28ff23564a8aebd1f88d19d8787a42dab55 Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Thu, 31 Jan 2013 19:57:59 +1100 Subject: Directly construct tmail object from body and attachments. Ugh. Because actionmailer uses mail under the hood --- app/controllers/api_controller.rb | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'app/controllers/api_controller.rb') 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 => { -- cgit v1.2.3 From 9d97fb84fe041a3479efae7c0c99c92abc07ad3d Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Mon, 25 Feb 2013 18:30:12 +1100 Subject: create_ is deprecated --- app/controllers/api_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/controllers/api_controller.rb') diff --git a/app/controllers/api_controller.rb b/app/controllers/api_controller.rb index 424f0444d..61b68a2db 100644 --- a/app/controllers/api_controller.rb +++ b/app/controllers/api_controller.rb @@ -168,7 +168,7 @@ class ApiController < ApplicationController mail.parts << attachment end else - mail = RequestMailer.create_external_response(request, body, sent_at, attachment_hashes) + mail = RequestMailer.external_response(request, body, sent_at, attachment_hashes) end request.receive(mail, mail.encoded, true) end -- cgit v1.2.3 From f07444d80961fcd3e7bb9555f5ed4a4e0b65b5db Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Wed, 27 Feb 2013 14:17:16 +1100 Subject: Remove Tmail and use the Mail gem under Ruby 1.8.7 as well --- app/controllers/api_controller.rb | 25 +++---------------------- 1 file changed, 3 insertions(+), 22 deletions(-) (limited to 'app/controllers/api_controller.rb') diff --git a/app/controllers/api_controller.rb b/app/controllers/api_controller.rb index 61b68a2db..57eca965e 100644 --- a/app/controllers/api_controller.rb +++ b/app/controllers/api_controller.rb @@ -148,28 +148,9 @@ class ApiController < ApplicationController :filename => filename ) end - 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.external_response(request, body, sent_at, attachment_hashes) - end + + mail = RequestMailer.external_response(request, body, sent_at, attachment_hashes) + request.receive(mail, mail.encoded, true) end render :json => { -- cgit v1.2.3 From cbdff06aa95a7987b54c712dc6729e138f608eca Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Sun, 3 Mar 2013 14:52:30 +1100 Subject: Rename Configuration class to avoid conflict with ActiveSupport::Configurable --- app/controllers/api_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/controllers/api_controller.rb') diff --git a/app/controllers/api_controller.rb b/app/controllers/api_controller.rb index 57eca965e..f039390b3 100644 --- a/app/controllers/api_controller.rb +++ b/app/controllers/api_controller.rb @@ -243,6 +243,6 @@ class ApiController < ApplicationController private def make_url(*args) - "http://" + Configuration::domain + "/" + args.join("/") + "http://" + AlaveteliConfiguration::domain + "/" + args.join("/") end end -- cgit v1.2.3