import rt 3.8.9
[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 => 43;
60 my ($baseurl, $m) = RT::Test->started_ok;
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" if $ENV{'TEST_VERBOSE'};
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       if $ENV{'TEST_VERBOSE'};
111     {
112         my $text = <<EOF;
113 From: root\@localhost
114 X-Mailer: $mailer
115 To: rt\@@{[RT->Config->Get('rtname')]}
116 Subject: outlook basic test
117 Content-Type: multipart/mixed;
118         boundary="----=_NextPart_000_000F_01CB045E.5222CB40"
119
120 ------=_NextPart_000_000F_01CB045E.5222CB40
121 Content-Type: multipart/alternative;
122         boundary="----=_NextPart_001_0010_01CB045E.5222CB40"
123
124
125 ------=_NextPart_001_0010_01CB045E.5222CB40
126 Content-Type: text/plain;
127         charset="us-ascii"
128 Content-Transfer-Encoding: 7bit
129
130 foo
131
132
133
134 bar
135
136 baz
137
138
139 ------=_NextPart_001_0010_01CB045E.5222CB40
140 Content-Type: text/html;
141         charset="us-ascii"
142 Content-Transfer-Encoding: quoted-printable
143
144 <html>this is fake</html>
145
146 ------=_NextPart_001_0010_01CB045E.5222CB40--
147
148 ------=_NextPart_000_000F_01CB045E.5222CB40
149 Content-Type: text/plain;
150         name="att.txt"
151 Content-Transfer-Encoding: quoted-printable
152 Content-Disposition: attachment;
153         filename="att.txt"
154
155 this is the attachment! :)=0A=
156
157 ------=_NextPart_000_000F_01CB045E.5222CB40--
158 EOF
159
160         my $content = <<EOF;
161 foo
162
163 bar
164 baz
165 EOF
166         test_email( $text, $content,
167             $mailer . ' with multipart/multipart, \n\n are replaced' );
168     }
169
170     diag "Test mail with with outlook, but the content type is text/plain"
171       if $ENV{'TEST_VERBOSE'};
172     {
173         my $text = <<EOF;
174 From: root\@localhost
175 X-Mailer: $mailer
176 To: rt\@@{[RT->Config->Get('rtname')]}
177 Subject: outlook basic test
178 Content-Type: text/plain; charset="us-ascii"
179 Content-Transfer-Encoding: 7bit
180
181 foo
182
183
184
185 bar
186
187 baz
188
189 EOF
190
191         my $content = <<EOF;
192 foo
193
194
195
196 bar
197
198 baz
199
200 EOF
201         test_email( $text, $content,
202             $mailer . ' with only text/plain, \n\n are not replaced' );
203     }
204 }
205
206 diag "Test mail with with multipart/alternative but x-mailer is not outlook "
207   if $ENV{'TEST_VERBOSE'};
208 {
209     my $text = <<EOF;
210 From: root\@localhost
211 X-Mailer: Mutt
212 To: rt\@@{[RT->Config->Get('rtname')]}
213 Subject: outlook basic test
214 Content-Type: multipart/alternative;
215         boundary="----=_NextPart_000_0004_01CB045C.A5A075D0"
216
217 ------=_NextPart_000_0004_01CB045C.A5A075D0
218 Content-Type: text/plain;
219         charset="us-ascii"
220 Content-Transfer-Encoding: 7bit
221
222 foo
223
224
225
226 bar
227
228 baz
229
230
231 ------=_NextPart_000_0004_01CB045C.A5A075D0
232 Content-Type: text/html;
233         charset="us-ascii"
234 Content-Transfer-Encoding: quoted-printable
235
236 <html>this is fake</html>
237
238
239 ------=_NextPart_000_0004_01CB045C.A5A075D0--
240
241 EOF
242
243     my $content = <<EOF;
244 foo
245
246
247
248 bar
249
250 baz
251
252 EOF
253     test_email( $text, $content, 'without outlook, \n\n are not replaced' );
254 }
255
256 sub test_email {
257     my ( $text, $content, $msg ) = @_;
258     my ( $status, $id ) = RT::Test->send_via_mailgate($text);
259     is( $status >> 8, 0, "The mail gateway exited normally" );
260     ok( $id, "Created ticket" );
261
262     my $ticket = RT::Test->last_ticket;
263     isa_ok( $ticket, 'RT::Ticket' );
264     is( $ticket->Id, $id, "correct ticket id" );
265     is( $ticket->Subject, 'outlook basic test', "subject of ticket $id" );
266     my $txns = $ticket->Transactions;
267     $txns->Limit( FIELD => 'Type', VALUE => 'Create' );
268     my $txn     = $txns->First;
269
270     is( $txn->Content, $content, $msg );
271 }
272