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

@@ -3,7 +3,7 @@ class ApplicationMailbox < ActionMailbox::Base
# Eg: email should be something like : reply+6bdc3f4d-0bec-4515-a284-5d916fdde489@domain.com
REPLY_EMAIL_USERNAME_PATTERN = /^reply\+([0-9a-f]{8}\b-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-\b[0-9a-f]{12})$/i.freeze
def self.reply_match_proc
def self.reply_mail?
proc do |inbound_mail_obj|
is_a_reply_email = false
inbound_mail_obj.mail.to.each do |email|
@@ -18,11 +18,26 @@ class ApplicationMailbox < ActionMailbox::Base
end
end
def self.default_mail_proc
def self.support_mail?
proc do |inbound_mail_obj|
is_a_support_email = false
inbound_mail_obj.mail.to.each do |email|
channel = Channel::Email.find_by(email: email)
if channel.present?
is_a_support_email = true
break
end
end
is_a_support_email
end
end
def self.catch_all_mail?
proc { |_mail| true }
end
# routing should be defined below the referenced procs
routing(reply_match_proc => :conversation)
routing(default_mail_proc => :default)
routing(reply_mail? => :reply)
routing(support_mail? => :support)
routing(catch_all_mail? => :default)
end