/[qa]/trunk/pts/bin/dispatch.pl
ViewVC logotype

Contents of /trunk/pts/bin/dispatch.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 561 - (show annotations) (download)
Tue Apr 22 21:23:31 2003 UTC (10 years, 1 month ago) by hertzog
File MIME type: text/plain
File size: 4700 byte(s)
- Do not require auto-approval for mails coming from bugzilla(s).
1 #!/usr/bin/perl -w
2
3 # Copyright 2002 Raphaƫl Hertzog <hertzog@debian.org>
4 # Available under the terms of the General Public License version 2
5 # or (at your option) any later version
6
7 use lib '/org/packages.qa.debian.org/perl';
8 use lib '/home/rhertzog/cvs/pts/perl';
9
10 use Mail::Internet;
11 use Mail::Address;
12 use DB_File;
13
14 use strict;
15 use vars qw($db $sendmail);
16
17 =head1 Script for *@packages.qa.debian.org
18
19 =head1 INSTALLATION INSTRUCTIONS
20
21 This script needs libmailtools-perl.
22
23 =cut
24
25 require "common.pl";
26
27 # Local configuration variables
28 my $nb_by_group = 20; # Number of emails sent together (in the same sendmail)
29 my $debug = 0;
30 my $spamc = '';
31 my $needs_approval = 1;
32
33 # Get the package name
34 my $package = lc($ENV{'LOCAL_PART'}); # Exim sets that ...
35 $package = lc(shift @ARGV) if ($debug && defined($ARGV[0]) && $ARGV[0]); #
36 die "Aren't you exim ?" if (! (defined($package) && $package));
37
38 # Get the keyword name
39 my $keyword = '';
40 if ($package =~ /(\S+)_(\S+)/) {
41 $package = $1;
42 $keyword = $2;
43 }
44
45 # Get the list of subscribers
46 open_db_read();
47 my @emails = $db->get_dup($package);
48 exit 0 if (! scalar(@emails)); # Don't parse anything if nobody is subscribed
49
50 # Parse the mail
51 my $mail = Mail::Internet->new(\*STDIN) or die "Parse failed !\n";
52
53 # Stop if bad X-Loop
54 my @xloop = grep { m/$package\@packages.qa.debian.org/ }
55 ($mail->head()->get('X-Loop'));
56 if (scalar(@xloop)) {
57 exit 0;
58 }
59
60 # Find the real keyword
61 if (! $keyword) {
62 $keyword = 'default';
63 if (scalar(grep { m/owner\@bugs\.debian\.org/ }
64 ($mail->head()->get('X-Loop'))
65 )
66 and $mail->head()->get('X-Debian-PR-Message')
67 )
68 {
69 $keyword = 'bts';
70 } elsif (scalar(grep { m/debbugs\@master\.debian\.org/ }
71 ($mail->head()->get('Sender'))
72 )
73 and ($mail->head()->get('Subject') =~ /^Processed:/)
74 )
75 {
76 $keyword = 'bts-control';
77 } elsif (($mail->head()->get('X-Katie') or $mail->head()->get('X-Lisa'))
78 and
79 ($mail->head()->get('Subject') =~ /^Accepted|INSTALLED|ACCEPTED/) and
80 (scalar(grep { /\.dsc\s*$/ } @{$mail->body()}))
81 )
82 {
83 exit(0) if ($mail->head()->get('Subject') =~ /INSTALLED|ACCEPTED/);
84 $keyword = 'upload-source';
85 } elsif (($mail->head()->get('X-Katie') or $mail->head()->get('X-Lisa'))
86 and
87 ($mail->head()->get('Subject') =~ /^Accepted|INSTALLED|ACCEPTED/)
88 )
89 {
90 #exit(0) if ($mail->head()->get('Subject') =~ /INSTALLED|ACCEPTED/);
91 $keyword = 'upload-binary';
92 } elsif ($mail->head()->get('X-Katie') or $mail->head()->get('X-Lisa'))
93 {
94 $keyword = 'katie-other';
95 }
96 }
97
98 # Build the real list of interested people
99 my $wantmail = sub {
100 my $address = shift;
101 foreach (get_tags($address, $package)) {
102 return 1 if ($_ eq $keyword);
103 }
104 return 0;
105 };
106 @emails = grep { &$wantmail($_) } @emails;
107 exit 0 if (! scalar(@emails));
108 close_db();
109
110 # If default keyword, it may be spam ... check with spamassassin
111 # before approving
112 if ($keyword eq "default") {
113 # Some mails comes from trusted sources
114 # which do not need auto-approval
115 if ($mail->head()->get('X-Bugzilla-Product')) {
116 # Bugzilla(s) are trusted sources
117 $needs_approval = 0;
118 }
119 # Check for spam
120 if (defined($spamc) && $spamc) {
121 open(SPAMC, "| $spamc -c >/dev/null") || die "Can't fork spamc: $!\n";
122 $mail->print(\*SPAMC);
123 my $res = close(SPAMC);
124 if (!$res and !$!) {
125 # Looks like it's spam
126 print STDERR "Your message appears to be spam (according to spamassassin).\n";
127 print STDERR "If it wasn't please retry by writing simple plain text mails.\n";
128 exit 2;
129 }
130 }
131 # Check for approval
132 if (defined($needs_approval) && $needs_approval) {
133 if (! $mail->head()->get('X-PTS-Approved')) {
134 print STDERR "The mail isn't auto-approved as it should be. Please include\n";
135 print STDERR "an 'X-PTS-Approved' (non-empty) header if you want to mail \n";
136 print STDERR "directly the Package Tracking System. This is made to avoid spam.\n";
137 exit 2;
138 }
139 }
140 }
141
142 # Modify the mail
143 $mail->head()->add("X-Loop", "$package\@packages.qa.debian.org");
144 $mail->head()->add("X-PTS-Package", $package);
145 $mail->head()->add("X-PTS-Keyword", $keyword);
146 $mail->head()->add("X-Unsubscribe",
147 "echo 'unsubscribe $package' | mail pts\@qa.debian.org");
148
149 # Forward the mail ... by group of $nb_by_group addresses
150 my @send;
151 while (defined($_ = shift @emails)) {
152 push @send, $_;
153 if (scalar(@send) == $nb_by_group) {
154 send_mail(@send);
155 @send = ();
156 }
157 }
158 send_mail(@send) if (scalar(@send));
159
160 sub send_mail {
161 open(MAIL, "| $sendmail -oi @_") || die "Can't fork sendmail: $!\n";
162 $mail->print(\*MAIL);
163 close MAIL or warn "Problem happened with sendmail: $!\n";
164 }

Properties

Name Value
svn:eol-style native
svn:executable *
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.5