diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2008-06-25 19:25:28 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2008-06-25 19:25:28 +0000 |
commit | 25bba80c9eb112b8ded40d2baf9f202c79d4e2ad (patch) | |
tree | 12be06ddc7c8af57a853531ea630ee3230f70c1a /app/controllers/mail_handler_controller.rb | |
parent | 4d6f50d3febff0e9cbbab158d39b2d8c0375c6a7 (diff) | |
download | redmine-25bba80c9eb112b8ded40d2baf9f202c79d4e2ad.tar.gz redmine-25bba80c9eb112b8ded40d2baf9f202c79d4e2ad.zip |
Adds a simple API and a standalone script that can be used to forward emails from a local or remote email server to Redmine (#1110).
git-svn-id: http://redmine.rubyforge.org/svn/trunk@1584 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/controllers/mail_handler_controller.rb')
-rw-r--r-- | app/controllers/mail_handler_controller.rb | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/app/controllers/mail_handler_controller.rb b/app/controllers/mail_handler_controller.rb new file mode 100644 index 000000000..8bcfce630 --- /dev/null +++ b/app/controllers/mail_handler_controller.rb @@ -0,0 +1,44 @@ +# redMine - project management software +# Copyright (C) 2006-2008 Jean-Philippe Lang +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +class MailHandlerController < ActionController::Base + before_filter :check_credential + + verify :method => :post, + :only => :index, + :render => { :nothing => true, :status => 405 } + + # Submits an incoming email to MailHandler + def index + options = params.dup + email = options.delete(:email) + if MailHandler.receive(email, options) + render :nothing => true, :status => :created + else + render :nothing => true, :status => :unprocessable_entity + end + end + + private + + def check_credential + User.current = nil + unless Setting.mail_handler_api_enabled? && params[:key] == Setting.mail_handler_api_key + render :nothing => true, :status => 403 + end + end +end |