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