-my $xmessage = 1;
-my $suppressnext = 0;
-my $found_msgid = 0;
-my %seen_msgid = ();
-
-my $thisheader = '';
-my $this = '';
-
-my $cmsg = 1;
-
-my $normstate= 'kill-init';
-my $linenum = 0;
-my @mail = ();
-my @mails = ();
-while(my $line = <L>) {
- $linenum++;
- if ($line =~ m/^.$/ and 1 <= ord($line) && ord($line) <= 7) {
- # state transitions
- my $newstate;
- my $statenum = ord($line);
-
- $newstate = 'autocheck' if ($statenum == 1);
- $newstate = 'recips' if ($statenum == 2);
- $newstate = 'kill-end' if ($statenum == 3);
- $newstate = 'go' if ($statenum == 5);
- $newstate = 'html' if ($statenum == 6);
- $newstate = 'incoming-recv' if ($statenum == 7);
-
- # disallowed transitions:
- $_ = "$normstate $newstate";
- unless (m/^(go|go-nox|html) kill-end$/
- || m/^(kill-init|kill-end) (incoming-recv|autocheck|recips|html)$/
- || m/^kill-body go$/)
- {
- &quitcgi("$ref: Transition from $normstate to $newstate at $linenum disallowed");
- }
-
-#$this .= "\n<br>states: $normstate $newstate<br>\n";
-
-# if ($newstate eq 'go') {
-# $this .= "<pre>\n";
-# }
- if ($newstate eq 'html') {
- $this = '';
- }
-
- if ($newstate eq 'kill-end') {
-
- my $show = 1;
- $show = $boring
- if ($suppressnext && $normstate ne 'html');
-
- $show = ($xmessage == $msg) if ($msg);
-
- push @mails, join( '', @mail ) if ( $mbox && @mail );
- if ($show) {
- if (not $mime and @mail) {
- $this .= htmlsanit(join '', @mail);
- } elsif (@mail) {
- my $parser = new MIME::Parser;
- $parser->tmp_to_core(1);
- $parser->output_to_core(1);
-# $parser->output_under("/tmp");
- my $entity = $parser->parse( new IO::Lines \@mail );
- # TODO: make local subdir, clean it ourselves
- # the following does NOT delete the msg dirs in /tmp
- END { if ( $entity ) { $entity->purge; } if ( $parser ) { $parser->filer->purge; } }
- my @attachments = ();
- display_entity($entity, $ref, 1, $xmessage, $this, @attachments);
- }
-# if ($normstate eq 'go' || $normstate eq 'go-nox') {
- if ($normstate ne 'html') {
- $this = "<pre>\n$this</pre>\n";
- }
- if ($normstate eq 'html') {
- $this = "<a name=\"msg$xmessage\">$this <em><a href=\"" . bugurl($ref, "msg=$xmessage") . "\">Full text</a> available.</em></a>";
- }
- $this = "$thisheader$this" if $thisheader && !( $normstate eq 'html' );;
- $thisheader = '';
- my $delim = $terse ? "<p>" : "<hr>";
- if ($reverse) {
- $log = "$this\n$delim$log";
- } else {
- $log .= "$this\n$delim\n";
- }
- }
-
- $xmessage++ if ($normstate ne 'html');
-
- $suppressnext = $normstate eq 'html';
- $found_msgid = 0;
- }
-
- $normstate = $newstate;
- @mail = ();
- next;
- }
-
- $_ = $line;
- if ($normstate eq 'incoming-recv') {
- my $pl= $_;
- $pl =~ s/\n+$//;
- m/^Received: \(at (\S+)\) by (\S+)\;/
- || &quitcgi("bad line \`$pl' in state incoming-recv");
- $thisheader = "<h2><a name=\"msg$xmessage\">"
- . "Message received at ".htmlsanit("$1\@$2")
- . ":</a></h2>\n";
- $this = '';
- $normstate= 'go';
- push @mail, $_;
- } elsif ($normstate eq 'html') {
- $this .= $_;
- } elsif ($normstate eq 'go') {
- s/^\030//;
- if (!$suppressnext && !$found_msgid &&
- /^Message-ID: <(.*)>/i) {
- my $msgid = $1;
- $found_msgid = 1;
- if ($seen_msgid{$msgid}) {
- $suppressnext = 1;
- } else {
- $seen_msgid{$msgid} = 1;
- }
- }
- if (@mail) {
- push @mail, $_;
- } else {
- $this .= htmlsanit($_);
- }
- } elsif ($normstate eq 'go-nox') {
- next if !s/^X//;
- if (!$suppressnext && !$found_msgid &&
- /^Message-ID: <(.*)>/i) {
- my $msgid = $1;
- $found_msgid = 1;
- if ($seen_msgid{$msgid}) {
- $suppressnext = 1;
- } else {
- $seen_msgid{$msgid} = 1;
- }
- }
- if (@mail) {
- push @mail, $_;
- } else {
- $this .= htmlsanit($_);
- }
- } elsif ($normstate eq 'recips') {
- if (m/^-t$/) {
- $thisheader = "<h2>Message sent:</h2>\n";
- } else {
- s/\04/, /g; s/\n$//;
- $thisheader = "<h2>Message sent to ".htmlsanit($_).":</h2>\n";
- }
- $this = "";
- $normstate= 'kill-body';
- } elsif ($normstate eq 'autocheck') {
- next if !m/^X-Debian-Bugs(-\w+)?: This is an autoforward from (\S+)/;
- $normstate= 'autowait';
- $thisheader = "<h2>Message received at $2:</h2>\n";
- $this = '';
- push @mail, $_;
- } elsif ($normstate eq 'autowait') {
- next if !m/^$/;
- $normstate= 'go-nox';
- } else {
- &quitcgi("$ref state $normstate line \`$_'");
- }