-# all of these support -c for stdout and -d for decompression,
-# mutt is commonly distributed with hooks for gz, bz2 and xz, at least
-# { foo => '' } means "--foo" is passed to the command-line,
-# otherwise { foo => '--bar' } passes "--bar"
-our %zsfx2cmd = (
- gz => [ qw(GZIP pigz gzip), { rsyncable => '' } ],
- bz2 => [ 'bzip2', {} ],
- xz => [ 'xz', {} ],
- # XXX does anybody care for these? I prefer zstd on entire FSes,
- # so it's probably not necessary on a per-file basis
- # zst => [ 'zstd', { -default => [ qw(-q) ], # it's noisy by default
- # rsyncable => '', threads => '-T' } ],
- # zz => [ 'pigz', { -default => [ '--zlib' ],
- # rsyncable => '', threads => '-p' }],
- # lzo => [ 'lzop', {} ],
- # lzma => [ 'lzma', {} ],
-);
-
-sub zsfx2cmd ($$$) {
- my ($zsfx, $decompress, $lei) = @_;
- my $x = $zsfx2cmd{$zsfx} // die "no support for suffix=.$zsfx";
- my @info = @$x;
- my $cmd_opt = pop @info;
- my @cmd = (undef, $decompress ? qw(-dc) : qw(-c));
- for my $exe (@info) {
- # I think respecting client's ENV{GZIP} is OK, not sure
- # about ENV overrides for other, less-common compressors
- if ($exe eq uc($exe)) {
- $exe = $lei->{env}->{$exe} or next;
- }
- $cmd[0] = which($exe) and last;
- }
- $cmd[0] // die join(' or ', @info)." missing for .$zsfx";
- # push @cmd, @{$cmd_opt->{-default}} if $cmd_opt->{-default};
- for my $bool (qw(rsyncable)) {
- my $switch = $cmd_opt->{rsyncable} // next;
- push @cmd, '--'.($switch || $bool);
- }
- for my $key (qw(rsyncable)) { # support compression level?
- my $switch = $cmd_opt->{$key} // next;
- my $val = $lei->{opt}->{$key} // next;
- push @cmd, $switch, $val;
- }
- \@cmd;
-}
-
-sub _post_augment_mbox { # open a compressor process