Merge pull request #4793 from rcgordon/smtp-fast-rejection
Added an API to ask if an incoming email should be dropped at the SMTP level.
This commit is contained in:
commit
93556bb950
|
@ -69,6 +69,19 @@ class Admin::EmailController < Admin::AdminController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def smtp_should_reject
|
||||||
|
params.require(:from)
|
||||||
|
params.require(:to)
|
||||||
|
# These strings aren't localized; they are sent to an anonymous SMTP user.
|
||||||
|
if !User.exists?(email: Email.downcase(params[:from])) && !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.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 }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def handle_mail
|
def handle_mail
|
||||||
params.require(:email)
|
params.require(:email)
|
||||||
Email::Processor.process!(params[:email])
|
Email::Processor.process!(params[:email])
|
||||||
|
|
|
@ -155,6 +155,7 @@ Discourse::Application.routes.draw do
|
||||||
get "/incoming_from_bounced/:id" => "email#incoming_from_bounced"
|
get "/incoming_from_bounced/:id" => "email#incoming_from_bounced"
|
||||||
get "preview-digest" => "email#preview_digest"
|
get "preview-digest" => "email#preview_digest"
|
||||||
get "send-digest" => "email#send_digest"
|
get "send-digest" => "email#send_digest"
|
||||||
|
get "smtp_should_reject"
|
||||||
post "handle_mail"
|
post "handle_mail"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -302,11 +302,11 @@ module Email
|
||||||
|
|
||||||
def destinations
|
def destinations
|
||||||
all_destinations
|
all_destinations
|
||||||
.map { |d| check_address(d) }
|
.map { |d| Email::Receiver.check_address(d) }
|
||||||
.drop_while(&:blank?)
|
.drop_while(&:blank?)
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_address(address)
|
def self.check_address(address)
|
||||||
# only check for a group/category when 'email_in' is enabled
|
# only check for a group/category when 'email_in' is enabled
|
||||||
if SiteSetting.email_in
|
if SiteSetting.email_in
|
||||||
group = Group.find_by_email(address)
|
group = Group.find_by_email(address)
|
||||||
|
@ -317,7 +317,7 @@ module Email
|
||||||
end
|
end
|
||||||
|
|
||||||
# reply
|
# reply
|
||||||
match = reply_by_email_address_regex.match(address)
|
match = Email::Receiver.reply_by_email_address_regex.match(address)
|
||||||
if match && match.captures
|
if match && match.captures
|
||||||
match.captures.each do |c|
|
match.captures.each do |c|
|
||||||
next if c.blank?
|
next if c.blank?
|
||||||
|
@ -443,7 +443,7 @@ module Email
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
def reply_by_email_address_regex
|
def self.reply_by_email_address_regex
|
||||||
@reply_by_email_address_regex ||= begin
|
@reply_by_email_address_regex ||= begin
|
||||||
reply_addresses = [
|
reply_addresses = [
|
||||||
SiteSetting.reply_by_email_address,
|
SiteSetting.reply_by_email_address,
|
||||||
|
@ -652,7 +652,7 @@ module Email
|
||||||
end
|
end
|
||||||
|
|
||||||
def should_invite?(email)
|
def should_invite?(email)
|
||||||
email !~ reply_by_email_address_regex &&
|
email !~ Email::Receiver.reply_by_email_address_regex &&
|
||||||
email !~ group_incoming_emails_regex &&
|
email !~ group_incoming_emails_regex &&
|
||||||
email !~ category_email_in_regex
|
email !~ category_email_in_regex
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue