diff options
author | Byron Jones <bjones@mozilla.com> | 2013-02-07 07:50:38 +0100 |
---|---|---|
committer | Byron Jones <bjones@mozilla.com> | 2013-02-07 07:50:38 +0100 |
commit | a8a6d1bf445b419f853fbdd8f89899e01f99230a (patch) | |
tree | c09003788dca41395a4d96fa2b52785d8b9e8482 /extensions/BMO | |
parent | e1221dce8f530e42ba2e15d5f3f88018871fbccd (diff) | |
download | bugzilla-a8a6d1bf445b419f853fbdd8f89899e01f99230a.tar.gz bugzilla-a8a6d1bf445b419f853fbdd8f89899e01f99230a.tar.xz |
Bug 836213: log bugmail sent to the syslog
Diffstat (limited to 'extensions/BMO')
-rw-r--r-- | extensions/BMO/Extension.pm | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/extensions/BMO/Extension.pm b/extensions/BMO/Extension.pm index af29bfaaf..a887582c3 100644 --- a/extensions/BMO/Extension.pm +++ b/extensions/BMO/Extension.pm @@ -40,7 +40,7 @@ use Bugzilla::Util; use Scalar::Util qw(blessed); use Date::Parse; use DateTime; -use Encode qw(find_encoding); +use Encode qw(find_encoding decode_utf8); use Sys::Syslog qw(:DEFAULT setlogsock); use Bugzilla::Extension::BMO::Constants; @@ -845,6 +845,8 @@ sub mailer_before_send { my ($self, $args) = @_; my $email = $args->{email}; + _log_sent_email($email); + # Add X-Bugzilla-Tracking header if ($email->header('X-Bugzilla-ID')) { my $bug_id = $email->header('X-Bugzilla-ID'); @@ -922,6 +924,40 @@ sub mailer_before_send { } } +# Log a summary of bugmail sent to the syslog, for auditing and monitoring +sub _log_sent_email { + my $email = shift; + + my $recipient = $email->header('to'); + return unless $recipient; + + my $subject = $email->header('Subject'); + + my $bug_id = $email->header('X-Bugzilla-ID'); + if (!$bug_id && $subject =~ /[\[\(]Bug (\d+)/i) { + $bug_id = $1; + } + $bug_id = $bug_id ? "bug-$bug_id" : '-'; + + my $message_type; + my $type = $email->header('X-Bugzilla-Type'); + my $reason = $email->header('X-Bugzilla-Reason'); + if ($type eq 'whine' || $type eq 'request' || $type eq 'admin') { + $message_type = $type; + } elsif ($reason && $reason ne 'None') { + $message_type = $reason; + } else { + $message_type = $email->header('X-Bugzilla-Watch-Reason'); + } + $message_type ||= '?'; + + $subject =~ s/[\[\(]Bug \d+[\]\)]\s*//; + + openlog('apache', 'cons,pid', 'local4'); + syslog('notice', decode_utf8("[bugmail] $recipient ($message_type) $bug_id $subject")); + closelog(); +} + sub post_bug_after_creation { my ($self, $args) = @_; my $vars = $args->{vars}; |