Bug#815198: Updated version of mbox script

Mike Gabriel <[email protected]>
Newsgroups gmane.linux.debian.devel.debbugs
Organization DAS-NETZWERKTEAM
Message-ID <20160220084432.Horde.b1F8QgJa7kFPaNoiOqyj7Gu__25645.8994620063$1455957945$gmane$org@mail.das-netzwerkteam.de>
Find attached an updated version of the "mbox" script I submitted yesterday.

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 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 die("open log for $ref: $!");
    $ENV{'PATH'} = $oldpath;
} else {
    $buglogfh = IO::File->new($buglog,'r') or die("open log for $ref: $!");
}

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

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

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

iQIcBAABCAAGBQJWyCdwAAoJEJr0azAldxsxq8UP/1PPMkLjVnx/PEZPWDvbn5t0
C3LRIvkW9prwt9BL8DiGVuzdXiBgJvMMkrfYDWv+o3Lrh+Yj6bgGHl8avCXoQnBd
eocjPz8JfUER9cOKJf/fiGURkNk5KKq6Dgc3oYC59ubtce8+J5a7p8TeKbDhfQ2W
duvg2YuQQgMvvJH+ol1BOqn8RVcxJOQXY3gyFTrIxC537C4+blyFeTtCNqhZx3bE
D0gCxqiNFuV7XhchuONrWBQ/CTKd6D6+7fBw1plxSrdGDaEPNCJfuBPh2bix0eUY
mePpZ0rdmnxFelXZmH/RcZnFzHgJJZZ3T2G/+RAY54vfzW+IU9Df5bZuLQzbePBo
rXzUHBUc4yoeZ85QIzBnqZEbKD29NICw3nL7XyAcO7nv/lCOmxzfcHH00c5cqdOW
YLEONRIiLs/OJdx4GLr98cTIV+xSu/3OkOgcs/AgJK4QwH+6G9KnpMV0ajgfYqQr
OkwEKpnvoYnzTslWObxvVJ0U9guynFquPJ/empPKR534VjFByDvkohs59Ujj0TvE
dpVpLViVTY+3w5k+PmeKH04GSrvBTZMxNpeeme3XauJGenxQyUYxvslS8FVl23Y6
GAOzhDKykRsgOTJUEcJDsb/VPGxo7n6+Jx0ePxMshoMyjW2w1FXOxGgb/KMsedJT
Stwo7toIkre/Cqt4P8g+
=qdGX
-----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.