Fixed issue #893 - Capital letters in article from cause problems in OTRS import.

This commit is contained in:
Thorsten Eckel 2017-03-27 12:47:33 +02:00
parent 943d917139
commit 4a1b4af6ae
3 changed files with 114 additions and 3 deletions

View file

@ -12,12 +12,19 @@ module Import
class << self
def find(article)
email = extract_email(article['From'])
email = local_email(article['From'])
user = ::User.find_by(email: email)
user ||= ::User.find_by(login: email)
user
end
def local_email(from)
# TODO: should get unified with User#check_email
extract_email(from).downcase
end
private
def extract_email(from)
Mail::Address.new(from).address
rescue
@ -38,7 +45,7 @@ module Import
end
def create(article)
email = self.class.extract_email(article['From'])
email = self.class.local_email(article['From'])
::User.create(
login: email,
firstname: extract_display_name(article['From']),

View file

@ -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@example.com"
}

View file

@ -36,8 +36,15 @@ RSpec.describe Import::OTRS::ArticleCustomer do
expect(User.last.login).to eq('user.hernandez@example.com')
end
it 'creates customers with special from email sytax' do
it 'creates customers with special from email syntax' 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
it 'converts emails to downcase' do
Setting.set('import_mode', true)
expect { described_class.new(load_article_json('from_capital_case')) }.to change { User.count }.by(1)
expect(User.last.email).to eq('user@example.com')
expect(User.last.login).to eq('user@example.com')
end
end