Improved ticket follow up detection if more T#'s in subject.

This commit is contained in:
Martin Edenhofer 2016-03-16 10:36:51 +01:00
parent 4a77b273e5
commit c0eae369d6
3 changed files with 81 additions and 27 deletions

View file

@ -13,9 +13,9 @@ module Ticket::Number::Date
# read counter
counter_increment = nil
Ticket::Counter.transaction do
counter = Ticket::Counter.where( generator: 'Date' ).lock(true).first
counter = Ticket::Counter.where(generator: 'Date').lock(true).first
if !counter
counter = Ticket::Counter.new( generator: 'Date', content: '0' )
counter = Ticket::Counter.new(generator: 'Date', content: '0')
end
# increase counter
@ -48,7 +48,7 @@ module Ticket::Number::Date
mult = 1
(1..number.length).each do |i|
digit = number.to_s[i, 1]
chksum = chksum + ( mult * digit.to_i )
chksum = chksum + (mult * digit.to_i)
mult += 1
if mult == 3
mult = 1
@ -73,10 +73,15 @@ module Ticket::Number::Date
ticket = nil
# probe format
if string =~ /#{ticket_hook}#{ticket_hook_divider}(#{system_id}\d{2,50})/i
ticket = Ticket.find_by( number: $1 )
elsif string =~ /#{ticket_hook}\s{0,2}(#{system_id}\d{2,50})/i
ticket = Ticket.find_by( number: $1 )
string.scan(/#{ticket_hook}#{ticket_hook_divider}(#{system_id}\d{2,48})/i) {
ticket = Ticket.find_by(number: $1)
break if ticket
}
if !ticket
string.scan(/#{ticket_hook}\s{0,2}(#{system_id}\d{2,48})/i) {
ticket = Ticket.find_by(number: $1)
break if ticket
}
end
ticket
end

View file

