Fix: Find mailbox with cc email (#4372)

This commit is contained in:
Tejaswini Chile
2022-04-08 11:20:19 +05:30
committed by GitHub
parent 14e6a5d6b0
commit 57359be37e
9 changed files with 103 additions and 12 deletions

View File

@@ -0,0 +1,15 @@
class EmailChannelFinder
def initialize(email_object)
@email_object = email_object
end
def perform
channel = nil
recipient_mails = @email_object.to.to_a + @email_object.cc.to_a
recipient_mails.each do |email|
channel = Channel::Email.find_by('lower(email) = ? OR lower(forward_to_email) = ?', email.downcase, email.downcase)
break if channel.present?
end
channel
end
end

View File

@@ -21,17 +21,20 @@ class ApplicationMailbox < ActionMailbox::Base
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('lower(email) = ? OR lower(forward_to_email) = ?', email.downcase, email.downcase)
if channel.present?
is_a_support_email = true
break
end
end
is_a_support_email = true if reply_to_mail?(inbound_mail_obj, is_a_support_email)
is_a_support_email
end
end
def self.reply_to_mail?(inbound_mail_obj, is_a_support_email)
return if is_a_support_email
channel = EmailChannelFinder.new(inbound_mail_obj.mail).perform
channel.present?
end
def self.catch_all_mail?
proc { |_mail| true }
end

View File

@@ -2,6 +2,8 @@ module MailboxHelper
private
def create_message
return if @conversation.messages.find_by(source_id: processed_mail.message_id).present?
@message = @conversation.messages.create(
account_id: @conversation.account_id,
sender: @conversation.contact,

View File

@@ -21,15 +21,17 @@ class SupportMailbox < ApplicationMailbox
private
def find_channel
mail.to.each do |email|
@channel = Channel::Email.find_by('lower(email) = ? OR lower(forward_to_email) = ?', email.downcase, email.downcase)
break if @channel.present?
end
find_channel_with_to_mail if @channel.blank?
raise 'Email channel/inbox not found' if @channel.nil?
@channel
end
def find_channel_with_to_mail
@channel = EmailChannelFinder.new(mail).perform
end
def load_account
@account = @channel.account
end