feat: add SKIP_INCOMING_BCC_PROCESSING as internal config (#12484)

Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
This commit is contained in:
Shivam Mishra
2025-09-22 17:52:56 +05:30
committed by GitHub
parent 3655f4cedc
commit 8764ade161
6 changed files with 163 additions and 13 deletions

View File

@@ -2,6 +2,7 @@ require 'rails_helper'
describe EmailChannelFinder do
include ActionMailbox::TestHelper
let!(:channel_email) { create(:channel_email) }
describe '#perform' do
@@ -48,6 +49,75 @@ describe EmailChannelFinder do
expect(channel).to eq(channel_email)
end
it 'skip bcc email when account is configured to skip BCC processing' do
channel_email.update(email: 'test@example.com')
reply_mail.mail['to'] = nil
reply_mail.mail['bcc'] = 'test@example.com'
allow(GlobalConfigService).to receive(:load)
.with('SKIP_INCOMING_BCC_PROCESSING', '')
.and_return(channel_email.account_id.to_s)
channel = described_class.new(reply_mail.mail).perform
expect(channel).to be_nil
end
it 'skip bcc email when account is in multiple account ids config' do
channel_email.update(email: 'test@example.com')
reply_mail.mail['to'] = nil
reply_mail.mail['bcc'] = 'test@example.com'
# Include this account along with other account IDs
other_account_ids = [123, 456, channel_email.account_id, 789]
allow(GlobalConfigService).to receive(:load)
.with('SKIP_INCOMING_BCC_PROCESSING', '')
.and_return(other_account_ids.join(','))
channel = described_class.new(reply_mail.mail).perform
expect(channel).to be_nil
end
it 'process bcc email when account is not in skip config' do
channel_email.update(email: 'test@example.com')
reply_mail.mail['to'] = nil
reply_mail.mail['bcc'] = 'test@example.com'
# Configure other account IDs but not this one
other_account_ids = [123, 456, 789]
allow(GlobalConfigService).to receive(:load)
.with('SKIP_INCOMING_BCC_PROCESSING', '')
.and_return(other_account_ids.join(','))
channel = described_class.new(reply_mail.mail).perform
expect(channel).to eq(channel_email)
end
it 'process bcc email when skip config is empty' do
channel_email.update(email: 'test@example.com')
reply_mail.mail['to'] = nil
reply_mail.mail['bcc'] = 'test@example.com'
allow(GlobalConfigService).to receive(:load)
.with('SKIP_INCOMING_BCC_PROCESSING', '')
.and_return('')
channel = described_class.new(reply_mail.mail).perform
expect(channel).to eq(channel_email)
end
it 'process bcc email when skip config is nil' do
channel_email.update(email: 'test@example.com')
reply_mail.mail['to'] = nil
reply_mail.mail['bcc'] = 'test@example.com'
allow(GlobalConfigService).to receive(:load)
.with('SKIP_INCOMING_BCC_PROCESSING', '')
.and_return(nil)
channel = described_class.new(reply_mail.mail).perform
expect(channel).to eq(channel_email)
end
it 'return channel with X-Original-To email' do
channel_email.update(email: 'test@example.com')
reply_mail.mail['to'] = nil
@@ -55,6 +125,19 @@ describe EmailChannelFinder do
channel = described_class.new(reply_mail.mail).perform
expect(channel).to eq(channel_email)
end
it 'process X-Original-To email even when account is configured to skip BCC processing' do
channel_email.update(email: 'test@example.com')
reply_mail.mail['to'] = nil
reply_mail.mail['X-Original-To'] = 'test@example.com'
allow(GlobalConfigService).to receive(:load)
.with('SKIP_INCOMING_BCC_PROCESSING', '')
.and_return(channel_email.account_id.to_s)
channel = described_class.new(reply_mail.mail).perform
expect(channel).to eq(channel_email)
end
end
end
end

View File

@@ -66,6 +66,20 @@ RSpec.describe ApplicationMailbox do
expect(dbl).to receive(:perform_processing).and_return(true)
described_class.route reply_cc_mail
end
it 'skips routing when BCC processing is disabled for account' do
allow(GlobalConfigService).to receive(:load).with('SKIP_INCOMING_BCC_PROCESSING', '').and_return(channel_email.account_id.to_s)
# Create a BCC-only email scenario
bcc_mail = create_inbound_email_from_fixture('support.eml')
bcc_mail.mail['to'] = nil
bcc_mail.mail['bcc'] = 'care@example.com'
channel_email.update(email: 'care@example.com')
expect(DefaultMailbox).to receive(:new).and_return(double.tap { |d| expect(d).to receive(:perform_processing) })
described_class.route bcc_mail
end
end
describe 'Invalid Mail To Address' do

View File

@@ -334,5 +334,19 @@ RSpec.describe SupportMailbox do
expect(conversation.messages.last.content_attributes['email']['subject']).to eq('attachment with html')
end
end
describe 'when BCC processing is disabled for account' do
before do
allow(GlobalConfigService).to receive(:load).with('SKIP_INCOMING_BCC_PROCESSING', '').and_return(account.id.to_s)
end
it 'does not process BCC-only emails' do
bcc_mail = create_inbound_email_from_fixture('support.eml')
bcc_mail.mail['to'] = nil
bcc_mail.mail['bcc'] = 'care@example.com'
expect { described_class.receive bcc_mail }.to raise_error('Email channel/inbox not found')
end
end
end
end