RT 4.2.11, ticket#13852
[freeside.git] / rt / t / mail / outlook.t
1 use strict;
2 use warnings;
3
4 use RT::Test tests => 66;
5
6 RT->Config->Set('CheckMoreMSMailHeaders', 1);
7
8 # 12.0 is outlook 2007, 14.0 is 2010
9 for my $mailer ( 'Microsoft Office Outlook 12.0', 'Microsoft Outlook 14.0' ) {
10     diag "Test mail with multipart/alternative";
11     {
12         my $text = <<EOF;
13 From: root\@localhost
14 X-Mailer: $mailer
15 To: rt\@@{[RT->Config->Get('rtname')]}
16 Subject: outlook basic test
17 Content-Type: multipart/alternative;
18 \tboundary="----=_NextPart_000_0004_01CB045C.A5A075D0"
19
20 ------=_NextPart_000_0004_01CB045C.A5A075D0
21 Content-Type: text/plain;
22 \tcharset="us-ascii"
23 Content-Transfer-Encoding: 7bit
24
25 here is the content
26
27
28
29 blahmm
30
31 another line
32
33
34 ------=_NextPart_000_0004_01CB045C.A5A075D0
35 Content-Type: text/html;
36 \tcharset="us-ascii"
37 Content-Transfer-Encoding: quoted-printable
38
39 <html>this is fake</html>
40
41
42 ------=_NextPart_000_0004_01CB045C.A5A075D0--
43
44 EOF
45
46         my $content = <<EOF;
47 here is the content
48
49 blahmm
50 another line
51 EOF
52         test_email( $text, $content,
53             $mailer . ' with multipart/alternative, \n\n are replaced' );
54     }
55
56     diag "Test mail with multipart/mixed, with multipart/alternative in it";
57     {
58         my $text = <<EOF;
59 From: root\@localhost
60 X-Mailer: $mailer
61 To: rt\@@{[RT->Config->Get('rtname')]}
62 Subject: outlook basic test
63 Content-Type: multipart/mixed;
64 \tboundary="----=_NextPart_000_000F_01CB045E.5222CB40"
65
66 ------=_NextPart_000_000F_01CB045E.5222CB40
67 Content-Type: multipart/alternative;
68 \tboundary="----=_NextPart_001_0010_01CB045E.5222CB40"
69
70
71 ------=_NextPart_001_0010_01CB045E.5222CB40
72 Content-Type: text/plain;
73 \tcharset="us-ascii"
74 Content-Transfer-Encoding: 7bit
75
76 foo
77
78
79
80 bar
81
82 baz
83
84
85 ------=_NextPart_001_0010_01CB045E.5222CB40
86 Content-Type: text/html;
87 \tcharset="us-ascii"
88 Content-Transfer-Encoding: quoted-printable
89
90 <html>this is fake</html>
91
92 ------=_NextPart_001_0010_01CB045E.5222CB40--
93
94 ------=_NextPart_000_000F_01CB045E.5222CB40
95 Content-Type: text/plain;
96 \tname="att.txt"
97 Content-Transfer-Encoding: quoted-printable
98 Content-Disposition: attachment;
99 \tfilename="att.txt"
100
101 this is the attachment! :)=0A=
102
103 ------=_NextPart_000_000F_01CB045E.5222CB40--
104 EOF
105
106         my $content = <<EOF;
107 foo
108
109 bar
110 baz
111 EOF
112         test_email( $text, $content,
113             $mailer . ' with multipart/multipart, \n\n are replaced' );
114     }
115
116     diag "Test mail with with outlook, but the content type is text/plain";
117     {
118         my $text = <<EOF;
119 From: root\@localhost
120 X-Mailer: $mailer
121 To: rt\@@{[RT->Config->Get('rtname')]}
122 Subject: outlook basic test
123 Content-Type: text/plain; charset="us-ascii"
124 Content-Transfer-Encoding: 7bit
125
126 foo
127
128
129
130 bar
131
132 baz
133
134 EOF
135
136         my $content = <<EOF;
137 foo
138
139
140
141 bar
142
143 baz
144
145 EOF
146         test_email( $text, $content,
147             $mailer . ' with only text/plain, \n\n are not replaced' );
148     }
149
150     diag "Test mail with with outlook, content type is base64";
151     {
152         my $text = <<EOF;
153 From: root\@localhost
154 X-Mailer: $mailer
155 To: rt\@@{[RT->Config->Get('rtname')]}
156 Subject: outlook basic test
157 Content-Type: text/plain; charset="utf-8"
158 Content-Transfer-Encoding: base64
159
160 VGhpcyBpcyB0aGUgYm9keSBvZiBhbiBlbWFpbC4KCkl0IGhhcyBtdWx0aXBs
161 ZSBleHRyYSBuZXdsaW5lcy4KCgoKTGlrZSBhIG1hbmdsZWQgT3V0bG9vayBt
162 ZXNzYWdlIG1pZ2h0LgoKCgpKb2huIFNtaXRoCgpTb21lIENvbXBhbnkKCmVt
163 YWlsQHNvbWVjby5jb20KCg==
164 EOF
165
166         my $content = <<EOF;
167 This is the body of an email.
168 It has multiple extra newlines.
169
170 Like a mangled Outlook message might.
171
172 John Smith
173 Some Company
174 email\@someco.com
175 EOF
176         test_email( $text, $content,
177             $mailer . ' with base64, \n\n are replaced' );
178     }
179 }
180
181 # In a sample we received, the two X-MS- headers included
182 # below were both present and had no values. For now, using
183 # the existence of these headers as evidence of MS Outlook
184 # or Exchange.
185
186 diag "Test mail with with outlook, no X-Mailer, content type is base64";
187 {
188         my $text = <<EOF;
189 From: root\@localhost
190 To: rt\@@{[RT->Config->Get('rtname')]}
191 Subject: outlook basic test
192 Content-Type: text/plain; charset="utf-8"
193 Content-Transfer-Encoding: base64
194 X-MS-Has-Attach:
195 X-MS-Tnef-Correlator:
196
197 VGhpcyBpcyB0aGUgYm9keSBvZiBhbiBlbWFpbC4KCkl0IGhhcyBtdWx0aXBs
198 ZSBleHRyYSBuZXdsaW5lcy4KCgoKTGlrZSBhIG1hbmdsZWQgT3V0bG9vayBt
199 ZXNzYWdlIG1pZ2h0LgoKCgpKb2huIFNtaXRoCgpTb21lIENvbXBhbnkKCmVt
200 YWlsQHNvbWVjby5jb20KCg==
201 EOF
202
203         my $content = <<EOF;
204 This is the body of an email.
205 It has multiple extra newlines.
206
207 Like a mangled Outlook message might.
208
209 John Smith
210 Some Company
211 email\@someco.com
212 EOF
213         test_email( $text, $content,
214                     ' with base64, no X-Mailer, \n\n are replaced' );
215 }
216
217
218 diag "Test mail with with multipart/alternative but x-mailer is not outlook ";
219 {
220     my $text = <<EOF;
221 From: root\@localhost
222 X-Mailer: Mutt
223 To: rt\@@{[RT->Config->Get('rtname')]}
224 Subject: outlook basic test
225 Content-Type: multipart/alternative;
226 \tboundary="----=_NextPart_000_0004_01CB045C.A5A075D0"
227
228 ------=_NextPart_000_0004_01CB045C.A5A075D0
229 Content-Type: text/plain;
230 \tcharset="us-ascii"
231 Content-Transfer-Encoding: 7bit
232
233 foo
234
235
236
237 bar
238
239 baz
240
241
242 ------=_NextPart_000_0004_01CB045C.A5A075D0
243 Content-Type: text/html;
244 \tcharset="us-ascii"
245 Content-Transfer-Encoding: quoted-printable
246
247 <html>this is fake</html>
248
249
250 ------=_NextPart_000_0004_01CB045C.A5A075D0--
251 EOF
252
253     my $content = <<EOF;
254 foo
255
256
257
258 bar
259
260 baz
261
262 EOF
263     test_email( $text, $content, 'without outlook, \n\n are not replaced' );
264 }
265
266 diag "Sample multipart email with Exchange headers";
267 {
268         my $text = <<EOF;
269 X-MimeOLE: Produced By Microsoft Exchange V6.5
270 Received: by example.com 
271         id <01CD63FC.33F4C15C\@example.com>; Tue, 17 Jul 2012 10:11:51 +0100
272 MIME-Version: 1.0
273 Content-Type: multipart/alternative;
274         boundary="----_=_NextPart_001_01CD63FC.33F4C15C"
275 Content-class: urn:content-classes:message
276 Subject: outlook basic test
277 Date: Tue, 17 Jul 2012 10:11:50 +0100
278 Message-ID: <AA6CEAFB02FF244999046B2A6B6B9D6F05FF9D12\@example.com>
279 X-MS-Has-Attach: 
280 X-MS-TNEF-Correlator: 
281 Thread-Topic: Testing Outlook HTML
282 Thread-Index: Ac1j/DNs7ly963bnRt63SJw9DkGwyw==
283 From: root\@localhost
284 To: rt\@@{[RT->Config->Get('rtname')]}
285
286 This is a multi-part message in MIME format.
287
288 ------_=_NextPart_001_01CD63FC.33F4C15C
289 Content-Type: text/plain;
290         charset="us-ascii"
291 Content-Transfer-Encoding: quoted-printable
292
293 This email contains a line of text containing multiple sentences.  Where
294 will RT wrap this when the text is quoted?  What about the footer below?
295
296 =20
297
298 This is a different line, with a blank line (paragraph) above.  Will
299 there be additional blank lines when the text is quoted?
300
301 =20
302
303 This isthesig
304
305 =20
306
307
308 ------_=_NextPart_001_01CD63FC.33F4C15C
309 Content-Type: text/html;
310         charset="us-ascii"
311 Content-Transfer-Encoding: quoted-printable
312
313 <html xmlns:v=3D"urn:schemas-microsoft-com:vml" =
314 xmlns:o=3D"urn:schemas-microsoft-com:office:office" =
315 xmlns:w=3D"urn:schemas-microsoft-com:office:word" =
316 xmlns:m=3D"http://schemas.microsoft.com/office/2004/12/omml" =
317 xmlns=3D"http://www.w3.org/TR/REC-html40"><head><META =
318 HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
319 charset=3Dus-ascii"><meta name=3DGenerator content=3D"Microsoft Word 12 =
320 (filtered medium)"><style><!--
321 /* Font Definitions */
322 \@font-face
323         {font-family:"Cambria Math";
324         panose-1:2 4 5 3 5 4 6 3 2 4;}
325 \@font-face
326         {font-family:Calibri;
327         panose-1:2 15 5 2 2 2 4 3 2 4;}
328 /* Style Definitions */
329 p.MsoNormal, li.MsoNormal, div.MsoNormal
330         {margin:0in;
331         margin-bottom:.0001pt;
332         font-size:11.0pt;
333         font-family:"Calibri","sans-serif";}
334 a:link, span.MsoHyperlink
335         {mso-style-priority:99;
336         color:blue;
337         text-decoration:underline;}
338 a:visited, span.MsoHyperlinkFollowed
339         {mso-style-priority:99;
340         color:purple;
341         text-decoration:underline;}
342 span.EmailStyle17
343         {mso-style-type:personal-compose;
344         font-family:"Calibri","sans-serif";
345         color:windowtext;}
346 .MsoChpDefault
347         {mso-style-type:export-only;}
348 \@page WordSection1
349         {size:8.5in 11.0in;
350         margin:1.0in 1.0in 1.0in 1.0in;}
351 div.WordSection1
352         {page:WordSection1;}
353 --></style><!--[if gte mso 9]><xml>
354 <o:shapedefaults v:ext=3D"edit" spidmax=3D"1026" />
355 </xml><![endif]--><!--[if gte mso 9]><xml>
356 <o:shapelayout v:ext=3D"edit">
357 <o:idmap v:ext=3D"edit" data=3D"1" />
358 </o:shapelayout></xml><![endif]--></head><body lang=3DEN-US link=3Dblue =
359 vlink=3Dpurple><div class=3DWordSection1><p class=3DMsoNormal>This email =
360 contains a line of text containing multiple sentences.&nbsp; Where will =
361 RT wrap this when the text is quoted?&nbsp; What about the footer =
362 below?<o:p></o:p></p><p class=3DMsoNormal><o:p>&nbsp;</o:p></p><p =
363 class=3DMsoNormal>This is a different line, with a blank line =
364 (paragraph) above.&nbsp; Will there be additional blank lines when the =
365 text is quoted?<o:p></o:p></p><p =
366 class=3DMsoNormal><o:p>&nbsp;</o:p></p><p class=3DMsoNormal><span =
367 lang=3DEN-GB =
368 style=3D'font-size:7.5pt;font-family:"Arial","sans-serif"'>This isthesig =
369 </span><o:p></o:p></p><p =
370 class=3DMsoNormal><o:p>&nbsp;</o:p></p></div></body></html>
371 ------_=_NextPart_001_01CD63FC.33F4C15C--
372 EOF
373
374         my $content = <<EOF;
375 This email contains a line of text containing multiple sentences.  Where
376 will RT wrap this when the text is quoted?  What about the footer below?
377
378 This is a different line, with a blank line (paragraph) above.  Will
379 there be additional blank lines when the text is quoted?
380
381 This isthesig
382
383 EOF
384
385         test_email( $text, $content,
386                     'Another sample multipart message with Exchange headers' );
387 }
388
389 sub test_email {
390     my ( $text, $content, $msg ) = @_;
391     my ( $status, $id ) = RT::Test->send_via_mailgate($text);
392     is( $status >> 8, 0, "The mail gateway exited normally" );
393     ok( $id, "Created ticket" );
394
395     my $ticket = RT::Test->last_ticket;
396     isa_ok( $ticket, 'RT::Ticket' );
397     is( $ticket->Id, $id, "correct ticket id" );
398     is( $ticket->Subject, 'outlook basic test', "subject of ticket $id" );
399     my $txns = $ticket->Transactions;
400     $txns->Limit( FIELD => 'Type', VALUE => 'Create' );
401     my $txn     = $txns->First;
402
403     is( $txn->Content, $content, $msg );
404 }
405