Skip to content

Commit b76ca1b

Browse files
author
Srdjan Marjanovic
committed
New row fixes and tests
1 parent 2e9982d commit b76ca1b

6 files changed

Lines changed: 490 additions & 8 deletions

File tree

src/ActiveCollab/EmailReplyExtractor/Extractor/Extractor.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ protected function processLines()
6767
public function joinLines()
6868
{
6969
// ltrim() strips BOM characters
70-
$this->body = ltrim(trim(implode("\n", $this->body), "\xEF\xBB\xBF"));
70+
$this->body = ltrim(trim(implode("\n", $this->body)), "\xEF\xBB\xBF");
7171
}
7272

7373
/**
@@ -349,6 +349,9 @@ static function toPlainText($html) {
349349
// <p> converts to 2 newlines
350350
$plain = (string) preg_replace('/<p[^>]*>/i', "\n\n", $plain); // <p>
351351

352+
// new line after div
353+
$plain = (string) preg_replace('/<div[^>]*>/i', "\n", $plain); // <div>
354+
352355
// uppercase html elements
353356
$plain = (string) preg_replace_callback('/<h[123456][^>]*>(.*?)<\/h[123456]>/i', function($matches) {
354357
return "\n\n" . mb_strtoupper($matches[1]) . "\n\n";
@@ -367,9 +370,6 @@ static function toPlainText($html) {
367370
// elements that convert to single newline
368371
$plain = (string) preg_replace(array('/<br[^>]*>/i', '/(<tr[^>]*>|<\/tr>)/i'), "\n", $plain); // <br> <tr>
369372

370-
// div elements
371-
$plain = (string) preg_replace('/<div[^>]*>(.*?)<\/div>/i', "\\1\n", $plain); // <div>with content</div>
372-
373373
// images
374374
$plain = (string) preg_replace(array('/<img\s+[^>]*src="([^"]*)"[^>]*>/i'), "[Image: \\1]", $plain); // <br> <tr>
375375

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
From: Example Example <example@activecollab.com>
2+
Content-Type: multipart/alternative;
3+
boundary="Apple-Mail=_0F32AAE9-6291-4585-AD91-0CE0C859A152"
4+
Message-Id: <0E7AF822-B243-4022-827D-082503386481@activecollab.com>
5+
Mime-Version: 1.0 (Mac OS X Mail 8.2 \(2104\))
6+
X-Smtp-Server: mail.activecollab.com
7+
Subject: Re: SRDJAN TEST
8+
Date: Tue, 22 Dec 2015 12:16:35 +0100
9+
X-Universally-Unique-Identifier: 33EFB96F-4AC7-42E2-BD5A-AA1136FEF04C
10+
References: <3ioskiot2x0o-22b9dn8928w0s@activecollab.com>
11+
To: example@activecollab.com
12+
In-Reply-To: <3ioskiot2x0o-22b9dn8928w0s@activecollab.com>
13+
14+
15+
--Apple-Mail=_0F32AAE9-6291-4585-AD91-0CE0C859A152
16+
Content-Transfer-Encoding: quoted-printable
17+
Content-Type: text/plain;
18+
charset=us-ascii
19+
20+
Daj neki,
21+
novi red=20
22+
23+
Cisto da budemo sigurni
24+
25+
Ovaj je komentar je npr. poslat iz Apple Mail (Version 8.2 (2104))
26+
> On Dec 22, 2015, at 12:14 PM, Example Example (Active Collab) =
27+
<notifications@activecollab.com> wrote:
28+
>=20
29+
> Naravno
30+
31+
32+
--Apple-Mail=_0F32AAE9-6291-4585-AD91-0CE0C859A152
33+
Content-Transfer-Encoding: quoted-printable
34+
Content-Type: text/html;
35+
charset=us-ascii
36+
37+
<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html =
38+
charset=3Dus-ascii"></head><body style=3D"word-wrap: break-word; =
39+
-webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" =
40+
class=3D"">Daj neki,<div class=3D"">novi red&nbsp;</div><div =
41+
class=3D""><br class=3D""></div><div class=3D"">Cisto da budemo =
42+
sigurni</div><div class=3D""><br class=3D""></div><div class=3D"">Ovaj =
43+
je komentar je npr. poslat iz <b class=3D"">Apple Mail</b> (Version 8.2 =
44+
(2104))</div><div class=3D""><div><blockquote type=3D"cite" =
45+
class=3D""><div class=3D"">On Dec 22, 2015, at 12:14 PM, Example Example =
46+
(Active Collab) &lt;<a href=3D"mailto:notifications@activecollab.com" =
47+
class=3D"">notifications@activecollab.com</a>&gt; wrote:</div><br =
48+
class=3D"Apple-interchange-newline"><div class=3D""><span =
49+
style=3D"font-family: Helvetica, Arial, sans-serif; font-size: 16px; =
50+
font-style: normal; font-variant: normal; font-weight: normal; =
51+
letter-spacing: normal; line-height: 22px; orphans: auto; text-align: =
52+
start; text-indent: 0px; text-transform: none; white-space: normal; =
53+
widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; =
54+
background-color: rgb(255, 255, 255); float: none; display: inline =
55+
!important;" class=3D"">Naravno</span></div></blockquote></div><br =
56+
class=3D""></div></body></html>=
57+
58+
--Apple-Mail=_0F32AAE9-6291-4585-AD91-0CE0C859A152--
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
2+
MIME-Version: 1.0
3+
Received: by 10.13.195.71 with HTTP; Tue, 22 Dec 2015 03:06:12 -0800 (PST)
4+
In-Reply-To: <311pkz53ws6q-1jjpwkt2bjkcg@activecollab.com>
5+
References: <311pkz53ws6q-1jjpwkt2bjkcg@activecollab.com>
6+
Date: Tue, 22 Dec 2015 12:06:12 +0100
7+
Delivered-To: example@gmail.com
8+
X-Gmail-Original-Message-ID: <CAJK1w3xWmKz25T4U_zHwx4w_wTkKgAQcXv=giWo5mQE-bZgXAA@mail.gmail.com>
9+
Message-ID: <CAJK1w3xWmKz25T4U_zHwx4w_wTkKgAQcXv=giWo5mQE-bZgXAA@mail.gmail.com>
10+
Subject: Re: SRDJAN TEST
11+
From: Example Example <example@activecollab.com>
12+
To: example@activecollab.com
13+
Content-Type: multipart/alternative; boundary=001a114e8100ee21f905277a971c
14+
15+
--001a114e8100ee21f905277a971c
16+
Content-Type: text/plain; charset=UTF-8
17+
Content-Transfer-Encoding: quoted-printable
18+
19+
Ahoy,
20+
Ovde sam opalio novi red.
21+
22+
Evo jo=C5=A1 jedan prazan, i novi red.
23+
24+
--
25+
Evo ga i signature,
26+
Bane Zaklan
27+
28+
On Tue, Dec 22, 2015 at 12:01 PM, Example Example (Active Collab) <
29+
example@activecollab.com> wrote:
30+
31+
> - Reply above this line to leave a comment -
32+
> New comment posted in:
33+
> SRDJAN TEST <https://app.example.com> [im=
34+
age:
35+
> Example Example] *Example Example* Dec 22, 2015
36+
> @Example Example odgovori mi na ovaj mail sa novim redovima
37+
>
38+
> Project: Feather Planning
39+
> Task List: Inbox =F0=9F=93=A5
40+
> People in this task: Example Example <example@activecollab.com>
41+
> and Example Example <example@activecollab.com>
42+
>
43+
> Delivered by ActiveCollab
44+
> Don't send me emails about this task any more
45+
> <https://app.activecollab.com/1/public/notifications/unsubscribe?test=test>
46+
>
47+
48+
--001a114e8100ee21f905277a971c
49+
Content-Type: text/html; charset=UTF-8
50+
Content-Transfer-Encoding: quoted-printable
51+
52+
<div dir=3D"ltr">Ahoy,<div>Ovde sam opalio novi red.</div><div><br></div><d=
53+
iv>Evo jo=C5=A1 jedan prazan, i novi red.</div><div><br></div><div>--</div>=
54+
<div>Evo ga i signature,</div><div>Bane Zaklan</div></div><div class=3D"gma=
55+
il_extra"><br><div class=3D"gmail_quote">On Tue, Dec 22, 2015 at 12:01 PM, =
56+
Example Example (Active Collab) <span dir=3D"ltr">&lt;<a href=3D"mailto:e=
57+
xample@activecollab.com" target=3D"_blank">example@activecollab=
58+
.com</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"ma=
59+
rgin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><u></u>
60+
61+
62+
=20
63+
=20
64+
65+
=20
66+
67+
<div>
68+
69+
70+
71+
72+
<table style=3D"width:100%;background-color:#f1f1f1" cellpadding=3D"10" cel=
73+
lspacing=3D"0" border=3D"0" align=3D"center">
74+
<tbody><tr>
75+
<td style=3D"font-family:Helvetica,Arial,sans-serif;font-size:11px;color:#9=
76+
99999" align=3D"center"><p style=3D"margin-top:0">- Reply above this line t=
77+
o leave a comment -</p><table style=3D"width:100%;max-width:600px;backgroun=
78+
d-color:#ffffff;border-width:1px;border-color:#d1d1d1;border-radius:3px" ce=
79+
llpadding=3D"20" cellspacing=3D"0" align=3D"center"><tbody><tr><td style=3D=
80+
"font-family:Helvetica,Arial,sans-serif;font-size:16px;line-height:22px;pad=
81+
ding-top:0;color:#000000" align=3D"left">
82+
<h1 style=3D"font-size:16px;font-weight:bold;margin-top:20px;margin-bottom:=
83+
16px">
84+
New comment posted in:<br>
85+
<a style=3D"display:block;overflow:hidden;text-overflow:ellipsis;white-spa=
86+
ce:nowrap;max-width:550px" href=3D"https://app.activecollab.com/1/projects/=
87+
106/tasks/46738" target=3D"_blank">SRDJAN TEST</a>
88+
</h1>
89+
90+
91+
92+
<table border=3D"0" cellpadding=3D"10" cellspacing=3D"0" bgcolor=3D"#ffffff=
93+
" style=3D"width:100%">
94+
=09
95+
<tbody><tr>
96+
<td valign=3D"top" style=3D"padding-left:0;width:36px">
97+
<img src=3D"https://app.activecollab.com/1/proxy.php?proxy=3Davatar&amp=
98+
;module=3Dsystem&amp;v=3D5.5.13&amp;b=3DDEV&amp;user_id=3D90&amp;size=3D36&=
99+
amp;timestamp=3D1448446784" width=3D"36" height=3D"36" alt=3D"Srdjan Marjan=
100+
ovic">
101+
</td>
102+
<td colspan=3D"2" valign=3D"top" style=3D"padding-left:0">
103+
<strong>Example Example</strong> <span style=3D"font-size:14px;line-h=
104+
eight:14px">=C2=A0Dec 22, 2015</span> <br>
105+
<span style=3D"word-wrap:break-word;word-break:break-word"><span style=
106+
=3D"background-color:#d9eeff;padding:0 2px;border:1px solid #aebfcc;border-=
107+
radius:3px">@Example Example</span>=C2=A0odgovori mi na ovaj mail sa novim=
108+
redovima</span>
109+
=09
110+
</td>
111+
</tr>
112+
113+
=09
114+
</tbody></table>
115+
116+
117+
<div style=3D"color:#999999;font-size:14px;line-height:21px"><p>Project: Fe=
118+
ather Planning<br>Task List: Inbox =F0=9F=93=A5<br>People in this task: <a =
119+
href=3D"mailto:example@activecollab.com" style=3D"color:#999999;te=
120+
xt-decoration:none" target=3D"_blank">Example Example</a> and <a href=3D"m=
121+
ailto:example@activecollab.com" style=3D"color:#999999;text-decor=
122+
ation:none" target=3D"_blank">Example Example</a></p></div></td></tr></tb=
123+
ody></table><p>Delivered by ActiveCollab<br><a href=3D"https://app.activeco=
124+
llab.com/1/public/notifications/unsubscribe?test=test" s=
125+
tyle=3D"color:#999999" target=3D"_blank">Don&#39;t send me emails about thi=
126+
s task any more</a></p>
127+
128+
</td>
129+
</tr>
130+
</tbody></table>
131+
132+
</div>
133+
134+
</blockquote></div><br></div>
135+
136+
--001a114e8100ee21f905277a971c--

test/example_messages/outlook_mac_2015.eml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ pace; -webkit-line-break: after-white-space; color: rgb(0, 0, 0); font-size:=
7474
</div><div><div id=3D"MAC_OUTLOOK_SIGNATURE"><div><br></div><div><br></div><di=
7575
v>--&nbsp;</div><div>Example Studen</div><div>www: <a href=3D"https://www.active=
7676
collab.com/index.html">https://www.activecollab.com/index.html</a></div><div=
77-
>tw:&nbsp;<a href=3D"https://twitter.com/istdn">https://twitter.com/istdn</a><=
77+
>tw:&nbsp;<a href=3D"https://twitter.com/example">https://twitter.com/example</a><=
7878
/div><div><br></div></div></div></div></div><div><br></div><span id=3D"OLK_SRC=
7979
_BODY_SECTION"><div style=3D"font-family:Calibri; font-size:12pt; text-align:l=
8080
eft; color:black; BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADD=

0 commit comments

Comments
 (0)