Fixed issue #1749 - Unable to send auto reply if from contains 2 or more senders with invalid email address.
This commit is contained in:
parent
c2a5c3d9e2
commit
22c5b24fb7
4 changed files with 177 additions and 3 deletions
|
@ -884,14 +884,25 @@ perform changes on ticket
|
||||||
next if skip_user
|
next if skip_user
|
||||||
|
|
||||||
# send notifications only to email adresses
|
# send notifications only to email adresses
|
||||||
next if !recipient_email
|
next if recipient_email.blank?
|
||||||
next if recipient_email !~ /@/
|
next if recipient_email !~ /@/
|
||||||
|
|
||||||
# check if address is valid
|
# check if address is valid
|
||||||
begin
|
begin
|
||||||
recipient_email = Mail::Address.new(recipient_email).address
|
Mail::AddressList.new(recipient_email).addresses.each do |address|
|
||||||
|
recipient_email = address.address
|
||||||
|
break if recipient_email.present? && recipient_email =~ /@/ && !recipient_email.match?(/\s/)
|
||||||
|
end
|
||||||
rescue
|
rescue
|
||||||
next # because unable to parse
|
if recipient_email.present?
|
||||||
|
if recipient_email !~ /^(.+?)<(.+?)@(.+?)>$/
|
||||||
|
next # no usable format found
|
||||||
|
end
|
||||||
|
recipient_email = "#{$2}@#{$3}"
|
||||||
|
end
|
||||||
|
next if recipient_email.blank?
|
||||||
|
next if recipient_email !~ /@/
|
||||||
|
next if recipient_email.match?(/\s/)
|
||||||
end
|
end
|
||||||
|
|
||||||
# do not sent notifications to this recipients
|
# do not sent notifications to this recipients
|
||||||
|
|
17
test/fixtures/mail65.box
vendored
Normal file
17
test/fixtures/mail65.box
vendored
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
From: =?iso-8859-1?Q?B=FCrling,=20Andreas?= <smith@example.com>
|
||||||
|
Content-Type: text/plain;
|
||||||
|
charset=iso-8859-1
|
||||||
|
Content-Transfer-Encoding: quoted-printable
|
||||||
|
Subject: =?iso-8859-1?Q?aa=E4=F6=FC=DFad_asd?=
|
||||||
|
X-Universally-Unique-Identifier: d12c15d2-e6d6-4ccd-86c7-abc2c3d0a2a2
|
||||||
|
Date: Fri, 4 May 2012 14:01:03 +0200
|
||||||
|
Message-Id: <BC182994-03FA-4DC5-8202-98CBFACA0887@example.com>
|
||||||
|
To: metest@znuny.com
|
||||||
|
Mime-Version: 1.0 (Apple Message framework v1257)
|
||||||
|
|
||||||
|
=E4=F6=FC=DF ad asd
|
||||||
|
|
||||||
|
-Martin
|
||||||
|
|
||||||
|
--
|
||||||
|
Old programmers never die. They just branch to a new address.
|
|
@ -2699,6 +2699,38 @@ Some Text',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
data: IO.binread('test/fixtures/mail65.box'),
|
||||||
|
success: true,
|
||||||
|
result: {
|
||||||
|
0 => {
|
||||||
|
priority: '2 normal',
|
||||||
|
title: 'aaäöüßad asd',
|
||||||
|
},
|
||||||
|
1 => {
|
||||||
|
from: '=?iso-8859-1?Q?B=FCrling, =20Andreas?= <smith@example.com>',
|
||||||
|
sender: 'Customer',
|
||||||
|
type: 'email',
|
||||||
|
body: 'äöüß ad asd
|
||||||
|
|
||||||
|
-Martin
|
||||||
|
|
||||||
|
--
|
||||||
|
Old programmers never die. They just branch to a new address.
|
||||||
|
',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
verify: {
|
||||||
|
users: [
|
||||||
|
{
|
||||||
|
firstname: '=20Andreas?=',
|
||||||
|
lastname: '',
|
||||||
|
fullname: '=20Andreas?=',
|
||||||
|
email: 'smith@example.com',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
]
|
]
|
||||||
assert_process(files)
|
assert_process(files)
|
||||||
end
|
end
|
||||||
|
|
|
@ -3905,4 +3905,118 @@ class TicketTriggerTest < ActiveSupport::TestCase
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test 'trigger auto reply with umlaut in form' do
|
||||||
|
trigger1 = Trigger.create_or_update(
|
||||||
|
name: 'auto reply',
|
||||||
|
condition: {
|
||||||
|
'ticket.action' => {
|
||||||
|
'operator' => 'is',
|
||||||
|
'value' => 'create',
|
||||||
|
},
|
||||||
|
'ticket.state_id' => {
|
||||||
|
'operator' => 'is',
|
||||||
|
'value' => Ticket::State.lookup(name: 'new').id.to_s,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
perform: {
|
||||||
|
'notification.email' => {
|
||||||
|
'body' => 'some text<br>#{ticket.customer.lastname}<br>#{ticket.title}<br>#{article.body}',
|
||||||
|
'recipient' => 'article_last_sender',
|
||||||
|
'subject' => 'Thanks for your inquiry (#{ticket.title})!',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
disable_notification: true,
|
||||||
|
active: true,
|
||||||
|
created_by_id: 1,
|
||||||
|
updated_by_id: 1,
|
||||||
|
)
|
||||||
|
|
||||||
|
ticket1 = Ticket.create!(
|
||||||
|
title: 'test 1',
|
||||||
|
group: Group.lookup(name: 'Users'),
|
||||||
|
customer: User.lookup(email: 'nicole.braun@zammad.org'),
|
||||||
|
updated_by_id: 1,
|
||||||
|
created_by_id: 1,
|
||||||
|
)
|
||||||
|
Ticket::Article.create!(
|
||||||
|
ticket_id: ticket1.id,
|
||||||
|
from: 'Sabine Schütz <some_sender@example.com>',
|
||||||
|
to: 'some_recipient@example.com',
|
||||||
|
subject: 'some subject',
|
||||||
|
message_id: 'some@id',
|
||||||
|
body: 'some message <b>note</b> hello ',
|
||||||
|
internal: false,
|
||||||
|
sender: Ticket::Article::Sender.find_by(name: 'Customer'),
|
||||||
|
type: Ticket::Article::Type.find_by(name: 'email'),
|
||||||
|
updated_by_id: 1,
|
||||||
|
created_by_id: 1,
|
||||||
|
)
|
||||||
|
|
||||||
|
ticket1.reload
|
||||||
|
assert_equal('test 1', ticket1.title, 'ticket1.title verify')
|
||||||
|
assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
|
||||||
|
assert_equal('new', ticket1.state.name, 'ticket1.state verify')
|
||||||
|
assert_equal('2 normal', ticket1.priority.name, 'ticket1.priority verify')
|
||||||
|
assert_equal(1, ticket1.articles.count, 'ticket1.articles verify')
|
||||||
|
assert_equal('Sabine Schütz <some_sender@example.com>', ticket1.articles.first.from, 'ticket1.articles.first.from verify')
|
||||||
|
assert_equal([], ticket1.tag_list)
|
||||||
|
|
||||||
|
Observer::Transaction.commit
|
||||||
|
|
||||||
|
ticket1.reload
|
||||||
|
assert_equal('test 1', ticket1.title, 'ticket1.title verify')
|
||||||
|
assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
|
||||||
|
assert_equal('new', ticket1.state.name, 'ticket1.state verify')
|
||||||
|
assert_equal(2, ticket1.articles.count, 'ticket1.articles verify')
|
||||||
|
article1 = ticket1.articles.last
|
||||||
|
assert_match('Zammad <zammad@localhost>', article1.from)
|
||||||
|
assert_match('some_sender@example.com', article1.to)
|
||||||
|
assert_match('Thanks for your inquiry (test 1)!', article1.subject)
|
||||||
|
assert_match('some message', article1.body)
|
||||||
|
assert_match('> some message <b>note</b> hello', article1.body)
|
||||||
|
assert_equal('text/html', article1.content_type)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
test 'trigger auto reply with 2 sender addresses in form' do
|
||||||
|
trigger1 = Trigger.create_or_update(
|
||||||
|
name: 'auto reply',
|
||||||
|
condition: {
|
||||||
|
'ticket.action' => {
|
||||||
|
'operator' => 'is',
|
||||||
|
'value' => 'create',
|
||||||
|
},
|
||||||
|
'ticket.state_id' => {
|
||||||
|
'operator' => 'is',
|
||||||
|
'value' => Ticket::State.lookup(name: 'new').id.to_s,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
perform: {
|
||||||
|
'notification.email' => {
|
||||||
|
'body' => 'some text<br>#{ticket.customer.lastname}<br>#{ticket.title}<br>#{article.body}',
|
||||||
|
'recipient' => 'article_last_sender',
|
||||||
|
'subject' => 'Thanks for your inquiry (#{ticket.title})!',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
disable_notification: true,
|
||||||
|
active: true,
|
||||||
|
created_by_id: 1,
|
||||||
|
updated_by_id: 1,
|
||||||
|
)
|
||||||
|
|
||||||
|
ticket1, article1, user, mail = Channel::EmailParser.new.process({}, IO.binread('test/fixtures/mail65.box'))
|
||||||
|
|
||||||
|
assert_equal('aaäöüßad asd', ticket1.title, 'ticket1.title verify')
|
||||||
|
assert_equal('Users', ticket1.group.name, 'ticket1.group verify')
|
||||||
|
assert_equal('new', ticket1.state.name, 'ticket1.state verify')
|
||||||
|
assert_equal(2, ticket1.articles.count, 'ticket1.articles verify')
|
||||||
|
article1 = ticket1.articles.last
|
||||||
|
assert_match('Zammad <zammad@localhost>', article1.from)
|
||||||
|
assert_match('smith@example.com', article1.to)
|
||||||
|
assert_match('Thanks for your inquiry (aaäöüßad asd)!', article1.subject)
|
||||||
|
assert_match('some text<br><br>aaäöüßad asd', article1.body)
|
||||||
|
assert_equal('text/html', article1.content_type)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue