Class: Bushido::MailController

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

Instance Method Summary collapse

Instance Method Details

#indexObject

POST /bushido/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/bushido/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
  Bushido::Mailroute.pretty_print_routes
  puts "Finished routing"
  
  # Mailroute is in charge of figuring out which callback to trigger
  Bushido::Mailroute.routes.process(mail)

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