]> git.donarmstrong.com Git - debbugs.git/blob - t/13_utf8_mail.t
7ef4aaffdc98c393d97f5a130a41bf8b52c5d906
[debbugs.git] / t / 13_utf8_mail.t
1 # -*- mode: cperl;-*-
2 # $Id: 05_mail.t,v 1.1 2005/08/17 21:46:17 don Exp $
3
4 use Test::More tests => 13;
5
6 use warnings;
7 use strict;
8
9 use utf8;
10
11 # Here, we're going to shoot messages through a set of things that can
12 # happen.
13
14 # First, we're going to send mesages to receive.
15 # To do so, we'll first send a message to submit,
16 # then send messages to the newly created bugnumber.
17
18 use IO::File;
19 use File::Temp qw(tempdir);
20 use Cwd qw(getcwd);
21 use Debbugs::MIME qw(create_mime_message);
22 use File::Basename qw(dirname basename);
23 # The test functions are placed here to make things easier
24 use lib qw(t/lib);
25 use DebbugsTest qw(:all);
26 use Data::Dumper;
27 use Encode qw(decode encode decode_utf8 encode_utf8);
28
29 # HTTP::Server:::Simple defines a SIG{CHLD} handler that breaks system; undef it here.
30 $SIG{CHLD} = sub {};
31 my %config;
32 eval {
33      %config = create_debbugs_configuration(debug => exists $ENV{DEBUG}?$ENV{DEBUG}:0);
34 };
35 if ($@) {
36      BAIL_OUT($@);
37 }
38
39 my $sendmail_dir = $config{sendmail_dir};
40 my $spool_dir = $config{spool_dir};
41 my $config_dir = $config{config_dir};
42
43 END{
44      if ($ENV{DEBUG}) {
45           diag("spool_dir:   $spool_dir\n");
46           diag("config_dir:   $config_dir\n");
47           diag("sendmail_dir: $sendmail_dir\n");
48      }
49 }
50
51 # We're going to use create mime message to create these messages, and
52 # then just send them to receive.
53
54 send_message(to=>'submit@bugs.something',
55              headers => [To   => 'submit@bugs.something',
56                          From => 'föoff@bugs.something',
57                          Subject => 'Submiting a bug',
58                         ],
59              body => <<EOF,attachments => [{Type=>"text/plain",Charset=>"utf-8",Data=>encode_utf8(<<EOF2)}]) or fail('Unable to send message');
60 Package: foo
61 Severity: normal
62
63 This is a silly bug
64 EOF
65 This is the silly bug's test ütff8 attachment.
66 EOF2
67
68
69
70 # now we check to see that we have a bug, and nextnumber has been incremented
71 ok(-e "$spool_dir/db-h/01/1.log",'log file created');
72 ok(-e "$spool_dir/db-h/01/1.summary",'sumary file created');
73 ok(-e "$spool_dir/db-h/01/1.status",'status file created');
74 ok(-e "$spool_dir/db-h/01/1.report",'report file created');
75 ok(system('sh','-c','[ $(grep "attachment." '.$spool_dir.'/db-h/01/1.log|grep -v "ütff8"|wc -l) -eq 0 ]') == 0,
76    'Everything attachment is escaped properly');
77
78 # next, we check to see that (at least) the proper messages have been
79 # sent out. 1) ack to submitter 2) mail to maintainer
80
81 # This keeps track of the previous size of the sendmail directory
82 my $SD_SIZE = 0;
83 $SD_SIZE =
84     num_messages_sent($SD_SIZE,2,
85                       $sendmail_dir,
86                       'submit messages appear to have been sent out properly',
87                      );
88
89
90 # now send a message to the bug
91
92 send_message(to => '1@bugs.something',
93              headers => [To   => '1@bugs.something',
94                          From => 'föoff@bugs.something',
95                          Subject => 'Sending a message to a bug',
96                         ],
97              body => <<EOF) or fail('sending message to 1@bugs.someting failed');
98 Package: foo
99 Severity: normal
100
101 This is a silly bug
102 EOF
103
104 $SD_SIZE =
105     num_messages_sent($SD_SIZE,2,
106                       $sendmail_dir,
107                       '1@bugs.something messages appear to have been sent out properly');
108
109 # just check to see that control doesn't explode
110 send_message(to => 'control@bugs.something',
111              headers => [To   => 'control@bugs.something',
112                          From => 'föoff@bugs.something',
113                          Subject => 'Munging a bug',
114                         ],
115              body => <<EOF) or fail 'message to control@bugs.something failed';
116 severity 1 wishlist
117 retitle 1 ütff8 title encoding test
118 thanks
119 EOF
120
121 $SD_SIZE =
122    num_messages_sent($SD_SIZE,1,
123                      $sendmail_dir,
124                      'control@bugs.something messages appear to have been sent out properly');
125 # now we need to check to make sure the control message was processed without errors
126 ok(system('sh','-c','find '.$sendmail_dir.q( -type f | xargs grep -q "Subject: Processed: Munging a bug")) == 0,
127    'control@bugs.something message was parsed without errors');
128 # now we need to check to make sure that the control message actually did anything
129 # This is an eval because $ENV{DEBBUGS_CONFIG_FILE} isn't set at BEGIN{} time
130 eval "use Debbugs::Status qw(read_bug writebug);";
131 my $status = read_bug(bug=>1);
132 ok($status->{subject} eq 'ütff8 title encoding test','bug 1 retitled');
133 ok($status->{severity} eq 'wishlist','bug 1 wishlisted');
134 ok(system('sh','-c','[ $(egrep "retitle.*encoding test" '.$spool_dir.'/db-h/01/1.log|grep -v "=C3=BCt=EF=AC=808"|wc -l) -eq 0 ]') == 0,
135    'Control messages escaped properly');
136 ok(system('sh','-c',encode_utf8('grep -q "föoff@bugs.something" '.$spool_dir.'/index.db'))==0,
137    'index.db not double escaped');