@ -12,9 +12,9 @@ module Ticket::Number::Increment
min_digs = config[:min_size] || 4
counter_increment = nil
Ticket::Counter.transaction do
counter = Ticket::Counter.where( generator: 'Increment' ).lock(true).first
counter = Ticket::Counter.where(generator: 'Increment').lock(true).first
if !counter
counter = Ticket::Counter.new( generator: 'Increment', content: '0' )
counter = Ticket::Counter.new(generator: 'Increment', content: '0')
end
counter_increment = counter.content.to_i
@ -31,9 +31,9 @@ module Ticket::Number::Increment
min_digs = min_digs.to_i - 1
end
fillup = Setting.get('system_id').to_s || '1'
( 1..100 ).each {
(1..100).each {
next if ( fillup.length.to_i + counter_increment.to_s.length.to_i ) >= min_digs.to_i
next if (fillup.length.to_i + counter_increment.to_s.length.to_i) >= min_digs.to_i
fillup = fillup + '0'
}
@ -53,7 +53,7 @@ module Ticket::Number::Increment
mult = 1
(1..number.length).each do |i|
digit = number.to_s[i, 1]
chksum = chksum + ( mult * digit.to_i )
chksum = chksum + (mult * digit.to_i)
mult += 1
if mult == 3
mult = 1
@ -78,10 +78,15 @@ module Ticket::Number::Increment
ticket = nil
# probe format
if string =~ /#{ticket_hook}#{ticket_hook_divider}(#{system_id}\d{2,48})/i
ticket = Ticket.find_by( number: $1 )
elsif string =~ /#{ticket_hook}\s{0,2}(#{system_id}\d{2,48})/i
ticket = Ticket.find_by( number: $1 )
string.scan(/#{ticket_hook}#{ticket_hook_divider}(#{system_id}\d{2,48})/i) {
ticket = Ticket.find_by(number: $1)
break if ticket
}
if !ticket
string.scan(/#{ticket_hook}\s{0,2}(#{system_id}\d{2,48})/i) {
ticket = Ticket.find_by(number: $1)
break if ticket
}
end
ticket
end

View file

@ -85,45 +85,45 @@ no reference "
Setting.set('postmaster_follow_up_search_in', %w(body attachment references))
sleep 1
ticket_p, article_p, user_p = Channel::EmailParser.new.process( {}, email_raw_string_subject)
ticket_p, article_p, user_p = Channel::EmailParser.new.process({}, email_raw_string_subject)
assert_equal(ticket.id, ticket_p.id)
sleep 1
ticket_p, article_p, user_p = Channel::EmailParser.new.process( {}, email_raw_string_body)
ticket_p, article_p, user_p = Channel::EmailParser.new.process({}, email_raw_string_body)
assert_equal(ticket.id, ticket_p.id)
sleep 1
ticket_p, article_p, user_p = Channel::EmailParser.new.process( {}, email_raw_string_attachment)
ticket_p, article_p, user_p = Channel::EmailParser.new.process({}, email_raw_string_attachment)
assert_equal(ticket.id, ticket_p.id)
sleep 1
ticket_p, article_p, user_p = Channel::EmailParser.new.process( {}, email_raw_string_references1)
ticket_p, article_p, user_p = Channel::EmailParser.new.process({}, email_raw_string_references1)
assert_equal(ticket.id, ticket_p.id)
sleep 1
ticket_p, article_p, user_p = Channel::EmailParser.new.process( {}, email_raw_string_references2)
ticket_p, article_p, user_p = Channel::EmailParser.new.process({}, email_raw_string_references2)
assert_equal(ticket.id, ticket_p.id)
Setting.set('postmaster_follow_up_search_in', setting_orig)
sleep 1
ticket_p, article_p, user_p = Channel::EmailParser.new.process( {}, email_raw_string_subject)
ticket_p, article_p, user_p = Channel::EmailParser.new.process({}, email_raw_string_subject)
assert_equal(ticket.id, ticket_p.id)
sleep 1
ticket_p, article_p, user_p = Channel::EmailParser.new.process( {}, email_raw_string_body)
ticket_p, article_p, user_p = Channel::EmailParser.new.process({}, email_raw_string_body)
assert_not_equal(ticket.id, ticket_p.id)
sleep 1
ticket_p, article_p, user_p = Channel::EmailParser.new.process( {}, email_raw_string_attachment)
ticket_p, article_p, user_p = Channel::EmailParser.new.process({}, email_raw_string_attachment)
assert_not_equal(ticket.id, ticket_p.id)
sleep 1
ticket_p, article_p, user_p = Channel::EmailParser.new.process( {}, email_raw_string_references1)
ticket_p, article_p, user_p = Channel::EmailParser.new.process({}, email_raw_string_references1)
assert_not_equal(ticket.id, ticket_p.id)
sleep 1
ticket_p, article_p, user_p = Channel::EmailParser.new.process( {}, email_raw_string_references2)
ticket_p, article_p, user_p = Channel::EmailParser.new.process({}, email_raw_string_references2)
assert_not_equal(ticket.id, ticket_p.id)
end
@ -165,7 +165,51 @@ Auto-Submitted: auto-replied
Some Text"
ticket_p, article_p, user_p, mail = Channel::EmailParser.new.process( {}, email_raw_string)
ticket_p, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string)
ticket = Ticket.find(ticket.id)
assert_equal(ticket.id, ticket_p.id)
assert_equal('open', ticket.state.name)
end
test 'process with follow up check - email with more forgein T#\'s in subject' do
ticket = Ticket.create(
title: 'email with more forgein T#\'s in subject',
group: Group.lookup(name: 'Users'),
customer_id: 2,
state: Ticket::State.lookup(name: 'closed'),
priority: Ticket::Priority.lookup(name: '2 normal'),
updated_by_id: 1,
created_by_id: 1,
)
article = Ticket::Article.create(
ticket_id: ticket.id,
from: 'some_sender@example.com',
to: 'some_recipient@example.com',
subject: 'follow up with references follow up check',
message_id: '<20151222145601.30.608881@edenhofer.zammad.com>',
body: 'some message with references follow up check',
internal: false,
sender: Ticket::Article::Sender.lookup(name: 'Agent'),
type: Ticket::Article::Type.lookup(name: 'email'),
updated_by_id: 1,
created_by_id: 1,
)
sleep 1
system_id = Setting.get('system_id')
ticket_hook = Setting.get('ticket_hook')
ticket_hook_divider = Setting.get('ticket_hook_divider')
tn = "[#{ticket_hook}#{ticket_hook_divider}#{system_id}#{Ticket::Number.generate}99]"
email_raw_string_subject = "From: me@example.com
To: customer@example.com
Subject: First foreign Tn #{tn} #{tn} #{tn} - #{ticket.subject_build('some new subject')}
Some Text"
ticket_p, article_p, user_p, mail = Channel::EmailParser.new.process({}, email_raw_string_subject)
ticket = Ticket.find(ticket.id)
assert_equal(ticket.id, ticket_p.id)
assert_equal('open', ticket.state.name)