diff options
author | John Ankarström <john@ankarstrom.se> | 2021-05-26 15:18:39 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2021-05-26 15:18:39 +0200 |
commit | c90d68024af530aea52f899ed1a2362ca06768c9 (patch) | |
tree | c838d535d4d9caafda03cc84139716a86cf43ae3 | |
parent | 55e8dbfa92eb9c549dfb28c808cfb1d3b978f104 (diff) | |
download | mum-c90d68024af530aea52f899ed1a2362ca06768c9.tar.gz |
mum: Implement 'p' command
-rwxr-xr-x | src/mum | 39 |
1 files changed, 35 insertions, 4 deletions
@@ -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 |