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

@@ -14,7 +14,6 @@ class Dmail < ApplicationRecord
belongs_to :from, :class_name => "User"
after_initialize :initialize_attributes, if: :new_record?
before_create :auto_read_if_filtered
after_create :update_recipient
after_commit :send_email, on: :create
@@ -185,16 +184,6 @@ class Dmail < ApplicationRecord
owner == to
end
def filtered?
CurrentUser.dmail_filter.try(:filtered?, self)
end
def auto_read_if_filtered
if is_recipient? && to.dmail_filter.try(:filtered?, self)
self.is_read = true
end
end
def update_recipient
if is_recipient? && !is_deleted? && !is_read?
to.update(has_mail: true, unread_dmail_count: to.dmails.unread.count)

View File

@@ -1,27 +0,0 @@
class DmailFilter < ApplicationRecord
extend Memoist
belongs_to :user
before_validation :initialize_user
def initialize_user
unless user_id
self.user_id = CurrentUser.user.id
end
end
def filtered?(dmail)
dmail.from.level < User::Levels::MODERATOR && has_filter? && (dmail.body.match?(regexp) || dmail.title.match?(regexp) || dmail.from.name.match?(regexp))
end
def has_filter?
!words.strip.empty?
end
def regexp
union = words.split(/[[:space:]]+/).map { |word| Regexp.escape(word) }.join("|")
/\b#{union}\b/i
end
memoize :regexp
end

View File

@@ -107,7 +107,6 @@ class User < ApplicationRecord
has_one :recent_ban, -> {order("bans.id desc")}, :class_name => "Ban"
has_one :api_key
has_one :dmail_filter
has_one :super_voter
has_one :token_bucket
has_many :notes, foreign_key: :creator_id
@@ -122,7 +121,6 @@ class User < ApplicationRecord
has_many :tag_aliases, foreign_key: :creator_id
has_many :tag_implications, foreign_key: :creator_id
belongs_to :inviter, class_name: "User", optional: true
accepts_nested_attributes_for :dmail_filter
enum theme: { light: 0, dark: 100 }, _suffix: true