mirror of
https://github.com/discourse/discourse.git
synced 2024-11-28 19:53:53 -06:00
FEATURE: new 'ignore_by_title' site setting
This commit is contained in:
parent
69dc706ba1
commit
c75d58ab21
@ -1178,6 +1178,7 @@ en:
|
||||
auto_generated_whitelist: "List of email addresses that won't be checked for auto-generated content."
|
||||
block_auto_generated_emails: "Block incoming emails identified as being auto generated."
|
||||
bounce_score_threshold: "Max score before we will stop emailing a user. Soft bounce adds 1, hard bounce adds 2, score reset 30 days after last bounce."
|
||||
ignore_by_title: "Ignore incoming emails based on their title."
|
||||
|
||||
manual_polling_enabled: "Push emails using the API for email replies."
|
||||
pop3_polling_enabled: "Poll via POP3 for email replies."
|
||||
|
@ -576,6 +576,9 @@ email:
|
||||
client: true
|
||||
default: 4
|
||||
min: 1
|
||||
ignore_by_title:
|
||||
type: list
|
||||
default: ''
|
||||
|
||||
|
||||
files:
|
||||
|
@ -38,14 +38,20 @@ module Email
|
||||
end
|
||||
|
||||
def process!
|
||||
return if is_blacklisted?
|
||||
@from_email, @from_display_name = parse_from_field
|
||||
@incoming_email = find_or_create_incoming_email
|
||||
process_internal
|
||||
rescue => e
|
||||
@incoming_email.update_columns(error: e.to_s)
|
||||
@incoming_email.update_columns(error: e.to_s) if @incoming_email
|
||||
raise
|
||||
end
|
||||
|
||||
def is_blacklisted?
|
||||
return false if SiteSetting.ignore_by_title.blank?
|
||||
Regexp.new(SiteSetting.ignore_by_title) =~ @mail.subject
|
||||
end
|
||||
|
||||
def find_or_create_incoming_email
|
||||
IncomingEmail.find_or_create_by(message_id: @message_id) do |ie|
|
||||
ie.raw = @raw_email
|
||||
|
@ -407,6 +407,11 @@ describe Email::Receiver do
|
||||
expect { process(:tl4_user) }.to change(Topic, :count)
|
||||
end
|
||||
|
||||
it "ignores by title" do
|
||||
SiteSetting.ignore_by_title = "foo"
|
||||
expect { process(:ignored) }.to_not change(Topic, :count)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
11
spec/fixtures/emails/ignored.eml
vendored
Normal file
11
spec/fixtures/emails/ignored.eml
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
Return-Path: <foo@bar.com>
|
||||
From: Foo Bar <foo@bar.com>
|
||||
To: category@foo.com
|
||||
Subject: This is a foo topic
|
||||
Date: Fri, 15 Jan 2016 00:12:43 +0100
|
||||
Message-ID: <53@foo.bar.mail>
|
||||
Mime-Version: 1.0
|
||||
Content-Type: text/plain; charset=UTF-8
|
||||
Content-Transfer-Encoding: quoted-printable
|
||||
|
||||
Hey, this is an incoming email that will be ignored ;)
|
Loading…
Reference in New Issue
Block a user