From c90d68024af530aea52f899ed1a2362ca06768c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Wed, 26 May 2021 15:18:39 +0200 Subject: mum: Implement 'p' command --- src/mum | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/src/mum b/src/mum index 7955a71..0d6eadb 100755 --- a/src/mum +++ b/src/mum @@ -42,6 +42,7 @@ my $d = qr{ my $MESSAGE = 0; # selected message my $INDEX = ''; # loaded mbox index +my $MBOX = ''; # associated mbox my @MESSAGES; # loaded messages my %MARKS; # saved marks my $SEARCH; # last search regex @@ -56,7 +57,7 @@ while () { $MESSAGE = 1 if $MESSAGE < 1; $MESSAGE = @MESSAGES if $MESSAGE > @MESSAGES; - print $tty "$INDEX:$MESSAGE& "; + print $tty "$MBOX:$MESSAGE& "; # Read next command from user @@ -108,7 +109,36 @@ h: my ($a, $b); $a = toloc(0, shift @RANGE) or next if @RANGE > 1; $b = toloc($a, shift @RANGE) or next if @RANGE; - print "p\n"; + $b = $MESSAGE if not $b; + $a = $b if not $a; + + open my $mbox, '<', $MBOX or do { + warn "failed to open $MBOX: $!\n"; + next; + }; + + for my $i ($a .. $b) { + $MESSAGES[$i-1] =~ /^M-Offset: (.*)$/m; + my $offset = $1; + $MESSAGES[$i-1] =~ /^M-Length: (.*)$/m; + my $length = $1; + + unless (defined $offset and defined $length) { + warn "ill-formatted message $i\n"; + next; + } + + seek $mbox, $offset, 0 or do { + warn "failed to retrieve message $i\n"; + next; + }; + + local $/ = \$length; + print scalar <$mbox>; + print "\n"; + } + + close $mbox; } # | @@ -132,7 +162,8 @@ h: warn "failed to open $idx: $!\n"; next; }; - ($INDEX = $idx) =~ s/\.i$//; + $INDEX = $idx; + ($MBOX = $INDEX) =~ s/\.i$//; local $/ = ''; @MESSAGES = () if not $cmd =~ /^ra/; # overwrite my $offset = 0; @@ -160,7 +191,7 @@ h: # Subroutines -# Parse ref/grep and return corresponding location +# Parse ref/grep and return corresponding location in index sub toloc { my $start = shift; # starting position for searches (optional) my %ref = %{(shift)}; # reference to parse -- cgit v1.2.3