2 # $Id: 05_mail.t,v 1.1 2005/08/17 21:46:17 don Exp $
4 use Test::More tests => 13;
11 # Here, we're going to shoot messages through a set of things that can
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.
19 use File::Temp qw(tempdir);
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
25 use DebbugsTest qw(:all);
27 use Encode qw(decode encode decode_utf8 encode_utf8);
29 # HTTP::Server:::Simple defines a SIG{CHLD} handler that breaks system; undef it here.
31 my %config = create_debbugs_configuration();
34 my $sendmail_dir = $config{sendmail_dir};
35 my $spool_dir = $config{spool_dir};
36 my $config_dir = $config{config_dir};
40 # We're going to use create mime message to create these messages, and
41 # then just send them to receive.
43 send_message(to=>'submit@bugs.something',
44 headers => [To => 'submit@bugs.something',
45 From => 'föoff@bugs.something',
46 Subject => 'Submiting a bug',
48 body => <<EOF,attachments => [{Type=>"text/plain",Charset=>"utf-8",Data=>encode_utf8(<<EOF2)}]) or fail('Unable to send message');
54 This is the silly bug's test ütff8 attachment.
59 # now we check to see that we have a bug, and nextnumber has been incremented
60 ok(-e "$spool_dir/db-h/01/1.log",'log file created');
61 ok(-e "$spool_dir/db-h/01/1.summary",'sumary file created');
62 ok(-e "$spool_dir/db-h/01/1.status",'status file created');
63 ok(-e "$spool_dir/db-h/01/1.report",'report file created');
64 ok(system('sh','-c','[ $(grep "attachment." '.$spool_dir.'/db-h/01/1.log|grep -v "ütff8"|wc -l) -eq 0 ]') == 0,
65 'Everything attachment is escaped properly');
67 # next, we check to see that (at least) the proper messages have been
68 # sent out. 1) ack to submitter 2) mail to maintainer
70 # This keeps track of the previous size of the sendmail directory
73 num_messages_sent($SD_SIZE,2,
75 'submit messages appear to have been sent out properly',
79 # now send a message to the bug
81 send_message(to => '1@bugs.something',
82 headers => [To => '1@bugs.something',
83 From => 'föoff@bugs.something',
84 Subject => 'Sending a message to a bug',
86 body => <<EOF) or fail('sending message to 1@bugs.someting failed');
94 num_messages_sent($SD_SIZE,2,
96 '1@bugs.something messages appear to have been sent out properly');
98 # just check to see that control doesn't explode
99 send_message(to => 'control@bugs.something',
100 headers => [To => 'control@bugs.something',
101 From => 'föoff@bugs.something',
102 Subject => 'Munging a bug',
104 body => <<EOF) or fail 'message to control@bugs.something failed';
106 retitle 1 ütff8 title encoding test
111 num_messages_sent($SD_SIZE,1,
113 'control@bugs.something messages appear to have been sent out properly');
114 # now we need to check to make sure the control message was processed without errors
115 ok(system('sh','-c','find '.$sendmail_dir.q( -type f | xargs grep -q "Subject: Processed: Munging a bug")) == 0,
116 'control@bugs.something message was parsed without errors');
117 # now we need to check to make sure that the control message actually did anything
118 # This is an eval because $ENV{DEBBUGS_CONFIG_FILE} isn't set at BEGIN{} time
119 eval "use Debbugs::Status qw(read_bug writebug);";
120 my $status = read_bug(bug=>1);
121 ok($status->{subject} eq 'ütff8 title encoding test','bug 1 retitled');
122 ok($status->{severity} eq 'wishlist','bug 1 wishlisted');
123 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,
124 'Control messages escaped properly');
125 ok(system('sh','-c',encode_utf8('grep -q "föoff@bugs.something" '.$spool_dir.'/index.db'))==0,
126 'index.db not double escaped');