Class: MailHandler
- Inherits:
-
ActionMailer::Base
- Object
- ActionMailer::Base
- MailHandler
- Includes:
- ActionView::Helpers::SanitizeHelper, Redmine::I18n
- Defined in:
- app/models/mail_handler.rb
Overview
redMine - project management software Copyright © 2006-2007 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.
Defined Under Namespace
Classes: MissingInformation, UnauthorizedAction
Instance Attribute Summary collapse
-
#email ⇒ Object
readonly
Returns the value of attribute email.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Class Method Summary collapse
Instance Method Summary collapse
-
#receive(email) ⇒ Object
Processes incoming emails Returns the created object (eg. an issue, a message) or false.
Methods included from Redmine::I18n
#current_language, #day_name, #find_language, #format_date, #format_time, included, #l, #l_hours, #l_or_humanize, #ll, #month_name, #set_language_if_valid, #valid_languages
Instance Attribute Details
#email ⇒ Object (readonly)
Returns the value of attribute email.
25 26 27 |
# File 'app/models/mail_handler.rb', line 25 def email @email end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
25 26 27 |
# File 'app/models/mail_handler.rb', line 25 def user @user end |
Class Method Details
.receive(email, options = {}) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/models/mail_handler.rb', line 27 def self.receive(email, ={}) @@handler_options = .dup @@handler_options[:issue] ||= {} @@handler_options[:allow_override] = @@handler_options[:allow_override].split(',').collect(&:strip) if @@handler_options[:allow_override].is_a?(String) @@handler_options[:allow_override] ||= [] # Project needs to be overridable if not specified @@handler_options[:allow_override] << 'project' unless @@handler_options[:issue].has_key?(:project) # Status overridable by default @@handler_options[:allow_override] << 'status' unless @@handler_options[:issue].has_key?(:status) @@handler_options[:no_permission_check] = (@@handler_options[:no_permission_check].to_s == '1' ? true : false) super email end |
Instance Method Details
#receive(email) ⇒ Object
Processes incoming emails Returns the created object (eg. an issue, a message) or false
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'app/models/mail_handler.rb', line 45 def receive(email) @email = email sender_email = email.from.to_a.first.to_s.strip # Ignore emails received from the application emission address to avoid hell cycles if sender_email.downcase == Setting.mail_from.to_s.strip.downcase logger.info "MailHandler: ignoring email from Redmine emission address [#{sender_email}]" if logger && logger.info return false end @user = User.find_by_mail(sender_email) if sender_email.present? if @user && !@user.active? logger.info "MailHandler: ignoring email from non-active user [#{@user.login}]" if logger && logger.info return false end if @user.nil? # Email was submitted by an unknown user case @@handler_options[:unknown_user] when 'accept' @user = User.anonymous when 'create' @user = MailHandler.create_user_from_email(email) if @user logger.info "MailHandler: [#{@user.login}] account created" if logger && logger.info Mailer.deliver_account_information(@user, @user.password) else logger.error "MailHandler: could not create account for [#{sender_email}]" if logger && logger.error return false end else # Default behaviour, emails from unknown users are ignored logger.info "MailHandler: ignoring email from unknown user [#{sender_email}]" if logger && logger.info return false end end User.current = @user dispatch end |