feat: email channel backend (#140) (#1255)

* feat: added support mailbox to handle email channel (#140)

Added a new mailbox called 'SupportMailbox' to handle all the
incoming emails other than reply emails.

An email channel will have a support email and forward email
associated with it. So we filter for the right email inbox based on
the support email of that inbox and route this to this mailbox.

This mailbox finds the account, inbox, contact (create a new one
if it does not exist) and creates a conversation and adds the
email content as the first message in the conversation.

Other minor things handled in this commit:

* renamed the procs for routing emails in application mailbox
* renamed ConversationMailbox to ReplyMailbox
* Added a fallback content in MailPresenter
* Added a record saving (bang) versions of enabling and disabling
features in Featurable module
* added new factory for the email channel

refs: #140
This commit is contained in:
Sony Mathew
2020-09-21 22:44:22 +05:30
committed by GitHub
parent 313b2da703
commit f9b0427751
12 changed files with 892 additions and 45 deletions

View File

@@ -6,19 +6,41 @@ RSpec.describe ApplicationMailbox, type: :mailbox do
describe 'route the inbound mail to appropriate mailbox' do
let(:welcome_mail) { create_inbound_email_from_fixture('welcome.eml') }
let(:reply_mail) { create_inbound_email_from_fixture('reply.eml') }
let(:support_mail) { create_inbound_email_from_fixture('support.eml') }
it 'catchall mails route to default inbox' do
dbl = double
expect(DefaultMailbox).to receive(:new).and_return(dbl)
expect(dbl).to receive(:perform_processing).and_return(true)
described_class.route welcome_mail
describe 'Default' do
it 'catchall mails route to Default Mailbox' do
dbl = double
expect(DefaultMailbox).to receive(:new).and_return(dbl)
expect(dbl).to receive(:perform_processing).and_return(true)
described_class.route welcome_mail
end
end
it 'routes reply emails to Conversation Mailbox' do
dbl = double
expect(ConversationMailbox).to receive(:new).and_return(dbl)
expect(dbl).to receive(:perform_processing).and_return(true)
described_class.route reply_mail
describe 'Reply' do
it 'routes reply emails to Reply Mailbox' do
dbl = double
expect(ReplyMailbox).to receive(:new).and_return(dbl)
expect(dbl).to receive(:perform_processing).and_return(true)
described_class.route reply_mail
end
end
describe 'Support' do
let!(:channel_email) { create(:channel_email) }
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 'routes support emails to Support Mailbox' do
dbl = double
expect(SupportMailbox).to receive(:new).and_return(dbl)
expect(dbl).to receive(:perform_processing).and_return(true)
described_class.route support_mail
end
end
end
end