diff --git a/app/models/channel/filter/follow_up_check.rb b/app/models/channel/filter/follow_up_check.rb index 94a7dca93..cdb522363 100644 --- a/app/models/channel/filter/follow_up_check.rb +++ b/app/models/channel/filter/follow_up_check.rb @@ -54,11 +54,9 @@ module Channel::Filter::FollowUpCheck end if references != '' message_ids = references.split(/\s+/) - sender_type_agent = Ticket::Article::Sender.lookup(name: 'Agent') - sender_type_system = Ticket::Article::Sender.lookup(name: 'System') message_ids.each {|message_id| message_id_md5 = Digest::MD5.hexdigest(message_id) - article = Ticket::Article.where(message_id_md5: message_id_md5, sender_id: [sender_type_agent.id, sender_type_system.id]).order('created_at DESC, id DESC').limit(1).first + article = Ticket::Article.where(message_id_md5: message_id_md5).order('created_at DESC, id DESC').limit(1).first next if !article Rails.logger.debug "Follow up for '##{article.ticket.number}' in references." mail[ 'x-zammad-ticket-id'.to_sym ] = article.ticket_id diff --git a/test/unit/email_process_follow_up_test.rb b/test/unit/email_process_follow_up_test.rb index b6e9a1011..bf13777dd 100644 --- a/test/unit/email_process_follow_up_test.rb +++ b/test/unit/email_process_follow_up_test.rb @@ -127,6 +127,48 @@ no reference " assert_not_equal(ticket.id, ticket_p.id) end + test 'process with follow up check with two external reference headers' do + + setting_orig = Setting.get('postmaster_follow_up_search_in') + Setting.set('postmaster_follow_up_search_in', %w(body attachment references)) + + data1 = "From: me@example.com +To: z@example.com +Subject: test 123 +Message-ID: <9d16181c-2db2-c6c1-ff7f-41f2da4e289a@linuxhotel.de> + +test 123 +" + ticket_p1, article_p1, user_p1 = Channel::EmailParser.new.process({}, data1) + + sleep 1 + + data1 = "From: me@example.com +To: z@example.com +Subject: test 123 +Message-ID: <9d16181c-2db2-c6c1-ff7f-41f2da4e289a@linuxhotel.de> + +test 123 +" + ticket_p2, article_p2, user_p2 = Channel::EmailParser.new.process({}, data1) + assert_not_equal(ticket_p1.id, ticket_p2.id) + + data2 = "From: you@example.com +To: y@example.com +Subject: RE: test 123 +Message-ID: +References: <9d16181c-2db2-c6c1-ff7f-41f2da4e289a@linuxhotel.de> + +test 123 +" + ticket_p3, article_p3, user_p3 = Channel::EmailParser.new.process({}, data2) + + assert_equal(ticket_p2.id, ticket_p3.id) + + Setting.set('postmaster_follow_up_search_in', setting_orig) + + end + test 'process with follow up check - with auto responses and no T# in subject_build' do ticket = Ticket.create(