From 5dd08133ef397d4e63545ef95aa287b91e1b0ed2 Mon Sep 17 00:00:00 2001 From: Toshi MARUYAMA Date: Tue, 31 Jan 2012 12:49:06 +0000 Subject: [PATCH] code layout cleanup app/models/mail_handler.rb git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8745 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/mail_handler.rb | 55 +++++++++++++++++++++++++++++--------- 1 file changed, 42 insertions(+), 13 deletions(-) diff --git a/app/models/mail_handler.rb b/app/models/mail_handler.rb index 151a23660..81af7e411 100644 --- a/app/models/mail_handler.rb +++ b/app/models/mail_handler.rb @@ -29,7 +29,9 @@ class MailHandler < ActionMailer::Base @@handler_options[:issue] ||= {} - @@handler_options[:allow_override] = @@handler_options[:allow_override].split(',').collect(&:strip) if @@handler_options[:allow_override].is_a?(String) + if @@handler_options[:allow_override].is_a?(String) + @@handler_options[:allow_override] = @@handler_options[:allow_override].split(',').collect(&:strip) + end @@handler_options[:allow_override] ||= [] # Project needs to be overridable if not specified @@handler_options[:allow_override] << 'project' unless @@handler_options[:issue].has_key?(:project) @@ -47,12 +49,16 @@ class MailHandler < ActionMailer::Base 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 + if logger && logger.info + logger.info "MailHandler: ignoring email from Redmine emission address [#{sender_email}]" + end 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 + if logger && logger.info + logger.info "MailHandler: ignoring email from non-active user [#{@user.login}]" + end return false end if @user.nil? @@ -63,15 +69,21 @@ class MailHandler < ActionMailer::Base when 'create' @user = create_user_from_email if @user - logger.info "MailHandler: [#{@user.login}] account created" if logger && logger.info + if logger && logger.info + logger.info "MailHandler: [#{@user.login}] account created" + end Mailer.deliver_account_information(@user, @user.password) else - logger.error "MailHandler: could not create account for [#{sender_email}]" if logger && logger.error + if logger && logger.error + logger.error "MailHandler: could not create account for [#{sender_email}]" + end 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 + if logger && logger.info + logger.info "MailHandler: ignoring email from unknown user [#{sender_email}]" + end return false end end @@ -149,7 +161,10 @@ class MailHandler < ActionMailer::Base return unless issue # check permission unless @@handler_options[:no_permission_check] - raise UnauthorizedAction unless user.allowed_to?(:add_issue_notes, issue.project) || user.allowed_to?(:edit_issues, issue.project) + unless user.allowed_to?(:add_issue_notes, issue.project) || + user.allowed_to?(:edit_issues, issue.project) + raise UnauthorizedAction + end end # ignore CLI-supplied defaults for new issues @@ -161,7 +176,9 @@ class MailHandler < ActionMailer::Base journal.notes = cleaned_up_text_body add_attachments(issue) issue.save! - logger.info "MailHandler: issue ##{issue.id} updated by #{user}" if logger && logger.info + if logger && logger.info + logger.info "MailHandler: issue ##{issue.id} updated by #{user}" + end journal end @@ -192,7 +209,9 @@ class MailHandler < ActionMailer::Base add_attachments(reply) reply else - logger.info "MailHandler: ignoring reply from [#{sender_email}] to a locked topic" if logger && logger.info + if logger && logger.info + logger.info "MailHandler: ignoring reply from [#{sender_email}] to a locked topic" + end end end end @@ -241,8 +260,12 @@ class MailHandler < ActionMailer::Base def extract_keyword!(text, attr, format=nil) keys = [attr.to_s.humanize] if attr.is_a?(Symbol) - keys << l("field_#{attr}", :default => '', :locale => user.language) if user && user.language.present? - keys << l("field_#{attr}", :default => '', :locale => Setting.default_language) if Setting.default_language.present? + if user && user.language.present? + keys << l("field_#{attr}", :default => '', :locale => user.language) + end + if Setting.default_language.present? + keys << l("field_#{attr}", :default => '', :locale => Setting.default_language) + end end keys.reject! {|k| k.blank?} keys.collect! {|k| Regexp.escape(k)} @@ -388,10 +411,16 @@ class MailHandler < ActionMailer::Base keyword = keyword.to_s.downcase assignable = issue.assignable_users assignee = nil - assignee ||= assignable.detect {|a| a.mail.to_s.downcase == keyword || a.login.to_s.downcase == keyword} + assignee ||= assignable.detect {|a| + a.mail.to_s.downcase == keyword || + a.login.to_s.downcase == keyword + } if assignee.nil? && keyword.match(/ /) firstname, lastname = *(keyword.split) # "First Last Throwaway" - assignee ||= assignable.detect {|a| a.is_a?(User) && a.firstname.to_s.downcase == firstname && a.lastname.to_s.downcase == lastname} + assignee ||= assignable.detect {|a| + a.is_a?(User) && a.firstname.to_s.downcase == firstname && + a.lastname.to_s.downcase == lastname + } end if assignee.nil? assignee ||= assignable.detect {|a| a.is_a?(Group) && a.name.downcase == keyword}