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