Refine email followup search logic (fixes #2038)

This commit is contained in:
Ryan Lue 2018-06-19 12:41:18 +08:00
parent 2da68fa177
commit adda2dfa5e
4 changed files with 24 additions and 6 deletions

View file

@ -18,7 +18,7 @@ module Channel::Filter::FollowUpCheck
# get ticket# from body # get ticket# from body
if setting.include?('body') if setting.include?('body')
ticket = Ticket::Number.check(mail[:body]) ticket = Ticket::Number.check(mail[:body].html2text)
if ticket if ticket
Rails.logger.debug { "Follow up for '##{ticket.number}' in body." } Rails.logger.debug { "Follow up for '##{ticket.number}' in body." }
mail['x-zammad-ticket-id'.to_sym] = ticket.id mail['x-zammad-ticket-id'.to_sym] = ticket.id
@ -30,7 +30,7 @@ module Channel::Filter::FollowUpCheck
if setting.include?('attachment') && mail[:attachments] if setting.include?('attachment') && mail[:attachments]
mail[:attachments].each do |attachment| mail[:attachments].each do |attachment|
next if !attachment[:data] next if !attachment[:data]
ticket = Ticket::Number.check(attachment[:data]) ticket = Ticket::Number.check(attachment[:data].html2text)
next if !ticket next if !ticket
Rails.logger.debug { "Follow up for '##{ticket.number}' in attachment." } Rails.logger.debug { "Follow up for '##{ticket.number}' in attachment." }
mail['x-zammad-ticket-id'.to_sym] = ticket.id mail['x-zammad-ticket-id'.to_sym] = ticket.id

View file

@ -86,12 +86,12 @@ module Ticket::Number::Date
end end
# probe format # probe format
string.scan(/#{Regexp.quote(ticket_hook)}#{Regexp.quote(ticket_hook_divider)}(\d{4,10}#{system_id}\d{2,40})/i) do string.scan(/\b#{Regexp.quote(ticket_hook)}#{Regexp.quote(ticket_hook_divider)}(\d{4,10}#{system_id}\d{2,40})\b/i) do
ticket = Ticket.find_by(number: $1) ticket = Ticket.find_by(number: $1)
break if ticket break if ticket
end end
if !ticket if !ticket
string.scan(/#{Regexp.quote(ticket_hook)}\s{0,2}(\d{4,10}#{system_id}\d{2,40})/i) do string.scan(/\b#{Regexp.quote(ticket_hook)}\s{0,2}(\d{4,10}#{system_id}\d{2,40})\b/i) do
ticket = Ticket.find_by(number: $1) ticket = Ticket.find_by(number: $1)
break if ticket break if ticket
end end

View file

@ -83,12 +83,12 @@ module Ticket::Number::Increment
end end
# probe format # probe format
string.scan(/#{Regexp.quote(ticket_hook)}#{Regexp.quote(ticket_hook_divider)}(#{system_id}\d{2,48})/i) do string.scan(/\b#{Regexp.quote(ticket_hook)}#{Regexp.quote(ticket_hook_divider)}(#{system_id}\d{2,48})\b/i) do
ticket = Ticket.find_by(number: $1) ticket = Ticket.find_by(number: $1)
break if ticket break if ticket
end end
if !ticket if !ticket
string.scan(/#{Regexp.quote(ticket_hook)}\s{0,2}(#{system_id}\d{2,48})/i) do string.scan(/\b#{Regexp.quote(ticket_hook)}\s{0,2}(#{system_id}\d{2,48})\b/i) do
ticket = Ticket.find_by(number: $1) ticket = Ticket.find_by(number: $1)
break if ticket break if ticket
end end

View file

@ -28,6 +28,24 @@ RSpec.describe Channel::EmailParser, type: :model do
.to change { ticket.articles.length } .to change { ticket.articles.length }
end end
end end
context 'as part of a larger word' do
let(:raw_mail) { File.read(mail_file).sub(/(?<=Hallo) =\n(?=Martin,<o:p>)/, test_string) }
it 'creates a separate ticket' do
expect { described_class.new.process({}, raw_mail) }
.not_to change { ticket.articles.length }
end
end
context 'in html attributes' do
let(:raw_mail) { File.read(mail_file).sub(%r{<a href.*?/a>}m, %(<table bgcolor="#{test_string}"> </table>)) }
it 'creates a separate ticket' do
expect { described_class.new.process({}, raw_mail) }
.not_to change { ticket.articles.length }
end
end
end end
end end
end end