blob: ad96428950e401e065a24bf7ec84d0e185156880 [file] [log] [blame]
timothy@apple.comf42518d2008-02-06 20:19:16 +00001#!/usr/bin/perl -w
2#
3# sendbugmail.pl
4#
5# Nick Barnes, Ravenbrook Limited, 2004-04-01.
6#
7# $Id: sendbugmail.pl,v 1.3 2005/02/24 23:42:48 mkanat%kerio.com Exp $
8#
9# Bugzilla email script for Bugzilla 2.17.4 and later. Invoke this to send
10# bugmail for a bug which has been changed directly in the database.
11# This uses Bugzilla's own BugMail facility, and will email the
12# users associated with the bug. Replaces the old "processmail"
13# script.
14#
15# Usage: perl -T contrib/sendbugmail.pl bug_id user_email
16
17use lib qw(.);
18
19require "globals.pl";
20use Bugzilla::BugMail;
21use Bugzilla::User;
22
23sub usage {
24 print STDERR "Usage: $0 bug_id user_email\n";
25 exit;
26}
27
28if (($#ARGV < 1) || ($#ARGV > 2)) {
29 usage();
30}
31
32# Get the arguments.
33my $bugnum = $ARGV[0];
34my $changer = $ARGV[1];
35
36# Validate the bug number.
37if (!($bugnum =~ /^(\d+)$/)) {
38 print STDERR "Bug number \"$bugnum\" not numeric.\n";
39 usage();
40}
41
42detaint_natural($bugnum);
43
44SendSQL("SELECT bug_id FROM bugs WHERE bug_id = $bugnum");
45
46if (!FetchOneColumn()) {
47 print STDERR "Bug number $bugnum does not exist.\n";
48 usage();
49}
50
51# Validate the changer address.
52my $match = Param('emailregexp');
53if ($changer !~ /$match/) {
54 print STDERR "Changer \"$changer\" doesn't match email regular expression.\n";
55 usage();
56}
57if(!login_to_id($changer)) {
58 print STDERR "\"$changer\" is not a login ID.\n";
59 usage();
60}
61
62# Send the email.
63my $outputref = Bugzilla::BugMail::Send($bugnum, {'changer' => $changer });
64
65# Report the results.
66my $sent = scalar(@{$outputref->{sent}});
67my $excluded = scalar(@{$outputref->{excluded}});
68
69if ($sent) {
70 print "email sent to $sent recipients:\n";
71} else {
72 print "No email sent.\n";
73}
74
75foreach my $sent (@{$outputref->{sent}}) {
76 print " $sent\n";
77}
78
79if ($excluded) {
80 print "$excluded recipients excluded:\n";
81} else {
82 print "No recipients excluded.\n";
83}
84
85foreach my $excluded (@{$outputref->{excluded}}) {
86 print " $excluded\n";
87}
88
89# This document is copyright (C) 2004 Perforce Software, Inc. All rights
90# reserved.
91#
92# Redistribution and use of this document in any form, with or without
93# modification, is permitted provided that redistributions of this
94# document retain the above copyright notice, this condition and the
95# following disclaimer.
96#
97# THIS DOCUMENT IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
98# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
99# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
100# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
101# HOLDERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
102# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
103# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
104# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
105# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
106# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
107# DOCUMENT, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.