Class: Cloudfuji::MailController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/cloudfuji/mail_controller.rb

Instance Method Summary collapse

Instance Method Details

#indexObject

POST /cloudfuji/mail



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/controllers/cloudfuji/mail_controller.rb', line 6

def index
  puts "Handling email!"
  mail = {}
  attachments = []

  # Strip the attachments first
  params.keys.each do |key|
    attachments << params.delete(key) if key =~ /attachment-\d+/
  end

  # Copy the params to the hook data
  (params.keys - ["controller", "action"]).each do |param|
    mail[param.downcase] = params[param]
  end

  mail["attachments"] = attachments

  puts "params: #{params.inspect}"
  puts "mail: #{mail.inspect}"

  # Output for debugging remotely
  Cloudfuji::Mailroute.pretty_print_routes
  puts "Finished routing"
  
  # Mailroute is in charge of figuring out which callback to trigger
  Cloudfuji::Mailroute.routes.process(mail)

  result = {:success => true, :message => nil, :data => {}}
  render :text => result.to_json, :status => 200
end