whineatnews.pl 2.36 KB
Newer Older
1
#!/usr/bin/perl -w
2 3
# -*- Mode: perl; indent-tabs-mode: nil -*-
#
4 5 6 7 8 9 10 11 12 13
# 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.
#
14
# The Original Code is the Bugzilla Bug Tracking System.
15
#
16
# The Initial Developer of the Original Code is Netscape Communications
17 18 19 20
# Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
21 22 23 24 25 26 27 28 29 30 31 32 33 34
# Contributor(s): Terry Weissman <terry@mozilla.org>


# This is a script suitable for running once a day from a cron job.  It 
# looks at all the bugs, and sends whiny mail to anyone who has a bug 
# assigned to them that has status NEW that has not been touched for
# more than 7 days.

use strict;

require "globals.pl";

ConnectToDatabase();

35
SendSQL("select bug_id,short_desc,login_name from bugs,profiles where " .
36 37 38 39
        "bug_status = 'NEW' and to_days(now()) - to_days(delta_ts) > " .
        Param('whinedays') . " and userid=assigned_to order by bug_id");

my %bugs;
40
my %desc;
41 42 43
my @row;

while (@row = FetchSQLData()) {
44
    my ($id, $desc, $email) = (@row);
45 46 47
    if (!defined $bugs{$email}) {
        $bugs{$email} = [];
    }
48 49 50
    if (!defined $desc{$email}) {
        $desc{$email} = [];
    }
51
    push @{$bugs{$email}}, $id;
52
    push @{$desc{$email}}, $desc;
53 54 55 56 57
}


my $template = Param('whinemail');
my $urlbase = Param('urlbase');
58
my $emailsuffix = Param('emailsuffix');
59 60 61

foreach my $email (sort (keys %bugs)) {
    my %substs;
62
    $substs{'email'} = $email . $emailsuffix;
63
    $substs{'userid'} = $email;
64 65 66
    my $msg = PerformSubsts($template, \%substs);

    foreach my $i (@{$bugs{$email}}) {
67 68
        $msg .= "  " . shift(@{$desc{$email}}) . "\n";
        $msg .= "    -> ${urlbase}show_bug.cgi?id=$i\n";
69
    }
70 71

    my $sendmailparam = Param('sendmailnow') ? '' : "-ODeliveryMode=deferred";
72
    open SENDMAIL, "|/usr/lib/sendmail $sendmailparam -t -i"
73
        or die "Can't open sendmail";
74 75 76 77
    print SENDMAIL $msg;
    close SENDMAIL;
    print "$email      " . join(" ", @{$bugs{$email}}) . "\n";
}