summaryrefslogtreecommitdiff
path: root/rt/t/mail/bounce.t
blob: 703e86d67d077b0d8e0eda61060a71780464c533 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use strict;
use warnings;

use RT::Test tests => undef;

RT->Config->Set( MailCommand  => 'sendmailpipe' );
RT->Config->Set( SetOutgoingMailFrom => 1 );
RT->Config->Set( OverrideOutgoingMailFrom  => { Default => 'queue@example.invalid' } );

# Ensure that the fake sendmail knows where to write to
$ENV{RT_MAILLOGFILE} = RT::Test->temp_directory . "/sendmailpipe.log";
my $fake = File::Spec->rel2abs( File::Spec->catfile(
        't', 'mail', 'fake-sendmail' ) );
RT->Config->Set( SendmailPath => $fake);

my $message = <<EOM;
From: doesnotexist\@willbounce.invalid
Subject: This is a test of new ticket creation

Bounce bounce bounce
EOM

{
    # by default, MailError wants to crit or error the email message
    # out to Screen, which scribbles all over the test output
    no warnings 'redefine';
    my $orig_mail_error = RT::Interface::Email->can('MailError');
    local *RT::Interface::Email::MailError = sub { $orig_mail_error->( @_, LogLevel => undef ) };
    RT::Test->send_via_mailgate($message);
}


open(LOG, "<", $ENV{RT_MAILLOGFILE}) or die "Can't open log file: $!";
my $fcount;
while (my $line = <LOG>) {
    $fcount++ if $line =~ /^-f/;
}
close(LOG);
# RT_MAILLOGFILE will contain all the command line flags if you need them
is($fcount,1,"Only one -f specified to sendmail command");

done_testing;