2008-12-15 15:53:33 +03:00
|
|
|
# The contents of this file are subject to the Mozilla Public
|
|
|
|
# License Version 1.1 (the "License"); you may not use this file
|
|
|
|
# except in compliance with the License. You may obtain a copy of
|
|
|
|
# the License at http://www.mozilla.org/MPL/
|
|
|
|
#
|
|
|
|
# Software distributed under the License is distributed on an "AS
|
|
|
|
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
# implied. See the License for the specific language governing
|
|
|
|
# rights and limitations under the License.
|
|
|
|
#
|
|
|
|
# The Original Code is the Bugzilla Bug Tracking System.
|
|
|
|
#
|
|
|
|
# The Initial Developer of the Original Code is Netscape Communications
|
|
|
|
# Corporation. Portions created by Netscape are
|
|
|
|
# Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
# Rights Reserved.
|
|
|
|
#
|
|
|
|
# Contributor(s): Terry Weissman <terry@mozilla.org>,
|
|
|
|
# Bryce Nesbitt <bryce-mozilla@nextbus.com>
|
|
|
|
# Dan Mosedale <dmose@mozilla.org>
|
|
|
|
# Alan Raetz <al_raetz@yahoo.com>
|
|
|
|
# Jacob Steenhagen <jake@actex.net>
|
|
|
|
# Matthew Tuck <matty@chariot.net.au>
|
|
|
|
# Bradley Baetz <bbaetz@student.usyd.edu.au>
|
|
|
|
# J. Paul Reed <preed@sigkill.com>
|
|
|
|
# Gervase Markham <gerv@gerv.net>
|
|
|
|
# Byron Jones <bugzilla@glob.com.au>
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
|
|
|
|
package Bugzilla::BugMail;
|
|
|
|
|
|
|
|
use Bugzilla::Error;
|
|
|
|
use Bugzilla::User;
|
|
|
|
use Bugzilla::Constants;
|
|
|
|
use Bugzilla::Util;
|
2009-10-14 19:22:05 +04:00
|
|
|
use Bugzilla::Hook;
|
2008-12-15 15:53:33 +03:00
|
|
|
use Bugzilla::Bug;
|
|
|
|
use Bugzilla::Classification;
|
|
|
|
use Bugzilla::Product;
|
|
|
|
use Bugzilla::Component;
|
|
|
|
use Bugzilla::Status;
|
|
|
|
use Bugzilla::Mailer;
|
2014-01-14 18:58:25 +04:00
|
|
|
use Bugzilla::Diff;
|
2008-12-15 15:53:33 +03:00
|
|
|
|
|
|
|
use Date::Parse;
|
|
|
|
use Date::Format;
|
2014-08-15 16:55:29 +04:00
|
|
|
use POSIX;
|
2008-12-15 15:53:33 +03:00
|
|
|
|
|
|
|
use constant FORMAT_TRIPLE => "%19s|%-28s|%-28s";
|
|
|
|
use constant FORMAT_3_SIZE => [19,28,28];
|
|
|
|
use constant FORMAT_DOUBLE => "%19s %-55s";
|
|
|
|
use constant FORMAT_2_SIZE => [19,55];
|
|
|
|
|
|
|
|
use constant BIT_DIRECT => 1;
|
|
|
|
use constant BIT_WATCHING => 2;
|
|
|
|
|
|
|
|
# We need these strings for the X-Bugzilla-Reasons header
|
|
|
|
# Note: this hash uses "," rather than "=>" to avoid auto-quoting of the LHS.
|
|
|
|
use constant REL_NAMES => {
|
2009-01-13 16:56:07 +03:00
|
|
|
REL_ASSIGNEE , "AssignedTo",
|
2008-12-15 15:53:33 +03:00
|
|
|
REL_REPORTER , "Reporter",
|
|
|
|
REL_QA , "QAcontact",
|
|
|
|
REL_CC , "CC",
|
|
|
|
REL_VOTER , "Voter",
|
|
|
|
REL_GLOBAL_WATCHER, "GlobalWatcher"
|
|
|
|
};
|
|
|
|
|
2010-09-27 20:20:16 +04:00
|
|
|
# Used to send email when an update is done.
|
|
|
|
sub send_results
|
|
|
|
{
|
|
|
|
shift if $_[0] eq __PACKAGE__;
|
|
|
|
my ($vars) = @_;
|
2014-07-28 12:57:30 +04:00
|
|
|
next if $vars->{message} eq 'bugmail' && $vars->{sent_bugmail};
|
|
|
|
# FIXME check if commentsilent is working correctly
|
|
|
|
if ($vars->{message} eq 'flagmail')
|
2013-07-12 11:23:30 +04:00
|
|
|
{
|
2014-07-28 12:57:30 +04:00
|
|
|
$vars->{message} = 'bugmail';
|
|
|
|
$vars->{type} = 'flag';
|
2013-07-12 11:23:30 +04:00
|
|
|
$vars->{sent_bugmail} = SendFlag($vars->{notify_data});
|
2013-07-12 16:51:41 +04:00
|
|
|
$vars->{new_flag} = {
|
|
|
|
name => $vars->{notify_data}->{flag} ? $vars->{notify_data}->{flag}->name : $vars->{notify_data}->{old_flag}->name,
|
|
|
|
status => $vars->{notify_data}->{flag} ? $vars->{notify_data}->{flag}->status : 'X',
|
|
|
|
};
|
2013-08-28 13:49:13 +04:00
|
|
|
$vars->{commentsilent} = 0; # Custis Bug 132647
|
2014-07-28 12:57:30 +04:00
|
|
|
delete $vars->{notify_data}; # erase data, don't store it in session
|
2013-07-12 11:23:30 +04:00
|
|
|
}
|
2014-07-28 12:57:30 +04:00
|
|
|
elsif ($vars->{message} eq 'votes-removed')
|
|
|
|
{
|
|
|
|
$vars->{message} = 'bugmail';
|
|
|
|
$vars->{sent_bugmail} = SendVotesRemoved($vars);
|
|
|
|
delete $vars->{notify_data}; # erase data, don't store it in session
|
|
|
|
}
|
|
|
|
elsif ($vars->{message} eq 'bugmail')
|
2013-07-12 11:23:30 +04:00
|
|
|
{
|
|
|
|
$vars->{sent_bugmail} = Send($vars->{bug_id}, $vars->{mailrecipients}, $vars->{commentsilent});
|
2014-10-10 15:15:48 +04:00
|
|
|
# FIXME Do not use input_params from Bugzilla::BugMail
|
|
|
|
$vars->{commentsilent} = Bugzilla->input_params->{commentsilent} ? 1 : 0;
|
2013-07-12 11:23:30 +04:00
|
|
|
}
|
2010-09-27 20:20:16 +04:00
|
|
|
return $vars;
|
|
|
|
}
|
|
|
|
|
2008-12-15 15:53:33 +03:00
|
|
|
# We use this instead of format because format doesn't deal well with
|
|
|
|
# multi-byte languages.
|
2014-05-19 18:18:31 +04:00
|
|
|
sub multiline_sprintf
|
|
|
|
{
|
2008-12-15 15:53:33 +03:00
|
|
|
my ($format, $args, $sizes) = @_;
|
|
|
|
my @parts;
|
|
|
|
my @my_sizes = @$sizes; # Copy this so we don't modify the input array.
|
2014-05-19 18:18:31 +04:00
|
|
|
foreach my $string (@$args)
|
|
|
|
{
|
2008-12-15 15:53:33 +03:00
|
|
|
my $size = shift @my_sizes;
|
|
|
|
my @pieces = split("\n", wrap_hard($string, $size));
|
|
|
|
push(@parts, \@pieces);
|
|
|
|
}
|
|
|
|
|
|
|
|
my $formatted;
|
2014-05-19 18:18:31 +04:00
|
|
|
while (1)
|
|
|
|
{
|
2008-12-15 15:53:33 +03:00
|
|
|
# Get the first item of each part.
|
|
|
|
my @line = map { shift @$_ } @parts;
|
|
|
|
# If they're all undef, we're done.
|
|
|
|
last if !grep { defined $_ } @line;
|
|
|
|
# Make any single undef item into ''
|
|
|
|
@line = map { defined $_ ? $_ : '' } @line;
|
|
|
|
# And append a formatted line
|
|
|
|
$formatted .= sprintf($format, @line);
|
2009-10-23 20:53:27 +04:00
|
|
|
# Remove trailing spaces, or they become lots of =20's in
|
2008-12-15 15:53:33 +03:00
|
|
|
# quoted-printable emails.
|
|
|
|
$formatted =~ s/\s+$//;
|
|
|
|
$formatted .= "\n";
|
|
|
|
}
|
|
|
|
return $formatted;
|
|
|
|
}
|
|
|
|
|
2014-05-19 18:18:31 +04:00
|
|
|
sub three_columns
|
|
|
|
{
|
2008-12-15 15:53:33 +03:00
|
|
|
return multiline_sprintf(FORMAT_TRIPLE, \@_, FORMAT_3_SIZE);
|
|
|
|
}
|
|
|
|
|
2013-07-12 16:51:41 +04:00
|
|
|
sub SendFlag
|
|
|
|
{
|
2013-07-12 11:23:30 +04:00
|
|
|
my ($flag_data) = (@_);
|
|
|
|
|
2013-07-12 16:51:41 +04:00
|
|
|
my @sent;
|
|
|
|
my @excluded;
|
2013-07-12 11:23:30 +04:00
|
|
|
|
2013-07-12 16:51:41 +04:00
|
|
|
foreach my $email (@{$flag_data->{mail}})
|
|
|
|
{
|
|
|
|
$email = { %$email, %$flag_data };
|
|
|
|
Bugzilla::Hook::process('flag-notify-pre-template', { vars => $email });
|
2013-07-12 11:23:30 +04:00
|
|
|
|
2013-07-12 16:51:41 +04:00
|
|
|
my $template = Bugzilla->template_inner($email->{lang});
|
|
|
|
my $message;
|
|
|
|
$template->process("request/email.txt.tmpl", $email, \$message)
|
|
|
|
|| ThrowTemplateError($template->error());
|
2013-07-12 11:23:30 +04:00
|
|
|
|
2013-07-12 16:51:41 +04:00
|
|
|
Bugzilla->template_inner("");
|
|
|
|
MessageToMTA($message);
|
2013-07-12 11:23:30 +04:00
|
|
|
|
2013-07-12 16:51:41 +04:00
|
|
|
Bugzilla::Hook::process('flag-notify-post-send', { vars => $email });
|
2013-07-12 11:23:30 +04:00
|
|
|
|
2013-07-12 16:51:41 +04:00
|
|
|
push @sent, $email->{to};
|
2013-07-12 11:23:30 +04:00
|
|
|
}
|
|
|
|
|
2013-07-12 16:51:41 +04:00
|
|
|
return { sent => \@sent, excluded => \@excluded };
|
2013-07-12 11:23:30 +04:00
|
|
|
}
|
|
|
|
|
2014-07-28 12:57:30 +04:00
|
|
|
sub SendVotesRemoved
|
|
|
|
{
|
|
|
|
my ($vars) = @_;
|
|
|
|
|
|
|
|
my @to;
|
|
|
|
for (@{$vars->{notify_data}})
|
|
|
|
{
|
|
|
|
$_->{bugid} = $vars->{bug_id};
|
|
|
|
my $voter = new Bugzilla::User($_->{userid});
|
|
|
|
my $template = Bugzilla->template_inner($voter->settings->{lang}->{value});
|
|
|
|
my $msg;
|
|
|
|
$template->process("email/votes-removed.txt.tmpl", $_, \$msg);
|
|
|
|
MessageToMTA($msg);
|
|
|
|
push @to, $voter->login;
|
|
|
|
}
|
|
|
|
Bugzilla->template_inner('');
|
|
|
|
|
|
|
|
return { sent => \@to, excluded => [] };
|
|
|
|
}
|
|
|
|
|
2008-12-15 15:53:33 +03:00
|
|
|
# This is a bit of a hack, basically keeping the old system()
|
|
|
|
# cmd line interface. Should clean this up at some point.
|
|
|
|
#
|
|
|
|
# args: bug_id, and an optional hash ref which may have keys for:
|
|
|
|
# changer, owner, qa, reporter, cc
|
|
|
|
# Optional hash contains values of people which will be forced to those
|
|
|
|
# roles when the email is sent.
|
|
|
|
# All the names are email addresses, not userids
|
|
|
|
# values are scalars, except for cc, which is a list
|
2014-05-19 03:15:46 +04:00
|
|
|
sub Send
|
|
|
|
{
|
2010-06-10 00:21:10 +04:00
|
|
|
my ($id, $forced, $silent) = (@_);
|
|
|
|
|
|
|
|
if ($silent)
|
|
|
|
{
|
|
|
|
Bugzilla->dbh->do('UPDATE bugs SET lastdiffed=NOW() WHERE bug_id = ?', undef, $id);
|
|
|
|
return { commentsilent => 1 };
|
|
|
|
}
|
2008-12-15 15:53:33 +03:00
|
|
|
|
|
|
|
my @headerlist;
|
|
|
|
my %fielddescription;
|
|
|
|
|
|
|
|
my $msg = "";
|
|
|
|
|
|
|
|
my $dbh = Bugzilla->dbh;
|
2010-05-15 00:02:34 +04:00
|
|
|
my $bug = new Bugzilla::Bug($id);
|
2008-12-15 15:53:33 +03:00
|
|
|
|
2014-06-23 18:24:15 +04:00
|
|
|
foreach my $field (Bugzilla->get_fields({ obsolete => 0, sort => 'sortkey' }))
|
2014-05-19 03:15:46 +04:00
|
|
|
{
|
|
|
|
push @headerlist, $field if $field->in_new_bugmail;
|
2008-12-15 15:53:33 +03:00
|
|
|
$fielddescription{$field->name} = $field->description;
|
|
|
|
}
|
|
|
|
|
2014-08-04 18:37:50 +04:00
|
|
|
my ($start, $creation_ts, $end) = $dbh->selectrow_array("SELECT lastdiffed, creation_ts, LOCALTIMESTAMP(0) FROM bugs WHERE bug_id=$id");
|
2008-12-15 15:53:33 +03:00
|
|
|
|
2009-10-23 20:53:27 +04:00
|
|
|
# User IDs of people in various roles. More than one person can 'have' a
|
2008-12-15 15:53:33 +03:00
|
|
|
# role, if the person in that role has changed, or people are watching.
|
2014-05-19 03:15:46 +04:00
|
|
|
my $reporter = $bug->reporter_id;
|
|
|
|
my @assignees = ($bug->assigned_to_id);
|
|
|
|
my @qa_contacts = ($bug->qa_contact_id);
|
|
|
|
my @ccs = map { $_->id } @{$bug->cc_users};
|
|
|
|
my @cc_login_names = map { $_->login } @{$bug->cc_users};
|
2008-12-15 15:53:33 +03:00
|
|
|
|
|
|
|
# Include the people passed in as being in particular roles.
|
|
|
|
# This can include people who used to hold those roles.
|
|
|
|
# At this point, we don't care if there are duplicates in these arrays.
|
2014-05-19 03:15:46 +04:00
|
|
|
my $changer = $forced->{changer};
|
|
|
|
if ($forced->{owner})
|
|
|
|
{
|
2014-10-13 19:45:17 +04:00
|
|
|
push @assignees, Bugzilla::User::login_to_id($forced->{owner}, THROW_ERROR);
|
2008-12-15 15:53:33 +03:00
|
|
|
}
|
2009-10-23 20:53:27 +04:00
|
|
|
|
2014-05-19 03:15:46 +04:00
|
|
|
if ($forced->{qacontact})
|
|
|
|
{
|
2014-10-13 19:45:17 +04:00
|
|
|
push @qa_contacts, Bugzilla::User::login_to_id($forced->{qacontact}, THROW_ERROR);
|
2008-12-15 15:53:33 +03:00
|
|
|
}
|
2009-10-23 20:53:27 +04:00
|
|
|
|
2014-05-19 03:15:46 +04:00
|
|
|
if ($forced->{cc})
|
|
|
|
{
|
|
|
|
foreach my $cc (@{$forced->{cc}})
|
|
|
|
{
|
2014-10-13 19:45:17 +04:00
|
|
|
push @ccs, Bugzilla::User::login_to_id($cc, THROW_ERROR);
|
2008-12-15 15:53:33 +03:00
|
|
|
}
|
|
|
|
}
|
2009-10-23 20:53:27 +04:00
|
|
|
|
2014-05-19 03:15:46 +04:00
|
|
|
my %values;
|
|
|
|
|
2008-12-15 15:53:33 +03:00
|
|
|
# Convert to names, for later display
|
|
|
|
# If no changer is specified, then it has no name.
|
2014-05-19 03:15:46 +04:00
|
|
|
if ($changer)
|
|
|
|
{
|
|
|
|
$changer = Bugzilla::User->new({ name => $changer }) if !ref $changer;
|
|
|
|
$values{changername} = $changer->name if $changer;
|
|
|
|
$values{changer} = $changer;
|
2008-12-15 15:53:33 +03:00
|
|
|
}
|
|
|
|
|
2014-08-04 18:37:50 +04:00
|
|
|
my @args = ($id, $start || $creation_ts, $end);
|
|
|
|
my @dep_args = ($id, $start || $creation_ts, $end);
|
|
|
|
my $when_restriction = ' AND bug_when > ? AND bug_when <= ?';
|
2008-12-15 15:53:33 +03:00
|
|
|
my $diffs = $dbh->selectall_arrayref(
|
2014-08-04 18:37:50 +04:00
|
|
|
"(SELECT profiles.login_name, profiles.realname, fielddefs.description fielddesc,
|
|
|
|
fielddefs.sortkey fieldsortkey,
|
2009-10-23 20:53:27 +04:00
|
|
|
bugs_activity.bug_when, bugs_activity.removed,
|
2013-10-01 14:54:20 +04:00
|
|
|
bugs_activity.added, bugs_activity.attach_id, fielddefs.name fieldname, null as comment_id, null as comment_count
|
2008-12-15 15:53:33 +03:00
|
|
|
FROM bugs_activity
|
|
|
|
INNER JOIN fielddefs
|
|
|
|
ON fielddefs.id = bugs_activity.fieldid
|
|
|
|
INNER JOIN profiles
|
|
|
|
ON profiles.userid = bugs_activity.who
|
|
|
|
WHERE bugs_activity.bug_id = ?
|
2014-08-04 18:37:50 +04:00
|
|
|
$when_restriction)
|
|
|
|
UNION (SELECT profile1.login_name, profile1.realname, fielddefs1.description fielddesc,
|
|
|
|
fielddefs1.sortkey fieldsortkey,
|
2013-10-01 14:54:20 +04:00
|
|
|
lh.bug_when, lh.oldthetext removed, lh.thetext added, null, fielddefs1.name fieldname, lh.comment_id, lh.comment_count
|
2013-09-26 12:04:33 +04:00
|
|
|
FROM longdescs_history lh
|
|
|
|
INNER JOIN profiles profile1
|
|
|
|
ON profile1.userid = lh.who
|
|
|
|
INNER JOIN fielddefs fielddefs1
|
2014-06-23 18:18:14 +04:00
|
|
|
ON fielddefs1.name = 'longdesc'
|
2013-09-26 12:04:33 +04:00
|
|
|
WHERE lh.bug_id = ?
|
2014-08-04 18:37:50 +04:00
|
|
|
$when_restriction)
|
|
|
|
ORDER BY bug_when, fieldsortkey", {Slice=>{}}, @args, @args);
|
2009-07-17 19:03:45 +04:00
|
|
|
|
2008-12-15 15:53:33 +03:00
|
|
|
my @new_depbugs;
|
2014-05-19 18:18:31 +04:00
|
|
|
foreach my $diff (@$diffs)
|
|
|
|
{
|
2010-05-11 18:34:12 +04:00
|
|
|
$diff->{attach_id} and $diff->{fielddesc} =~ s/^(Attachment )?/Attachment #$diff->{attach_id} /;
|
|
|
|
if ($diff->{fieldname} eq 'estimated_time' ||
|
2014-05-19 18:18:31 +04:00
|
|
|
$diff->{fieldname} eq 'remaining_time')
|
|
|
|
{
|
2010-05-11 18:34:12 +04:00
|
|
|
$diff->{removed} = format_time_decimal($diff->{removed});
|
|
|
|
$diff->{added} = format_time_decimal($diff->{added});
|
2008-12-15 15:53:33 +03:00
|
|
|
}
|
2014-05-19 18:18:31 +04:00
|
|
|
if ($diff->{fieldname} eq 'dependson')
|
|
|
|
{
|
2010-05-11 18:34:12 +04:00
|
|
|
push(@new_depbugs, grep {$_ =~ /^\d+$/} split(/[\s,]+/, $diff->{added}));
|
2008-12-15 15:53:33 +03:00
|
|
|
}
|
2014-05-19 18:18:31 +04:00
|
|
|
if ($diff->{attach_id})
|
|
|
|
{
|
2010-05-11 18:34:12 +04:00
|
|
|
($diff->{isprivate}) = $dbh->selectrow_array(
|
2008-12-15 15:53:33 +03:00
|
|
|
'SELECT isprivate FROM attachments WHERE attach_id = ?',
|
2010-05-11 18:34:12 +04:00
|
|
|
undef, ($diff->{attach_id}));
|
2008-12-15 15:53:33 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
my @depbugs;
|
|
|
|
my $deptext = "";
|
|
|
|
# Do not include data about dependent bugs when they have just been added.
|
|
|
|
# Completely skip checking for dependent bugs on bug creation as all
|
|
|
|
# dependencies bugs will just have been added.
|
2014-05-19 18:18:31 +04:00
|
|
|
if ($start)
|
|
|
|
{
|
2008-12-15 15:53:33 +03:00
|
|
|
my $dep_restriction = "";
|
2014-05-19 18:18:31 +04:00
|
|
|
if (scalar @new_depbugs)
|
|
|
|
{
|
|
|
|
$dep_restriction = "AND bugs_activity.bug_id NOT IN (" . join(", ", @new_depbugs) . ")";
|
2008-12-15 15:53:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
my $dependency_diffs = $dbh->selectall_arrayref(
|
2010-05-11 18:48:00 +04:00
|
|
|
"SELECT bugs_activity.bug_id dep, bugs.short_desc, fielddefs.name fieldname,
|
2010-05-11 19:01:51 +04:00
|
|
|
fielddefs.description fielddesc, bugs_activity.removed, bugs_activity.added,
|
2010-05-11 18:57:02 +04:00
|
|
|
profiles.login_name, profiles.realname
|
2008-12-15 15:53:33 +03:00
|
|
|
FROM bugs_activity
|
|
|
|
INNER JOIN bugs
|
|
|
|
ON bugs.bug_id = bugs_activity.bug_id
|
|
|
|
INNER JOIN dependencies
|
|
|
|
ON bugs_activity.bug_id = dependencies.dependson
|
|
|
|
INNER JOIN fielddefs
|
|
|
|
ON fielddefs.id = bugs_activity.fieldid
|
2010-05-11 18:57:02 +04:00
|
|
|
INNER JOIN profiles
|
|
|
|
ON profiles.userid = bugs_activity.who
|
2008-12-15 15:53:33 +03:00
|
|
|
WHERE dependencies.blocked = ?
|
|
|
|
AND (fielddefs.name = 'bug_status'
|
|
|
|
OR fielddefs.name = 'resolution')
|
|
|
|
$when_restriction
|
|
|
|
$dep_restriction
|
2014-08-04 18:37:50 +04:00
|
|
|
ORDER BY bugs_activity.bug_when, bugs.bug_id, fielddefs.sortkey", {Slice=>{}}, @dep_args);
|
2008-12-15 15:53:33 +03:00
|
|
|
|
|
|
|
my $thisdiff = "";
|
|
|
|
my $lastbug = "";
|
|
|
|
my $interestingchange = 0;
|
2009-07-17 19:03:45 +04:00
|
|
|
my @diff_tmp = ();
|
2014-05-19 18:18:31 +04:00
|
|
|
foreach my $dep_diff (@$dependency_diffs)
|
|
|
|
{
|
2010-05-11 18:34:12 +04:00
|
|
|
$dep_diff->{bug_id} = $id;
|
|
|
|
$dep_diff->{type} = 'dep';
|
2014-05-19 18:18:31 +04:00
|
|
|
if ($dep_diff->{dep} ne $lastbug)
|
|
|
|
{
|
|
|
|
if ($interestingchange)
|
|
|
|
{
|
2010-05-11 18:34:12 +04:00
|
|
|
push @$diffs, @diff_tmp;
|
2008-12-15 15:53:33 +03:00
|
|
|
}
|
2010-05-11 18:34:12 +04:00
|
|
|
@diff_tmp = ();
|
|
|
|
$lastbug = $dep_diff->{dep};
|
2008-12-15 15:53:33 +03:00
|
|
|
$interestingchange = 0;
|
|
|
|
}
|
2014-05-19 18:18:31 +04:00
|
|
|
if ($dep_diff->{fieldname} eq 'bug_status' &&
|
2014-07-23 19:47:56 +04:00
|
|
|
scalar(grep { $_->is_open && $_->name eq $dep_diff->{removed} } Bugzilla::Status->get_all) !=
|
|
|
|
scalar(grep { $_->is_open && $_->name eq $dep_diff->{added} } Bugzilla::Status->get_all))
|
2008-12-15 15:53:33 +03:00
|
|
|
{
|
|
|
|
$interestingchange = 1;
|
|
|
|
}
|
2010-05-11 18:34:12 +04:00
|
|
|
push @depbugs, $dep_diff->{dep};
|
|
|
|
push @diff_tmp, $dep_diff;
|
2008-12-15 15:53:33 +03:00
|
|
|
}
|
|
|
|
|
2014-05-19 18:18:31 +04:00
|
|
|
if ($interestingchange)
|
|
|
|
{
|
2010-05-11 18:34:12 +04:00
|
|
|
push @$diffs, @diff_tmp;
|
2008-12-15 15:53:33 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-15 00:02:34 +04:00
|
|
|
my $comments = $bug->comments({ after => $start, to => $end });
|
2008-12-15 15:53:33 +03:00
|
|
|
|
|
|
|
###########################################################################
|
|
|
|
# Start of email filtering code
|
|
|
|
###########################################################################
|
2009-10-23 20:53:27 +04:00
|
|
|
|
2008-12-15 15:53:33 +03:00
|
|
|
# A user_id => roles hash to keep track of people.
|
|
|
|
my %recipients;
|
|
|
|
my %watching;
|
2009-10-23 20:53:27 +04:00
|
|
|
|
2008-12-15 15:53:33 +03:00
|
|
|
# Now we work out all the people involved with this bug, and note all of
|
|
|
|
# the relationships in a hash. The keys are userids, the values are an
|
|
|
|
# array of role constants.
|
2009-10-23 20:53:27 +04:00
|
|
|
|
2008-12-15 15:53:33 +03:00
|
|
|
# Voters
|
2014-05-19 03:15:46 +04:00
|
|
|
my $voters = $dbh->selectcol_arrayref("SELECT who FROM votes WHERE bug_id = ?", undef, ($id));
|
2009-10-23 20:53:27 +04:00
|
|
|
|
2008-12-15 15:53:33 +03:00
|
|
|
$recipients{$_}->{+REL_VOTER} = BIT_DIRECT foreach (@$voters);
|
|
|
|
|
|
|
|
# CCs
|
|
|
|
$recipients{$_}->{+REL_CC} = BIT_DIRECT foreach (@ccs);
|
2009-10-23 20:53:27 +04:00
|
|
|
|
2008-12-15 15:53:33 +03:00
|
|
|
# Reporter (there's only ever one)
|
|
|
|
$recipients{$reporter}->{+REL_REPORTER} = BIT_DIRECT;
|
2009-10-23 20:53:27 +04:00
|
|
|
|
2008-12-15 15:53:33 +03:00
|
|
|
# QA Contact
|
2014-08-01 21:13:45 +04:00
|
|
|
if (Bugzilla->get_field('qa_contact')->enabled)
|
2014-05-19 18:18:31 +04:00
|
|
|
{
|
|
|
|
foreach (@qa_contacts)
|
|
|
|
{
|
2008-12-15 15:53:33 +03:00
|
|
|
# QA Contact can be blank; ignore it if so.
|
|
|
|
$recipients{$_}->{+REL_QA} = BIT_DIRECT if $_;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Assignee
|
|
|
|
$recipients{$_}->{+REL_ASSIGNEE} = BIT_DIRECT foreach (@assignees);
|
|
|
|
|
2009-10-23 20:53:27 +04:00
|
|
|
# The last relevant set of people are those who are being removed from
|
2008-12-15 15:53:33 +03:00
|
|
|
# their roles in this change. We get their names out of the diffs.
|
2014-05-19 18:18:31 +04:00
|
|
|
foreach my $diff (@$diffs)
|
|
|
|
{
|
|
|
|
if ($diff->{removed})
|
|
|
|
{
|
2008-12-15 15:53:33 +03:00
|
|
|
# You can't stop being the reporter, and mail isn't sent if you
|
|
|
|
# remove your vote.
|
|
|
|
# Ignore people whose user account has been deleted or renamed.
|
2014-05-19 18:18:31 +04:00
|
|
|
if ($diff->{fielddesc} eq "CC")
|
|
|
|
{
|
|
|
|
foreach my $cc_user (split(/[\s,]+/, $diff->{removed}))
|
|
|
|
{
|
2014-10-13 19:45:17 +04:00
|
|
|
my $uid = Bugzilla::User::login_to_id($cc_user);
|
2008-12-15 15:53:33 +03:00
|
|
|
$recipients{$uid}->{+REL_CC} = BIT_DIRECT if $uid;
|
|
|
|
}
|
|
|
|
}
|
2014-05-19 18:18:31 +04:00
|
|
|
elsif ($diff->{fielddesc} eq "QAContact")
|
|
|
|
{
|
2014-10-13 19:45:17 +04:00
|
|
|
my $uid = Bugzilla::User::login_to_id($diff->{removed});
|
2008-12-15 15:53:33 +03:00
|
|
|
$recipients{$uid}->{+REL_QA} = BIT_DIRECT if $uid;
|
|
|
|
}
|
2014-05-19 18:18:31 +04:00
|
|
|
elsif ($diff->{fielddesc} eq "AssignedTo")
|
|
|
|
{
|
2014-10-13 19:45:17 +04:00
|
|
|
my $uid = Bugzilla::User::login_to_id($diff->{removed});
|
2008-12-15 15:53:33 +03:00
|
|
|
$recipients{$uid}->{+REL_ASSIGNEE} = BIT_DIRECT if $uid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-10-23 20:53:27 +04:00
|
|
|
|
2014-05-19 18:18:31 +04:00
|
|
|
Bugzilla::Hook::process('bugmail_recipients', { bug => $bug, recipients => \%recipients });
|
2010-05-15 00:02:34 +04:00
|
|
|
|
2009-12-17 14:52:27 +03:00
|
|
|
# Find all those user-watching anyone on the current list, who is not
|
|
|
|
# on it already themselves.
|
|
|
|
my $involved = join(",", keys %recipients);
|
|
|
|
|
2014-05-19 18:18:31 +04:00
|
|
|
my $userwatchers = $dbh->selectall_arrayref(
|
|
|
|
"SELECT watcher, watched FROM watch WHERE watched IN ($involved)"
|
|
|
|
);
|
2009-12-17 14:52:27 +03:00
|
|
|
|
|
|
|
# Mark these people as having the role of the person they are watching
|
2014-05-19 18:18:31 +04:00
|
|
|
foreach my $watch (@$userwatchers)
|
|
|
|
{
|
|
|
|
while (my ($role, $bits) = each %{$recipients{$watch->[1]}})
|
|
|
|
{
|
|
|
|
$recipients{$watch->[0]}->{$role} |= BIT_WATCHING if $bits & BIT_DIRECT;
|
2009-12-17 14:52:27 +03:00
|
|
|
}
|
2009-07-29 15:21:49 +04:00
|
|
|
push(@{$watching{$watch->[0]}}, $watch->[1]);
|
2008-12-15 15:53:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
# Global watcher
|
2014-05-19 18:18:31 +04:00
|
|
|
my @watchers = split(/[,\s]+/, Bugzilla->params->{globalwatchers});
|
|
|
|
foreach (@watchers)
|
|
|
|
{
|
2014-10-13 19:45:17 +04:00
|
|
|
my $watcher_id = Bugzilla::User::login_to_id($_);
|
2008-12-15 15:53:33 +03:00
|
|
|
next unless $watcher_id;
|
|
|
|
$recipients{$watcher_id}->{+REL_GLOBAL_WATCHER} = BIT_DIRECT;
|
|
|
|
}
|
|
|
|
|
|
|
|
# We now have a complete set of all the users, and their relationships to
|
|
|
|
# the bug in question. However, we are not necessarily going to mail them
|
|
|
|
# all - there are preferences, permissions checks and all sorts to do yet.
|
|
|
|
my @sent;
|
|
|
|
my @excluded;
|
|
|
|
|
2014-05-19 18:18:31 +04:00
|
|
|
foreach my $user_id (keys %recipients)
|
|
|
|
{
|
2008-12-15 15:53:33 +03:00
|
|
|
my %rels_which_want;
|
|
|
|
my $sent_mail = 0;
|
|
|
|
|
|
|
|
my $user = new Bugzilla::User($user_id);
|
|
|
|
# Deleted users must be excluded.
|
|
|
|
next unless $user;
|
|
|
|
|
2014-05-19 18:18:31 +04:00
|
|
|
if ($user->can_see_bug($id))
|
|
|
|
{
|
2008-12-15 15:53:33 +03:00
|
|
|
# Go through each role the user has and see if they want mail in
|
|
|
|
# that role.
|
2014-05-19 18:18:31 +04:00
|
|
|
foreach my $relationship (keys %{$recipients{$user_id}})
|
|
|
|
{
|
|
|
|
if ($user->wants_bug_mail($id, $relationship, $diffs, $comments, $deptext, $changer, !$start))
|
2008-12-15 15:53:33 +03:00
|
|
|
{
|
2014-05-19 03:15:46 +04:00
|
|
|
$rels_which_want{$relationship} = $recipients{$user_id}->{$relationship};
|
2008-12-15 15:53:33 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-07-17 19:03:45 +04:00
|
|
|
|
2014-05-19 18:18:31 +04:00
|
|
|
if (scalar(%rels_which_want))
|
|
|
|
{
|
2008-12-15 15:53:33 +03:00
|
|
|
# So the user exists, can see the bug, and wants mail in at least
|
|
|
|
# one role. But do we want to send it to them?
|
|
|
|
|
2010-05-26 21:15:20 +04:00
|
|
|
# Make sure the user isn't in the nomail list.
|
2014-05-19 18:18:31 +04:00
|
|
|
if ($user->email_enabled)
|
|
|
|
{
|
2008-12-15 15:53:33 +03:00
|
|
|
# OK, OK, if we must. Email the user.
|
2014-05-19 18:18:31 +04:00
|
|
|
$sent_mail = sendMail({
|
2010-05-17 16:11:17 +04:00
|
|
|
bug => $bug,
|
2009-07-17 19:03:45 +04:00
|
|
|
user => $user,
|
|
|
|
headers => \@headerlist,
|
|
|
|
rels => \%rels_which_want,
|
2014-05-19 18:18:31 +04:00
|
|
|
changer => $values{changer},
|
|
|
|
changername => $values{changername},
|
2009-07-17 19:03:45 +04:00
|
|
|
fields => \%fielddescription,
|
2010-05-11 18:34:12 +04:00
|
|
|
diffs => $diffs,
|
2014-05-19 18:18:31 +04:00
|
|
|
new_comments => $comments,
|
2009-07-17 19:03:45 +04:00
|
|
|
isnew => !$start,
|
|
|
|
watch => exists $watching{$user_id} ? $watching{$user_id} : undef,
|
2014-05-19 18:18:31 +04:00
|
|
|
});
|
2008-12-15 15:53:33 +03:00
|
|
|
}
|
|
|
|
}
|
2009-10-23 20:53:27 +04:00
|
|
|
|
2014-05-19 18:18:31 +04:00
|
|
|
if ($sent_mail)
|
|
|
|
{
|
2009-10-23 20:53:27 +04:00
|
|
|
push(@sent, $user->login);
|
|
|
|
}
|
2014-05-19 18:18:31 +04:00
|
|
|
else
|
|
|
|
{
|
2009-10-23 20:53:27 +04:00
|
|
|
push(@excluded, $user->login);
|
|
|
|
}
|
2008-12-15 15:53:33 +03:00
|
|
|
}
|
2009-10-23 20:53:27 +04:00
|
|
|
|
2014-05-19 18:18:31 +04:00
|
|
|
$dbh->do('UPDATE bugs SET lastdiffed = ? WHERE bug_id = ?', undef, ($end, $id));
|
2008-12-15 15:53:33 +03:00
|
|
|
|
2014-05-19 18:18:31 +04:00
|
|
|
return { sent => \@sent, excluded => \@excluded };
|
2008-12-15 15:53:33 +03:00
|
|
|
}
|
|
|
|
|
2009-07-17 19:03:45 +04:00
|
|
|
sub sendMail
|
|
|
|
{
|
2014-05-19 18:18:31 +04:00
|
|
|
my ($args) = @_;
|
|
|
|
|
|
|
|
my $user = $args->{user};
|
|
|
|
my $bug = $args->{bug};
|
|
|
|
my $new_comments = $args->{new_comments};
|
2008-12-15 15:53:33 +03:00
|
|
|
|
2010-05-11 18:34:12 +04:00
|
|
|
# Filter changes by verifying the user should see them
|
|
|
|
my $new_diffs = [];
|
2014-05-19 18:18:31 +04:00
|
|
|
foreach my $diff (@{$args->{diffs}})
|
2009-07-22 17:07:10 +04:00
|
|
|
{
|
2010-05-26 21:15:20 +04:00
|
|
|
# Exclude diffs with timetracking information for non-timetrackers
|
|
|
|
# Exclude diffs with private attachments for non-insiders
|
|
|
|
# Exclude dependency diffs with if dependencies are not visible to the user
|
2010-05-28 22:35:07 +04:00
|
|
|
if (exists($diff->{fieldname}) &&
|
2014-06-23 18:22:24 +04:00
|
|
|
(!TIMETRACKING_FIELDS->{$diff->{fieldname}} || $user->is_timetracker) &&
|
2010-05-28 22:35:07 +04:00
|
|
|
(!$diff->{isprivate} || $user->is_insider) &&
|
2010-05-26 21:15:20 +04:00
|
|
|
(!$diff->{dep} || $user->can_see_bug($diff->{dep})))
|
2009-07-29 15:21:49 +04:00
|
|
|
{
|
2010-05-11 18:34:12 +04:00
|
|
|
push @$new_diffs, $diff;
|
2008-12-15 15:53:33 +03:00
|
|
|
}
|
|
|
|
}
|
2009-07-22 17:07:10 +04:00
|
|
|
|
2014-05-19 18:18:31 +04:00
|
|
|
if (!$user->is_insider)
|
|
|
|
{
|
2010-05-26 21:15:20 +04:00
|
|
|
# Exclude private comments for non-insiders
|
2014-05-19 18:18:31 +04:00
|
|
|
$new_comments = [ grep { !$_->is_private } @$new_comments ];
|
2010-05-15 00:02:34 +04:00
|
|
|
}
|
|
|
|
|
2014-05-19 18:18:31 +04:00
|
|
|
if (!@$new_diffs && !scalar(@$new_comments) && !$args->{isnew})
|
|
|
|
{
|
2009-07-22 17:07:10 +04:00
|
|
|
# Whoops, no differences!
|
|
|
|
return 0;
|
2008-12-15 15:53:33 +03:00
|
|
|
}
|
2009-07-22 17:07:10 +04:00
|
|
|
|
2014-05-19 18:18:31 +04:00
|
|
|
my $showfieldvalues = []; # for HTML emails
|
|
|
|
if ($args->{isnew})
|
2014-05-19 03:15:46 +04:00
|
|
|
{
|
|
|
|
my ($value, $f);
|
2014-05-19 18:18:31 +04:00
|
|
|
foreach my $field (@{$args->{headers}})
|
2014-05-19 03:15:46 +04:00
|
|
|
{
|
|
|
|
$f = $field->name;
|
|
|
|
$value = $bug->get_string($field);
|
2009-02-09 18:57:34 +03:00
|
|
|
# If there isn't anything to show, don't include this header.
|
|
|
|
next unless $value;
|
2010-05-11 18:34:12 +04:00
|
|
|
# Only send time tracking information if it is enabled and the user is in the group.
|
2014-06-23 18:22:24 +04:00
|
|
|
if (!TIMETRACKING_FIELDS->{$f} || $user->is_timetracker)
|
2014-05-19 03:15:46 +04:00
|
|
|
{
|
2014-05-19 18:18:31 +04:00
|
|
|
push @$showfieldvalues, { desc => $args->{fields}->{$f}, value => $value };
|
2009-02-09 18:57:34 +03:00
|
|
|
}
|
|
|
|
}
|
2008-12-15 15:53:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
my (@reasons, @reasons_watch);
|
2014-05-19 18:18:31 +04:00
|
|
|
while (my ($relationship, $bits) = each %{$args->{rels}})
|
|
|
|
{
|
2008-12-15 15:53:33 +03:00
|
|
|
push(@reasons, $relationship) if ($bits & BIT_DIRECT);
|
|
|
|
push(@reasons_watch, $relationship) if ($bits & BIT_WATCHING);
|
|
|
|
}
|
|
|
|
|
|
|
|
my @headerrel = map { REL_NAMES->{$_} } @reasons;
|
|
|
|
my @watchingrel = map { REL_NAMES->{$_} } @reasons_watch;
|
2009-07-22 17:07:10 +04:00
|
|
|
push @headerrel, 'None' unless @headerrel;
|
|
|
|
push @watchingrel, 'None' unless @watchingrel;
|
2014-09-03 19:27:55 +04:00
|
|
|
push @watchingrel, map { $_->login } @{ Bugzilla::User->new_from_list($args->{watch}) };
|
2008-12-15 15:53:33 +03:00
|
|
|
|
2014-05-19 18:18:31 +04:00
|
|
|
for my $change (@$new_diffs)
|
2013-11-27 14:18:02 +04:00
|
|
|
{
|
2014-01-14 18:58:25 +04:00
|
|
|
my $field = Bugzilla->get_field($change->{fieldname});
|
|
|
|
if (($change->{fieldname} eq 'longdesc' || $field->{type} eq FIELD_TYPE_TEXTAREA) && !$change->{lines})
|
2013-11-27 14:18:02 +04:00
|
|
|
{
|
2014-01-14 18:58:25 +04:00
|
|
|
my $diff = new Bugzilla::Diff($change->{removed}, $change->{added});
|
|
|
|
$change->{lines} = $diff->get_table;
|
|
|
|
$change->{diff_removed} = $diff->get_removed;
|
|
|
|
$change->{diff_added} = $diff->get_added;
|
2013-11-27 14:18:02 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-15 15:53:33 +03:00
|
|
|
my $vars = {
|
2014-05-19 18:18:31 +04:00
|
|
|
isnew => $args->{isnew},
|
|
|
|
showfieldvalues => $showfieldvalues,
|
2009-07-22 17:07:10 +04:00
|
|
|
to => $user->email,
|
2010-05-11 18:34:12 +04:00
|
|
|
to_user => $user,
|
2010-05-17 16:11:17 +04:00
|
|
|
bug => $bug,
|
2014-05-19 18:18:31 +04:00
|
|
|
bugid => $bug->id,
|
2009-07-22 17:07:10 +04:00
|
|
|
reasons => \@reasons,
|
|
|
|
reasons_watch => \@reasons_watch,
|
|
|
|
reasonsheader => join(" ", @headerrel),
|
2008-12-15 15:53:33 +03:00
|
|
|
reasonswatchheader => join(" ", @watchingrel),
|
2014-05-19 18:18:31 +04:00
|
|
|
changer => $args->{changer},
|
|
|
|
changername => $args->{changername},
|
|
|
|
diffs => $new_diffs,
|
|
|
|
new_comments => $new_comments,
|
|
|
|
threadingmarker => build_thread_marker($bug->id, $user->id, $args->{isnew}),
|
2010-05-11 18:34:12 +04:00
|
|
|
three_columns => \&three_columns,
|
2008-12-15 15:53:33 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
my $msg;
|
2009-10-14 19:22:05 +04:00
|
|
|
my $tmpl = '';
|
|
|
|
|
2009-01-13 16:56:07 +03:00
|
|
|
my $template = Bugzilla->template_inner($user->settings->{lang}->{value});
|
2009-10-14 19:22:05 +04:00
|
|
|
Bugzilla::Hook::process('bugmail-pre_template', { tmpl => \$tmpl, vars => $vars });
|
|
|
|
$tmpl = "email/newchangedmail.txt.tmpl" unless $template->template_exists($tmpl);
|
|
|
|
$template->process($tmpl, $vars, \$msg) || ThrowTemplateError($template->error());
|
2008-12-15 15:53:33 +03:00
|
|
|
Bugzilla->template_inner("");
|
|
|
|
|
2014-08-15 16:55:29 +04:00
|
|
|
logMail($vars);
|
2008-12-15 15:53:33 +03:00
|
|
|
MessageToMTA($msg);
|
|
|
|
|
2010-07-19 14:53:49 +04:00
|
|
|
Bugzilla::Hook::process('bugmail-post_send', { tmpl => \$tmpl, vars => $vars });
|
2009-08-28 16:05:50 +04:00
|
|
|
|
2008-12-15 15:53:33 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-08-15 16:55:29 +04:00
|
|
|
# Log all messages with comment and diff count to data/maillog
|
|
|
|
sub logMail
|
|
|
|
{
|
|
|
|
my ($vars) = @_;
|
|
|
|
my $datadir = bz_locations()->{datadir};
|
|
|
|
my $fd;
|
|
|
|
if (-w "$datadir/maillog" && open $fd, ">>$datadir/maillog")
|
|
|
|
{
|
|
|
|
my $s = [ POSIX::strftime("%Y-%m-%d %H:%M:%S: ", localtime) . ($vars->{isnew} ? "" : "Re: ") . "Bug #$vars->{bugid} mail to $vars->{to}" ];
|
|
|
|
if ($vars->{new_comments} && @{$vars->{new_comments}})
|
|
|
|
{
|
|
|
|
push @$s, scalar(@{$vars->{new_comments}}) . ' comment(s) (#' . (join ',', map { $_->{count} } @{$vars->{new_comments}}) . ')';
|
|
|
|
}
|
|
|
|
if ($vars->{diffarray} && @{$vars->{diffarray}})
|
|
|
|
{
|
|
|
|
push @$s, scalar(grep { $_->{type} eq 'change' } @{$vars->{diffarray}}) . ' diffs';
|
|
|
|
}
|
|
|
|
$s = join "; ", @$s;
|
|
|
|
print $fd $s, "\n";
|
|
|
|
close $fd;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-15 15:53:33 +03:00
|
|
|
1;
|