[Rt-commit] rt branch, 4.2/mbox-output, created. rt-4.2.5-54-gceed149
Alex Vandiver
alexmv at bestpractical.com
Thu Jun 19 20:43:47 EDT 2014
The branch, 4.2/mbox-output has been created
at ceed149381779c1e7c3da04cd046ae0387f3ea18 (commit)
- Log -----------------------------------------------------------------
commit ceed149381779c1e7c3da04cd046ae0387f3ea18
Author: Alex Vandiver <alexmv at bestpractical.com>
Date: Tue May 6 18:28:36 2014 -0400
Persistant email logging, in mbox format
The "testfile" output format is useful, but has two limitations:
1. It is a temporary file; if the process completes successfully, the
tempfile is removed, making it impossible to examine the email
contents
2. The file format that it outputs is almost, but not quite, the
standard mbox format.
This adds an additional MailCommand option, "mbox", which writes
mbox-formatted output to the var directory based on the current
timestamp.
diff --git a/lib/RT/Config.pm b/lib/RT/Config.pm
index 7842e57..0f37b6a 100644
--- a/lib/RT/Config.pm
+++ b/lib/RT/Config.pm
@@ -630,7 +630,7 @@ our %META;
my $self = shift;
my $value = $self->Get('MailCommand');
return if ref($value) eq "CODE"
- or $value =~/^(sendmail|sendmailpipe|qmail|testfile)$/;
+ or $value =~/^(sendmail|sendmailpipe|qmail|testfile|mbox)$/;
$RT::Logger->error("Unknown value for \$MailCommand: $value; defaulting to sendmailpipe");
$self->Set( MailCommand => 'sendmailpipe' );
},
diff --git a/lib/RT/Interface/Email.pm b/lib/RT/Interface/Email.pm
index facdb38..fdc2308 100644
--- a/lib/RT/Interface/Email.pm
+++ b/lib/RT/Interface/Email.pm
@@ -50,6 +50,7 @@ package RT::Interface::Email;
use strict;
use warnings;
+use 5.010;
use Email::Address;
use MIME::Entity;
@@ -498,8 +499,29 @@ sub SendEmail {
}
return 0;
}
- }
- else {
+ } elsif ( $mail_command eq 'mbox' ) {
+ my $now = RT::Date->new(RT->SystemUser);
+ $now->SetToNow;
+
+ state $logfile;
+ unless ($logfile) {
+ my $when = $now->ISO( Timezone => "server" );
+ $when =~ s/\s+/-/g;
+ $logfile = "$RT::VarPath/$when.mbox";
+ $RT::Logger->info("Storing outgoing emails in $logfile");
+ }
+
+ my $fh;
+ unless (open($fh, ">>", $logfile)) {
+ $RT::Logger->crit( "Can't open mbox file $logfile: $!" );
+ return 0;
+ }
+ my $content = $args{Entity}->stringify;
+ $content =~ s/^(>*From )/>$1/mg;
+ print $fh "From $ENV{USER}\@localhost ".localtime."\n";
+ print $fh $content, "\n";
+ close $fh;
+ } else {
local ($ENV{'MAILADDRESS'}, $ENV{'PERL_MAILERS'});
my @mailer_args = ($mail_command);
-----------------------------------------------------------------------
More information about the rt-commit
mailing list