timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame^] | 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.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 | |
| 17 | use lib qw(.); |
| 18 | |
| 19 | require "globals.pl"; |
| 20 | use Bugzilla::BugMail; |
| 21 | use Bugzilla::User; |
| 22 | |
| 23 | sub usage { |
| 24 | print STDERR "Usage: $0 bug_id user_email\n"; |
| 25 | exit; |
| 26 | } |
| 27 | |
| 28 | if (($#ARGV < 1) || ($#ARGV > 2)) { |
| 29 | usage(); |
| 30 | } |
| 31 | |
| 32 | # Get the arguments. |
| 33 | my $bugnum = $ARGV[0]; |
| 34 | my $changer = $ARGV[1]; |
| 35 | |
| 36 | # Validate the bug number. |
| 37 | if (!($bugnum =~ /^(\d+)$/)) { |
| 38 | print STDERR "Bug number \"$bugnum\" not numeric.\n"; |
| 39 | usage(); |
| 40 | } |
| 41 | |
| 42 | detaint_natural($bugnum); |
| 43 | |
| 44 | SendSQL("SELECT bug_id FROM bugs WHERE bug_id = $bugnum"); |
| 45 | |
| 46 | if (!FetchOneColumn()) { |
| 47 | print STDERR "Bug number $bugnum does not exist.\n"; |
| 48 | usage(); |
| 49 | } |
| 50 | |
| 51 | # Validate the changer address. |
| 52 | my $match = Param('emailregexp'); |
| 53 | if ($changer !~ /$match/) { |
| 54 | print STDERR "Changer \"$changer\" doesn't match email regular expression.\n"; |
| 55 | usage(); |
| 56 | } |
| 57 | if(!login_to_id($changer)) { |
| 58 | print STDERR "\"$changer\" is not a login ID.\n"; |
| 59 | usage(); |
| 60 | } |
| 61 | |
| 62 | # Send the email. |
| 63 | my $outputref = Bugzilla::BugMail::Send($bugnum, {'changer' => $changer }); |
| 64 | |
| 65 | # Report the results. |
| 66 | my $sent = scalar(@{$outputref->{sent}}); |
| 67 | my $excluded = scalar(@{$outputref->{excluded}}); |
| 68 | |
| 69 | if ($sent) { |
| 70 | print "email sent to $sent recipients:\n"; |
| 71 | } else { |
| 72 | print "No email sent.\n"; |
| 73 | } |
| 74 | |
| 75 | foreach my $sent (@{$outputref->{sent}}) { |
| 76 | print " $sent\n"; |
| 77 | } |
| 78 | |
| 79 | if ($excluded) { |
| 80 | print "$excluded recipients excluded:\n"; |
| 81 | } else { |
| 82 | print "No recipients excluded.\n"; |
| 83 | } |
| 84 | |
| 85 | foreach 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. |