commit - 70b47196e34f4f26bce03cb299d75aee2b6e34f6
commit + 53bed50154a249d1263a3066d28500b3541539d5
blob - 56d7c607a3cfd9f8e92396ffd70c7bce43d193af
blob + 8f291686b1442a49b81b17cfe468f87b9a6d5084
--- mexp
+++ mexp
use strict;
use warnings;
use v5.32;
-use File::Temp qw(tempfile);
use OpenBSD::Pledge;
use OpenBSD::Unveil;
unveil("/usr/local/bin/mshow", "rx") or die "unveil mshow: $!";
unveil($outdir, "rwc") or die "unveil $outdir: $!";
-# can't use tmppath because File::Temp checks whether /tmp exists.
-unveil("/tmp", "rwc") or die "unveil /tmp: $!";
unveil(".", "r") or die "unveil .: $!";
-# fattr for File::Temp
-pledge("stdio rpath wpath cpath proc exec fattr") or die "pledge: $!";
+pledge("stdio rpath wpath cpath proc exec") or die "pledge: $!";
sub export_part {
my ($fh, $n, $fname) = @_;
open(my $parts, '-|', 'mshow', '-t', $fname)
or die "can't exec mshow: $!";
- my $part_seen = 0;
+ my $partno = 0;
while (<$parts>) {
my ($n, $mime, $size, $name) =
m/(\d+): ([^ ]+) size=(\d+) name="(.*)"/ or next;
# text/* is bundled in the body by mshow(1).
- if (!$part_seen) {
- $part_seen = 1;
- say $fh "<ul class='parts'>";
- }
+ say $fh "<ul class='parts'>" if $partno == 0;
+ $partno++;
- my ($p, $path) = tempfile "$outdir/parts/$mid.XXXXXXXXXX";
+ my $path = "$outdir/parts/$mid.$partno.$ext";
+ open my $p, '>', $path
+ or die "can't open $fname: $!";
export_part($p, $n, $fname);
close($p);
- rename $path, "$path.$ext"
- or die "can' rename $path as $path.ext";
- chmod 0644, "$path.$ext";
$path =~ s,^.*/parts/,/parts/,;
- my $url = san("$path.$ext");
+ my $url = san($path);
my $hs = humanize $size;
say $fh "<li><a href='$url'>$name ($hs)</a></li>";
}
- say $fh "</ul>" if $part_seen;
+ say $fh "</ul>" if $partno > 0;
my $encmid = urlencode $mid;
my $enctid = urlencode $tid;