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