From 56c61ae8ff0496a6fb9ff69bdc360dc1db5dfd27 Mon Sep 17 00:00:00 2001 From: Byron Jones Date: Wed, 12 Aug 2015 15:36:02 +0800 Subject: Bug 1036872 - Bugmail filtering allows through bugmail that should be blocked when combined with the standard email prefs --- extensions/BugmailFilter/Extension.pm | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'extensions/BugmailFilter') diff --git a/extensions/BugmailFilter/Extension.pm b/extensions/BugmailFilter/Extension.pm index 002f27a39..4cbf3d984 100644 --- a/extensions/BugmailFilter/Extension.pm +++ b/extensions/BugmailFilter/Extension.pm @@ -24,6 +24,7 @@ use Bugzilla::Product; use Bugzilla::User; use Bugzilla::Util qw(template_var); use Encode; +use List::MoreUtils qw(uniq); use Sys::Syslog qw(:DEFAULT); # @@ -217,12 +218,19 @@ sub user_preferences { sub user_wants_mail { my ($self, $args) = @_; - my ($user, $wants_mail, $diffs, $comments) = @$args{qw( user wants_mail fieldDiffs comments )}; + # already filtered by email prefs return unless $$wants_mail; + # avoid recursion + my $depth = 0; + for (my $stack = 1; my $sub = (caller($stack))[3]; $stack++) { + $depth++ if $sub eq 'Bugzilla::User::wants_bug_mail'; + } + return if $depth > 1; + my $cache = Bugzilla->request_cache->{bugmail_filters} //= {}; my $filters = $cache->{$user->id} //= Bugzilla::Extension::BugmailFilter::Filter->match({ @@ -242,6 +250,30 @@ sub user_wants_mail { @$diffs ]; + # if more than one field was changed we need to check if the normal email + # preferences would have excluded the field. + if (@$fields > 1) { + # check each field individually and create filter objects if required + my @arg_list = @$args{qw( bug relationship fieldDiffs comments dep_mail changer )}; + foreach my $field (@$fields) { + # just a single diff + foreach my $diff (@$diffs) { + next unless $diff->{field_name} eq $field->{field_name}; + $arg_list[2] = [ $diff ]; + last; + } + if (!$user->wants_bug_mail(@arg_list)) { + # changes to just this field would have been dropped by email + # preferences. build a corresponding filter object so we + # interact with email preferences correctly. + push @$filters, Bugzilla::Extension::BugmailFilter::Filter->new_from_hash({ + field_name => $field->{field_name}, + action => 1, + }); + } + } + } + # insert fake fields for new attachments and comments if (@$comments) { if (grep { $_->type == CMT_ATTACHMENT_CREATED } @$comments) { -- cgit v1.2.3-24-g4f1b