fix: search for nil in-reply-to messages (#7286)
This commit is contained in:
@@ -35,9 +35,9 @@ class Imap::ImapMailbox
|
||||
end
|
||||
|
||||
def find_conversation_by_in_reply_to
|
||||
return if in_reply_to.blank? && @inbound_mail.references.blank?
|
||||
return if in_reply_to.blank?
|
||||
|
||||
message = @inbox.messages.find_by(source_id: in_reply_to) || find_message_by_references
|
||||
message = @inbox.messages.find_by(source_id: in_reply_to)
|
||||
if message.nil?
|
||||
@inbox.conversations.where("additional_attributes->>'in_reply_to' = ?", in_reply_to).first
|
||||
else
|
||||
@@ -45,6 +45,16 @@ class Imap::ImapMailbox
|
||||
end
|
||||
end
|
||||
|
||||
def find_conversation_by_reference_ids
|
||||
return if @inbound_mail.references.blank? && in_reply_to.present?
|
||||
|
||||
message = find_message_by_references
|
||||
|
||||
return if message.nil?
|
||||
|
||||
@inbox.conversations.find(message.conversation_id)
|
||||
end
|
||||
|
||||
def in_reply_to
|
||||
@inbound_mail.in_reply_to
|
||||
end
|
||||
@@ -52,8 +62,6 @@ class Imap::ImapMailbox
|
||||
def find_message_by_references
|
||||
message_to_return = nil
|
||||
|
||||
return if @inbound_mail.references.blank?
|
||||
|
||||
references = Array.wrap(@inbound_mail.references)
|
||||
|
||||
references.each do |message_id|
|
||||
@@ -64,18 +72,22 @@ class Imap::ImapMailbox
|
||||
end
|
||||
|
||||
def find_or_create_conversation
|
||||
@conversation = find_conversation_by_in_reply_to || ::Conversation.create!({ account_id: @account.id,
|
||||
inbox_id: @inbox.id,
|
||||
contact_id: @contact.id,
|
||||
contact_inbox_id: @contact_inbox.id,
|
||||
additional_attributes: {
|
||||
source: 'email',
|
||||
in_reply_to: in_reply_to,
|
||||
mail_subject: @processed_mail.subject,
|
||||
initiated_at: {
|
||||
timestamp: Time.now.utc
|
||||
}
|
||||
} })
|
||||
@conversation = find_conversation_by_in_reply_to || find_conversation_by_reference_ids || ::Conversation.create!(
|
||||
{
|
||||
account_id: @account.id,
|
||||
inbox_id: @inbox.id,
|
||||
contact_id: @contact.id,
|
||||
contact_inbox_id: @contact_inbox.id,
|
||||
additional_attributes: {
|
||||
source: 'email',
|
||||
in_reply_to: in_reply_to,
|
||||
mail_subject: @processed_mail.subject,
|
||||
initiated_at: {
|
||||
timestamp: Time.now.utc
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
end
|
||||
|
||||
def find_or_create_contact
|
||||
|
||||
Reference in New Issue
Block a user