Do follow up detection also with references header and comparing subject per default.
This commit is contained in:
parent
136713c45f
commit
0b244d00cb
6 changed files with 121 additions and 16 deletions
|
@ -31,9 +31,10 @@ returns
|
||||||
end
|
end
|
||||||
|
|
||||||
return data if !self['created_by_id'] && !self['updated_by_id']
|
return data if !self['created_by_id'] && !self['updated_by_id']
|
||||||
|
app_model_user = User.to_app_model
|
||||||
%w(created_by_id updated_by_id).each { |local_user_id|
|
%w(created_by_id updated_by_id).each { |local_user_id|
|
||||||
next if !self[ local_user_id ]
|
next if !self[ local_user_id ]
|
||||||
next if data[ User.to_app_model ] && data[ User.to_app_model ][ self[ local_user_id ] ]
|
next if data[ app_model_user ] && data[ app_model_user ][ self[ local_user_id ] ]
|
||||||
user = User.lookup(id: self[ local_user_id ])
|
user = User.lookup(id: self[ local_user_id ])
|
||||||
next if !user
|
next if !user
|
||||||
data = user.assets(data)
|
data = user.assets(data)
|
||||||
|
|
|
@ -65,5 +65,44 @@ module Channel::Filter::FollowUpCheck
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# get ticket# from references current email has same subject as inital article
|
||||||
|
if !mail[:subject].empty?
|
||||||
|
|
||||||
|
# get all references 'References' + 'In-Reply-To'
|
||||||
|
references = ''
|
||||||
|
if mail[:references]
|
||||||
|
references += mail[:references]
|
||||||
|
end
|
||||||
|
if mail['in-reply-to'.to_sym]
|
||||||
|
if references != ''
|
||||||
|
references += ' '
|
||||||
|
end
|
||||||
|
references += mail['in-reply-to'.to_sym]
|
||||||
|
end
|
||||||
|
if references != ''
|
||||||
|
message_ids = references.split(/\s+/)
|
||||||
|
message_ids.each { |message_id|
|
||||||
|
message_id_md5 = Digest::MD5.hexdigest(message_id)
|
||||||
|
article = Ticket::Article.where(message_id_md5: message_id_md5).order('created_at DESC, id DESC').limit(1).first
|
||||||
|
next if !article
|
||||||
|
ticket = article.ticket
|
||||||
|
next if !ticket
|
||||||
|
article_first = ticket.articles.first
|
||||||
|
next if !article_first
|
||||||
|
|
||||||
|
# remove leading "..:\s" and "..[\d+]:\s" e. g. "Re: " or "Re[5]: "
|
||||||
|
subject_to_check = mail[:subject]
|
||||||
|
subject_to_check.gsub!(/^(..(\[\d+\])?:\s)+/, '')
|
||||||
|
|
||||||
|
# if subject is different, it's no followup
|
||||||
|
next if subject_to_check != article_first.subject
|
||||||
|
|
||||||
|
Rails.logger.debug "Follow up for '##{article.ticket.number}' in references with same subject as inital article."
|
||||||
|
mail[ 'x-zammad-ticket-id'.to_sym ] = article_first.ticket_id
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -257,4 +257,69 @@ Some Text"
|
||||||
assert_equal('open', ticket.state.name)
|
assert_equal('open', ticket.state.name)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test 'process with follow up check - ticket initiated by customer without T# in subject and other people in Cc reply to all' do
|
||||||
|
|
||||||
|
# check if follow up based on inital system sender address
|
||||||
|
setting_orig = Setting.get('postmaster_follow_up_search_in')
|
||||||
|
Setting.set('postmaster_follow_up_search_in', [])
|
||||||
|
|
||||||
|
subject = "ticket initiated by customer without T# in subject and other people in Cc reply to all #{rand(9999)}"
|
||||||
|
|
||||||
|
email_raw_string = "From: me@example.com
|
||||||
|
To: my@system.test, bob@example.com
|
||||||
|
Subject: #{subject}
|
||||||
|
Message-ID: <123456789-$follow-up-test§-1@linuxhotel.de>
|
||||||
|
|
||||||
|
Some Text"
|
||||||
|
|
||||||
|
ticket_p1, article_1, user_1, mail = Channel::EmailParser.new.process({}, email_raw_string)
|
||||||
|
ticket1 = Ticket.find(ticket_p1.id)
|
||||||
|
assert_equal(subject, ticket1.title)
|
||||||
|
|
||||||
|
# follow up possible because same subject
|
||||||
|
email_raw_string = "From: bob@example.com
|
||||||
|
To: my@system.test, me@example.com
|
||||||
|
Subject: AW: #{subject}
|
||||||
|
Message-ID: <123456789-$follow-up-test§-2@linuxhotel.de>
|
||||||
|
References: <123456789-$follow-up-test§-1@linuxhotel.de>
|
||||||
|
|
||||||
|
Some Text"
|
||||||
|
|
||||||
|
ticket_p2, article_p2, user_p2, mail = Channel::EmailParser.new.process({}, email_raw_string)
|
||||||
|
ticket2 = Ticket.find(ticket_p2.id)
|
||||||
|
assert_equal(ticket1.id, ticket2.id)
|
||||||
|
assert_equal(subject, ticket2.title)
|
||||||
|
|
||||||
|
# follow up possible because same subject
|
||||||
|
email_raw_string = "From: bob@example.com
|
||||||
|
To: my@system.test, me@example.com
|
||||||
|
Subject: AW: RE: #{subject}
|
||||||
|
Message-ID: <123456789-$follow-up-test§-2@linuxhotel.de>
|
||||||
|
References: <123456789-$follow-up-test§-1@linuxhotel.de>
|
||||||
|
|
||||||
|
Some Text"
|
||||||
|
|
||||||
|
ticket_p3, article_p3, user_p3, mail = Channel::EmailParser.new.process({}, email_raw_string)
|
||||||
|
ticket3 = Ticket.find(ticket_p3.id)
|
||||||
|
assert_equal(ticket1.id, ticket3.id)
|
||||||
|
assert_equal(subject, ticket3.title)
|
||||||
|
|
||||||
|
# follow up not possible because subject has changed
|
||||||
|
subject = "new subject without ticket ref #{rand(9_999_999)}"
|
||||||
|
email_raw_string = "From: bob@example.com
|
||||||
|
To: my@system.test
|
||||||
|
Subject: #{subject}
|
||||||
|
Message-ID: <123456789-$follow-up-test§-3@linuxhotel.de>
|
||||||
|
References: <123456789-$follow-up-test§-1@linuxhotel.de>
|
||||||
|
|
||||||
|
Some Text"
|
||||||
|
|
||||||
|
ticket_p4, article_p4, user_p4, mail = Channel::EmailParser.new.process({}, email_raw_string)
|
||||||
|
ticket4 = Ticket.find(ticket_p4.id)
|
||||||
|
assert_not_equal(ticket1.id, ticket4.id)
|
||||||
|
assert_equal(subject, ticket4.title)
|
||||||
|
|
||||||
|
Setting.set('postmaster_follow_up_search_in', setting_orig)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue