FEATURE: new 'ignore_by_title' site setting

This commit is contained in:
Régis Hanol 2016-05-18 23:07:01 +02:00
parent 69dc706ba1
commit c75d58ab21
5 changed files with 27 additions and 1 deletions

View File

@ -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."

View File

@ -576,6 +576,9 @@ email:
client: true
default: 4
min: 1
ignore_by_title:
type: list
default: ''
files:

View File

@ -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

View File

@ -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
View 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 ;)