diff --git a/app/mailboxes/reply_mailbox.rb b/app/mailboxes/reply_mailbox.rb index 85d5733dc..82181ad3b 100644 --- a/app/mailboxes/reply_mailbox.rb +++ b/app/mailboxes/reply_mailbox.rb @@ -63,14 +63,19 @@ class ReplyMailbox < ApplicationMailbox # find conversation uuid from below pattern # def find_conversation_with_in_reply_to - in_reply_to = mail.in_reply_to - match_result = in_reply_to.match(ApplicationMailbox::CONVERSATION_MESSAGE_ID_PATTERN) if in_reply_to.present? - - if match_result - find_conversation_by_uuid(match_result) - else - find_conversation_by_message_id(in_reply_to) + match_result = nil + in_reply_to_addresses = mail.in_reply_to + in_reply_to_addresses = [in_reply_to_addresses] if in_reply_to_addresses.is_a?(String) + in_reply_to_addresses.each do |in_reply_to| + match_result = in_reply_to.match(::ApplicationMailbox::CONVERSATION_MESSAGE_ID_PATTERN) + break if match_result end + find_by_in_reply_to_addresses(match_result, in_reply_to_addresses) + end + + def find_by_in_reply_to_addresses(match_result, in_reply_to_addresses) + find_conversation_by_uuid(match_result) if match_result + find_conversation_by_message_id(in_reply_to_addresses) if @conversation.blank? end def verify_decoded_params diff --git a/spec/fixtures/files/forwarder_email.eml b/spec/fixtures/files/forwarder_email.eml index 1fc8185b1..fb6d427f9 100644 --- a/spec/fixtures/files/forwarder_email.eml +++ b/spec/fixtures/files/forwarder_email.eml @@ -4,7 +4,7 @@ Content-Type: multipart/alternative; boundary="Apple-Mail=_33A037C7-4BB3-4772-AE Subject: Discussion: Let's debate these attachments Date: Tue, 20 Apr 2020 04:20:20 -0400 X-Forwarded-For: reply+6bdc3f4d-0bec-4515-a284-5d916fdde489@example.com -In-Reply-To: +In-Reply-To: References: <4e6e35f5a38b4_479f13bb90078178@small-app-01.mail> Message-Id: <0CB459E0-0336-41DA-BC88-E6E28C697DDB@chatwoot.com> X-Mailer: Apple Mail (2.1244.3) diff --git a/spec/fixtures/files/reply.eml b/spec/fixtures/files/reply.eml index 5eb78f1e1..1ab026aca 100644 --- a/spec/fixtures/files/reply.eml +++ b/spec/fixtures/files/reply.eml @@ -3,7 +3,7 @@ Mime-Version: 1.0 (Apple Message framework v1244.3) Content-Type: multipart/alternative; boundary="Apple-Mail=_33A037C7-4BB3-4772-AE52-FCF2D7535F74" Subject: Discussion: Let's debate these attachments Date: Tue, 20 Apr 2020 04:20:20 -0400 -In-Reply-To: <4e6e35f5a38b4_479f13bb90078178@small-app-01.mail> +In-Reply-To: <4e6e35f5a38b4_479f13bb90078178@small-app-01.mail>, <4e6e35f5a38b4_479f13bb90078178@small-app-01.mail> To: "Replies" References: <4e6e35f5a38b4_479f13bb90078178@small-app-01.mail> Message-Id: <0CB459E0-0336-41DA-BC88-E6E28C697DDB@chatwoot.com> @@ -628,4 +628,4 @@ r/Fxp3Y0d2/4tvsR95f/AAH7Gvwmn9rUHsOgUCg//9k= --Apple-Mail=_83444AF4-343C-4F75-AF8F-14E1E7434FC1-- ---Apple-Mail=_33A037C7-4BB3-4772-AE52-FCF2D7535F74-- \ No newline at end of file +--Apple-Mail=_33A037C7-4BB3-4772-AE52-FCF2D7535F74-- diff --git a/spec/fixtures/files/reply_mail_without_uuid.eml b/spec/fixtures/files/reply_mail_without_uuid.eml index e2a5e2378..c5ab3187b 100644 --- a/spec/fixtures/files/reply_mail_without_uuid.eml +++ b/spec/fixtures/files/reply_mail_without_uuid.eml @@ -3,7 +3,7 @@ Mime-Version: 1.0 (Apple Message framework v1244.3) Content-Type: multipart/alternative; boundary="Apple-Mail=_33A037C7-4BB3-4772-AE52-FCF2D7535F74" Subject: Discussion: Let's debate these attachments Date: Tue, 20 Apr 2020 04:20:20 -0400 -In-Reply-To: +In-Reply-To: To: "Replies" References: <4e6e35f5a38b4_479f13bb90078178@small-app-01.mail> Message-Id: <0CB459E0-0336-41DA-BC88-E6E28C697DDB@chatwoot.com>