DEV: Delete dead Topic#incoming_email_addresses code (#19970)

This code has been dead since b463a80cbf,
we can delete it now.
This commit is contained in:
Martin Brennan 2023-01-25 09:34:41 +10:00 committed by GitHub
parent 3866867e45
commit 88a972c61b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 123 deletions

View File

@ -1892,46 +1892,6 @@ class Topic < ActiveRecord::Base
.first
end
def incoming_email_addresses(group: nil, received_before: Time.zone.now)
email_addresses = Set.new
# TODO(martin) Look at improving this N1, it will just get slower the
# more replies/incoming emails there are for the topic.
self
.incoming_email
.where("created_at <= ?", received_before)
.each do |incoming_email|
to_addresses = incoming_email.to_addresses_split
cc_addresses = incoming_email.cc_addresses_split
combined_addresses = [to_addresses, cc_addresses].flatten
# We only care about the emails addressed to the group or CC'd to the
# group if the group is present. If combined addresses is empty we do
# not need to do this check, and instead can proceed on to adding the
# from address.
#
# Will not include test1@gmail.com if the only IncomingEmail
# is:
#
# from: test1@gmail.com
# to: test+support@discoursemail.com
#
# Because we don't care about the from addresses and also the to address
# is not the email_username, which will be something like test1@gmail.com.
if group.present? && combined_addresses.any?
next if combined_addresses.none? { |address| address =~ group.email_username_regex }
end
email_addresses.add(incoming_email.from_address)
email_addresses.merge(combined_addresses)
end
email_addresses.subtract([nil, ""])
email_addresses.delete(group.email_username) if group.present?
email_addresses.to_a
end
def create_invite_notification!(target_user, notification_type, invited_by, post_number: 1)
if UserCommScreener.new(
acting_user: invited_by,

View File

@ -1550,10 +1550,12 @@ RSpec.describe Email::Receiver do
handler_calls = 0
handler =
proc do |topic|
expect(topic.incoming_email_addresses).to contain_exactly(
"discourse@bar.com",
"category@foo.com",
)
expect(
[
topic.incoming_email.first.from_address,
topic.incoming_email.first.to_addresses_split,
].flatten,
).to contain_exactly("discourse@bar.com", "category@foo.com")
handler_calls += 1
end

View File

@ -3271,85 +3271,6 @@ RSpec.describe Topic do
end
end
describe "#incoming_email_addresses" do
fab!(:group) do
Fabricate(
:group,
smtp_server: "imap.gmail.com",
smtp_port: 587,
email_username: "discourse@example.com",
email_password: "discourse@example.com",
)
end
fab!(:topic) do
Fabricate(
:private_message_topic,
topic_allowed_groups: [Fabricate.build(:topic_allowed_group, group: group)],
)
end
let!(:incoming1) do
Fabricate(
:incoming_email,
to_addresses: "discourse@example.com",
from_address: "johnsmith@user.com",
topic: topic,
post: topic.posts.first,
created_at: 20.minutes.ago,
)
end
let!(:incoming2) do
Fabricate(
:incoming_email,
from_address: "discourse@example.com",
to_addresses: "johnsmith@user.com",
topic: topic,
post: Fabricate(:post, topic: topic),
created_at: 10.minutes.ago,
)
end
let!(:incoming3) do
Fabricate(
:incoming_email,
to_addresses: "discourse@example.com",
from_address: "johnsmith@user.com",
topic: topic,
post: topic.posts.first,
cc_addresses: "otherguy@user.com",
created_at: 2.minutes.ago,
)
end
let!(:incoming4) do
Fabricate(
:incoming_email,
to_addresses: "unrelated@test.com",
from_address: "discourse@example.com",
topic: topic,
post: topic.posts.first,
created_at: 1.minutes.ago,
)
end
it "returns an array of all the incoming email addresses" do
expect(topic.incoming_email_addresses).to match_array(
%w[discourse@example.com johnsmith@user.com otherguy@user.com unrelated@test.com],
)
end
it "returns an array of all the incoming email addresses where incoming was received before X" do
expect(topic.incoming_email_addresses(received_before: 5.minutes.ago)).to match_array(
%w[discourse@example.com johnsmith@user.com],
)
end
context "when the group is present" do
it "excludes incoming emails that are not to or CCd to the group" do
expect(topic.incoming_email_addresses(group: group)).not_to include("unrelated@test.com")
end
end
end
describe "#cannot_permanently_delete_reason" do
fab!(:post) { Fabricate(:post) }
let!(:topic) { post.topic }