From a51c191a665c592711232c9f2010522f0af2f55d Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Wed, 5 Apr 2017 12:45:58 -0400 Subject: [PATCH] Make Email::Receiver.check_address() into a class method. --- app/controllers/admin/email_controller.rb | 2 +- lib/email/receiver.rb | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/controllers/admin/email_controller.rb b/app/controllers/admin/email_controller.rb index ca7dd112c00..0d9d0aca269 100644 --- a/app/controllers/admin/email_controller.rb +++ b/app/controllers/admin/email_controller.rb @@ -75,7 +75,7 @@ class Admin::EmailController < Admin::AdminController # These strings aren't localized; they are sent to an anonymous SMTP user. if User.find_by_email(params[:from]).nil? && !SiteSetting.enable_staged_users render json: { reject: true, reason: "Mail from your address is not accepted. Do you have an account here?" } - elsif Email::Receiver.new(params[:from]).check_address(params[:to]).nil? + elsif Email::Receiver.check_address(Email.downcase(params[:to])).nil? render json: { reject: true, reason: "Mail to this address is not accepted. Check the address and try to send again?" } else render json: { reject: false } diff --git a/lib/email/receiver.rb b/lib/email/receiver.rb index ec113b504ac..2322970bae1 100644 --- a/lib/email/receiver.rb +++ b/lib/email/receiver.rb @@ -302,11 +302,11 @@ module Email def destinations all_destinations - .map { |d| check_address(d) } + .map { |d| Email::Receiver.check_address(d) } .drop_while(&:blank?) end - def check_address(address) + def self.check_address(address) # only check for a group/category when 'email_in' is enabled if SiteSetting.email_in group = Group.find_by_email(address) @@ -317,7 +317,7 @@ module Email end # reply - match = reply_by_email_address_regex.match(address) + match = Email::Receiver.reply_by_email_address_regex.match(address) if match && match.captures match.captures.each do |c| next if c.blank? @@ -443,7 +443,7 @@ module Email true end - def reply_by_email_address_regex + def self.reply_by_email_address_regex @reply_by_email_address_regex ||= begin reply_addresses = [ SiteSetting.reply_by_email_address, @@ -652,7 +652,7 @@ module Email end def should_invite?(email) - email !~ reply_by_email_address_regex && + email !~ Email::Receiver.reply_by_email_address_regex && email !~ group_incoming_emails_regex && email !~ category_email_in_regex end