From b82b0375f03ad376fff6963f3ef32e348159c32a Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Thu, 2 Nov 2017 14:09:47 +0100 Subject: [PATCH] Improved error handling for strange/invalid email addresses. --- app/models/ticket.rb | 4 ++-- test/unit/email_process_test.rb | 39 +++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/app/models/ticket.rb b/app/models/ticket.rb index 8568dc75c..d630dbce1 100644 --- a/app/models/ticket.rb +++ b/app/models/ticket.rb @@ -922,7 +922,7 @@ perform changes on ticket ticket_id: id, sender: Ticket::Article::Sender.find_by(name: 'System'), type: Ticket::Article::Type.find_by(name: 'email'), - ).where("ticket_articles.created_at > ? AND ticket_articles.to LIKE '%#{recipient_email.strip}%'", Time.zone.now - minutes.minutes).count + ).where('ticket_articles.created_at > ? AND ticket_articles.to LIKE ?', Time.zone.now - minutes.minutes, "%#{recipient_email.strip}%").count next if already_sent < count logger.info "Send no trigger based notification to #{recipient_email} because already sent #{count} for this ticket within last #{minutes} minutes (loop protection)" skip = true @@ -941,7 +941,7 @@ perform changes on ticket already_sent = Ticket::Article.where( sender: Ticket::Article::Sender.find_by(name: 'System'), type: Ticket::Article::Type.find_by(name: 'email'), - ).where("ticket_articles.created_at > ? AND ticket_articles.to LIKE '%#{recipient_email.strip}%'", Time.zone.now - minutes.minutes).count + ).where('ticket_articles.created_at > ? AND ticket_articles.to LIKE ?', Time.zone.now - minutes.minutes, "%#{recipient_email.strip}%").count next if already_sent < count logger.info "Send no trigger based notification to #{recipient_email} because already sent #{count} in total within last #{minutes} minutes (loop protection)" skip = true diff --git a/test/unit/email_process_test.rb b/test/unit/email_process_test.rb index e2ecb83d7..3df6d1844 100644 --- a/test/unit/email_process_test.rb +++ b/test/unit/email_process_test.rb @@ -69,6 +69,45 @@ Some Textäöü", }, }, }, + { + data: "From: me@exampl'e.com +To: customer@exampl'e.com +Subject: äöü some subject + +Some Textäöü", + channel: { + trusted: false, + }, + success: true, + result: { + 0 => { + priority: '2 normal', + title: 'äöü some subject', + }, + 1 => { + body: 'Some Textäöü', + sender: 'Customer', + type: 'email', + internal: false, + }, + }, + verify: { + users: [ + { + firstname: '', + lastname: '', + fullname: 'me@exampl\'e.com', + email: 'me@exampl\'e.com', + }, + { + firstname: '', + lastname: '', + fullname: 'customer@exampl\'e.com', + email: 'customer@exampl\'e.com', + }, + ], + }, + }, { data: "From: me@example.com To: customer@example.com