Browse Source

Fixes #3894 - Follow-up detection does not work for the body of plain text mails.

Florian Liebe 2 years ago
parent
commit
c332eb2a56

+ 4 - 1
app/models/channel/filter/follow_up_check.rb

@@ -18,7 +18,10 @@ module Channel::Filter::FollowUpCheck
 
     # get ticket# from body
     if setting.include?('body')
-      ticket = Ticket::Number.check(mail[:body].html2text)
+      body = mail[:body]
+      body = body.html2text if mail[:content_type] == 'text/html'
+
+      ticket = Ticket::Number.check(body)
       if ticket
         Rails.logger.debug { "Follow-up for '##{ticket.number}' in body." }
         mail[:'x-zammad-ticket-id'] = ticket.id

+ 14 - 0
spec/models/channel/email_parser_spec.rb

@@ -632,6 +632,20 @@ RSpec.describe Channel::EmailParser, type: :model do
               include_examples 'adds message to ticket'
             end
 
+            context 'in visible text with a linebreak' do
+              let(:raw_mail) { <<~RAW.chomp }
+                From: me@example.com
+                To: customer@example.com
+                Subject: no reference
+
+                Lorem ipsum dolor #{ticket_ref}
+                consetetur sadipscing elitr
+                sed diam nonumy eirmod
+              RAW
+
+              include_examples 'adds message to ticket'
+            end
+
             context 'as part of a larger word' do
               let(:ticket_ref) { "Foo#{Setting.get('ticket_hook')}#{Setting.get('ticket_hook_divider')}#{ticket.number}bar" }