aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/sendbugmail.pl
blob: ad96428950e401e065a24bf7ec84d0e185156880 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/perl -w
#
#                    sendbugmail.pl
#
# Nick Barnes, Ravenbrook Limited, 2004-04-01.
#
# $Id: sendbugmail.pl,v 1.3 2005/02/24 23:42:48 mkanat%kerio.com Exp $
# 
# Bugzilla email script for Bugzilla 2.17.4 and later.  Invoke this to send
# bugmail for a bug which has been changed directly in the database.
# This uses Bugzilla's own BugMail facility, and will email the
# users associated with the bug.  Replaces the old "processmail"
# script.
# 
# Usage: perl -T contrib/sendbugmail.pl bug_id user_email

use lib qw(.);

require "globals.pl";
use Bugzilla::BugMail;
use Bugzilla::User;

sub usage {
    print STDERR "Usage: $0 bug_id user_email\n";
    exit;
}

if (($#ARGV < 1) || ($#ARGV > 2)) {
    usage();
}

# Get the arguments.
my $bugnum = $ARGV[0];
my $changer = $ARGV[1];

# Validate the bug number.
if (!($bugnum =~ /^(\d+)$/)) {
  print STDERR "Bug number \"$bugnum\" not numeric.\n";
  usage();
}

detaint_natural($bugnum);

SendSQL("SELECT bug_id FROM bugs WHERE bug_id = $bugnum");

if (!FetchOneColumn()) {
  print STDERR "Bug number $bugnum does not exist.\n";
  usage();
}

# Validate the changer address.
my $match = Param('emailregexp');
if ($changer !~ /$match/) {
    print STDERR "Changer \"$changer\" doesn't match email regular expression.\n";
    usage();
}
if(!login_to_id($changer)) {
    print STDERR "\"$changer\" is not a login ID.\n";
    usage();
}

# Send the email.
my $outputref = Bugzilla::BugMail::Send($bugnum, {'changer' => $changer });

# Report the results.
my $sent = scalar(@{$outputref->{sent}});
my $excluded = scalar(@{$outputref->{excluded}});

if ($sent) {
    print "email sent to $sent recipients:\n";
} else {
    print "No email sent.\n";
}

foreach my $sent (@{$outputref->{sent}}) {
  print "  $sent\n";
}

if ($excluded) {
    print "$excluded recipients excluded:\n";
} else {
    print "No recipients excluded.\n";
}

foreach my $excluded (@{$outputref->{excluded}}) {
  print "  $excluded\n";
}

# This document is copyright (C) 2004 Perforce Software, Inc.  All rights
# reserved.
# 
# Redistribution and use of this document in any form, with or without
# modification, is permitted provided that redistributions of this
# document retain the above copyright notice, this condition and the
# following disclaimer.
# 
# THIS DOCUMENT IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# HOLDERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# DOCUMENT, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
class="hl opt">, /* that Sun forgot */ NFSERR_FBIG = 27, NFSERR_NOSPC = 28, NFSERR_ROFS = 30, NFSERR_OPNOTSUPP = 45, NFSERR_NAMETOOLONG = 63, NFSERR_NOTEMPTY = 66, NFSERR_DQUOT = 69, NFSERR_STALE = 70, NFSERR_WFLUSH = 99 }; enum nfs_ftype { NFNON = 0, NFREG = 1, NFDIR = 2, NFBLK = 3, NFCHR = 4, NFLNK = 5, NFSOCK = 6, NFBAD = 7, NFFIFO = 8 }; struct nfs_fh { char data[NFS_FHSIZE]; }; #define NFS_PROGRAM 100003 #define NFS_VERSION 2 #define NFSPROC_NULL 0 #define NFSPROC_GETATTR 1 #define NFSPROC_SETATTR 2 #define NFSPROC_ROOT 3 #define NFSPROC_LOOKUP 4 #define NFSPROC_READLINK 5 #define NFSPROC_READ 6 #define NFSPROC_WRITECACHE 7 #define NFSPROC_WRITE 8 #define NFSPROC_CREATE 9 #define NFSPROC_REMOVE 10 #define NFSPROC_RENAME 11 #define NFSPROC_LINK 12 #define NFSPROC_SYMLINK 13 #define NFSPROC_MKDIR 14 #define NFSPROC_RMDIR 15 #define NFSPROC_READDIR 16 #define NFSPROC_STATFS 17 /* Mount support for NFSroot */ #ifdef __KERNEL__ #define NFS_MNT_PROGRAM 100005 #define NFS_MNT_VERSION 1 #define NFS_MNT_PORT 627 #define NFS_MNTPROC_MNT 1 #define NFS_MNTPROC_UMNT 3 #endif #if defined(__KERNEL__) || defined(NFS_NEED_KERNEL_TYPES) extern struct rpc_program nfs_program; extern struct rpc_stat nfs_rpcstat; struct nfs_time { __u32 seconds; __u32 useconds; }; struct nfs_fattr { enum nfs_ftype type; __u32 mode; __u32 nlink; __u32 uid; __u32 gid; __u32 size; __u32 blocksize; __u32 rdev; __u32 blocks; __u32 fsid; __u32 fileid; struct nfs_time atime; struct nfs_time mtime; struct nfs_time ctime; }; struct nfs_sattr { __u32 mode; __u32 uid; __u32 gid; __u32 size; struct nfs_time atime; struct nfs_time mtime; }; struct nfs_fsinfo { __u32 tsize; __u32 bsize; __u32 blocks; __u32 bfree; __u32 bavail; }; struct nfs_writeargs { struct nfs_fh * fh; __u32 offset; __u32 count; const void * buffer; }; #ifdef NFS_NEED_XDR_TYPES struct nfs_sattrargs { struct nfs_fh * fh; struct nfs_sattr * sattr; }; struct nfs_diropargs { struct nfs_fh * fh; const char * name; }; struct nfs_readargs { struct nfs_fh * fh; __u32 offset; __u32 count; void * buffer; }; struct nfs_createargs { struct nfs_fh * fh; const char * name; struct nfs_sattr * sattr; }; struct nfs_renameargs { struct nfs_fh * fromfh; const char * fromname; struct nfs_fh * tofh; const char * toname; }; struct nfs_linkargs { struct nfs_fh * fromfh; struct nfs_fh * tofh; const char * toname; }; struct nfs_symlinkargs { struct nfs_fh * fromfh; const char * fromname; const char * topath; struct nfs_sattr * sattr; }; struct nfs_readdirargs { struct nfs_fh * fh; __u32 cookie; void * buffer; unsigned int bufsiz; }; struct nfs_diropok { struct nfs_fh * fh; struct nfs_fattr * fattr; }; struct nfs_readres { struct nfs_fattr * fattr; unsigned int count; }; struct nfs_readlinkres { char ** string; unsigned int * lenp; unsigned int maxlen; void * buffer; }; struct nfs_readdirres { void * buffer; unsigned int bufsiz; }; #endif /* NFS_NEED_XDR_TYPES */ #endif /* __KERNEL__ */ #endif