Extraction de EmailImporter + début de tests

This commit is contained in:
Jérémy Lecour 2020-12-31 11:56:13 +01:00
parent d220e79313
commit c280234698
5 changed files with 656 additions and 95 deletions

View file

@ -1,90 +1,9 @@
class InMailbox < ApplicationMailbox
def process
email = Email.new(
message_id: mail.message_id,
subject: mail.subject,
date: mail.date,
to: mail.to,
delivered_to: delivered_to(mail),
from: mail.from,
plain_body: text_plain_body(mail),
headers: hashed_headers(mail),
cron: sent_by_cron?(mail),
mailing_list: mailing_list?(mail),
clients: clients(mail),
servers: servers(mail),
tickets: tickets(mail)
)
email_importer = EmailImporter.new()
repository = EmailRepository.new
email = email_importer.import(mail)
repository.save(email)
rescue => ex
binding.pry
end
def delivered_to(mail)
header = mail.header["Delivered-To"]
if header.present?
if header.respond_to?(:map)
header.map(&:value)
else
header.value
end
else
mail.to
end
end
def text_plain_body(mail)
if mail.parts.present?
mail.text_part.decoded
else
mail.decoded
end
end
def hashed_headers(mail)
mail.header.map { |h|
{
name: h.name,
value: h.value
}
}
end
def sent_by_cron?(mail)
mail.subject.match?(/cron/i) \
|| mail.header["X-Cron-Env"].present?
end
def mailing_list?(mail)
mail.header["List-Unsubscribe"].present?
end
def clients(mail)
Array(mail.header["X-Client-ID"].value) if mail.header["X-Client-ID"].present?
end
def servers(mail)
if mail.header["X-Server-Name"].present?
Array(mail.header["X-Server-Name"].value)
else
matching_header = ["To", "Delivered-To", "From", "Subject"].detect { |header_name|
address_match_evolix_net?(mail.header[header_name].value) if mail.header[header_name].present?
}
Array(extract_server_name_from_address(mail.header[matching_header].value)) if matching_header
end
end
def tickets(mail)
Array(mail.header["X-Ticket-ID"].value) if mail.header["X-Ticket-ID"].present?
end
def address_match_evolix_net?(address)
address.match?(/@(.+)\.evolix\.net/i)
end
def extract_server_name_from_address(address)
address.match(/@(.+)\.evolix\.net/i)[1]
end
end

View file

@ -0,0 +1,103 @@
class EmailImporter
attr_accessor :klass
def initialize(klass = Email)
@klass = klass
end
def import(mail)
email = klass.new(
message_id: mail.message_id,
subject: mail.subject,
date: mail.date,
to: mail.to,
delivered_to: delivered_to(mail),
from: mail.from,
plain_body: text_plain_body(mail),
headers: hashed_headers(mail),
cron: sent_by_cron?(mail),
mailing_list: mailing_list?(mail),
clients: clients(mail),
servers: servers(mail),
tickets: tickets(mail)
)
rescue => ex
binding.pry
end
def delivered_to(mail)
if mail.header["Delivered-To"]
mail.header["Delivered-To"]
else
mail.to
end
end
def text_plain_body(mail)
if mail.parts.present?
if mail.text_part.present?
mail.text_part.decoded
elsif mail.html_part.present?
Nokogiri::HTML(mail.html_part.decoded).text
else
mail.parts[0].decoded
end
elsif mail.content_type.match?(/text\/html/)
Nokogiri::HTML(mail.body.decoded).text
else
mail.body.decoded
end
end
def hashed_headers(mail)
mail.header.map { |header|
{
name: header.name,
value: header.value
}
}
end
def sent_by_cron?(mail)
(mail.subject.present? && mail.subject.match?(/cron/i)) \
|| mail.header["X-Cron-Env"].present?
end
def mailing_list?(mail)
mail.header["List-Unsubscribe"].present?
end
def clients(mail)
values_for_header(mail.header["X-Client-ID"])
end
def servers(mail)
["To", "Delivered-To", "From", "Subject"].filter_map() { |header|
mail.header[header]
}.flatten.map(&:value).select { |text|
if address_match_evolix_net?(text)
extract_server_name_from_address(text)
end
}
end
def tickets(mail)
values_for_header(mail.header["X-Ticket-ID"])
end
def address_match_evolix_net?(address)
address.match?(/@(.+)\.evolix\.net/i)
end
def extract_server_name_from_address(address)
address.match(/@(.+)\.evolix\.net/i)[1]
end
def values_for_header(header)
if header.present?
if header.respond_to?(:map)
header.map(&:value)
else
header.value
end
end
end
end

View file

@ -1,11 +0,0 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
# This model initially had no columns defined. If you add columns to the
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value

536
test/fixtures/files/html_only.eml vendored Normal file
View file

@ -0,0 +1,536 @@
Return-Path: <bounce+17eb5e.ac57-maintenance=evolix.fr@mg.s35798.fr>
X-Original-To: maintenance@evolix.fr
Delivered-To: equipe@evolix.fr
Received: from m207-15.mailgun.net (m207-15.mailgun.net [161.38.207.15])
by pele.evolix.net (Postfix) with ESMTPS id 7D2077F5D1
for <maintenance@evolix.fr>; Tue, 27 Oct 2020 12:58:19 +0100 (CET)
DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.s35798.fr; q=dns/txt;
s=krs; t=1603799902; h=Content-Transfer-Encoding: Mime-Version:
Content-Type: Subject: From: To: Sender: Reply-To: Message-Id: Date:
List-Unsubscribe: List-Unsubscribe-Post;
bh=bLPQd8jozY53WvIsLaomSUDhri3r+GcUcKSlfcoIpnY=; b=i7Kt8MTqEqLNlpP2Lm38A/l3Ynay1yZuPGDx7+ZfBpGWrOtyknKQRpU0NJyIilJGTSS6iLdc
1Ezqr/7kR8O2zGxTM9m/Z4P4PJTr527ue+Ncl3dWfAcIM1MpvgAVvtbSkXnebRe26no9q1v/
aQJH+fwxGUsRAjns2RsRfwGGwXY=
X-Mailgun-Sending-Ip: 161.38.207.15
X-Mailgun-Sid: WyJmMTRjNyIsICJtYWludGVuYW5jZUBldm9saXguZnIiLCAiYWM1NyJd
List-Unsubscribe-Post: List-Unsubscribe=One-Click
List-Unsubscribe: <mailto:u+mq6wcyzvg4tgspjsgazdamjqgi3tcmjvhaytglrrfzddeqsehaytiqrxircucrryincsknbqnvts44ztgu3tsobomzzcm2b5mm3tgyjxmvrtcy3gmq4dmobqmvrtkmdgha4dgzjwmi4wenzume3sm4r5nvqws3tumvxgc3tdmustimdfozxwy2lyfzthejtuhvqwgylemvwxsllgnzss2nbqgbvv6mjxgu@mg.s35798.fr>,
<https://link.eu.mailgun.com/u/eJwVzUsOgjAQANDTyI5mph9mWHQhAtcwpUyVYGuCxOjtxQO8vNmH6KhavAYNCJoQHaNRqEbd9Yy2o344j3wZThbyTb2Mo5ZV2qq7j2QCScSYZm4YJDpIzEaaqZ3IBqo2n8NSdimhRDm8vJ-P5fPH-9GGWfK3TkVqC7BekdwPbX4omA>
X-Mailgun-Batch-Id: 5f980b55fe8623b9ec342122
Received: by luna.mailgun.net with HTTP; Tue, 27 Oct 2020 11:58:13 +0000
Date: Tue, 27 Oct 2020 11:58:13 +0000
Message-Id: <20201027115813.1.F2BD814B7DEAF8CE@mg.s35798.fr>
Reply-To: Alerte Formation <alerte_formation@mg.s35798.fr>Alerte Formation
<alerte_formation@mg.s35798.fr>
Sender: Alerte Formation <alerte_formation@mg.s35798.fr>
X-Mailgun-Tag: academy-fne-400k_175
To: '' <maintenance@evolix.fr>
From: Alerte Formation <alerte_formation@mg.s35798.fr>
Subject: =?utf-8?q?Fin_du_FNE_le_31/10_=3A_plus_que_quelques_jours_pour_f?=
=?utf-8?q?aire_financer_votre_formation_=C3=A0_100=25?=
Content-Type: text/html; charset="utf-8"
Mime-Version: 1.0
Content-Transfer-Encoding: quoted-printable
<meta charset=3D"utf-8"><!-- utf-8 works for most cases --><meta name=3D"vi=
ewport" content=3D"width=3Ddevice-width"><!-- Forcing initial-scale shouldn=
't be necessary --><meta http-equiv=3D"X-UA-Compatible" content=3D"IE=3Dedg=
e"><!-- Use the latest (edge) version of IE rendering engine --><meta name=
=3D"x-apple-disable-message-reformatting"><!-- Disable auto-scale in iOS 10=
Mail entirely -->
<title></title>
<!-- The title tag shows in email notifications, like Android 4.4. --><!-- =
Web Font / @font-face : BEGIN --><!-- NOTE: If web fonts are not required, =
lines 10 - 27 can be safely removed. --><!-- Desktop Outlook chokes on web =
font references and defaults to Times New Roman, so we force a safe fallbac=
k font. --><!--[if mso]>
<style>
* {
font-family: sans-serif !important;
}
</style>
<![endif]--><!-- All other clients get the webfont reference; some will=
render the font and others will silently fail to the fallbacks. More on th=
at here: http://stylecampaign.com/blog/2015/02/webfont-support-in-email/ --=
><!--[if !mso]><!--><!-- insert web font reference, eg: <link href=3D'https=
://fonts.googleapis.com/css?family=3DRoboto:400,700' rel=3D'stylesheet' typ=
e=3D'text/css'> --><!--<![endif]--><!-- Web Font / @font-face : END --><!--=
CSS Reset : BEGIN -->
<style type=3D"text/css">/* What it does: Remove spaces around the email de=
sign added by some email clients. */
/* Beware: It can remove the padding / margin and add a background =
color to the compose a reply window. */
html,
body {
margin: 0 auto !important;
padding: 0 !important;
height: 100% !important;
width: 100% !important;
}
/* What it does: Stops email clients resizing small text. */
* {
-ms-text-size-adjust: 100%;
-webkit-text-size-adjust: 100%;
}
/* What it does: Centers email on Android 4.4 */
div[style*=3D"margin: 16px 0"] {
margin: 0 !important;
}
/* What it does: Stops Outlook from adding extra spacing to tables.=
*/
table,
td {
mso-table-lspace: 0pt !important;
mso-table-rspace: 0pt !important;
}
/* What it does: Fixes webkit padding issue. Fix for Yahoo mail tab=
le alignment bug. Applies table-layout to the first 2 tables then removes f=
or anything nested deeper. */
table {
border-spacing: 0 !important;
border-collapse: collapse !important;
table-layout: fixed !important;
margin: 0 auto !important;
}
table table table {
table-layout: auto;
}
/* What it does: Uses a better rendering method when resizing image=
s in IE. */
img {
-ms-interpolation-mode:bicubic;
}
/* What it does: A work-around for email clients meddling in trigge=
red links. */
*[x-apple-data-detectors], /* iOS */
.unstyle-auto-detected-links *,
.aBn {
border-bottom: 0 !important;
cursor: default !important;
color: inherit !important;
text-decoration: none !important;
font-size: inherit !important;
font-family: inherit !important;
font-weight: inherit !important;
line-height: inherit !important;
}
/* What it does: Prevents Gmail from displaying a download button o=
n large, non-linked images. */
.a6S {
display: none !important;
opacity: 0.01 !important;
}
/* If the above doesn't work, add a .g-img class to any image in que=
stion. */
img.g-img + div {
display: none !important;
}
/* What it does: Prevents underlining the button text in Windows 10 =
*/
.button-link {
text-decoration: none !important;
}
/* What it does: Removes right gutter in Gmail iOS app: https://git=
hub.com/TedGoas/Cerberus/issues/89 */
/* Create one of these media queries for each additional viewport s=
ize you'd like to fix */
/* iPhone 4, 4S, 5, 5S, 5C, and 5SE */
@media only screen and (min-device-width: 320px) and (max-device-wi=
dth: 374px) {
.email-container {
min-width: 320px !important;
}
}
/* iPhone 6, 6S, 7, 8, and X */
@media only screen and (min-device-width: 375px) and (max-device-wi=
dth: 413px) {
.email-container {
min-width: 375px !important;
}
}
/* iPhone 6+, 7+, and 8+ */
@media only screen and (min-device-width: 414px) {
.email-container {
min-width: 414px !important;
}
}
</style>
<!-- CSS Reset : END --><!-- Reset list spacing because Outlook ignores muc=
h of our inline CSS. --><!--[if mso]>
<style type=3D"text/css">
ul,
ol {
margin: 0 !important;
}
li {
margin-left: 30px !important;
}
li.list-item-first {
margin-top: 0 !important;
}
li.list-item-last {
margin-bottom: 10px !important;
}
</style>
<![endif]--><!-- Progressive Enhancements : BEGIN -->
<style type=3D"text/css">/* What it does: Hover styles for buttons */
.button-td,
.button-a {
transition: all 100ms ease-in;
}
.button-td-primary:hover,
.button-a-primary:hover {
background: #555555 !important;
border-color: #555555 !important;
}
/* Media Queries */
@media screen and (max-width: 600px) {
.email-container {
width: 100% !important;
margin: auto !important;
}
/* What it does: Forces elements to resize to the full width of=
their container. Useful for resizing images beyond their max-width. */
.fluid {
max-width: 100% !important;
height: auto !important;
margin-left: auto !important;
margin-right: auto !important;
}
/* What it does: Forces table cells into full-width rows. */
.stack-column,
.stack-column-center {
display: block !important;
width: 100% !important;
max-width: 100% !important;
direction: ltr !important;
}
/* And center justify these ones. */
.stack-column-center {
text-align: center !important;
}
/* What it does: Generic utility class for centering. Useful fo=
r images, buttons, and nested tables. */
.center-on-narrow {
text-align: center !important;
display: block !important;
margin-left: auto !important;
margin-right: auto !important;
float: none !important;
}
table.center-on-narrow {
display: inline-block !important;
}
/* What it does: Adjust typography on small screens to improve =
readability */
.email-container p {
font-size: 12px !important;
}
}
</style>
<!-- Progressive Enhancements : END --><!-- What it does: Makes background =
images in 72ppi Outlook render at correct size. --><!--[if gte mso 9]>
<xml>
<o:OfficeDocumentSettings>
<o:AllowPNG/>
<o:PixelsPerInch>96</o:PixelsPerInch>
</o:OfficeDocumentSettings>
</xml>
<![endif]--><!--
The email background color (#cccccc) is defined in three places:
1. body tag: for most email clients
2. center tag: for Gmail and Inbox mobile apps and web versions of Gmail, =
GSuite, Inbox, Yahoo, AOL, Libero, Comcast, freenet, Mail.ru, Orange.fr
3. mso conditional: For Windows 10 Mail
-->
<p><span class=3D"preheader" style=3D"display:none">Attention, plus que que=
lques jours pour b=C3=A9n=C3=A9ficier du FNE !</span></p>
<center style=3D"width: 100%; background-color: #cccccc; text-align: left;"=
><!--[if mso | IE]>
<table role=3D"presentation" border=3D"0" cellpadding=3D"0" cellspacing=
=3D"0" width=3D"100%" style=3D"background-color: #cccccc;">
<tr>
<td>
<![endif]--><!-- Visually Hidden Preheader Text : BEGIN -->
<div style=3D"display: none; font-size: 1px; line-height: 1px; max-height: =
0px; max-width: 0px; opacity: 0; overflow: hidden; mso-hide: all; font-fami=
ly: sans-serif;">Attention, plus que quelques jours pour b&eacute;n&eacute;=
ficier du FNE !</div>
<!-- Visually Hidden Preheader Text : END --><!-- Create white space after =
the desired preview text so email clients don=E2=80=99t pull other distract=
ing text into the inbox preview. Extend as necessary. --><!-- Preview Text =
Spacing Hack : BEGIN -->
<div style=3D"display: none; font-size: 1px; line-height: 1px; max-height: =
0px; max-width: 0px; opacity: 0; overflow: hidden; mso-hide: all; font-fami=
ly: sans-serif;">&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbs=
p;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&=
zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwnj;&nbsp;&zwn=
j;&nbsp;</div>
<!-- Preview Text Spacing Hack : END --><!-- Email Body : BEGIN -->
<table align=3D"center" border=3D"0" cellpadding=3D"0" cellspacing=3D"0" cl=
ass=3D"email-container" role=3D"presentation" style=3D"margin: 0 auto;" wid=
th=3D"600"><!-- Hero Image, Flush : BEGIN -->
<tbody>
<tr>
<td style=3D"background-color: #103144;"><a href=3D"http://email.mg.s357=
98.fr/c/eJwVjztuxCAYhE-DOyMeJrAFxW5sylwh-sPDRmswMqyV3D7saIqR5itmnAYr5BA1I4x=
QwiSlQlGOKTbsMSs6PeS83I36XNBE0oorF_KmcDiHTVNuORFgg_KW-Q-ugrsxANclLLifYddba6=
UifkfMdIfjTNDikccr1lj2V8X2SL1IEPeY157qK15vMubRfC24bAVxU2D1iM8h--HUnc3NZ8jW9=
0n-Ovb4-97T-hNwPv2NnRsnQp7fVIp_leRFcg" target=3D"_blank"><img alt=3D"alt_te=
xt" border=3D"0" class=3D"g-img" height=3D"173 " src=3D"https://formation-=
visiplus.com/mailing/images/img-fin-FNE.jpg" style=3D"width: 100%; max-widt=
h: 600px; height: auto; background: #fff; font-family: sans-serif; font-siz=
e: 15px; line-height: 15px; color: #555555; margin: auto;" width=3D"600" />=
</a></td>
</tr>
<!-- Hero Image, Flush : END --><!-- 1 Column Text : BEGIN -->
<tr>
<td style=3D"background-color: #103144;">
<table border=3D"0" cellpadding=3D"0" cellspacing=3D"0" role=3D"presenta=
tion" width=3D"100%">
<tbody>
<tr>
<td style=3D"padding: 20px 40px 4px 40px; font-family: sans-serif; fo=
nt-size: 14px; line-height: 18px; color: #ffffff;">
<h1 style=3D"margin: 0px 0px 4px 0px; font-size: 24px; line-height: 2=
6px; color: #fbc30e; text-align: left"><strong>Attention, plus que quelques=
jours pour b&eacute;n&eacute;ficier du FNE !</strong></h1>
<h2 style=3D"margin: 0px 0px 14px 0px; font-size: 18px; line-height: =
20px; color: #ffffff; text-align: left"><strong>Le 31 Octobre, il sera trop=
tard pour b&eacute;n&eacute;ficier d&rsquo;une formation financ&eacute;e &=
agrave; 100% par l&rsquo;Etat</strong></h2>
<p style=3D"margin: 0 0 6px;">Le fonds National pour l&rsquo;emploi a=
ussi appel&eacute; FNE a &eacute;t&eacute; mis en place &agrave; la suite d=
e la crise saitaire. Ce dispositif vous permet de faire financer &agrave; 1=
00% votre formation professionnelle si votre entreprise conna&icirc;t de l&=
rsquo;activit&eacute; partielle, et ce quel que soit votre secteur d&rsquo;=
activit&eacute;.</p>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<!-- 1 Column Text : END --><!-- 1 Column Text : BEGIN -->
<tr>
<td style=3D"background-color: #103144;">
<table border=3D"0" cellpadding=3D"0" cellspacing=3D"0" role=3D"presenta=
tion" width=3D"100%">
<tbody>
<tr>
<td style=3D"padding: 0px 40px 10px 40px; font-family: sans-serif; fo=
nt-size: 14px; line-height: 18px; color: #ffffff;">
<p style=3D"margin: 0 0 6px;">Des milliers de fran&ccedil;ais ont auj=
ourd&rsquo;hui b&eacute;n&eacute;fici&eacute; du FNE, mais la fin de cette =
aide exceptionnelle est annonc&eacute;e pour le 31 Octobre. Elle ne couvrir=
a en effet plus par la suite l&rsquo;int&eacute;gralit&eacute; de vos co&uc=
irc;ts formation.</p>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<!-- 1 Column Text : END --><!-- 1 Column Text + Button : BEGIN -->
<tr>
<td style=3D"background-color: #103144;">
<table border=3D"0" cellpadding=3D"0" cellspacing=3D"0" role=3D"presenta=
tion" width=3D"100%">
<tbody>
<tr>
<td style=3D"padding: 10px 20px 24px 20px;"><!-- Button : BEGIN -->
<table align=3D"center" border=3D"0" cellpadding=3D"0" cellspacing=3D=
"0" role=3D"presentation" style=3D"margin: auto;">
<tbody>
<tr>
<td class=3D"button-td button-td-primary" style=3D"border-radius: =
50px; background: #fbc30e;"><a class=3D"button-a button-a-primary" href=3D"=
http://email.mg.s35798.fr/c/eJwVjztuxCAYhE-DOyMeJrAFxW5sylwh-sPDRmswMqyV3D7=
saIqR5itmnAYr5BA1I4xQwiSlQlGOKTbsMSs6PeS83I36XNBE0oorF_KmcDiHTVNuORFgg_KW-Q=
-ugrsxANclLLifYddba6UifkfMdIfjTNDikccr1lj2V8X2SL1IEPeY157qK15vMubRfC24bAVxU=
2D1iM8h--HUnc3NZ8jW90n-Ovb4-97T-hNwPv2NnRsnQp7fVIp_leRFcg" style=3D"backgro=
und: #fbc30e; border: 1px solid #fbc30e; font-family: sans-serif; font-size=
: 15px; line-height: 15px; text-decoration: none; padding: 13px 17px; color=
: #103144; display: block; border-radius: 50px; font-weight:bold"><strong>E=
N SAVOIR PLUS</strong></a></td>
</tr>
</tbody>
</table>
<!-- Button : END --></td>
</tr>
</tbody>
</table>
</td>
</tr>
<!-- 1 Column Text + Button : END --><!-- 1 Column Text : BEGIN -->
<tr>
<td style=3D"background-color: #f1f1f1;">
<table border=3D"0" cellpadding=3D"0" cellspacing=3D"0" role=3D"presenta=
tion" width=3D"100%">
<tbody>
<tr>
<td style=3D"padding: 20px 40px 0px 40px; font-family: sans-serif; fo=
nt-size: 14px; line-height: 18px; color: #103144;">
<h2 style=3D"margin: 0px 0px 6px 0px; font-size: 20px; line-height: 2=
4px; color: #103144; text-align: center"><strong>Nous vous accompagnons pas=
&agrave; pas dans les d&eacute;marches et le montage du dossier de finance=
ment,</strong></h2>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<!-- 1 Column Text : END --><!-- 1 Column Text + Button : BEGIN -->
<tr>
<td style=3D"background-color: #f1f1f1;">
<table border=3D"0" cellpadding=3D"0" cellspacing=3D"0" role=3D"presenta=
tion" width=3D"100%">
<tbody>
<tr>
<td style=3D"padding: 10px 20px 26px 20px;"><!-- Button : BEGIN -->
<table align=3D"center" border=3D"0" cellpadding=3D"0" cellspacing=3D=
"0" role=3D"presentation" style=3D"margin: auto;">
<tbody>
<tr>
<td class=3D"button-td button-td-primary" style=3D"border-radius: =
50px; background: #103144;"><a class=3D"button-a button-a-primary" href=3D"=
http://email.mg.s35798.fr/c/eJwVj7tuxCAURL8Gd0ZcHgspKHZjU-YXIhZjG8U8ZFgr-fu=
w0hQjzSnOLNo6IYegKaEECJUAQgHDgA19TAr4Q07z3ajPGXESN1yZkB8Kr-ew6ycwJwUsjj89Bw=
k3xS2Ad8ot7CasGg69t1YqYndETc-az2hbyGm8Qg3leFXscuxDtOEIaeutvsL1JkMazdeMy14QM=
8VuHrHJ5TScurOp-WST813JX_kIv2-f1p_Yxce_cU1-5IT8fIMU_99hRCo" style=3D"backgr=
ound: #103144; border: 1px solid #103144; font-family: sans-serif; font-siz=
e: 15px; line-height: 15px; text-decoration: none; padding: 13px 17px; colo=
r: #fff; display: block; border-radius: 50px; font-weight:bold"><strong>CON=
TACTER UN CONSEILLER</strong></a></td>
</tr>
</tbody>
</table>
<!-- Button : END --></td>
</tr>
</tbody>
</table>
</td>
</tr>
<!-- 1 Column Text + Button : END --><!-- Thumbnail Left, Text Right : B=
EGIN -->
<tr>
<td dir=3D"ltr" style=3D"padding: 0px; background-color: #212123;" valig=
n=3D"top" width=3D"100%">
<table border=3D"0" cellpadding=3D"0" cellspacing=3D"0" role=3D"presenta=
tion" width=3D"100%">
<tbody>
<tr><!-- Column : BEGIN -->
<td class=3D"stack-column-center" width=3D"35%">
<table border=3D"0" cellpadding=3D"20" cellspacing=3D"0" role=3D"pres=
entation" width=3D"100%">
<tbody>
<tr>
<td dir=3D"ltr" style=3D"padding: 0 20px;" valign=3D"top"><img alt=
=3D"alt_text" border=3D"0" class=3D"center-on-narrow" height=3D"74" src=3D"=
https://formation-visiplus.com/mailing/images/logo-academy-blanc.png" style=
=3D"height: auto; font-family: sans-serif; font-size: 15px; line-height: 15=
px; color: #555555;" width=3D"180" /></td>
</tr>
</tbody>
</table>
</td>
<!-- Column : END --><!-- Column : BEGIN -->
<td class=3D"stack-column-center" width=3D"65%">
<table border=3D"0" cellpadding=3D"20" cellspacing=3D"0" role=3D"pres=
entation" width=3D"100%">
<tbody>
<tr>
<td class=3D"center-on-narrow" dir=3D"ltr" style=3D"font-family: s=
ans-serif; font-size: 16px; line-height: 20px; color: #ffffff; text-align: =
left;" valign=3D"top"><span style=3D"margin: 0; font-family: sans-serif; fo=
nt-size: 16px; line-height: 20px; color: #ffffff;"><strong>Le d&eacute;velo=
ppement des comp&eacute;tences<br />
au service de votre carri&egrave;re professionnelle</strong></span=
></td>
</tr>
</tbody>
</table>
</td>
<!-- Column : END -->
</tr>
</tbody>
</table>
</td>
</tr>
<!-- Thumbnail Left, Text Right : END --><!-- 1 Column Text : BEGIN -->
<tr>
<td style=3D"background-color: #cccccc;">
<table border=3D"0" cellpadding=3D"0" cellspacing=3D"0" role=3D"presenta=
tion" width=3D"100%">
<tbody>
<tr>
<td style=3D"height: 5px;">&nbsp;</td>
</tr>
</tbody>
</table>
</td>
</tr>
<!-- 1 Column Text : END --><!-- 1 Column Text : BEGIN -->
<tr>
<td style=3D"background-color: #cccccc;">
<p style=3D"color:#747474; font-family:arial, sans-serif; font-size:10px=
;">Si vous ne souhaitez plus recevoir de messages, <a href=3D"http://email.=
mg.s35798.fr/c/eJxFj8mOhDAQQ78Gbo2qQiWpHDgkDfwGCpAMqFlaLLP8_WROI_lgy3qSPVZ-=
kDqfKwECEIRGlIxlgUUrXM1ITteNbfnZZATrR3GWUhsu4pFPleoZovc09BIjmEgclYxMoxlLg4r=
zpZqu652VNhNt0v1Pp_QV-mnfX8nF_RhCd2_n3Z_DMffh7MLq5yVV6Cw1z5otobHkWDXsSqNrBa=
IVUrIhNkikEB046SA_qkRuV9j8NoQ0OXzuy_z9t_dKT_0Y1p9H3MKDAF4davkLNJBJMA" style=
=3D"color: #888888;">cliquez-ici</a>, <a href=3D"http://email.mg.s35798.fr/=
c/eJxFj8mOhDAQQ78Gbo2qQiWpHDgkDfwGCpAMqFlaLLP8_WROI_lgy3qSPVZ-kDqfKwECEIRGl=
IxlgUUrXM1ITteNbfnZZATrR3GWUhsu4pFPleoZovc09BIjmEgclYxMoxlLg4rzpZqu652VNhNt=
0v1Pp_QV-mnfX8nF_RhCd2_n3Z_DMffh7MLq5yVV6Cw1z5otobHkWDXsSqNrBaIVUrIhNkikEB0=
46SA_qkRuV9j8NoQ0OXzuy_z9t_dKT_0Y1p9H3MKDAF4davkLNJBJMA" style=3D"font-size=
: 10px; color: #888888;">Signaler un email ind&eacute;sirable</a>, <a href=
=3D"http://email.mg.s35798.fr/c/eJxFj8mOhDAQQ78Gbo2qQiWpHDgkDfwGCpAMqFlaLLP=
8_WROI_lgy3qSPVZ-kDqfKwECEIRGlIxlgUUrXM1ITteNbfnZZATrR3GWUhsu4pFPleoZovc09B=
IjmEgclYxMoxlLg4rzpZqu652VNhNt0v1Pp_QV-mnfX8nF_RhCd2_n3Z_DMffh7MLq5yVV6Cw1z=
5otobHkWDXsSqNrBaIVUrIhNkikEB046SA_qkRuV9j8NoQ0OXzuy_z9t_dKT_0Y1p9H3MKDAF4d=
avkLNJBJMA" style=3D"font-size: 10px; color: #888888;">Unsubscribe</a></p>
<table border=3D"0" cellpadding=3D"0" cellspacing=3D"0" role=3D"presenta=
tion" width=3D"100%">
<tbody>
<tr>
</tr>
</tbody>
</table>
</td>
</tr>
<!-- 1 Column Text : END -->
</tbody>
</table>
<!-- Email Body : END --><!--[if mso | IE]>
</td>
</tr>
</table>
<![endif]--></center>
<img width=3D"1px" height=3D"1px" alt=3D"" src=3D"http://email.mg.s35798.fr=
/o/eJwVzUsOgjAQANDTyI5mph9mWHQhAtcwpUyVYGuCxOjtxQO8vNmH6KhavAYNCJoQHaNRqEbd=
9Yy2o344j3wZThbyTb2Mo5ZV2qq7j2QCScSYZm4YJDpIzEaaqZ3IBqo2n8NSdimhRDm8vJ-P5fP=
H-9GGWfK3TkVqC7BekdwPbX4omA">

View file

@ -0,0 +1,14 @@
require 'test_helper'
class EmailImporterTest < ActiveSupport::TestCase
test "convert html to text when html only" do
eml = file_fixture("html_only.eml").read
mail = Mail.from_source(eml)
email_importer = EmailImporter.new
email = email_importer.import(mail)
assert_match(/Attention, plus que quelques jours pour bénéficier du FNE !/, email.plain_body)
assert_no_match(/<\/?(p|b|br|img)\/?>/, email.plain_body)
end
end