You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mail_handler_controller.rb 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006-2022 Jean-Philippe Lang
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License
  7. # as published by the Free Software Foundation; either version 2
  8. # of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. class MailHandlerController < ActionController::Base
  19. include ActiveSupport::SecurityUtils
  20. before_action :check_credential
  21. # Displays the email submission form
  22. def new
  23. end
  24. # Submits an incoming email to MailHandler
  25. def index
  26. # MailHandlerController#index should permit all options set by
  27. # RedmineMailHandler#submit in rdm-mailhandler.rb.
  28. # It must be kept in sync.
  29. options = params.permit(
  30. :key,
  31. :email,
  32. :allow_override,
  33. :unknown_user,
  34. :default_group,
  35. :no_account_notice,
  36. :no_notification,
  37. :no_permission_check,
  38. :project_from_subaddress,
  39. {
  40. issue: [
  41. :project,
  42. :status,
  43. :tracker,
  44. :category,
  45. :priority,
  46. :assigned_to,
  47. :fixed_version,
  48. :is_private
  49. ]
  50. }
  51. ).to_h
  52. email = options.delete(:email)
  53. if MailHandler.safe_receive(email, options)
  54. head :created
  55. else
  56. head :unprocessable_entity
  57. end
  58. end
  59. private
  60. def check_credential
  61. User.current = nil
  62. unless Setting.mail_handler_api_enabled? && secure_compare(params[:key].to_s, Setting.mail_handler_api_key.to_s)
  63. render :plain => 'Access denied. Incoming emails WS is disabled or key is invalid.', :status => 403
  64. end
  65. end
  66. end