2 # $Id: 05_mail.t,v 1.1 2005/08/17 21:46:17 don Exp $
4 use Test::More tests => 20;
9 # Here, we're going to shoot messages through a set of things that can
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.
17 use File::Temp qw(tempdir);
19 use Debbugs::MIME qw(create_mime_message);
22 my $sendmail_dir = tempdir(CLEANUP => $ENV{DEBUG}?0:1);
23 my $spool_dir = tempdir(CLEANUP => $ENV{DEBUG}?0:1);
24 my $config_dir = tempdir(CLEANUP => $ENV{DEBUG}?0:1);
28 print STDERR "\nspool_dir: $spool_dir\n";
29 print STDERR "config_dir: $config_dir\n";
30 print STDERR "sendmail_dir: $sendmail_dir\n";
34 $ENV{SENDMAIL_TESTDIR} = $sendmail_dir;
35 my $sendmail_tester = getcwd().'/t/sendmail_tester';
37 unless (-x $sendmail_tester) {
38 BAIL_OUT(q(t/sendmail_tester doesn't exist or isn't executable. You may be in the wrong directory.));
41 my %files_to_create = ("$config_dir/debbugs_config" => <<END,
42 \$gSendmail='$sendmail_tester';
43 \$gSpoolDir='$spool_dir';
45 "$spool_dir/nextnumber" => qq(1\n),
46 "$config_dir/Maintainers" => qq(foo Blah Bleargh <bar\@baz.com>),
48 while (my ($file,$contents) = each %files_to_create) {
49 my $fh = new IO::File $file,'w' or
50 BAIL_OUT("Unable to create $file: $!");
51 print {$fh} $contents;
55 system('touch',"$spool_dir/index.db.realtime");
56 system('ln','-s','index.db.realtime',
57 "$spool_dir/index.db");
58 system('touch',"$spool_dir/index.archive.realtime");
59 system('ln','-s','index.archive.realtime',
60 "$spool_dir/index.archive");
63 $ENV{DEBBUGS_CONFIG_FILE} ="$config_dir/debbugs_config";
65 # create the spool files and sub directories
66 map {system('mkdir','-p',"$spool_dir/$_"); }
67 map {('db-h/'.$_,'archive/'.$_)}
68 map { sprintf "%02d",$_ % 100} 0..99;
69 system('mkdir','-p',"$spool_dir/incoming");
72 # We're going to use create mime message to create these messages, and
73 # then just send them to receive.
75 # First, check that submit@ works
77 $ENV{LOCAL_PART} = 'submit@bugs.something';
78 my $receive = new IO::File ('|scripts/receive.in') or BAIL_OUT("Unable to start receive.in: $!");
80 print {$receive} create_mime_message([To => 'submit@bugs.something',
81 From => 'foo@bugs.something',
82 Subject => 'Submiting a bug',
92 ok($?==0,'receive took the mail');
93 # now we should run processall to see if the message gets processed
94 ok(system('scripts/processall.in') == 0,'processall ran');
96 # now we check to see that we have a bug, and nextnumber has been incremented
97 ok(-e "$spool_dir/db-h/01/1.log",'log file created');
98 ok(-e "$spool_dir/db-h/01/1.summary",'sumary file created');
99 ok(-e "$spool_dir/db-h/01/1.status",'status file created');
100 ok(-e "$spool_dir/db-h/01/1.report",'report file created');
102 # next, we check to see that (at least) the proper messages have been
103 # sent out. 1) ack to submitter 2) mail to maintainer
108 my @content = grep {!/^\.\.?$/} readdir(DIR);
110 return scalar @content;
113 # This keeps track of the previous size of the sendmail directory
114 my $SD_SIZE_PREV = 0;
115 my $SD_SIZE_NOW = dirsize($sendmail_dir);
116 ok($SD_SIZE_NOW-$SD_SIZE_PREV >= 2,'submit messages appear to have been sent out properly');
117 $SD_SIZE_PREV=$SD_SIZE_NOW;
119 # now send a message to the bug
121 $ENV{LOCAL_PART} = '1@bugs.something';
122 $receive = new IO::File ('|scripts/receive.in') or
123 BAIL_OUT("Unable to start receive.in: $!");
125 print {$receive} create_mime_message([To => '1@bugs.something',
126 From => 'foo@bugs.something',
127 Subject => 'Sending a message to a bug',
137 ok($?==0,'receive took the mail');
138 # now we should run processall to see if the message gets processed
139 ok(system('scripts/processall.in') == 0,'processall ran');
140 $SD_SIZE_NOW = dirsize($sendmail_dir);
141 ok($SD_SIZE_NOW-$SD_SIZE_PREV >= 2,'1@bugs.something messages appear to have been sent out properly');
142 $SD_SIZE_PREV=$SD_SIZE_NOW;
144 # just check to see that control doesn't explode
145 $ENV{LOCAL_PART} = 'control@bugs.something';
146 $receive = new IO::File ('|scripts/receive.in') or
147 BAIL_OUT("Unable to start receive.in: $!");
149 print {$receive} create_mime_message([To => 'control@bugs.something',
150 From => 'foo@bugs.something',
151 Subject => 'Munging a bug',
159 ok($?==0,'receive took the mail');
160 # now we should run processall to see if the message gets processed
161 ok(system('scripts/processall.in') == 0,'processall ran');
162 $SD_SIZE_NOW = dirsize($sendmail_dir);
163 ok($SD_SIZE_NOW-$SD_SIZE_PREV >= 2,'1@bugs.something messages appear to have been sent out properly');
164 $SD_SIZE_PREV=$SD_SIZE_NOW;