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