From 12cd15b6ad2783634308cdee2d03f70d07adbb3c Mon Sep 17 00:00:00 2001 From: Sojan Jose Date: Wed, 26 Oct 2022 03:40:47 -0700 Subject: [PATCH] chore: Disable email processing for suspended accounts (#5762) - Disable email processing for suspended accounts --- app/mailboxes/support_mailbox.rb | 2 ++ spec/mailboxes/support_mailbox_spec.rb | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/app/mailboxes/support_mailbox.rb b/app/mailboxes/support_mailbox.rb index 8accda902..ca7f39a9a 100644 --- a/app/mailboxes/support_mailbox.rb +++ b/app/mailboxes/support_mailbox.rb @@ -7,6 +7,8 @@ class SupportMailbox < ApplicationMailbox :decorate_mail def process + # to turn off spam conversation creation + return unless @account.active? # prevent loop from chatwoot notification emails return if notification_email_from_chatwoot? diff --git a/spec/mailboxes/support_mailbox_spec.rb b/spec/mailboxes/support_mailbox_spec.rb index 946275b71..a3a85de9e 100644 --- a/spec/mailboxes/support_mailbox_spec.rb +++ b/spec/mailboxes/support_mailbox_spec.rb @@ -16,6 +16,26 @@ RSpec.describe SupportMailbox, type: :mailbox do end end + describe 'when an account is suspended' do + let(:account) { create(:account, status: :suspended) } + let(:agent) { create(:user, email: 'agent1@example.com', account: account) } + let!(:channel_email) { create(:channel_email, account: account) } + let(:support_mail) { create_inbound_email_from_fixture('support.eml') } + let(:described_subject) { described_class.receive support_mail } + let(:conversation) { Conversation.where(inbox_id: channel_email.inbox).last } + + before do + # this email is hardcoded in the support.eml, that's why we are updating this + channel_email.email = 'care@example.com' + channel_email.save! + end + + it 'shouldnt create a conversation in the channel' do + described_subject + expect(conversation.present?).to be(false) + end + end + describe 'add mail as a new ticket in the email inbox' do let(:account) { create(:account) } let(:agent) { create(:user, email: 'agent1@example.com', account: account) }