mirror of
https://github.com/TracksApp/tracks.git
synced 2025-09-22 05:50:47 +02:00
Adding cloudmailin support for adding tasks
This commit is contained in:
parent
cf78ad3659
commit
c0956a7e76
4 changed files with 64 additions and 8 deletions
1
Gemfile
1
Gemfile
|
@ -18,6 +18,7 @@ gem "ruby-openid", :require => "openid"
|
|||
gem "sqlite3"
|
||||
gem 'bcrypt-ruby', '~> 2.1.4'
|
||||
gem 'htmlentities', '~> 4.3.0'
|
||||
gem "mail"
|
||||
|
||||
gem "webrat", ">=0.7.0", :groups => [:cucumber, :test]
|
||||
gem "database_cleaner", ">=0.5.0", :groups => [:cucumber, :selenium]
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
class IntegrationsController < ApplicationController
|
||||
|
||||
skip_before_filter :login_required, :only => [:search_plugin, :google_gadget]
|
||||
require 'mail'
|
||||
|
||||
skip_before_filter :login_required, :only => [:cloudmailin, :search_plugin, :google_gadget]
|
||||
before_filter :verify_cloudmailin_signature, :only => [:cloudmailin]
|
||||
|
||||
def index
|
||||
@page_title = 'TRACKS::Integrations'
|
||||
|
@ -26,14 +28,61 @@ class IntegrationsController < ApplicationController
|
|||
end
|
||||
|
||||
def search_plugin
|
||||
@icon_data = [File.open(RAILS_ROOT + '/public/images/done.png').read].
|
||||
pack('m').gsub(/\n/, '')
|
||||
|
||||
render :layout => false
|
||||
@icon_data = [File.open(RAILS_ROOT + '/public/images/done.png').read].
|
||||
pack('m').gsub(/\n/, '')
|
||||
|
||||
render :layout => false
|
||||
end
|
||||
|
||||
def google_gadget
|
||||
render :layout => false, :content_type => Mime::XML
|
||||
end
|
||||
|
||||
def cloudmailin
|
||||
message = Mail.new(params[:message])
|
||||
|
||||
# debug
|
||||
#puts message.from.addresses.first
|
||||
|
||||
# find user
|
||||
user = User.find(:first, :include => [:preference], :conditions => ["preferences.sms_email = ?", message.from.addresses.first])
|
||||
if user.nil?
|
||||
render :text => "No user found", :status => 404
|
||||
return false
|
||||
end
|
||||
|
||||
context = user.prefs.sms_context
|
||||
# prepare body
|
||||
if message.body.multipart?
|
||||
#body = message.body.parts[0].to_s
|
||||
body = message.body.preamble
|
||||
else
|
||||
body = message.body.to_s
|
||||
end
|
||||
|
||||
# parse mail
|
||||
if message.subject.to_s.empty?
|
||||
description = body
|
||||
notes = nil
|
||||
else
|
||||
description = message.subject.decoded.to_s
|
||||
notes = body
|
||||
end
|
||||
|
||||
todo = Todo.from_rich_message(user, context.id, description, notes)
|
||||
todo.save!
|
||||
render :text => 'success', :status => 200
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def verify_cloudmailin_signature
|
||||
provided = request.request_parameters.delete(:signature)
|
||||
signature = Digest::MD5.hexdigest(request.request_parameters.sort.map{|k,v| v}.join + SITE_CONFIG['cloudmailin'])
|
||||
|
||||
if provided != signature
|
||||
render :text => "Message signature fail #{provided} != #{signature}", :status => 403
|
||||
return false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -86,8 +86,9 @@ ActionController::Routing::Routes.draw do |map|
|
|||
map.with_options :controller => :integrations do |i|
|
||||
i.integrations 'integrations', :action => 'index'
|
||||
i.rest_api_docs 'integrations/rest_api', :action => "rest_api"
|
||||
i.search_plugin 'integrations/search_plugin.xml', :controller => 'integrations', :action => 'search_plugin', :format => 'xml'
|
||||
i.google_gadget 'integrations/google_gadget.xml', :controller => 'integrations', :action => 'google_gadget', :format => 'xml'
|
||||
i.search_plugin 'integrations/search_plugin.xml', :action => 'search_plugin', :format => 'xml'
|
||||
i.google_gadget 'integrations/google_gadget.xml', :action => 'google_gadget', :format => 'xml'
|
||||
i.cloudmailin 'integrations/cloudmailin', :action => 'cloudmailin'
|
||||
end
|
||||
|
||||
map.with_options :controller => :preferences do |p|
|
||||
|
|
|
@ -51,3 +51,8 @@ open_signups: false
|
|||
# - 'localhost'
|
||||
# use_ssl: false
|
||||
# login_format: 'cn=%s,dc=example,dc=com'
|
||||
|
||||
# When integrating your tracks instance with http://cloudmailin.com/ by using the /integrations/cloudmailin URL,
|
||||
# this value is the cloudmailin-secret for verifying the authenticity of the request.
|
||||
# (see http://docs.cloudmailin.com/validating_the_sender)
|
||||
# cloudmailin: asdasd
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue