From: Toshi MARUYAMA Date: Sat, 19 Oct 2019 13:34:05 +0000 (+0000) Subject: code cleanup: rubocop: fix Lint/IneffectiveAccessModifier in app/models/mail_handler.rb X-Git-Tag: 4.1.0~321 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=f2b274476ae775a147df8a44ea0c3fdbd184c6ff;p=redmine.git code cleanup: rubocop: fix Lint/IneffectiveAccessModifier in app/models/mail_handler.rb git-svn-id: http://svn.redmine.org/redmine/trunk@18782 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 519f17fe2..a782c472c 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -388,10 +388,6 @@ Lint/HandleExceptions: - 'lib/redmine/scm/adapters/cvs_adapter.rb' - 'lib/redmine/scm/adapters/subversion_adapter.rb' -Lint/IneffectiveAccessModifier: - Exclude: - - 'app/models/mail_handler.rb' - Lint/InterpolationCheck: Exclude: - 'app/models/user.rb' diff --git a/app/models/mail_handler.rb b/app/models/mail_handler.rb index 3e7b02b90..7f03591e2 100644 --- a/app/models/mail_handler.rb +++ b/app/models/mail_handler.rb @@ -523,18 +523,6 @@ class MailHandler < ActionMailer::Base subject.strip[0,255] end - # Converts a HTML email body to text - def self.html_body_to_text(html) - Redmine::WikiFormatting.html_parser.to_text(html) - end - - # Converts a plain/text email body to text - def self.plain_text_body_to_text(text) - # Removes leading spaces that would cause the line to be rendered as - # preformatted text with textile - text.gsub(/^ +(?![*#])/, '') - end - def self.assign_string_attribute_with_limit(object, attribute, value, limit=nil) limit ||= object.class.columns_hash[attribute.to_s].limit || 255 value = value.to_s.slice(0, limit) @@ -542,29 +530,43 @@ class MailHandler < ActionMailer::Base end private_class_method :assign_string_attribute_with_limit - # Returns a User from an email address and a full name - def self.new_user_from_attributes(email_address, fullname=nil) - user = User.new + # Singleton class method is public + class << self + # Converts a HTML email body to text + def html_body_to_text(html) + Redmine::WikiFormatting.html_parser.to_text(html) + end + + # Converts a plain/text email body to text + def plain_text_body_to_text(text) + # Removes leading spaces that would cause the line to be rendered as + # preformatted text with textile + text.gsub(/^ +(?![*#])/, '') + end - # Truncating the email address would result in an invalid format - user.mail = email_address - assign_string_attribute_with_limit(user, 'login', email_address, User::LOGIN_LENGTH_LIMIT) + # Returns a User from an email address and a full name + def new_user_from_attributes(email_address, fullname=nil) + user = User.new - names = fullname.blank? ? email_address.gsub(/@.*$/, '').split('.') : fullname.split - assign_string_attribute_with_limit(user, 'firstname', names.shift, 30) - assign_string_attribute_with_limit(user, 'lastname', names.join(' '), 30) - user.lastname = '-' if user.lastname.blank? - user.language = Setting.default_language - user.generate_password = true - user.mail_notification = 'only_my_events' + # Truncating the email address would result in an invalid format + user.mail = email_address + assign_string_attribute_with_limit(user, 'login', email_address, User::LOGIN_LENGTH_LIMIT) - unless user.valid? - user.login = "user#{Redmine::Utils.random_hex(6)}" unless user.errors[:login].blank? - user.firstname = "-" unless user.errors[:firstname].blank? - (puts user.errors[:lastname]; user.lastname = "-") unless user.errors[:lastname].blank? - end + names = fullname.blank? ? email_address.gsub(/@.*$/, '').split('.') : fullname.split + assign_string_attribute_with_limit(user, 'firstname', names.shift, 30) + assign_string_attribute_with_limit(user, 'lastname', names.join(' '), 30) + user.lastname = '-' if user.lastname.blank? + user.language = Setting.default_language + user.generate_password = true + user.mail_notification = 'only_my_events' - user + unless user.valid? + user.login = "user#{Redmine::Utils.random_hex(6)}" unless user.errors[:login].blank? + user.firstname = "-" unless user.errors[:firstname].blank? + (puts user.errors[:lastname]; user.lastname = "-") unless user.errors[:lastname].blank? + end + user + end end # Creates a User for the +email+ sender