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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
#!/usr/bin/perl -wT
# -*- Mode: perl; indent-tabs-mode: nil -*-
#
# 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): Erik Stambaugh <erik@dasbistro.com>
# Gervase Markham <gerv@gerv.net>
# Matt Tyson <mtyson@redhat.com>
use strict;
use warnings;
use 5.10.1;
use lib qw(. lib);
BEGIN {
use Bugzilla;
Bugzilla->extensions;
}
use Bugzilla::User;
use Bugzilla::Mailer;
use Bugzilla::Extension::RequestWhiner::Constants;
my $dbh = Bugzilla->dbh;
my $sth_get_requests = $dbh->prepare(
"SELECT profiles.login_name,
flagtypes.name,
flags.attach_id,
bugs.bug_id,
bugs.short_desc, "
. $dbh->sql_to_days('NOW()') . " - "
. $dbh->sql_to_days('flags.modification_date') . "
AS age_in_days
FROM flags
JOIN bugs ON bugs.bug_id = flags.bug_id,
flagtypes,
profiles
WHERE flags.status = '?'
AND flags.requestee_id = profiles.userid
AND flags.type_id = flagtypes.id
AND "
. $dbh->sql_to_days('NOW()') . " - "
. $dbh->sql_to_days('flags.modification_date') . " > "
. WHINE_AFTER_DAYS . "
ORDER BY flags.modification_date"
);
$sth_get_requests->execute();
# Build data structure
my $requests = {};
while (
my ($login_name, $flag_name, $attach_id, $bug_id, $short_desc, $age_in_days)
= $sth_get_requests->fetchrow_array())
{
if (!defined($requests->{$login_name})) {
$requests->{$login_name} = {};
}
if (!defined($requests->{$login_name}->{$flag_name})) {
$requests->{$login_name}->{$flag_name} = [];
}
push(
@{$requests->{$login_name}->{$flag_name}},
{
bug_id => $bug_id,
attach_id => $attach_id,
summary => $short_desc,
age => $age_in_days
}
);
}
$sth_get_requests->finish();
foreach my $recipient (keys %$requests) {
my $user = new Bugzilla::User({name => $recipient});
# Don't send any email if email is disabled, or if the account is disabled.
next if $user->email_disabled;
next if length($user->disabledtext) > 0;
mail({
from => Bugzilla->params->{'mailfrom'},
recipient => $user,
subject => "Your Outstanding Requests",
requests => $requests->{$recipient},
threshold => WHINE_AFTER_DAYS
});
}
exit;
###############################################################################
# Functions
#
# This function will check the users preferences and only send HTML email
# if they have enabled HTML mails in their user config.
#
###############################################################################
sub mail {
my $args = shift;
my $addressee = $args->{recipient};
my $template
= Bugzilla->template_inner($addressee->settings->{'lang'}->{'value'});
# Variables to hold the template output.
my ($msg_header, $msg_body);
# Create the email header
$template->process("requestwhiner/mail-header.tmpl", $args, \$msg_header)
or die($template->error());
# Create the plain text version
$template->process("requestwhiner/mail.txt.tmpl", $args, \$msg_body)
or die($template->error());
my @parts = (Email::MIME->create(
attributes => {content_type => "text/plain",},
body => $msg_body
));
# Check the users email settings and supply the email in their preferred
# format only.
if ($addressee->setting('email_format') eq 'html') {
# If the user wants HTML,
my $msg_body_html;
$template->process("requestwhiner/mail.html.tmpl", $args, \$msg_body_html)
or die($template->error());
push @parts,
Email::MIME->create(
attributes => {content_type => "text/html",},
body => $msg_body_html
);
}
my $email = new Email::MIME("$msg_header\n");
if (scalar(@parts) == 1) {
$email->content_type_set($parts[0]->content_type);
}
else {
$email->content_type_set('multipart/alternative');
$email->charset_set('UTF-8') if Bugzilla->params->{'utf8'};
}
$email->parts_set(\@parts);
MessageToMTA($email);
return;
}
|