]> git.donarmstrong.com Git - debbugs.git/blob - scripts/process.in
f516670fbc05a455f2dd99261bfc6839ec99c7a7
[debbugs.git] / scripts / process.in
1 #!/usr/bin/perl
2 # $Id: process.in,v 1.9 1999/10/14 19:56:58 gecko Exp $
3 #
4 # Usage: process nn
5 # Temps:  incoming/Pnn
6
7 use Mail::Address;
8 require( '/etc/debbugs/config' );
9 require( '/usr/lib/debbugs/errorlib' );
10 chdir( "$gSpoolDir" ) || die 'chdir spool: $!\n';
11 @showseverities=();
12
13 #open(DEBUG,"> /tmp/debbugs.debug");
14
15 defined( $intdate= time ) || &quit( "failed to get time: $!" );
16
17 $_=shift;
18 m/^([BMQFDU])(\d*)\.\d+$/ || &quit("bad argument");
19 $codeletter= $1;
20 $tryref= length($2) ? $2+0 : -1;
21 $nn= $_;
22
23 if (!rename("incoming/G$nn","incoming/P$nn")) 
24 {       $_=$!.'';  m/no such file or directory/i && exit 0;
25     &quit("renaming to lock: $!");
26 }    
27
28 $baddress= 'bugs' if $codeletter eq 'B';
29 $baddress= 'maintonly' if $codeletter eq 'M';
30 $baddress= 'quiet' if $codeletter eq 'Q';
31 $baddress= 'forwarded' if $codeletter eq 'F';
32 $baddress= 'done' if $codeletter eq 'D';
33 $baddress= 'submitter' if $codeletter eq 'U';
34 $baddress || &quit("bad codeletter $codeletter");
35 $baddressroot= $baddress;
36 $baddress= "$tryref-$baddress" if $tryref>=0;
37
38 open(M,"incoming/P$nn");
39 @log=<M>;
40 close(M);
41
42 @msg=@log;
43 grep(s/\n+$//,@msg);
44
45 print DEBUG "###\n",join("##\n",@msg),"\n###\n";
46
47 chop($tdate= `date -u '+%a, %d %h %Y %T GMT'`);
48 $fwd= <<END;
49 X-Loop: $gMaintainerEmail
50 Received: via spool by $baddress\@$gEmailDomain id=$nn
51           (code $codeletter ref $tryref); $tdate
52 END
53
54 for ($i=0; $i<=$#msg; $i++) {
55     $_ = $msg[$i];
56     last unless length($_);
57     &quit("looping detected") if m/^x-loop: (\S+)$/i && $1 eq "$gMaintainerEmail";
58     $ins= !m/^subject:/i && !m/^reply-to:/i && !m/^return-path:/i
59        && !m/^From / && !m/^X-Debbugs-CC:/i && !m/^received:/i;
60     $fwd .= $_."\n" if $ins;
61     while ($msg[$i+1] =~ m/^\s/) {
62         $i++;
63         $fwd .= $msg[$i]."\n" if $ins;
64         $_ .= ' '.$msg[$i];
65     }
66 # print DEBUG ">$_<\n";
67     if (s/^(\S+):\s*//) {
68         $v= $1; $v =~ y/A-Z/a-z/;
69                 print DEBUG ">$v=$_<\n";
70         $header{$v}= $_;
71     } else {
72         print DEBUG "!>$_<\n";
73     }
74 }
75
76 #remove blank lines
77 while ($i <= $#msg && !length($msg[$i])) { $fwd .= "\n"; $i++; }
78
79 #skips the "this is mime" message and any blank space after it
80 if ( $msg[$i] =~ /^This is a multi-part message in MIME format./ )
81 {
82         while ( $i <= $#msg && length( $msg[$i] ) ) { $fwd .= $msg[$i] . "\n"; $i++; }
83         while ( $i <= $#msg && !length( $msg[$i] ) ) { $fwd .= "\n"; $i++; }
84 }
85 #if the lines starts with -- or is nothing but blank space...
86 #skip to the next blank line(s) then skip past the blank line(s)
87 if ( $msg[$i] =~ /^--/ || $msg[$i] =~ /^\s*$/ )
88 {
89         while ( $i <= $#msg && length( $msg[$i] ) ) { $fwd .= $msg[$i] . "\n"; $i++; }
90         while ( $i <= $#msg && !length( $msg[$i] ) ) { $fwd .= "\n"; $i++; }
91 }               
92
93 while (defined ($msg[$i] ) )
94 {
95         last if ( $msg[$i] !~ m/^([\w]+):\s*(\S+)/ );
96         $i++;
97         $fn = $1; $fv = $2;
98         print DEBUG ">$fn|$'|\n";
99     $fwd .= $fn.': '.$fv."\n";
100     $fn =~ y/A-Z/a-z/;
101     $fv =~ y/A-Z/a-z/;
102     $pheader{$fn}= $fv;
103         print DEBUG ">$fn~$fv<\n";
104 }
105
106
107 $fwd .= join("\n",@msg[$i..$#msg]);
108
109 print DEBUG "***\n$fwd\n***\n";
110
111 defined($header{'from'}) || &quit("no From header");
112 $replyto= defined($header{'reply-to'}) ? $header{'reply-to'} : $header{'from'};
113
114 $_= $replyto;
115 $_= "$2 <$1>" if m/^([^\<\> \t\n\(\)]+) \(([^\(\)\<\>]+)\)$/;
116 $replytocompare= $_;
117 print DEBUG "replytocompare >$replytocompare<\n";
118     
119 if (!defined($header{'subject'})) 
120 {       $brokenness.= <<END;
121
122 Your message did not contain a Subject field.  This is broken, I am
123 afraid - the Subject: line is a Required Header according to RFC822.
124 Please remember to include a Subject field in your messages in future.
125 If you did so the fact that it got lost probably indicates a poorly
126 configured mail system at your site or an intervening one.
127 END
128     $subject= '(no subject)';
129 } else { $subject= $header{'subject'}; }
130
131 $ref=-1;
132 $subject =~ s/^Re:\s*//i; $_= $subject."\n";
133 if ($tryref < 0 && m/^Bug ?\#(\d+)\D/i) { $tryref= $1+0; }
134
135 if ($tryref >= 0) 
136 {       $bfound= &lockreadbugmerge($tryref);
137     if ($bfound) { $ref= $tryref; } 
138         else 
139         {       &htmllog("Reply","sent", $replyto,"Unknown problem report number <code>$tryref</code>.");
140         &sendmessage(<<END, '');
141 From: $gMaintainerEmail ($gProject $gBug Tracking System)
142 To: $replyto
143 Subject: Unknown problem report $gBug#$tryref ($subject)
144 Message-ID: <handler.x.$nn.unknown\@$gEmailDomain>
145 In-Reply-To: $header{'message-id'}
146 References: $header{'message-id'} $s_msgid
147 X-$gProject-PR-Message: error
148
149 You sent a message to the $gBug tracking system which gave (in the
150 Subject line or encoded into the recipient at $gEmailDomain),
151 the number of a nonexistent $gBug report (#$tryref).
152
153 This may be because that $gBug report has been resolved for more than $gRemoveAge
154 days, and the record of it has been expunged, or because you mistyped
155 the $gBug report number.
156
157 Your message was dated $header{'date'} and was sent to
158 $baddress\@$gEmailDomain.  It had
159 Message-ID $header{'message-id'}
160 and Subject $subject.
161
162 It has been filed (under junk) but otherwise ignored.
163
164 Please consult your records to find the correct $gBug report number, or
165 contact me, the system administrator, for assistance.
166
167 $gMaintainer
168 (administrator, $gProject $gBugs database)
169
170 (NB: If you are a system administrator and have no idea what I am
171 talking about this indicates a serious mail system misconfiguration
172 somewhere.  Please contact me immediately.)
173
174 END
175                 &appendlog;
176         &finish;
177     }
178 } else { &filelock('lock/-1'); }
179
180 if ($codeletter eq 'D' || $codeletter eq 'F') 
181 {       if ($replyto =~ m/$gBounceFroms/o ||
182                 $header{'from'} =~ m/$gBounceFroms/o) 
183                 { &quit("bounce detected !  Mwaap! Mwaap!"); }
184     $markedby= $header{'from'} eq $replyto ? $replyto :
185                "$header{'from'} (reply to $replyto)";
186     if ($codeletter eq 'F') 
187         {       (&appendlog,&finish) if length($s_forwarded);
188         $receivedat= "forwarded\@$gEmailDomain";
189         $markaswhat= 'forwarded';
190         $set_forwarded= $header{'to'};
191                 if ( length( $gListDomain ) > 0 && length( $gFowardList ) > 0 ) 
192                         { $generalcc= "$gFowardList\@$gListDomain"; } 
193                 else { $generalcc=''; }
194     } else 
195         {       (&appendlog,&finish) if length($s_done);
196         $receivedat= "done\@$gEmailDomain";
197         $markaswhat= 'done';
198         $set_done= $header{'from'};
199                 if ( length( $gListDomain ) > 0 && length( $gDoneList ) > 0 ) 
200                         { $generalcc= "$gDoneList\@$gListDomain"; } 
201                 else { $generalcc=''; }
202     }
203     if ($ref<0) 
204         {       &htmllog("Warning","sent",$replyto,"Message ignored.");
205         &sendmessage(<<END, '');
206 From: $gMaintainerEmail ($gProject $gBug Tracking System)
207 To: $replyto
208 Subject: Message with no $gBug number ignored by $receivedat
209          ($subject)
210 Message-ID: <header.x.$nn.warnignore\@$gEmailDomain>
211 In-Reply-To: $header{'message-id'}
212 References: $header{'message-id'} $s_msgid
213 X-$gProject-PR-Message: error
214
215 You sent a message to the $gProject $gBug tracking system old-style
216 unified mark as $markaswhat address ($receivedat),
217 without a recognisable $gBug number in the Subject.
218 Your message has been filed under junk but otherwise ignored.
219
220 If you don't know what I'm talking about then probably either:
221
222 (a) you unwittingly sent a message to done\@$gEmailDomain
223 because you replied to all recipients of the message a developer used
224 to mark a $gBug as done and you modified the Subject.  In this case,
225 please do not be alarmed.  To avoid confusion do not do it again, but
226 there is no need to apologise or mail anyone asking for an explanation.
227
228 (b) you are a system administrator, reading this because the $gBug 
229 tracking system is responding to a misdirected bounce message.  In this
230 case there is a serious mail system misconfiguration somewhere - please
231 contact me immediately.
232
233 Your message was dated $header{'date'} and had
234 message-id $header{'message-id'}
235 and subject $subject.
236
237 If you need any assistance or explanation please contact me.
238
239 $gMaintainer
240 (administrator, $gProject $gBugs database)
241
242 END
243                 &appendlog;
244                 &finish;
245     }
246     &checkmaintainers;
247     $noticeccval.= join(', ', grep($_ ne $replyto,@maintaddrs));
248     $noticeccval =~ s/\s+\n\s+/ /g; $noticeccval =~ s/^\s+/ /; $noticeccval =~ s/\s+$//;
249     if (length($noticeccval)) { $noticecc= "Cc: $noticeccval\n"; }
250         if (length($generalcc)) { $noticecc.= "Bcc: $generalcc\n"; }
251     @process= ($ref,split(/ /,$s_mergedwith));
252     $orgref= $ref;
253     for $ref (@process) 
254         {       if ($ref != $orgref) 
255                 {       &unfilelock;
256                 &lockreadbug($ref) || die "huh ? $ref from $orgref out of @process";
257                 }
258         $s_done= $set_done if defined($set_done);
259         $s_forwarded= $set_forwarded if defined($set_forwarded);
260                 &overwrite("db/$ref.status",
261                    "$s_originator\n$s_date\n$s_subject\n$s_msgid\n".
262                    "$s_package\n$s_keywords\n$s_done\n$s_forwarded\n$s_mergedwith\n$s_severity\n");
263         open(O,"db/$ref.report") || &quit("read original report: $!");
264         $x= join('',<O>); close(O);
265         if ($codeletter eq 'F') 
266                 {       &htmllog("Reply","sent",$replyto,"You have marked $gBug as forwarded.");
267             &sendmessage(<<END.$x, '');
268 From: $gMaintainerEmail ($gProject $gBug Tracking System)
269 To: $replyto
270 ${noticecc}Subject: $gBug#$ref: marked as forwarded ($s_subject)
271 Message-ID: <header.$ref.$nn.ackfwdd\@$gEmailDomain>
272 In-Reply-To: $header{'message-id'}
273 References: $header{'message-id'} $s_msgid
274 X-$gProject-PR-Message: forwarded $ref
275
276 Your message dated $header{'date'}
277 with message-id $header{'message-id'}
278 and subject line $subject
279 has caused the $gProject $gBug report #$ref,
280 regarding $s_subject
281 to be marked as having been forwarded to the upstream software
282 author(s) $s_forwarded.
283
284 (NB: If you are a system administrator and have no idea what I am
285 talking about this indicates a serious mail system misconfiguration
286 somewhere.  Please contact me immediately.)
287
288 $gMaintainer
289 (administrator, $gProject $gBugs database)
290
291 END
292         } else 
293                 {   &htmllog("Reply","sent",$replyto,"You have taken responsibility.");
294             &sendmessage(<<END."--------------------------------------\n".$x."---------------------------------------\n".join( "\n", @msg ), '');
295 From: $gMaintainerEmail ($gProject $gBug Tracking System)
296 To: $replyto
297 ${noticecc}Subject: $gBug#$ref: marked as done ($s_subject)
298 Message-ID: <handler.$ref.$nn.ackdone\@$gEmailDomain>
299 In-Reply-To: $header{'message-id'}
300 References: $header{'message-id'} $s_msgid
301 X-$gProject-PR-Message: closed $ref
302
303 Your message dated $header{'date'}
304 with message-id $header{'message-id'}
305 and subject line $subject
306 has caused the attached $gBug report to be marked as done.
307
308 This means that you claim that the problem has been dealt with.
309 If this is not the case it is now your responsibility to reopen the
310 $gBug report if necessary, and/or fix the problem forthwith.
311
312 (NB: If you are a system administrator and have no idea what I am
313 talking about this indicates a serious mail system misconfiguration
314 somewhere.  Please contact me immediately.)
315
316 $gMaintainer
317 (administrator, $gProject $gBugs database)
318
319 END
320             &htmllog("Notification","sent",$s_originator, 
321                                 "$gBug acknowledged by developer.");
322             &sendmessage(<<END.join("\n",@msg),'');
323 From: $gMaintainerEmail ($gProject $gBug Tracking System)
324 To: $s_originator
325 Subject: $gBug#$ref acknowledged by developer ($s_subject)
326 Message-ID: <handler.$ref.$nn.notifdone\@$gEmailDomain>
327 In-Reply-To: $s_msgid
328 References: $header{'message-id'} $s_msgid
329 X-$gProject-PR-Message: they-closed $ref
330
331 This is an automatic notification regarding your $gBug report.
332
333 It has been closed by one of the developers, namely
334 $markedby.
335
336 Their explanation is attached below.  If this explanation is
337 unsatisfactory and you have not received a better one in a separate
338 message then please contact the developer directly, or email
339 submit\@$gEmailDomain or me.
340
341 $gMaintainer
342 (administrator, $gProject $gBugs database)
343
344 END
345         }
346                 &appendlog;
347     }
348     &finish;
349 }
350
351 if ($ref<0) 
352 {       if ($codeletter eq 'U') 
353         {       &htmllog("Warning","sent",$replyto,"Message not forwarded.");
354         &sendmessage(<<END, '');
355 From: $gMaintainerEmail ($gProject $gBug Tracking System)
356 To: $replyto
357 Subject: Message with no $gBug number cannot be sent to submitter !
358          ($subject)
359 Message-ID: <handler.x.$nn.nonumnosub\@$gEmailDomain>
360 In-Reply-To: $header{'message-id'}
361 References: $header{'message-id'} $s_msgid
362 X-$gProject-PR-Message: error
363
364 You sent a message to the $gProject $gBug tracking system send to $gBug 
365 report submitter address $baddress\@$gEmailDomain, without a
366 recognisable $gBug number in the Subject.  Your message has been filed
367 under junk but otherwise ignored.
368
369 If you don't know what I'm talking about then probably either:
370
371 (a) you unwittingly sent a message to $baddress\@$gEmailDomain
372 because you replied to all recipients of the message a developer sent
373 to a $gBug's submitter and you modified the Subject.  In this case,
374 please do not be alarmed.  To avoid confusion do not do it again, but
375 there is no need to apologise or mail anyone asking for an
376 explanation.
377
378 (b) you are a system administrator, reading this because the $gBug 
379 tracking system is responding to a misdirected bounce message.  In this
380 case there is a serious mail system misconfiguration somewhere - please
381 contact me immediately.
382
383 Your message was dated $header{'date'} and had
384 message-id $header{'message-id'}
385 and subject $subject.
386
387 If you need any assistance or explanation please contact me.
388
389 $gMaintainer
390 (administrator, $gProject $gBugs database)
391
392 END
393         &appendlog;
394         &finish;
395     }
396     if (!defined($pheader{'package'}))
397         {       &htmllog("Warning","sent",$replyto,"Message not forwarded.");
398                 print " sending no package header msg\n";
399         &sendmessage(<<END, '');
400 From: $gMaintainerEmail ($gProject $gBug Tracking System)
401 To: $replyto
402 Subject: Message with no Package: tag cannot be processed!
403          ($subject)
404 Message-ID: <handler.x.$nn.nonumnosub\@$gEmailDomain>
405 In-Reply-To: $header{'message-id'}
406 References: $header{'message-id'} $s_msgid
407 X-$gProject-PR-Message: error
408
409 Your message didn't have a Package: line at the start (in the
410 pseudo-header following the real mail header), or didn't have a
411 psuedo-header at all.
412
413 This makes it much harder for us to categorise and deal with your
414 problem report. Please resubmit your report and tell us which package the
415 report is on.  For help, check out http://$gWebDomain/Reporting.html.
416
417 Your message was dated $header{'date'} and had
418 message-id $header{'message-id'}
419 and subject $subject.
420
421 If you need any assistance or explanation please contact me.
422
423 $gMaintainer
424 (administrator, $gProject $gBugs database)
425
426 END
427         print " append log\n";
428         &appendlog;
429         print " finish\n";
430         &finish;
431         print " done\n";
432     } else { $s_package= $pheader{'package'}; }
433     if (defined($pheader{'keywords'})) {
434         $s_keywords= $pheader{'keywords'};
435     }
436     $s_severity= '';
437     if (defined($pheader{'severity'})) {
438         $s_severity= $pheader{'severity'};
439         if (!grep($_ eq $s_severity, @severities, "$gDefaultSeverity")) {
440             $brokenness.= <<END;
441
442 Your message specified a Severity: in the psuedo-header, but
443 the severity value $s_severity was not recognised.
444 The default severity $gDefaultSeverity is being used instead.
445 The recognised values are: @showseverities.
446 END
447             $s_severity= '';
448         }
449     }
450     &filelock("nextnumber.lock");
451     open(N,"nextnumber") || &quit("nextnumber: read: $!");
452     $v=<N>; $v =~ s/\n$// || &quit("nextnumber bad format");
453     $ref= $v+0;  $v += 1;  $newref=1;
454     &overwrite('nextnumber', "$v\n");
455     &unfilelock;
456     &overwrite("db/$ref.log",'');
457     &overwrite("db/$ref.status",
458                "$replyto\n$intdate\n$subject\n$header{'message-id'}\n".
459                "$s_package\n$s_keywords\n\n\n\n$s_severity\n");
460     &overwrite("db/$ref.report",
461                join("\n",@msg)."\n");
462 }
463
464 &checkmaintainers;
465
466 print DEBUG "maintainers >@maintaddrs<\n";
467
468 $orgsender= defined($header{'sender'}) ? "Orignal-Sender: $header{'sender'}\n" : '';
469 $newsubject= $subject;  $newsubject =~ s/^$gBug#$ref\W*\s*//;
470
471 $xcchdr= $header{ 'x-debbugs-cc' };
472 if ($xcchdr =~ m/\S/) {
473     push(@resentccs,$xcchdr);
474     $resentccexplain.= <<END;
475
476 As you requested using X-Debbugs-CC, your message was also forwarded to
477    $xcchdr
478 (after having been given a $gBug report number, if it did not have one).
479 END
480 }
481
482 if (@maintaddrs && ($codeletter eq 'B' || $codeletter eq 'M')) {
483     push(@resentccs,@maintaddrs);
484     $resentccexplain.= <<END." ".join("\n ",@maintaddrs)."\n";
485
486 Your message has been sent to the package maintainer(s):
487 END
488 }
489
490 $veryquiet= $codeletter eq 'Q';
491 if ($codeletter eq 'M' && !@maintaddrs) {
492     $veryquiet= 1;
493     $brokenness.= <<END;
494
495 You requested that the message be sent to the package maintainer(s)
496 but either the $gBug report is not associated with any package (probably
497 because of a missing Package psuedo-header field in the original $gBug
498 report), or the package(s) specified do not have any maintainer(s).
499
500 Your message has *not* been sent to any package maintainers; it has
501 merely been filed in the $gBug tracking system.  If you require assistance
502 please contact $gMaintainerEmail quoting the $gBug number $ref.
503 END
504 }
505
506 $resentccval.= join(', ',@resentccs);
507 $resentccval =~ s/\s+\n\s+/ /g; $resentccval =~ s/^\s+/ /; $resentccval =~ s/\s+$//;
508 if (length($resentccval)) { $resentcc= "Resent-CC: $resentccval\n"; }
509
510 if ($codeletter eq 'U') {
511     &htmllog("Message", "sent on", $s_originator, "$gBug#$ref.");
512     &sendmessage(<<END,$s_originator,@resentccs);
513 Subject: $gBug#$ref: $newsubject
514 Reply-To: $replyto, $ref-quiet\@$gEmailDomain
515 ${orgsender}Resent-To: $s_originator
516 ${resentcc}Resent-Date: $tdate
517 Resent-Message-ID: <handler.$ref.$nn\@$gEmailDomain>
518 Resent-Sender: $gMaintainerEmail
519 X-$gProject-PR-Message: report $ref
520 X-$gProject-PR-Package: $s_package
521 X-$gProject-PR-Keywords: $s_keywords
522 $fwd
523 END
524 } elsif ($codeletter eq 'B') {
525     &htmllog($newref ? "Report" : "Information", "forwarded",
526              join(', ',"$gSubmitList\@$gListDomain",@resentccs),
527              "<code>$gBug#$ref</code>".
528              (length($s_package)? "; Package <code>".&sani($s_package)."</code>" : '').
529              (length($s_keywords)? "; Keywords <code>".&sani($s_keywords)."</code>":'').
530              ".");
531     &sendmessage(<<END,"$gSubmitList\@$gListDomain",@resentccs);
532 Subject: $gBug#$ref: $newsubject
533 Reply-To: $replyto, $ref\@$gEmailDomain
534 Resent-From: $header{'from'}
535 ${orgsender}Resent-To: $gSubmitList\@$gListDomain
536 ${resentcc}Resent-Date: $tdate
537 Resent-Message-ID: <handler.$ref.$nn\@$gEmailDomain>
538 Resent-Sender: $gMaintainerEmail
539 X-$gProject-PR-Message: report $ref
540 X-$gProject-PR-Package: $s_package
541 X-$gProject-PR-Keywords: $s_keywords
542 $fwd
543 END
544 } elsif (@resentccs) {
545     # D and F done far earlier; B just done - so this must be M or Q
546     # We preserve whichever it was in the Reply-To (possibly adding
547     # the $gBug#).
548     &htmllog($newref ? "Report" : "Information", "forwarded",
549              $resentccval,
550              "<code>$gBug#$ref</code>".
551              (length($s_package)? "; Package <code>".&sani($s_package)."</code>" : '').
552              (length($s_keywords)? "; Keywords <code>".&sani($s_keywords)."</code>":'').
553              ".");
554     &sendmessage(<<END,@resentccs);
555 Subject: $gBug#$ref: $newsubject
556 Reply-To: $replyto, $ref-$baddressroot\@$gEmailDomain
557 Resent-From: $header{'from'}
558 ${orgsender}Resent-To: $resentccval
559 Resent-Date: $tdate
560 Resent-Message-ID: <handler.$ref.$nn\@$gEmailDomain>
561 Resent-Sender: $gMaintainerEmail
562 X-$gProject-PR-Message: report $ref
563 X-$gProject-PR-Package: $s_package
564 X-$gProject-PR-Keywords: $s_keywords
565 $fwd
566 END
567 }
568
569 $htmlbreak= length($brokenness) ? "<p>\n".&sani($brokenness)."\n<p>\n" : '';
570 $htmlbreak =~ s/\n\n/\n<P>\n\n/g;
571 if (length($resentccval)) {
572     $htmlbreak =
573         "  Copy sent to <code>".&sani($resentccval)."</code>.".
574         $htmlbreak;
575 }
576 if ($newref) {
577     &htmllog("Acknowledgement","sent",$replyto,
578              ($veryquiet ?
579               "New $gBug report received and filed, but not forwarded." :
580               "New $gBug report received and forwarded."). $htmlbreak);
581     &sendmessage($veryquiet ? <<END : $codeletter eq 'M' ? <<END : <<END,'');
582 From: $gMaintainerEmail ($gProject $gBug Tracking System)
583 To: $replyto
584 Subject: $gBug#$ref: Acknowledgement of QUIET report
585          ($subject)
586 Message-ID: <handler.$ref.$nn.ackquiet\@$gEmailDomain>
587 In-Reply-To: $header{'message-id'}
588 References: $header{'message-id'}
589 X-$gProject-PR-Message: ack-quiet $ref
590
591 Thank you for the problem report you have sent regarding $gProject.
592 This is an automatically generated reply, to let you know your message
593 has been received.  It has not been forwarded to the developers or
594 their mailing list; you should ensure that the developers are aware of
595 the problem you have entered into the system - preferably quoting the
596 $gBug reference number, #$ref.
597 $resentccexplain
598 If you wish to submit further information on your problem, please send it
599 to $ref-$baddressroot\@$gEmailDomain (and *not*
600 to $baddress\@$gEmailDomain).
601
602 Please do not reply to the address at the top of this message,
603 unless you wish to report a problem with the $gBug-tracking system.
604 $brokenness
605 $gMaintainer
606 (administrator, $gProject $gBugs database)
607 END
608 From: $gMaintainerEmail ($gProject $gBug Tracking System)
609 To: $replyto
610 Subject: $gBug#$ref: Acknowledgement of maintainer-only report
611          ($subject)
612 Message-ID: <handler.$ref.$nn.ackmaint\@$gEmailDomain>
613 In-Reply-To: $header{'message-id'}
614 References: $header{'message-id'}
615 X-$gProject-PR-Message: ack-maintonly $ref
616
617 Thank you for the problem report you have sent regarding $gProject.
618 This is an automatically generated reply, to let you know your message has
619 been received.  It is being forwarded to the developers (but not the mailing
620 list, as you requested) for their attention; they will reply in due course.
621 $resentccexplain
622 If you wish to submit further information on your problem, please send
623 it to $ref-$baddressroot\@$gEmailDomain (and *not*
624 to $baddress\@$gEmailDomain).
625
626 Please do not reply to the address at the top of this message,
627 unless you wish to report a problem with the $gBug-tracking system.
628 $brokenness
629 $gMaintainer
630 (administrator, $gProject $gBugs database)
631 END
632 From: $gMaintainerEmail ($gProject $gBug Tracking System)
633 To: $replyto
634 Subject: $gBug#$ref: Acknowledgement ($subject)
635 Message-ID: <handler.$ref.$nn.ack\@$gEmailDomain>
636 In-Reply-To: $header{'message-id'}
637 References: $header{'message-id'}
638 X-$gProject-PR-Message: ack $ref
639
640 Thank you for the problem report you have sent regarding $gProject.
641 This is an automatically generated reply, to let you know your message has
642 been received.  It is being forwarded to the developers mailing list for
643 their attention; they will reply in due course.
644 $resentccexplain
645 If you wish to submit further information on your problem, please send
646 it to $ref\@$gEmailDomain (and *not* to
647 $baddress\@$gEmailDomain).
648
649 Please do not reply to the address at the top of this message,
650 unless you wish to report a problem with the $gBug-tracking system.
651 $brokenness
652 $gMaintainer
653 (administrator, $gProject $gBugs database)
654 END
655 } elsif ($codeletter ne 'U') {
656     &htmllog("Acknowledgement","sent",$replyto,
657              ($veryquiet ? "Extra info received and filed, but not forwarded." :
658               $codeletter eq 'M' ? "Extra info received and forwarded to maintainer." :
659               "Extra info received and forwarded to list."). $htmlbreak);
660     &sendmessage($veryquiet ? <<END : $codeletter eq 'M' ? <<END : <<END,'');
661 From: $gMaintainerEmail ($gProject $gBug Tracking System)
662 To: $replyto
663 Subject: $gBug#$ref: Info received and FILED only
664          (was $subject)
665 Message-ID: <handler.$ref.$nn.ackinfoquiet\@$gEmailDomain>
666 In-Reply-To: $header{'message-id'}
667 References: $header{'message-id'}
668 X-$gProject-PR-Message: ack-info-quiet $ref
669
670 Thank you for the additional information you have supplied regarding
671 this problem report.  It has NOT been forwarded to the developers, but
672 will accompany the original report in the $gBug tracking system.  Please
673 ensure that you yourself have sent a copy of the additional
674 information to any relevant developers or mailing lists.
675 $resentccexplain
676 If you wish to continue to submit further information on your problem,
677 please send it to $ref-$baddressroot\@$gEmailDomain, as before.
678
679 Please do not reply to the address at the top of this message,
680 unless you wish to report a problem with the $gBug-tracking system.
681 $brokenness
682 $gMaintainer
683 (administrator, $gProject $gBugs database)
684 END
685 From: $gMaintainerEmail ($gProject $gBug Tracking System)
686 To: $replyto
687 Subject: $gBug#$ref: Info received for maintainer only
688          (was $subject)
689 Message-ID: <handler.$ref.$nn.ackinfomaint\@$gEmailDomain>
690 In-Reply-To: $header{'message-id'}
691 References: $header{'message-id'}
692 X-$gProject-PR-Message: ack-info $ref
693
694 Thank you for the additional information you have supplied regarding
695 this problem report.  It has been forwarded to the developer(s) (but
696 not to the mailing list) to accompany the original report.
697 $resentccexplain
698 If you wish to continue to submit further information on your problem,
699 please send it to $ref-$baddressroot\@$gEmailDomain, as before.
700
701 Please do not reply to the address at the top of this message,
702 unless you wish to report a problem with the $gBug-tracking system.
703 $brokenness
704 $gMaintainer
705 (administrator, $gProject $gBugs database)
706 END
707 From: $gMaintainerEmail ($gProject $gBug Tracking System)
708 To: $replyto
709 Subject: $gBug#$ref: Info received (was $subject)
710 Message-ID: <handler.$ref.$nn.ackinfo\@$gEmailDomain>
711 In-Reply-To: $header{'message-id'}
712 References: $header{'message-id'}
713 X-$gProject-PR-Message: ack-info-maintonly $ref
714
715 Thank you for the additional information you have supplied regarding
716 this problem report.  It has been forwarded to the developer(s) and
717 to the developers mailing list to accompany the original report.
718 $resentccexplain
719 If you wish to continue to submit further information on your problem,
720 please send it to $ref\@$gEmailDomain, as before.
721
722 Please do not reply to the address at the top of this message,
723 unless you wish to report a problem with the $gBug-tracking system.
724 $brokenness
725 $gMaintainer
726 (administrator, $gProject $gBugs database)
727 END
728 }
729
730 &appendlog;
731 &finish;
732
733 sub overwrite {
734     local ($f,$v) = @_;
735     open(NEW,">$f.new") || &quit("$f.new: create: $!");
736     print(NEW "$v") || &quit("$f.new: write: $!");
737     close(NEW) || &quit("$f.new: close: $!");
738     rename("$f.new","$f") || &quit("rename $f.new to $f: $!");
739 }
740
741 sub appendlog {
742     if (!open(AP,">>db/$ref.log")) {
743         print DEBUG "failed open log<\n";
744         print DEBUG "failed open log err $!<\n";
745         &quit("opening db/$ref.log (li): $!");
746     }
747     print(AP "\7\n",@log,"\n\3\n") || &quit("writing db/$ref.log (li): $!");
748     close(AP) || &quit("closing db/$ref.log (li): $!");
749 }
750
751 sub finish {
752     utime(time,time,"db");
753     local ($u);
754     while ($u= $cleanups[$#cleanups]) { &$u; }
755     unlink("incoming/P$nn") || &quit("unlinking incoming/P$nn: $!");
756     exit $_[0];
757 }
758
759 &quit("wot no exit");
760
761 sub chldhandle { $chldexit = 'yes'; }
762
763 sub htmllog {
764     local ($whatobj,$whatverb,$where,$desc) = @_;
765     open(AP,">>db/$ref.log") || &quit("opening db/$ref.log (lh): $!");
766     print(AP
767           "\6\n".
768           "<strong>$whatobj $whatverb</strong> to <code>".&sani($where).
769           "</code>:<br>\n". $desc.
770           "\n\3\n") || &quit("writing db/$ref.log (lh): $!");
771     close(AP) || &quit("closing db/$ref.log (lh): $!");
772 }    
773
774 sub get_addresses {
775         return
776                 map { $_->address() }
777                 map { Mail::Address->parse($_) } @_;
778 }
779
780
781 sub sendmessage {
782     local ($msg,@recips) = @_;
783     if ($recips[0] eq '' && $#recips == 0) { @recips= ('-t'); }
784
785         #save email to the log
786     open(AP,">>db/$ref.log") || &quit("opening db/$ref.log (lo): $!");
787     print(AP "\2\n",join("\4",@recips),"\n\5\n$msg\n\3\n") ||
788         &quit("writing db/$ref.log (lo): $!");
789     close(AP) || &quit("closing db/$ref.log (lo): $!");
790     
791         #if debbuging.. save email to a log
792 #       open AP, ">>debug";
793 #       print AP join( '|', @recips )."\n>>";
794 #       print AP get_addresses( @recips );
795 #       print AP "<<\n".$msg;
796 #       print AP "\n--------------------------------------------------------\n";
797 #       close AP;
798
799         #start mailing
800         $msg =~ /^Subject: (.*)$/;
801     $SIG{'CHLD'}='chldhandle';
802         #print DEBUG "mailing sigchild set up<\n";
803         $chldexit = 'no';
804     $c= open(U,"-|");
805         #print DEBUG "mailing opened pipe fork<\n";
806     defined($c) || die $!;
807         #print DEBUG "mailing opened pipe fork ok $c<\n";
808     if (!$c) { # ie, we are in the child process
809                 #print DEBUG "mailing child<\n";
810         unless (open(STDERR,">&STDOUT")) {
811                         #print DEBUG "mailing child opened stderr<\n";
812             print STDOUT "redirect stderr: $!\n";
813                         #print DEBUG "mailing child opened stderr fail<\n";
814             exit 1;
815                         #print DEBUG "mailing child opened stderr fail exit !?<\n";
816         }
817                 #print DEBUG "mailing child opened stderr ok<\n";
818         $c= open(D,"|-");
819                 #print DEBUG "mailing child forked again<\n";
820         defined($c) || die $!;
821                 #print DEBUG "mailing child forked again ok $c<\n";
822         if (!$c) { # ie, we are the child process
823                         #print DEBUG "mailing grandchild<\n";
824             exec '/usr/lib/sendmail','-f'."$gMaintainerEmail",'-odi','-oem','-oi',get_addresses(@recips);
825                         #print DEBUG "mailing grandchild exec failed<\n";
826             die $!;
827                         #print DEBUG "mailing grandchild died !?<\n";
828         }
829                 #print DEBUG "mailing child not grandchild<\n";
830         print(D $msg) || die $!;
831                 #print DEBUG "mailing child printed msg<\n";
832         close(D);
833                 #print DEBUG "mailing child closed pipe<\n";
834         die "\n*** command returned exit status $?\n" if $?;
835                 #print DEBUG "mailing child exit status ok<\n";
836         exit 0;
837                 #print DEBUG "mailing child exited ?!<\n";
838     }
839         #print DEBUG "mailing parent<\n";
840     $results='';
841         #print DEBUG "mailing parent results emptied<\n";
842     while( $chldexit eq 'no' ) { $results.= $_; }
843         #print DEBUG "mailing parent results read >$results<\n";
844     close(U);
845         #print DEBUG "mailing parent results closed<\n";
846     $results.= "\n*** child returned exit status $?\n" if $?;
847         #print DEBUG "mailing parent exit status ok<\n";
848     $SIG{'CHLD'}='DEFAULT';
849         #print DEBUG "mailing parent sigchild default<\n";
850     if (length($results)) { &quit("running sendmail: $results"); }
851         #print DEBUG "mailing parent results ok<\n";
852 }
853
854 sub checkmaintainers {
855     return if $maintainerschecked++;
856     return if !length($s_package);
857     open(MAINT,"$gMaintainerFile") || die &quit("maintainers open: $!");
858     while (<MAINT>) {
859         m/^(\S+)\s+(\S.*\S)\n$/ || &quit("maintainers bogus \`$_'");
860         $a= $1; $b= $2; $a =~ y/A-Z/a-z/;
861         $maintainerof{$1}= $2;
862     }
863     close(MAINT);
864     $anymaintfound=0; $anymaintnotfound=0;
865     for $p (split(m/[ \t?,()]+/,$s_package)) {
866         $p =~ y/A-Z/a-z/;
867         if (defined($maintainerof{$p})) {
868 print DEBUG "maintainer add >$p|$maintainerof{$p}<\n";
869             $addmaint= $maintainerof{$p};
870             push(@maintaddrs,$addmaint) unless
871                 $addmaint eq $replyto || grep($_ eq $addmaint, @maintaddrs);
872             $anymaintfound++;
873         } else {
874 print DEBUG "maintainer none >$p<\n";
875             $anymaintnotfound++;
876             last;
877         }
878     }
879 }