Fix: fixing mail to and in_reply_to issues (#3451)
This commit is contained in:
@@ -13,6 +13,7 @@ class ApplicationMailbox < ActionMailbox::Base
|
||||
is_a_reply_email = true if reply_uuid_mail?(email)
|
||||
end
|
||||
is_a_reply_email = true if in_reply_to_mail?(inbound_mail_obj, is_a_reply_email)
|
||||
|
||||
is_a_reply_email
|
||||
end
|
||||
end
|
||||
@@ -44,7 +45,7 @@ class ApplicationMailbox < ActionMailbox::Base
|
||||
|
||||
return false if in_reply_to.blank?
|
||||
|
||||
return true if in_reply_to.match(CONVERSATION_MESSAGE_ID_PATTERN)
|
||||
return true if in_reply_to_matches?(in_reply_to)
|
||||
|
||||
message = Message.find_by(source_id: in_reply_to)
|
||||
return true if message.present?
|
||||
@@ -52,6 +53,18 @@ class ApplicationMailbox < ActionMailbox::Base
|
||||
false
|
||||
end
|
||||
|
||||
def self.in_reply_to_matches?(in_reply_to)
|
||||
in_reply_to_match = false
|
||||
if in_reply_to.is_a?(Array)
|
||||
in_reply_to.each do |in_reply_to_mail|
|
||||
in_reply_to_match ||= in_reply_to_mail.match(CONVERSATION_MESSAGE_ID_PATTERN)
|
||||
end
|
||||
else
|
||||
in_reply_to_match = in_reply_to.match(CONVERSATION_MESSAGE_ID_PATTERN)
|
||||
end
|
||||
in_reply_to_match
|
||||
end
|
||||
|
||||
# checks if follow this pattern send it to reply_mailbox
|
||||
# reply+<conversation-uuid>@<mailer-domain.com>
|
||||
def self.reply_uuid_mail?(email)
|
||||
|
||||
@@ -26,7 +26,11 @@ class ReplyMailbox < ApplicationMailbox
|
||||
end
|
||||
|
||||
def conversation_uuid_from_to_address
|
||||
mail.to.each do |email|
|
||||
@mail = MailPresenter.new(mail)
|
||||
|
||||
return if @mail.mail_receiver.blank?
|
||||
|
||||
@mail.mail_receiver.each do |email|
|
||||
username = email.split('@')[0]
|
||||
match_result = username.match(ApplicationMailbox::REPLY_EMAIL_UUID_PATTERN)
|
||||
if match_result
|
||||
@@ -37,10 +41,6 @@ class ReplyMailbox < ApplicationMailbox
|
||||
@conversation_uuid
|
||||
end
|
||||
|
||||
def verify_decoded_params
|
||||
raise 'Conversation uuid not found' if conversation_uuid.nil?
|
||||
end
|
||||
|
||||
# find conversation uuid from below pattern
|
||||
# reply+<conversation-uuid>@<mailer-domain.com>
|
||||
def find_conversation_with_uuid
|
||||
@@ -73,6 +73,10 @@ class ReplyMailbox < ApplicationMailbox
|
||||
end
|
||||
end
|
||||
|
||||
def verify_decoded_params
|
||||
raise 'Conversation uuid not found' if conversation_uuid.nil?
|
||||
end
|
||||
|
||||
def validate_resource(resource)
|
||||
raise "#{resource.class.name} not found" if resource.nil?
|
||||
|
||||
|
||||
@@ -90,6 +90,20 @@ class MailPresenter < SimpleDelegator
|
||||
@mail['X-Original-Sender'].try(:value) || from.first
|
||||
end
|
||||
|
||||
def email_forwarded_for
|
||||
@mail['X-Forwarded-For'].try(:value)
|
||||
end
|
||||
|
||||
def mail_receiver
|
||||
if @mail.to.blank?
|
||||
return [email_forwarded_for] if email_forwarded_for.present?
|
||||
|
||||
[]
|
||||
else
|
||||
@mail.to
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# forcing the encoding of the content to UTF-8 so as to be compatible with database and serializers
|
||||
|
||||
Reference in New Issue
Block a user