From 73a258b7968c0ee6cfaf817f067295f1bf3c6279 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Thu, 16 Mar 2017 06:50:01 +0100 Subject: [PATCH] Fixed issue #763 - Customer names are sometimes wrapped with quotes. --- app/models/channel/email_parser.rb | 7 +- app/models/channel/filter/identify_sender.rb | 14 +++- test/unit/email_process_test.rb | 68 ++++++++++++++++++++ 3 files changed, 84 insertions(+), 5 deletions(-) diff --git a/app/models/channel/email_parser.rb b/app/models/channel/email_parser.rb index 387d1c0de..45b18166d 100644 --- a/app/models/channel/email_parser.rb +++ b/app/models/channel/email_parser.rb @@ -129,8 +129,7 @@ class Channel::EmailParser data[:from_email] = "#{$2}@#{$3}" data[:from_local] = $2 data[:from_domain] = $3 - data[:from_display_name] = $1.strip - data[:from_display_name].delete!('"') + data[:from_display_name] = $1 else data[:from_email] = from data[:from_local] = from @@ -140,6 +139,10 @@ class Channel::EmailParser # do extra decoding because we needed to use field.value data[:from_display_name] = Mail::Field.new('X-From', data[:from_display_name]).to_s + data[:from_display_name].delete!('"') + data[:from_display_name].strip! + data[:from_display_name].gsub!(/^'/, '') + data[:from_display_name].gsub!(/'$/, '') # compat headers data[:message_id] = data['message-id'.to_sym] diff --git a/app/models/channel/filter/identify_sender.rb b/app/models/channel/filter/identify_sender.rb index 5226e4c8c..db2c51b31 100644 --- a/app/models/channel/filter/identify_sender.rb +++ b/app/models/channel/filter/identify_sender.rb @@ -112,7 +112,7 @@ module Channel::Filter::IdentifySender address = $1 end if recipient =~ /^(.+?)<(.+?)>/ - display_name = ($1).strip + display_name = $1 end next if address.empty? user_create( @@ -135,8 +135,12 @@ module Channel::Filter::IdentifySender # check if firstname or lastname need to be updated if user - if user.firstname.empty? && user.lastname.empty? - if !data[:firstname].empty? + if user.firstname.blank? && user.lastname.blank? + if data[:firstname].present? + data[:firstname].strip! + data[:firstname].delete!('"') + data[:firstname].gsub!(/^'/, '') + data[:firstname].gsub!(/'$/, '') user.update_attributes( firstname: data[:firstname] ) @@ -153,6 +157,10 @@ module Channel::Filter::IdentifySender if data[item.to_sym].nil? data[item.to_sym] = '' end + data[item.to_sym].strip! + data[item.to_sym].delete!('"') + data[item.to_sym].gsub!(/^'/, '') + data[item.to_sym].gsub!(/'$/, '') } data[:password] = '' data[:active] = true diff --git a/test/unit/email_process_test.rb b/test/unit/email_process_test.rb index 09d681a26..0bac8d1ff 100644 --- a/test/unit/email_process_test.rb +++ b/test/unit/email_process_test.rb @@ -1862,6 +1862,74 @@ AElFTkSuQmCC }, }, }, + { + data: 'From: =?UTF-8?Q?=22Frieda_H=C3=B6flich1=22?= +To: =?UTF-8?Q?=22Bob1=22?= +Subject: some subject frieda hoeflich1 + +Some Text', + success: true, + result: { + 0 => { + priority: '2 normal', + title: 'some subject frieda hoeflich1', + }, + 1 => { + sender: 'Customer', + type: 'email', + }, + }, + verify: { + users: [ + { + firstname: 'Frieda', + lastname: 'Höflich1', + fullname: 'Frieda Höflich1', + email: 'frieda.hoeflich1@example.com', + }, + { + firstname: 'Bob1', + lastname: '', + fullname: 'Bob1', + email: 'bod+frieda.hoeflich1@example.com', + }, + ], + } + }, + { + data: 'From: =?utf-8?Q?=27Frieda_H=C3=B6flich2=27?= +To: =?utf-8?Q?=27Bob2=27?= +Subject: some subject frieda hoeflich2 + +Some Text', + success: true, + result: { + 0 => { + priority: '2 normal', + title: 'some subject frieda hoeflich2', + }, + 1 => { + sender: 'Customer', + type: 'email', + }, + }, + verify: { + users: [ + { + firstname: 'Frieda', + lastname: 'Höflich2', + fullname: 'Frieda Höflich2', + email: 'frieda.hoeflich2@example.com', + }, + { + firstname: 'Bob2', + lastname: '', + fullname: 'Bob2', + email: 'bod+frieda.hoeflich2@example.com', + }, + ], + } + }, { data: 'From: Some Body To: Bob