mirror of
https://github.com/TracksApp/tracks.git
synced 2026-02-05 23:41:48 +01:00
Add Mailgun endpoint for receiving email tasks via Mailgun
This commit is contained in:
parent
daef1c440b
commit
8a2da01d51
8 changed files with 193 additions and 2 deletions
38
app/controllers/mailgun_controller.rb
Normal file
38
app/controllers/mailgun_controller.rb
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
require 'openssl'
|
||||
|
||||
class MailgunController < ApplicationController
|
||||
|
||||
skip_before_filter :login_required, :only => [:mailgun]
|
||||
before_filter :verify, :only => [:mailgun]
|
||||
protect_from_forgery with: :null_session
|
||||
|
||||
def mailgun
|
||||
unless params.include? 'body-mime'
|
||||
Rails.logger.info "Cannot process Mailgun request, no body-mime sent"
|
||||
render_failure "Unacceptable body-mime", 406
|
||||
return
|
||||
end
|
||||
|
||||
todo = MessageGateway.receive(params['body-mime'])
|
||||
if todo
|
||||
render :xml => todo.to_xml( *todo_xml_params )
|
||||
else
|
||||
render_failure "Todo not saved", 406
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def verify
|
||||
unless params['signature'] == OpenSSL::HMAC.hexdigest(
|
||||
OpenSSL::Digest::Digest.new('sha256'),
|
||||
SITE_CONFIG['mailgun_api_key'],
|
||||
'%s%s' % [params['timestamp'], params['token']]
|
||||
)
|
||||
Rails.logger.info "Cannot verify Mailgun signature"
|
||||
render_failure "Access denied", 406
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue