From b09ecbe23e761344ad9b76b01e19de22c090e3b4 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Thu, 16 Mar 2017 15:06:24 +0100 Subject: [PATCH] Fixed issue #842 - Special chars in article 'From' causing OTRS import to create user with wrong login. --- lib/import/otrs/article_customer.rb | 4 +- .../otrs/article/customer_special_chars.json | 97 +++++++++++++++++++ .../article/from_bracket_email_syntax.json | 97 +++++++++++++++++++ spec/import/otrs/article_customer_sepc.rb | 10 ++ 4 files changed, 206 insertions(+), 2 deletions(-) create mode 100644 spec/fixtures/import/otrs/article/customer_special_chars.json create mode 100644 spec/fixtures/import/otrs/article/from_bracket_email_syntax.json diff --git a/lib/import/otrs/article_customer.rb b/lib/import/otrs/article_customer.rb index 4d63e0a42..acb1e2d74 100644 --- a/lib/import/otrs/article_customer.rb +++ b/lib/import/otrs/article_customer.rb @@ -21,8 +21,8 @@ module Import def extract_email(from) Mail::Address.new(from).address rescue - return from if from !~ /<\s*([^\s]+)/ - $1 + return from if from !~ /<\s*([^>]+)/ + $1.strip end end diff --git a/spec/fixtures/import/otrs/article/customer_special_chars.json b/spec/fixtures/import/otrs/article/customer_special_chars.json new file mode 100644 index 000000000..bccc1d180 --- /dev/null +++ b/spec/fixtures/import/otrs/article/customer_special_chars.json @@ -0,0 +1,97 @@ +{ + "Age": 63188310, + "PriorityID": "3", + "ContentType": "text/plain; charset=utf-8", + "AttachmentIDOfHTMLBody": "1", + "DynamicField_SugarCRMCompanySelection": null, + "ServiceID": null, + "TicketFreeText11": null, + "DynamicField_ITSMDueDate": "2014-11-24 00:15:00", + "DynamicField_Topic": null, + "StateID": "2", + "DynamicField_Hostname": null, + "Body": "test #3", + "DynamicField_ZammadMigratorChanged": null, + "EscalationTime": "0", + "Changed": "2014-11-21 00:21:08", + "OwnerID": "3", + "DynamicField_ZarafaTN": null, + "DynamicField_ProcessManagementActivityID": null, + "DynamicField_TopicID": null, + "DynamicField_ScomHostname": null, + "Owner": "agent-2", + "AgeTimeUnix": 63188309, + "TicketFreeKey11": null, + "ArticleID": "3970", + "Created": "2014-11-21 00:17:41", + "DynamicField_ScomUUID": null, + "DynamicField_TicketFreeText11": null, + "DynamicField_TicketFreeKey11": null, + "DynamicField_ITSMReviewRequired": "No", + "DynamicField_OpenExchangeTicketNumber": null, + "DynamicField_ITSMDecisionDate": null, + "ArticleTypeID": "5", + "QueueID": "1", + "ReplyTo": "", + "DynamicField_ITSMImpact": null, + "TicketID": "730", + "DynamicField_ITSMRecoveryStartTime": null, + "Cc": "", + "EscalationResponseTime": "0", + "DynamicField_ProcessManagementProcessID": null, + "IncomingTime": "1416525461", + "Charset": "utf-8", + "DynamicField_CheckboxExample": null, + "DynamicField_Location": null, + "CustomerUserID": "BetreuterKunde2", + "DynamicField_Vertriebsweg": null, + "Attachments": [], + "DynamicField_CustomerLocation": null, + "DynamicField_SugarCRMRemoteID": null, + "DynamicField_OpenExchangeTN": null, + "Service": "", + "Type": "Incident", + "ContentCharset": "utf-8", + "DynamicField_TETest": null, + "Responsible": "root@localhost", + "SenderType": "customer", + "ResponsibleID": "1", + "SLA": "", + "MimeType": "text/plain", + "DynamicField_Combine": null, + "Subject": "test #3", + "InReplyTo": "", + "RealTillTimeNotUsed": "0", + "DynamicField_ScomService": null, + "CustomerID": "3333333333", + "TypeID": "1", + "MessageID": "", + "Priority": "3 normal", + "To": "Postmaster", + "DynamicField_SugarCRMCompanySelectedID": null, + "UntilTime": 0, + "EscalationUpdateTime": "0", + "CreatedBy": "3", + "Queue": "Postmaster", + "DynamicField_ITSMRepairStartTime": null, + "ToRealname": "Postmaster", + "State": "closed successful", + "SenderTypeID": "3", + "DynamicField_ZammadMigratorChangedOld": "1", + "Title": "test #3", + "DynamicField_ScomState": null, + "References": "", + "DynamicField_Department": null, + "ArticleType": "phone", + "StateType": "closed", + "FromRealname": "Betreuter Kunde", + "EscalationSolutionTime": "0", + "LockID": "1", + "TicketNumber": "20141121305000012", + "DynamicField_ITSMDecisionResult": null, + "Lock": "unlock", + "CreateTimeUnix": "1416525460", + "SLAID": null, + "DynamicField_ITSMCriticality": null, + "From": "User Hernández " +} \ No newline at end of file diff --git a/spec/fixtures/import/otrs/article/from_bracket_email_syntax.json b/spec/fixtures/import/otrs/article/from_bracket_email_syntax.json new file mode 100644 index 000000000..2ae4d393a --- /dev/null +++ b/spec/fixtures/import/otrs/article/from_bracket_email_syntax.json @@ -0,0 +1,97 @@ +{ + "Age": 63188310, + "PriorityID": "3", + "ContentType": "text/plain; charset=utf-8", + "AttachmentIDOfHTMLBody": "1", + "DynamicField_SugarCRMCompanySelection": null, + "ServiceID": null, + "TicketFreeText11": null, + "DynamicField_ITSMDueDate": "2014-11-24 00:15:00", + "DynamicField_Topic": null, + "StateID": "2", + "DynamicField_Hostname": null, + "Body": "test #3", + "DynamicField_ZammadMigratorChanged": null, + "EscalationTime": "0", + "Changed": "2014-11-21 00:21:08", + "OwnerID": "3", + "DynamicField_ZarafaTN": null, + "DynamicField_ProcessManagementActivityID": null, + "DynamicField_TopicID": null, + "DynamicField_ScomHostname": null, + "Owner": "agent-2", + "AgeTimeUnix": 63188309, + "TicketFreeKey11": null, + "ArticleID": "3970", + "Created": "2014-11-21 00:17:41", + "DynamicField_ScomUUID": null, + "DynamicField_TicketFreeText11": null, + "DynamicField_TicketFreeKey11": null, + "DynamicField_ITSMReviewRequired": "No", + "DynamicField_OpenExchangeTicketNumber": null, + "DynamicField_ITSMDecisionDate": null, + "ArticleTypeID": "5", + "QueueID": "1", + "ReplyTo": "", + "DynamicField_ITSMImpact": null, + "TicketID": "730", + "DynamicField_ITSMRecoveryStartTime": null, + "Cc": "", + "EscalationResponseTime": "0", + "DynamicField_ProcessManagementProcessID": null, + "IncomingTime": "1416525461", + "Charset": "utf-8", + "DynamicField_CheckboxExample": null, + "DynamicField_Location": null, + "CustomerUserID": "BetreuterKunde2", + "DynamicField_Vertriebsweg": null, + "Attachments": [], + "DynamicField_CustomerLocation": null, + "DynamicField_SugarCRMRemoteID": null, + "DynamicField_OpenExchangeTN": null, + "Service": "", + "Type": "Incident", + "ContentCharset": "utf-8", + "DynamicField_TETest": null, + "Responsible": "root@localhost", + "SenderType": "customer", + "ResponsibleID": "1", + "SLA": "", + "MimeType": "text/plain", + "DynamicField_Combine": null, + "Subject": "test #3", + "InReplyTo": "", + "RealTillTimeNotUsed": "0", + "DynamicField_ScomService": null, + "CustomerID": "3333333333", + "TypeID": "1", + "MessageID": "", + "Priority": "3 normal", + "To": "Postmaster", + "DynamicField_SugarCRMCompanySelectedID": null, + "UntilTime": 0, + "EscalationUpdateTime": "0", + "CreatedBy": "3", + "Queue": "Postmaster", + "DynamicField_ITSMRepairStartTime": null, + "ToRealname": "Postmaster", + "State": "closed successful", + "SenderTypeID": "3", + "DynamicField_ZammadMigratorChangedOld": "1", + "Title": "test #3", + "DynamicField_ScomState": null, + "References": "", + "DynamicField_Department": null, + "ArticleType": "phone", + "StateType": "closed", + "FromRealname": "Betreuter Kunde", + "EscalationSolutionTime": "0", + "LockID": "1", + "TicketNumber": "20141121305000012", + "DynamicField_ITSMDecisionResult": null, + "Lock": "unlock", + "CreateTimeUnix": "1416525460", + "SLAID": null, + "DynamicField_ITSMCriticality": null, + "From": "(Firstname Lastname) user@example.com" +} \ No newline at end of file diff --git a/spec/import/otrs/article_customer_sepc.rb b/spec/import/otrs/article_customer_sepc.rb index 4c6d6caac..7afece12c 100644 --- a/spec/import/otrs/article_customer_sepc.rb +++ b/spec/import/otrs/article_customer_sepc.rb @@ -30,4 +30,14 @@ RSpec.describe Import::OTRS::ArticleCustomer do expect(import_object).to receive(:create).and_return(existing_object) start_import_test end + + it 'creates customers with special encoding in name' do + expect { described_class.new(load_article_json('customer_special_chars')) }.to change { User.count }.by(1) + expect(User.last.login).to eq('user.hernandez@example.com') + end + + it 'creates customers with special from email sytax' do + expect { described_class.new(load_article_json('from_bracket_email_syntax')) }.to change { User.count }.by(1) + expect(User.last.login).to eq('user@example.com') + end end