Skip to content

Commit

Permalink
airbnb matching fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
jgargallo-air committed Feb 12, 2024
1 parent 0333ee2 commit 96de561
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions app/mailboxes/support_mailbox.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,18 @@ def booking_grouping_key
"#{grouping_key[1]}@mchat.booking.com" if grouping_key
end

AIRBNB_REPLYTO_NAME = /"([^"]+)\s+\(.+@reply.airbnb.com>/
AIRBNB_CHAT = /.+@reply.airbnb.com>/
def airbnb_grouping_key
# Airbnb subject looks like 'Re: Reserva en Estudio para el 27 de enero de 2024 - 28 de enero de 2024'
# We need a combination of subject and inhabitants name
# since reply-to email ("Pepe (Airbnb)" <4z8kvv4vb0duoemgwzhdax39vft4s1rznedx@reply.airbnb.com>) changes on each message
airbnb_name = @processed_mail.from.map { |f| AIRBNB_REPLYTO_NAME.match(f) }.find(&:itself)
"[#{airbnb_name[1]}@reply.airbnb.com] #{@processed_mail.subject}" if airbnb_name
reply_to = mail['Reply-To'].try(:value)
return nil unless reply_to

airbnb_match = AIRBNB_CHAT.match(reply_to)
return unless airbnb_match && @processed_mail.sender_name && @processed_mail.subject

"[#{@processed_mail.sender_name}@reply.airbnb.com] #{@processed_mail.subject}"
end

def in_reply_to
Expand Down

0 comments on commit 96de561

Please sign in to comment.