Bug#815198: NEW script: /usr/lib/debbug/mbox <bugno>

Mike Gabriel <[email protected]>
Newsgroups gmane.linux.debian.devel.debbugs
Organization DAS-NETZWERKTEAM
Message-ID <20160220002141.Horde.R30kdpf1DWRgyjVy1m-Fqic__44350.0408590355$1455927875$gmane$org@mail.das-netzwerkteam.de>
Package: debbugs
Version: 2.6.0~exp1+git20160213.3eea543
Severity: wishlist

Hi,

I have hacked together a little new script named "mbox". I have it in  
/usr/lib/debbugs.

The script prints a bug number's mailbox to stdout. Maybe it is helpful.

Script is attached. It has been derived from bugreport.cgi.

Greets,
Mike
-- 

DAS-NETZWERKTEAM
mike gabriel, herweg 7, 24357 fleckeby
fon: +49 (1520) 1976 148

GnuPG Key ID 0x25771B31
mail: [email protected], http://das-netzwerkteam.de

freeBusy:
https://mail.das-netzwerkteam.de/mailxchange/kronolith/fb.php?u=m.gabriel%40das-netzwerkteam.de
mbox (text/plain, 2.2 KB)
#!/usr/bin/perl

use warnings;
use strict;

use POSIX qw(strftime);

use Debbugs::Config qw(:globals :text);

# for read_log_records
use Debbugs::Log qw(read_log_records);
use Debbugs::Common qw(buglog bug_status);
use Debbugs::Status qw( split_status_fields get_bug_status);
use Debbugs::MIME qw(create_mime_message);

use List::Util qw(max);

my $ref = shift or die;


my %bugusertags;

my $buglog = buglog($ref);
my $bug_status = bug_status($ref);

my $buglogfh;
if ($buglog =~ m/\.gz$/) {
    my $oldpath = $ENV{'PATH'};
    $ENV{'PATH'} = '/bin:/usr/bin';
    $buglogfh = IO::File->new("zcat $buglog |") or quitcgi("open log for $ref: $!");
    $ENV{'PATH'} = $oldpath;
} else {
    $buglogfh = IO::File->new($buglog,'r') or quitcgi("open log for $ref: $!");
}

my %status =
    %{split_status_fields(get_bug_status(bug=>$ref,
                                         bugusertags => \%bugusertags,
                                        ))};

my @records;
eval{
     @records = read_log_records($buglogfh);
};

my $mbox = 1;

my @log;
if ( $mbox ) {
     binmode(STDOUT,":raw");
     my $date = strftime "%a %b %d %T %Y", localtime;

     my $message_number=0;
     my %seen_message_ids;
     for my $record (@records) {
	  next if $record->{type} !~ /^(?:recips|incoming-recv)$/;
	  my $wanted_type = 'incoming-recv';
	  # we want to include control messages anyway
	  my $record_wanted_anyway = 0;
	  my ($msg_id) = $record->{text} =~ /^Message-Id:\s+<(.+)>/im;
	  next if defined $msg_id and exists $seen_message_ids{$msg_id};
	  next if defined $msg_id and $msg_id =~/handler\..+\.ack(?:info|done)?\@/;
	  $record_wanted_anyway = 1 if $record->{text} =~ /^Received: \(at control\)/;
	  next if not $record->{type} eq $wanted_type and not $record_wanted_anyway and @records > 1;
	  $seen_message_ids{$msg_id} = 1 if defined $msg_id;
	  my @lines = split( "\n", $record->{text}, -1 );
	  if ( $lines[ 1 ] =~ m/^From / ) {
	       my $tmp = $lines[ 0 ];
	       $lines[ 0 ] = $lines[ 1 ];
	       $lines[ 1 ] = $tmp;
	  }
	  if ( !( $lines[ 0 ] =~ m/^From / ) ) {
	       unshift @lines, "From unknown $date";
	  }
	  map { s/^(>*From )/>$1/ } @lines[ 1 .. $#lines ];
	  print join( "\n", @lines ) . "\n";
     }
     exit 0;
}
signature.asc (application/pgp-signature, 819 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iQIcBAABCAAGBQJWx7GUAAoJEJr0azAldxsxguoQAIkCWNtyglnBbf+t1d1vX5/S
INr8PiA5inIstdO2wKYtSk8sqqoNMaOWAHOQl7qZZpIe1pPwyluo2s41T6Nx39Us
0jtLyP8AdlPxtVk1sQpCDcGrsXwEt3Jyed1kwaOOE1VvLCJ45GLE6ukS9fF8Rig6
yZK/wfazgjdhW6lQcfgc9XtePsafagewr7dz2Hb+odrb144TonTuEv7FbO+ONjMR
02o3OY/wNSz/QMhsdcotuIxTysWUAA3GOY6eE9cQ7AO3I7wLRdwTkSRKMfJG0xkW
y6PSuvK00rMjyndqMBTT2TqykIC8mp+gX+HEv3gJrtPyEkbxuD01fnT13Kaz+kMI
68b/NieIks/qiMEC62MMsbjSP5WSA6XzoysvFJI+o7frNzzvj5mSOBhDsShcpwJT
hHv50gH/2nHsyGKiHhzWAOWxAu+XH0rZqV1ZFXKgHCOdkBbHp8pGKoGapG/A9glV
JVAGCDuAfYB+MFYAV1JCb/o1lWrM0uWtCffs54C2zOa/JBXSheEhhFO5yzbtgVuF
2ZIiiqL8f6jZzLft50Axc77Tk+U16Y2/xa5usp1yop1qNc8fukg/vB3M/615zzSh
mR7TyCPQuAMqzncLU+9Nm1o9y46jNTGiSxqgqPzgDrL0Uh61JF9N1gEJykHzi4gG
YsAVUjSXPBiDwjPx4dGq
=vTGi
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.