Improved email parsing, added tests.
This commit is contained in:
parent
716e428f07
commit
09dca3b50a
4 changed files with 217 additions and 47 deletions
|
@ -66,7 +66,14 @@ class Channel::EmailParser
|
||||||
|
|
||||||
# set all headers
|
# set all headers
|
||||||
mail.header.fields.each { |field|
|
mail.header.fields.each { |field|
|
||||||
data[field.name.to_s.downcase.to_sym] = Encode.conv( 'utf8', field.to_s )
|
if field.name
|
||||||
|
|
||||||
|
# full line, encode, ready for storage
|
||||||
|
data[field.name.to_s.downcase.to_sym] = Encode.conv( 'utf8', field.to_s )
|
||||||
|
|
||||||
|
# if we need to access the lines by objects later again
|
||||||
|
data[ "raw-#{field.name.downcase.to_s}".to_sym ] = field
|
||||||
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
# get sender
|
# get sender
|
||||||
|
@ -367,9 +374,9 @@ class Channel::EmailParser
|
||||||
end
|
end
|
||||||
|
|
||||||
# create to and cc user
|
# create to and cc user
|
||||||
['to', 'cc'].each { |item|
|
['raw-to', 'raw-cc'].each { |item|
|
||||||
if mail[item.to_sym]
|
if mail[item.to_sym] && mail[item.to_sym].tree
|
||||||
items = Mail::AddressList.new( mail[item.to_sym] )
|
items = mail[item.to_sym].tree
|
||||||
items.addresses.each {|item|
|
items.addresses.each {|item|
|
||||||
user_create(
|
user_create(
|
||||||
:firstname => item.display_name,
|
:firstname => item.display_name,
|
||||||
|
|
82
test/fixtures/mail30.box
vendored
Normal file
82
test/fixtures/mail30.box
vendored
Normal file
|
@ -0,0 +1,82 @@
|
||||||
|
From Manfred.Haert@example.com Fri Jan 9 14:19:00 2015
|
||||||
|
Return-Path: <Manfred.Haert@example.com>
|
||||||
|
X-Original-To: info@znuny.inc
|
||||||
|
Delivered-To: znuny-sales@arber.znuny.inc
|
||||||
|
Received: from mprox01.example.com (mail.example.com [194.113.173.37])
|
||||||
|
by arber.znuny.inc (Postfix) with ESMTP id DDC3C5FEBB
|
||||||
|
for <info@znuny.inc>; Fri, 9 Jan 2015 14:18:59 +0100 (CET)
|
||||||
|
Message-ID: <54AFD538.10306@example.com>
|
||||||
|
Date: Fri, 9 Jan 2015 14:18:48 +0100
|
||||||
|
From: Manfred Haert <Manfred.Haert@example.com>
|
||||||
|
MIME-Version: 1.0
|
||||||
|
To: <info@znuny.inc>
|
||||||
|
CC: =?UTF-8?Q?Bert_J=c3=b6rg?= <Joerg.Bert@example.com>,
|
||||||
|
"Test,
|
||||||
|
Karl-Heinz" <Karl-Heinz.Test@example.com>
|
||||||
|
Subject: Antragswesen in TesT abbilden
|
||||||
|
Content-Type: text/html; charset="UTF-8"
|
||||||
|
Content-Transfer-Encoding: 8bit
|
||||||
|
X-UID: 2208
|
||||||
|
Status: RO
|
||||||
|
Content-Length: 3214
|
||||||
|
Lines: 64
|
||||||
|
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
|
||||||
|
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||||
|
</head>
|
||||||
|
<body bgcolor="#FFFFFF" text="#000066">
|
||||||
|
<font face="Helvetica, Arial, sans-serif">Sehr geehrte Damen und
|
||||||
|
Herren,<br>
|
||||||
|
<br>
|
||||||
|
wir hatten bereits letztes Jahr einen TesT-Workshop mit Ihrem
|
||||||
|
Herrn XXX durchgeführt und würden nun gerne erneut
|
||||||
|
Ihre Dienste in Anspruch nehmen.<br>
|
||||||
|
<br>
|
||||||
|
Mittlerweile setzen wir TesT produktiv ein und würden nun gerne an
|
||||||
|
einem Anwendungsfall (Change-Management) die Machbarkeit des
|
||||||
|
Abbildens eines derzeit "per Papier" durchgeführten Antragswesens
|
||||||
|
in TesT prüfen wollen.<br>
|
||||||
|
<br>
|
||||||
|
Wir bitten gerne um ein entsprechendes Angebot.<br>
|
||||||
|
<br>
|
||||||
|
Für Rückfragen stehe ich gerne zur Verfügung. Vielen Dank!<br>
|
||||||
|
<br>
|
||||||
|
</font>
|
||||||
|
<div class="moz-signature">-- <br>
|
||||||
|
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||||
|
<title></title>
|
||||||
|
<font face="Helvetica, Arial, sans-serif"> Freundliche Grüße<br>
|
||||||
|
i.A. Manfred Härt<br>
|
||||||
|
<br>
|
||||||
|
<small><small>Test Somewhere GmbH<br>
|
||||||
|
Ferdinand-Straße 99<br>
|
||||||
|
99073 Korlben<br>
|
||||||
|
<b>Bitte beachten Sie die neuen Rufnummern!</b><br>
|
||||||
|
Telefon: 011261 00000-2460<br>
|
||||||
|
Fax: 011261 0000-7460<br>
|
||||||
|
<a class="moz-txt-link-freetext" href="mailto:manfred.haertel@example.com">mailto:manfred.haertel@example.com</a><br>
|
||||||
|
<a class="moz-txt-link-freetext" href="http://www.example.com">http://www.example.com</a><br>
|
||||||
|
JETZT AUCH BEI FACEBOOK !<br>
|
||||||
|
<a class="moz-txt-link-freetext" href="https://www.facebook.com/test">https://www.facebook.com/test</a><br>
|
||||||
|
___________________________________<br>
|
||||||
|
Test Somewhere GmbH<br>
|
||||||
|
</small></small> </font>
|
||||||
|
<p><font face="Helvetica, Arial, sans-serif"><small><small>Diese
|
||||||
|
e-Mail ist ausschließlich für den beabsichtigten Empfänger
|
||||||
|
bestimmt. Sollten Sie irrtümlich diese e-Mail erhalten
|
||||||
|
haben, unterrichten Sie uns bitte umgehend unter
|
||||||
|
<a class="moz-txt-link-abbreviated" href="mailto:kontakt@example.com">kontakt@example.com</a> und vernichten Sie diese Mitteilung
|
||||||
|
einschließlich der ggf. beigefügten Dateien.<br>
|
||||||
|
Weil wir die Echtheit oder Vollständigkeit der in dieser
|
||||||
|
Nachricht enthaltenen Informationen nicht garantieren
|
||||||
|
können, bitten wir um Verständnis, dass wir zu Ihrem und
|
||||||
|
unserem Schutz die rechtliche Verbindlichkeit der
|
||||||
|
vorstehenden Erklärungen ausschließen, soweit wir mit
|
||||||
|
Ihnen keine anders lautenden Vereinbarungen getroffen
|
||||||
|
haben.</small></small> </font> </p>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
|
@ -598,6 +598,51 @@ Registration AG Ulm HRB 534075 * General Manager Holger Felgner
|
||||||
[3] http://www.teamviewer.com",
|
[3] http://www.teamviewer.com",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
:data => IO.read('test/fixtures/mail30.box'),
|
||||||
|
:body_md5 => 'bba63e2dbe29e7b82d893c2554ff466a',
|
||||||
|
:params => {
|
||||||
|
:from => 'Manfred Haert <Manfred.Haert@example.com>',
|
||||||
|
:from_email => 'Manfred.Haert@example.com',
|
||||||
|
:from_display_name => "Manfred Haert",
|
||||||
|
:subject => "Antragswesen in TesT abbilden",
|
||||||
|
:to => 'info@znuny.inc',
|
||||||
|
:body => "Sehr geehrte Damen undHerren,
|
||||||
|
|
||||||
|
wir hatten bereits letztes Jahr einen TesT-Workshop mit IhremHerrn XXX durchgeführt und würden nun gerne erneutIhre Dienste in Anspruch nehmen.
|
||||||
|
|
||||||
|
Mittlerweile setzen wir TesT produktiv ein und würden nun gerne aneinem Anwendungsfall (Change-Management) die Machbarkeit desAbbildens eines derzeit \"per Papier\" durchgeführten Antragswesensin TesT prüfen wollen.
|
||||||
|
|
||||||
|
Wir bitten gerne um ein entsprechendes Angebot.
|
||||||
|
|
||||||
|
Für Rückfragen stehe ich gerne zur Verfügung. Vielen Dank!
|
||||||
|
|
||||||
|
--
|
||||||
|
Freundliche Grüße
|
||||||
|
i.A. Manfred Härt
|
||||||
|
|
||||||
|
Test Somewhere GmbH
|
||||||
|
Ferdinand-Straße 99
|
||||||
|
99073 Korlben
|
||||||
|
Bitte beachten Sie die neuen Rufnummern!
|
||||||
|
Telefon: 011261 00000-2460
|
||||||
|
Fax: 011261 0000-7460
|
||||||
|
[1] mailto:manfred.haertel@example.com
|
||||||
|
[2] http://www.example.com
|
||||||
|
JETZT AUCH BEI FACEBOOK !
|
||||||
|
[3] https://www.facebook.com/test
|
||||||
|
___________________________________
|
||||||
|
Test Somewhere GmbH
|
||||||
|
Diesee-Mail ist ausschließlich für den beabsichtigten Empfängerbestimmt. Sollten Sie irrtümlich diese e-Mail erhaltenhaben, unterrichten Sie uns bitte umgehend unter[4] kontakt@example.com und vernichten Sie diese Mitteilungeinschließlich der ggf. beigefügten Dateien.
|
||||||
|
Weil wir die Echtheit oder Vollständigkeit der in dieserNachricht enthaltenen Informationen nicht garantierenkönnen, bitten wir um Verständnis, dass wir zu Ihrem undunserem Schutz die rechtliche Verbindlichkeit dervorstehenden Erklärungen ausschließen, soweit wir mitIhnen keine anders lautenden Vereinbarungen getroffenhaben.
|
||||||
|
|
||||||
|
|
||||||
|
[1] mailto:manfred.haertel@example.com
|
||||||
|
[2] http://www.example.com
|
||||||
|
[3] https://www.facebook.com/test
|
||||||
|
[4] mailto:kontakt@example.com",
|
||||||
|
},
|
||||||
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
files.each { |file|
|
files.each { |file|
|
||||||
|
|
|
@ -1823,6 +1823,85 @@ AElFTkSuQmCC
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
:data => 'From: Some Body <somebody@example.com>
|
||||||
|
To: Bob <bod@example.com>
|
||||||
|
Cc: any@example.com
|
||||||
|
Subject: some subject
|
||||||
|
|
||||||
|
Some Text',
|
||||||
|
:trusted => false,
|
||||||
|
:success => true,
|
||||||
|
:result => {
|
||||||
|
0 => {
|
||||||
|
:group => 'Users',
|
||||||
|
:priority => '2 normal',
|
||||||
|
:title => 'some subject',
|
||||||
|
},
|
||||||
|
1 => {
|
||||||
|
:sender => 'Customer',
|
||||||
|
:type => 'email',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
:verify => {
|
||||||
|
:users => [
|
||||||
|
{
|
||||||
|
:firstname => 'Some',
|
||||||
|
:lastname => 'Body',
|
||||||
|
:email => 'somebody@example.com',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
:firstname => 'Bob',
|
||||||
|
:lastname => '',
|
||||||
|
:fullname => 'Bob',
|
||||||
|
:email => 'bod@example.com',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
:firstname => '',
|
||||||
|
:lastname => '',
|
||||||
|
:email => 'any@example.com',
|
||||||
|
:fullname => 'any@example.com',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
:data => IO.read('test/fixtures/mail30.box'),
|
||||||
|
:success => true,
|
||||||
|
:result => {
|
||||||
|
0 => {
|
||||||
|
:priority => '2 normal',
|
||||||
|
:title => 'Antragswesen in TesT abbilden',
|
||||||
|
},
|
||||||
|
1 => {
|
||||||
|
:sender => 'Customer',
|
||||||
|
:type => 'email',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
:verify => {
|
||||||
|
:users => [
|
||||||
|
{
|
||||||
|
:firstname => 'Bert',
|
||||||
|
:lastname => 'Jörg',
|
||||||
|
:fullname => 'Bert Jörg',
|
||||||
|
:email => 'joerg.bert@example.com',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
:firstname => 'Karl-Heinz',
|
||||||
|
:lastname => 'Test',
|
||||||
|
:fullname => 'Karl-Heinz Test',
|
||||||
|
:email => 'karl-heinz.test@example.com',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
:firstname => 'Manfred',
|
||||||
|
:lastname => 'Haert',
|
||||||
|
:email => 'manfred.haert@example.com',
|
||||||
|
:fullname => 'Manfred Haert',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
]
|
]
|
||||||
process(files)
|
process(files)
|
||||||
end
|
end
|
||||||
|
@ -1971,49 +2050,6 @@ Some Text',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
|
||||||
:data => 'From: Some Body <somebody@example.com>
|
|
||||||
To: Bob <bod@example.com>
|
|
||||||
Cc: any@example.com
|
|
||||||
Subject: some subject
|
|
||||||
|
|
||||||
Some Text',
|
|
||||||
:trusted => false,
|
|
||||||
:success => true,
|
|
||||||
:result => {
|
|
||||||
0 => {
|
|
||||||
:group => group2.name,
|
|
||||||
:priority => '2 normal',
|
|
||||||
:title => 'some subject',
|
|
||||||
},
|
|
||||||
1 => {
|
|
||||||
:sender => 'Customer',
|
|
||||||
:type => 'email',
|
|
||||||
:internal => true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
:verify => {
|
|
||||||
:users => [
|
|
||||||
{
|
|
||||||
:firstname => 'Some',
|
|
||||||
:lastname => 'Body',
|
|
||||||
:email => 'somebody@example.com',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
:firstname => 'Bob',
|
|
||||||
:lastname => '',
|
|
||||||
:fullname => 'Bob',
|
|
||||||
:email => 'bod@example.com',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
:firstname => '',
|
|
||||||
:lastname => '',
|
|
||||||
:email => 'any@example.com',
|
|
||||||
:fullname => 'any@example.com',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}
|
|
||||||
},
|
|
||||||
]
|
]
|
||||||
process(files)
|
process(files)
|
||||||
PostmasterFilter.destroy_all
|
PostmasterFilter.destroy_all
|
||||||
|
|
Loading…
Reference in a new issue