ddkilzer@apple.com | 8040bb0 | 2017-03-21 16:27:49 +0000 | [diff] [blame^] | 1 | #!/usr/bin/perl -T |
| 2 | # This Source Code Form is subject to the terms of the Mozilla Public |
| 3 | # License, v. 2.0. If a copy of the MPL was not distributed with this |
| 4 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 5 | # |
ddkilzer@apple.com | 8040bb0 | 2017-03-21 16:27:49 +0000 | [diff] [blame^] | 6 | # This Source Code Form is "Incompatible With Secondary Licenses", as |
| 7 | # defined by the Mozilla Public License, v. 2.0. |
| 8 | |
| 9 | use 5.10.1; |
| 10 | use strict; |
| 11 | use warnings; |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 12 | |
ddkilzer@apple.com | 097da08 | 2009-07-03 02:14:25 +0000 | [diff] [blame] | 13 | use lib qw(. lib); |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 14 | |
ddkilzer@apple.com | f3615fc | 2009-07-03 02:13:41 +0000 | [diff] [blame] | 15 | use Bugzilla; |
| 16 | use Bugzilla::Util; |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 17 | use Bugzilla::BugMail; |
| 18 | use Bugzilla::User; |
| 19 | |
ddkilzer@apple.com | f3615fc | 2009-07-03 02:13:41 +0000 | [diff] [blame] | 20 | my $dbh = Bugzilla->dbh; |
| 21 | |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 22 | sub usage { |
ddkilzer@apple.com | 8040bb0 | 2017-03-21 16:27:49 +0000 | [diff] [blame^] | 23 | say STDERR "Usage: $0 bug_id user_email"; |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 24 | exit; |
| 25 | } |
| 26 | |
| 27 | if (($#ARGV < 1) || ($#ARGV > 2)) { |
| 28 | usage(); |
| 29 | } |
| 30 | |
| 31 | # Get the arguments. |
| 32 | my $bugnum = $ARGV[0]; |
| 33 | my $changer = $ARGV[1]; |
| 34 | |
| 35 | # Validate the bug number. |
| 36 | if (!($bugnum =~ /^(\d+)$/)) { |
ddkilzer@apple.com | 8040bb0 | 2017-03-21 16:27:49 +0000 | [diff] [blame^] | 37 | say STDERR "Bug number \"$bugnum\" not numeric."; |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 38 | usage(); |
| 39 | } |
| 40 | |
| 41 | detaint_natural($bugnum); |
| 42 | |
ddkilzer@apple.com | f3615fc | 2009-07-03 02:13:41 +0000 | [diff] [blame] | 43 | my ($id) = $dbh->selectrow_array("SELECT bug_id FROM bugs WHERE bug_id = ?", |
| 44 | undef, $bugnum); |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 45 | |
ddkilzer@apple.com | f3615fc | 2009-07-03 02:13:41 +0000 | [diff] [blame] | 46 | if (!$id) { |
ddkilzer@apple.com | 8040bb0 | 2017-03-21 16:27:49 +0000 | [diff] [blame^] | 47 | say STDERR "Bug number $bugnum does not exist."; |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 48 | usage(); |
| 49 | } |
| 50 | |
| 51 | # Validate the changer address. |
ddkilzer@apple.com | f3615fc | 2009-07-03 02:13:41 +0000 | [diff] [blame] | 52 | my $match = Bugzilla->params->{'emailregexp'}; |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 53 | if ($changer !~ /$match/) { |
ddkilzer@apple.com | 8040bb0 | 2017-03-21 16:27:49 +0000 | [diff] [blame^] | 54 | say STDERR "Changer \"$changer\" doesn't match email regular expression."; |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 55 | usage(); |
| 56 | } |
ddkilzer@apple.com | 5777284 | 2014-10-16 16:00:58 +0000 | [diff] [blame] | 57 | my $changer_user = new Bugzilla::User({ name => $changer }); |
| 58 | unless ($changer_user) { |
ddkilzer@apple.com | 8040bb0 | 2017-03-21 16:27:49 +0000 | [diff] [blame^] | 59 | say STDERR "\"$changer\" is not a valid user."; |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 60 | usage(); |
| 61 | } |
| 62 | |
| 63 | # Send the email. |
ddkilzer@apple.com | 5777284 | 2014-10-16 16:00:58 +0000 | [diff] [blame] | 64 | my $outputref = Bugzilla::BugMail::Send($bugnum, {'changer' => $changer_user }); |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 65 | |
| 66 | # Report the results. |
| 67 | my $sent = scalar(@{$outputref->{sent}}); |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 68 | |
| 69 | if ($sent) { |
ddkilzer@apple.com | 8040bb0 | 2017-03-21 16:27:49 +0000 | [diff] [blame^] | 70 | say "email sent to $sent recipients:"; |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 71 | } else { |
ddkilzer@apple.com | 8040bb0 | 2017-03-21 16:27:49 +0000 | [diff] [blame^] | 72 | say "No email sent."; |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | foreach my $sent (@{$outputref->{sent}}) { |
ddkilzer@apple.com | 8040bb0 | 2017-03-21 16:27:49 +0000 | [diff] [blame^] | 76 | say " $sent"; |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | # This document is copyright (C) 2004 Perforce Software, Inc. All rights |
| 80 | # reserved. |
| 81 | # |
| 82 | # Redistribution and use of this document in any form, with or without |
| 83 | # modification, is permitted provided that redistributions of this |
| 84 | # document retain the above copyright notice, this condition and the |
| 85 | # following disclaimer. |
| 86 | # |
| 87 | # THIS DOCUMENT IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS |
| 88 | # IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
| 89 | # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
| 90 | # PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 91 | # HOLDERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 92 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED |
| 93 | # TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 94 | # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 95 | # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 96 | # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 97 | # DOCUMENT, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |