diff options
| author | Robin Houston <robin.houston@gmail.com> | 2012-06-07 22:04:53 +0100 | 
|---|---|---|
| committer | Robin Houston <robin.houston@gmail.com> | 2012-06-07 22:04:53 +0100 | 
| commit | 1ff635e834c004600faa445fc53e757996cde30d (patch) | |
| tree | 9854dff8f88afbb9b7738703b44523d25dbae069 /app/controllers/api_controller.rb | |
| parent | 428438732a90aab880dde72d22151105b46d9908 (diff) | |
WIP API
Diffstat (limited to 'app/controllers/api_controller.rb')
| -rw-r--r-- | app/controllers/api_controller.rb | 36 | 
1 files changed, 8 insertions, 28 deletions
| diff --git a/app/controllers/api_controller.rb b/app/controllers/api_controller.rb index 5661819b9..c1156845d 100644 --- a/app/controllers/api_controller.rb +++ b/app/controllers/api_controller.rb @@ -136,40 +136,20 @@ class ApiController < ApplicationController              )          else              # In the 'response' direction, i.e. what we (Alaveteli) regard as incoming -             -            raw_email = RawEmail.new -            incoming_message = IncomingMessage.new( -                :info_request => request, -                :raw_email => raw_email, -                :sent_at => sent_at -            ) -            raw_email.incoming_message = incoming_message -            raw_email.save! -            raw_email.data = "From external\nFrom: <none@example.org>\nTo: <none@example.org>\nDate: #{sent_at.rfc2822}\nSubject: Response\n\n" + body -             -            request.incoming_messages << incoming_message -            request.save! -             -            attachments.each_with_index do |attachment, i| +            attachment_hashes = [] +            (attachments || []).each_with_index do |attachment, i|                  filename = File.basename(attachment.original_filename)                  body = attachment.read                  content_type = AlaveteliFileTypes.filename_and_content_to_mimetype(filename, body) || 'application/octet-stream' -                 -                a = FoiAttachment.new( -                    :incoming_message_id => incoming_message.id, -                    :filename => filename, -                    :content_type => content_type +                attachment_hashes.push( +                    :content_type => content_type, +                    :body => body, +                    :filename => filename                  ) -                a.body = body -                a.save!              end -            request.log_event("response", -                :api => true, -                :email => nil, -                :incoming_message_id => incoming_message.id, -                :smtp_message_id => nil -            ) +            mail = RequestMailer.create_external_response(request, body, sent_at, attachment_hashes) +            request.receive(mail, mail.encoded, true)          end          head :no_content | 
