summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2021-05-26 15:18:39 +0200
committerJohn Ankarström <john@ankarstrom.se>2021-05-26 15:18:39 +0200
commitc90d68024af530aea52f899ed1a2362ca06768c9 (patch)
treec838d535d4d9caafda03cc84139716a86cf43ae3
parent55e8dbfa92eb9c549dfb28c808cfb1d3b978f104 (diff)
downloadmum-c90d68024af530aea52f899ed1a2362ca06768c9.tar.gz
mum: Implement 'p' command
-rwxr-xr-xsrc/mum39
1 files 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