first pass RT4 merge, RT#13852
[freeside.git] / rt / t / mail / outlook.t
1 #!/usr/bin/perl -w
2 # BEGIN BPS TAGGED BLOCK {{{
3
4 # COPYRIGHT:
5 #  
6 # This software is Copyright (c) 1996-2004 Best Practical Solutions, LLC 
7 #                                          <jesse.com>
8
9 # (Except where explicitly superseded by other copyright notices)
10
11
12 # LICENSE:
13
14 # This work is made available to you under the terms of Version 2 of
15 # the GNU General Public License. A copy of that license should have
16 # been provided with this software, but in any event can be snarfed
17 # from www.gnu.org.
18
19 # This work is distributed in the hope that it will be useful, but
20 # WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
22 # General Public License for more details.
23
24 # You should have received a copy of the GNU General Public License
25 # along with this program; if not, write to the Free Software
26 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
27 # 02110-1301 or visit their web page on the internet at
28 # http://www.gnu.org/copyleft/gpl.html.
29
30
31 # CONTRIBUTION SUBMISSION POLICY:
32
33 # (The following paragraph is not intended to limit the rights granted
34 # to you to modify and distribute this software under the terms of
35 # the GNU General Public License and is only of importance to you if
36 # you choose to contribute your changes and enhancements to the
37 # community by submitting them to Best Practical Solutions, LLC.)
38
39 # By intentionally submitting any modifications, corrections or
40 # derivatives to this work, or any other work intended for use with
41 # Request Tracker, to Best Practical Solutions, LLC, you confirm that
42 # you are the copyright holder for those contributions and you grant
43 # Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
44 # royalty-free, perpetual, license to use, copy, create derivative
45 # works based on those contributions, and sublicense and distribute
46 # those contributions and any derivatives thereof.
47
48 # END BPS TAGGED BLOCK }}}
49
50 =head1 NAME
51
52 rt-mailgate - Mail interface to RT3.
53
54 =cut
55
56 use strict;
57 use warnings;
58
59 use RT::Test tests => 42;
60
61 # 12.0 is outlook 2007, 14.0 is 2010
62 for my $mailer ( 'Microsoft Office Outlook 12.0', 'Microsoft Outlook 14.0' ) {
63     diag "Test mail with multipart/alternative";
64     {
65         my $text = <<EOF;
66 From: root\@localhost
67 X-Mailer: $mailer
68 To: rt\@@{[RT->Config->Get('rtname')]}
69 Subject: outlook basic test
70 Content-Type: multipart/alternative;
71         boundary="----=_NextPart_000_0004_01CB045C.A5A075D0"
72
73 ------=_NextPart_000_0004_01CB045C.A5A075D0
74 Content-Type: text/plain;
75         charset="us-ascii"
76 Content-Transfer-Encoding: 7bit
77
78 here is the content
79
80
81
82 blahmm
83
84 another line
85
86
87 ------=_NextPart_000_0004_01CB045C.A5A075D0
88 Content-Type: text/html;
89         charset="us-ascii"
90 Content-Transfer-Encoding: quoted-printable
91
92 <html>this is fake</html>
93
94
95 ------=_NextPart_000_0004_01CB045C.A5A075D0--
96
97 EOF
98
99         my $content = <<EOF;
100 here is the content
101
102 blahmm
103 another line
104 EOF
105         test_email( $text, $content,
106             $mailer . ' with multipart/alternative, \n\n are replaced' );
107     }
108
109     diag "Test mail with multipart/mixed, with multipart/alternative in it";
110     {
111         my $text = <<EOF;
112 From: root\@localhost
113 X-Mailer: $mailer
114 To: rt\@@{[RT->Config->Get('rtname')]}
115 Subject: outlook basic test
116 Content-Type: multipart/mixed;
117         boundary="----=_NextPart_000_000F_01CB045E.5222CB40"
118
119 ------=_NextPart_000_000F_01CB045E.5222CB40
120 Content-Type: multipart/alternative;
121         boundary="----=_NextPart_001_0010_01CB045E.5222CB40"
122
123
124 ------=_NextPart_001_0010_01CB045E.5222CB40
125 Content-Type: text/plain;
126         charset="us-ascii"
127 Content-Transfer-Encoding: 7bit
128
129 foo
130
131
132
133 bar
134
135 baz
136
137
138 ------=_NextPart_001_0010_01CB045E.5222CB40
139 Content-Type: text/html;
140         charset="us-ascii"
141 Content-Transfer-Encoding: quoted-printable
142
143 <html>this is fake</html>
144
145 ------=_NextPart_001_0010_01CB045E.5222CB40--
146
147 ------=_NextPart_000_000F_01CB045E.5222CB40
148 Content-Type: text/plain;
149         name="att.txt"
150 Content-Transfer-Encoding: quoted-printable
151 Content-Disposition: attachment;
152         filename="att.txt"
153
154 this is the attachment! :)=0A=
155
156 ------=_NextPart_000_000F_01CB045E.5222CB40--
157 EOF
158
159         my $content = <<EOF;
160 foo
161
162 bar
163 baz
164 EOF
165         test_email( $text, $content,
166             $mailer . ' with multipart/multipart, \n\n are replaced' );
167     }
168
169     diag "Test mail with with outlook, but the content type is text/plain";
170     {
171         my $text = <<EOF;
172 From: root\@localhost
173 X-Mailer: $mailer
174 To: rt\@@{[RT->Config->Get('rtname')]}
175 Subject: outlook basic test
176 Content-Type: text/plain; charset="us-ascii"
177 Content-Transfer-Encoding: 7bit
178
179 foo
180
181
182
183 bar
184
185 baz
186
187 EOF
188
189         my $content = <<EOF;
190 foo
191
192
193
194 bar
195
196 baz
197
198 EOF
199         test_email( $text, $content,
200             $mailer . ' with only text/plain, \n\n are not replaced' );
201     }
202 }
203
204 diag "Test mail with with multipart/alternative but x-mailer is not outlook ";
205 {
206     my $text = <<EOF;
207 From: root\@localhost
208 X-Mailer: Mutt
209 To: rt\@@{[RT->Config->Get('rtname')]}
210 Subject: outlook basic test
211 Content-Type: multipart/alternative;
212         boundary="----=_NextPart_000_0004_01CB045C.A5A075D0"
213
214 ------=_NextPart_000_0004_01CB045C.A5A075D0
215 Content-Type: text/plain;
216         charset="us-ascii"
217 Content-Transfer-Encoding: 7bit
218
219 foo
220
221
222
223 bar
224
225 baz
226
227
228 ------=_NextPart_000_0004_01CB045C.A5A075D0
229 Content-Type: text/html;
230         charset="us-ascii"
231 Content-Transfer-Encoding: quoted-printable
232
233 <html>this is fake</html>
234
235
236 ------=_NextPart_000_0004_01CB045C.A5A075D0--
237
238 EOF
239
240     my $content = <<EOF;
241 foo
242
243
244
245 bar
246
247 baz
248
249 EOF
250     test_email( $text, $content, 'without outlook, \n\n are not replaced' );
251 }
252
253 sub test_email {
254     my ( $text, $content, $msg ) = @_;
255     my ( $status, $id ) = RT::Test->send_via_mailgate($text);
256     is( $status >> 8, 0, "The mail gateway exited normally" );
257     ok( $id, "Created ticket" );
258
259     my $ticket = RT::Test->last_ticket;
260     isa_ok( $ticket, 'RT::Ticket' );
261     is( $ticket->Id, $id, "correct ticket id" );
262     is( $ticket->Subject, 'outlook basic test', "subject of ticket $id" );
263     my $txns = $ticket->Transactions;
264     $txns->Limit( FIELD => 'Type', VALUE => 'Create' );
265     my $txn     = $txns->First;
266
267     is( $txn->Content, $content, $msg );
268 }
269