~ubuntu-branches/ubuntu/oneiric/bugzilla/oneiric

« back to all changes in this revision

Viewing changes to contrib/sendbugmail.pl

  • Committer: Bazaar Package Importer
  • Author(s): Raphael Bossek
  • Date: 2008-06-27 22:34:34 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20080627223434-0ib57vstn43bb4a3
Tags: 3.0.4.1-1
* Update of French, Russian and German translations. (closes: #488251)
* Added Bulgarian and Belarusian translations.

Show diffs side-by-side

added added

removed removed

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