first pass RT4 merge, RT#13852
[freeside.git] / rt / t / mail / bounce.t
1 use strict;
2 use warnings;
3
4 use RT::Test tests => undef;
5
6 RT->Config->Set( MailCommand  => 'sendmailpipe' );
7 RT->Config->Set( SetOutgoingMailFrom => 1 );
8 RT->Config->Set( OverrideOutgoingMailFrom  => { Default => 'queue@example.invalid' } );
9
10 # Ensure that the fake sendmail knows where to write to
11 $ENV{RT_MAILLOGFILE} = RT::Test->temp_directory . "/sendmailpipe.log";
12 my $fake = File::Spec->rel2abs( File::Spec->catfile(
13         't', 'mail', 'fake-sendmail' ) );
14 RT->Config->Set( SendmailPath => $fake);
15
16 my $message = <<EOM;
17 From: doesnotexist\@willbounce.invalid
18 Subject: This is a test of new ticket creation
19
20 Bounce bounce bounce
21 EOM
22
23 {
24     # by default, MailError wants to crit or error the email message
25     # out to Screen, which scribbles all over the test output
26     no warnings 'redefine';
27     my $orig_mail_error = RT::Interface::Email->can('MailError');
28     local *RT::Interface::Email::MailError = sub { $orig_mail_error->( @_, LogLevel => undef ) };
29     RT::Test->send_via_mailgate($message);
30 }
31
32
33 open(LOG, "<", $ENV{RT_MAILLOGFILE}) or die "Can't open log file: $!";
34 my $fcount;
35 while (my $line = <LOG>) {
36     $fcount++ if $line =~ /^-f/;
37 }
38 close(LOG);
39 # RT_MAILLOGFILE will contain all the command line flags if you need them
40 is($fcount,1,"Only one -f specified to sendmail command");
41
42 done_testing;