diff --git a/app/mailboxes/support_mailbox.rb b/app/mailboxes/support_mailbox.rb index ca7f39a9ab181..94ee9bfdfb36c 100644 --- a/app/mailboxes/support_mailbox.rb +++ b/app/mailboxes/support_mailbox.rb @@ -52,8 +52,14 @@ def find_conversation_by_in_reply_to @account.conversations.where("additional_attributes->>'in_reply_to' = ?", in_reply_to).first end + BOOKING_CHAT_GROUPING = /(\d+)-.+@mchat.booking.com/ + def in_reply_to - mail['In-Reply-To'].try(:value) + in_reply_to = mail['In-Reply-To'].try(:value) + return in_reply_to if in_reply_to + + m = BOOKING_CHAT_GROUPING.match(mail.from) + "#{m[1]}@mchat.booking.com" if m end def find_or_create_conversation