Drop dmail filters.

Few people used dmail filters (~900 users in 5 years) and even fewer
used them correctly. Most people used them to try to block dmail spam,
but usually they either blocked too much (by adding common words that
are present in nearly all dmails, causing all mails to them to be
filtered) or too little (blocking specific email addresses or urls,
which usually are never seen again after the spammer is banned).
Nowadays the spam detection system does a better job of filtering spam.
This commit is contained in:
evazion
2020-01-19 12:55:58 -06:00
parent c2688e3aff
commit cae9a5d7e3
15 changed files with 11 additions and 317 deletions

View File

@@ -1,57 +0,0 @@
require 'test_helper'
class DmailFilterTest < ActiveSupport::TestCase
def setup
super
@receiver = FactoryBot.create(:user)
@sender = FactoryBot.create(:user)
end
def create_dmail(body, title)
CurrentUser.scoped(@sender, "127.0.0.1") do
Dmail.create_split(:to_id => @receiver.id, :body => body, :title => title)
end
end
context "a dmail filter for a word" do
setup do
@dmail_filter = @receiver.create_dmail_filter(:words => "banned")
end
should "filter on that word in the body" do
create_dmail("banned", "okay")
assert_equal(true, @receiver.dmails.last.is_read?)
end
should "filter on that word in the title" do
create_dmail("okay", "banned")
assert_equal(true, @receiver.dmails.last.is_read?)
end
should "be case insensitive" do
create_dmail("Banned.", "okay")
assert_equal(true, @receiver.dmails.last.is_read?)
end
end
context "a dmail filter for a user name" do
setup do
@dmail_filter = @receiver.create_dmail_filter(:words => @sender.name)
end
should "filter on the sender" do
create_dmail("okay", "okay")
assert_equal(true, @receiver.dmails.last.is_read?)
end
end
context "a dmail filter containing multiple words" do
should "filter dmails containing any of the words" do
@receiver.create_dmail_filter(words: "foo bar spam")
create_dmail("this is a test (not *SPAM*)", "hello world")
assert_equal(true, @receiver.dmails.last.is_read?)
end
end
end

View File

@@ -43,49 +43,6 @@ class DmailTest < ActiveSupport::TestCase
end
end
context "filter" do
setup do
@recipient = FactoryBot.create(:user)
@recipient.create_dmail_filter(:words => "banned")
@dmail = FactoryBot.build(:dmail, :title => "xxx", :owner => @recipient, :body => "banned word here", :to => @recipient, :from => @user)
end
should "detect banned words" do
assert(@recipient.dmail_filter.filtered?(@dmail))
end
should "autoread if it has a banned word" do
@dmail.save
assert_equal(true, @dmail.is_read?)
end
should "not update the recipient's has_mail if filtered" do
@dmail.save
@recipient.reload
assert_equal(false, @recipient.has_mail?)
end
should "be ignored when sender is a moderator" do
CurrentUser.scoped(FactoryBot.create(:moderator_user), "127.0.0.1") do
@dmail = FactoryBot.create(:dmail, :owner => @recipient, :body => "banned word here", :to => @recipient)
end
assert_equal(false, @recipient.dmail_filter.filtered?(@dmail))
assert_equal(false, @dmail.is_read?)
assert_equal(true, @recipient.has_mail?)
end
context "that is empty" do
setup do
@recipient.dmail_filter.update(words: " ")
end
should "not filter everything" do
assert(!@recipient.dmail_filter.filtered?(@dmail))
end
end
end
context "from a banned user" do
setup do
@user.update_attribute(:is_banned, true)