Improved email parsing.
This commit is contained in:
parent
2019fced1d
commit
3e07697954
4 changed files with 71 additions and 6 deletions
|
@ -108,9 +108,18 @@ class Channel::EmailParser
|
|||
data[:from_display_name] = Mail::Address.new(from).display_name ||
|
||||
(Mail::Address.new(from).comments && Mail::Address.new(from).comments[0])
|
||||
rescue
|
||||
data[:from_email] = from
|
||||
data[:from_local] = from
|
||||
data[:from_domain] = from
|
||||
from.strip!
|
||||
if from =~ /^(.+?)<(.+?)@(.+?)>$/
|
||||
data[:from_email] = "#{$2}@#{$3}"
|
||||
data[:from_local] = $2
|
||||
data[:from_domain] = $3
|
||||
data[:from_display_name] = $1.strip
|
||||
data[:from_display_name].delete!('"')
|
||||
else
|
||||
data[:from_email] = from
|
||||
data[:from_local] = from
|
||||
data[:from_domain] = from
|
||||
end
|
||||
end
|
||||
|
||||
# do extra decoding because we needed to use field.value
|
||||
|
|
18
test/fixtures/mail45.box
vendored
Normal file
18
test/fixtures/mail45.box
vendored
Normal file
|
@ -0,0 +1,18 @@
|
|||
To: James-Max ROGER <james-max.roger@example.com>, Support <zammad@example.com>
|
||||
Subject: Nouveau message contact élégibilité Zammad
|
||||
X-PHP-Originating-Script: 111:contact.php
|
||||
From: Ups Rémi <r.ordonaud@example.com>
|
||||
Message-Id: <20170111111111.8CEF15FB28@01.localdomain>
|
||||
Date: Fri, 6 Jan 2017 19:23:41 +0100 (CET)
|
||||
|
||||
Nouveau message :
|
||||
=============================
|
||||
Nom: Orberer
|
||||
Prénom: Rémi
|
||||
Téléphone: xxxx
|
||||
Email: xxx@example.com
|
||||
Societé: KG
|
||||
Adresse: RdL
|
||||
CP: 11111
|
||||
Ville: Olèchena
|
||||
|
|
@ -680,13 +680,25 @@ end
|
|||
body_md5: '2f0f5a21e4393c174d4670a188fc5548',
|
||||
params: {
|
||||
from: '"Clement.Si" <Claudia.Shu@yahoo.com.>',
|
||||
from_email: '"Clement.Si" <Claudia.Shu@yahoo.com.>',
|
||||
from_display_name: '',
|
||||
from_email: 'Claudia.Shu@yahoo.com.',
|
||||
from_display_name: 'Clement.Si',
|
||||
subject: '精益生产闪婚,是谁的责任',
|
||||
to: 'abuse@domain.com',
|
||||
cc: nil,
|
||||
},
|
||||
},
|
||||
{
|
||||
data: IO.binread('test/fixtures/mail45.box'),
|
||||
body_md5: '1d847e3626145a9e886914ecf0d89368',
|
||||
params: {
|
||||
from: '"Ups Rémi" <r.ordonaud@example.com>',
|
||||
from_email: 'r.ordonaud@example.com',
|
||||
from_display_name: 'Ups Rémi',
|
||||
subject: 'Nouveau message contact élégibilité Zammad',
|
||||
to: 'James-Max ROGER <james-max.roger@example.com>, Support <zammad@example.com>',
|
||||
cc: nil,
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
count = 0
|
||||
|
|
|
@ -2015,7 +2015,33 @@ Some Text',
|
|||
},
|
||||
{
|
||||
data: IO.binread('test/fixtures/mail44.box'),
|
||||
success: false,
|
||||
success: true,
|
||||
result: {
|
||||
0 => {
|
||||
priority: '2 normal',
|
||||
title: '精益生产闪婚,是谁的责任',
|
||||
},
|
||||
1 => {
|
||||
sender: 'Customer',
|
||||
type: 'email',
|
||||
},
|
||||
},
|
||||
verify: {
|
||||
users: [
|
||||
{
|
||||
firstname: 'Clement.Si',
|
||||
lastname: '',
|
||||
fullname: 'Clement.Si',
|
||||
email: 'claudia.shu@yahoo.com.',
|
||||
},
|
||||
{
|
||||
firstname: '',
|
||||
lastname: '',
|
||||
fullname: 'abuse@domain.com',
|
||||
email: 'abuse@domain.com',
|
||||
},
|
||||
],
|
||||
}
|
||||
},
|
||||
]
|
||||
assert_process(files)
|
||||
|
|
Loading…
Reference in a new issue