27
'(^|/)crontab[^/]+$' => 'text/x-crontab', #'
28
'/man\d*/' => 'application/x-troff-man', #'
29
'\.\d[^\.]*$' => 'application/x-troff-man', #'
27
'(^|/)crontab[^/]+$' => 'text/x-crontab', #'
28
'/man\d*/' => 'application/x-troff-man', #'
29
'\.\d[^\.]*$' => 'application/x-troff-man', #'
36
print STDERR $error,"\n\n" if $error;
38
print STDERR "Use: $0 <--opt=val> [...] [<mime-type>:[<encoding>:]]<file> [...]\n\n";
39
print STDERR "Options:\n";
40
print STDERR " action specify what action to do on these files (default=view)\n";
41
print STDERR " debug be verbose about what's going on (any non-zero value)\n";
43
print STDERR "Mime-Type:\n";
44
print STDERR " any standard mime type designation in the form <class>/<subtype> -- if\n";
45
print STDERR " not specified, it will be determined from the filename extension\n\n";
46
print STDERR "Encoding:\n";
47
print STDERR " how the file (and type) has been encoded (only \"gzip\", \"bzip\", \"bzip2\"\n";
48
print STDERR " and \"compress\" are supported) -- if not specified, it will be determined\n";
49
print STDERR " from the filename extension\n\n";
51
exit ($error ? 1 : 0);
36
print STDERR $error,"\n\n" if $error;
38
print STDERR "Use: $0 <--action=VAL> [--debug] [MIME-TYPE:[ENCODING:]]FILE [...]\n\n";
39
print STDERR "Options:\n";
40
print STDERR " action specify what action to do on these files (default=view)\n";
41
print STDERR " debug be verbose about what's going on\n";
43
print STDERR "Mime-Type:\n";
44
print STDERR " any standard mime type designation in the form <class>/<subtype> -- if\n";
45
print STDERR " not specified, it will be determined from the filename extension\n\n";
46
print STDERR "Encoding:\n";
47
print STDERR " how the file (and type) has been encoded (only \"gzip\", \"bzip\", \"bzip2\"\n";
48
print STDERR " and \"compress\" are supported) -- if not specified, it will be determined\n";
49
print STDERR " from the filename extension\n\n";
51
exit ($error ? 1 : 0);
56
56
sub EncodingForFile {
60
if ($file =~ m/\.gz$/) { $encoding = "gzip"; }
61
if ($file =~ m/\.bz$/) { $encoding = "bzip"; }
62
if ($file =~ m/\.bz2$/) { $encoding = "bzip2"; }
63
if ($file =~ m/\.Z$/) { $encoding = "compress"; }
65
print STDERR " - file \"$file\" has encoding \"$encoding\"\n" if $debug && $encoding;
60
if ($file =~ m/\.gz$/) { $encoding = "gzip"; }
61
if ($file =~ m/\.bz$/) { $encoding = "bzip"; }
62
if ($file =~ m/\.bz2$/) { $encoding = "bzip2"; }
63
if ($file =~ m/\.Z$/) { $encoding = "compress"; }
65
print STDERR " - file \"$file\" has encoding \"$encoding\"\n" if $debug && $encoding;
72
72
sub ReadMimetypes {
75
return unless -r $file;
77
print STDERR " - Reading mime.types file \"$file\"...\n" if $debug;
78
open(MIMETYPES,"<$file") || die "Error: could not read \"$file\" -- $!\n";
83
my($type,@exts) = split;
86
$mimetypes{$_} = $type unless exists $mimetypes{$_};
75
return unless -r $file;
77
print STDERR " - Reading mime.types file \"$file\"...\n" if $debug;
78
open(MIMETYPES,"<$file") || die "Error: could not read \"$file\" -- $!\n";
85
my($type,@exts) = split;
88
$mimetypes{$_} = $type unless exists $mimetypes{$_};
98
return unless -r $file;
100
print STDERR " - Reading mailcap file \"$file\"...\n" if $debug;
101
open(MAILCAP,"<$file") || die "Error: could not read \"$file\" -- $!\n";
107
if ($line =~ m/^\s*\#/) {
111
if ($line =~ m/\\$/) {
114
$line =~ s/\\;/$quotedsemi/go;
115
$line =~ s/\\%/$quotedprct/go;
100
return unless -r $file;
102
print STDERR " - Reading mailcap file \"$file\"...\n" if $debug;
103
open(MAILCAP,"<$file") || die "Error: could not read \"$file\" -- $!\n";
109
if ($line =~ m/^\s*\#/) {
113
if ($line =~ m/\\$/) {
116
$line =~ s/\\;/$quotedsemi/go;
117
$line =~ s/\\%/$quotedprct/go;
127
my($cmd,$head,$tail,$tmpfile);
129
($head,$tail) = split(/%s/,$template,2);
131
# $tmpfile = POSIX::tmpnam($name);
134
$cmd = "tempfile --mode=600";
135
$cmd .= " --prefix $head" if $head;
136
$cmd .= " --suffix $tail" if $tail;
141
# $tmpfile = $ENV{TMPDIR};
142
# $tmpfile = "/tmp" unless $tmpfile;
143
# $tmpfile.= "/$name";
129
my($cmd,$head,$tail,$tmpfile);
130
$template = "" unless (defined $template);
132
($head,$tail) = split(/%s/,$template,2);
134
# $tmpfile = POSIX::tmpnam($name);
137
$cmd = "tempfile --mode=600";
138
$cmd .= " --prefix $head" if $head;
139
$cmd .= " --suffix $tail" if $tail;
144
# $tmpfile = $ENV{TMPDIR};
145
# $tmpfile = "/tmp" unless $tmpfile;
146
# $tmpfile.= "/$name";
153
my($tmpfile,$amt,$buf);
155
$tmpfile = $1 if ($match =~ m/nametemplate=(.*?)\s*($|;)/);
156
$tmpfile = TempFile($tmpfile);
157
open(TMPFILE,">$tmpfile") || die "Error: could not write \"$tmpfile\" -- $!\n";
159
$amt = read(STDIN,$buf,102400);
160
print TMPFILE $buf if $amt;
156
my($tmpfile,$amt,$buf);
158
$tmpfile = $1 if ($match =~ m/nametemplate=(.*?)\s*($|;)/);
159
$tmpfile = TempFile($tmpfile);
160
open(TMPFILE,">$tmpfile") || die "Error: could not write \"$tmpfile\" -- $!\n";
162
$amt = read(STDIN,$buf,102400);
163
print TMPFILE $buf if $amt;
170
my($efile,$encoding,$action) = @_;
174
$file =~ s!^.*/!!; # remove leading directories
175
$file =~ s!\.[^\.]*$!!; # remove encoding extension
176
$file =~ s!^\.?[^\.]*!%s!; # replace name with placeholder
177
$file = undef if ($efile eq '-');
178
my $tmpfile = TempFile($file);
180
print STDERR " - decoding \"$efile\" as \"$tmpfile\"\n" if $debug;
182
# unlink($tmpfile); # should still be acceptable for "compose" output even if exists
183
return $tmpfile if (($efile ne '-' && ! -e $efile) || $action eq 'compose');
185
if ($encoding eq "gzip") {
187
$res = system "gzip -d >\Q$tmpfile\E";
189
$res = system "gzip -dc \Q$efile\E >\Q$tmpfile\E";
191
} elsif ($encoding eq "bzip") {
193
$res = system "bzip -d >\Q$tmpfile\E";
195
$res = system "bzip -dc <\Q$efile\E >\Q$tmpfile\E";
197
} elsif ($encoding eq "bzip2") {
199
$res = system "bzip2 -d >\Q$tmpfile\E";
201
$res = system "bzip2 -dc <\Q$efile\E >\Q$tmpfile\E";
203
} elsif ($encoding eq "compress") {
205
$res = system "uncompress >\Q$tmpfile\E";
207
$res = system "uncompress <\Q$efile\E >\Q$tmpfile\E";
210
die "Fatal: unknown encoding \"$encoding\" at";
213
$res = int($res/256);
215
print STDERR "Error: could not decode \"$efile\" -- $!\n";
216
$retcode = 2 if ($retcode < 2);
221
# chmod 0600,$tmpfile; # done already by TempFile
173
my($efile,$encoding,$action) = @_;
177
$file =~ s!^.*/!!; # remove leading directories
178
$file =~ s!\.[^\.]*$!!; # remove encoding extension
179
$file =~ s!^\.?[^\.]*!%s!; # replace name with placeholder
180
$file = undef if ($efile eq '-');
181
my $tmpfile = TempFile($file);
183
print STDERR " - decoding \"$efile\" as \"$tmpfile\"\n" if $debug;
185
# unlink($tmpfile); # should still be acceptable for "compose" output even if exists
186
return $tmpfile if (($efile ne '-' && ! -e $efile) || $action eq 'compose');
188
if ($encoding eq "gzip") {
190
$res = system "gzip -d >\Q$tmpfile\E";
192
$res = system "gzip -dc \Q$efile\E >\Q$tmpfile\E";
194
} elsif ($encoding eq "bzip") {
196
$res = system "bzip -d >\Q$tmpfile\E";
198
$res = system "bzip -dc <\Q$efile\E >\Q$tmpfile\E";
200
} elsif ($encoding eq "bzip2") {
202
$res = system "bzip2 -d >\Q$tmpfile\E";
204
$res = system "bzip2 -dc <\Q$efile\E >\Q$tmpfile\E";
206
} elsif ($encoding eq "compress") {
208
$res = system "uncompress >\Q$tmpfile\E";
210
$res = system "uncompress <\Q$efile\E >\Q$tmpfile\E";
213
die "Fatal: unknown encoding \"$encoding\" at";
216
$res = int($res/256);
218
print STDERR "Error: could not decode \"$efile\" -- $!\n";
219
$retcode = 2 if ($retcode < 2);
224
# chmod 0600,$tmpfile; # done already by TempFile
228
my($dfile,$efile,$encoding) = @_;
231
print STDERR " - encoding \"$dfile\" as \"$efile\"\n";
233
if ($encoding eq "gzip") {
235
$res = system "gzip -c \Q$dfile\E";
237
$res = system "gzip -c \Q$dfile\E >\Q$efile\E";
239
} elsif ($encoding eq "compress") {
241
$res = system "compress <\Q$dfile\E";
243
$res = system "compress <\Q$dfile\E >\Q$efile\E";
246
die "Fatal: unknown encoding \"$encoding\" at";
249
$res = int($res/256);
251
print STDERR "Error: could not encode \"$efile\" (left as \"$dfile\")\n";
252
$retcode = 2 if ($retcode < 2);
231
my($dfile,$efile,$encoding) = @_;
234
print STDERR " - encoding \"$dfile\" as \"$efile\"\n";
236
if ($encoding eq "gzip") {
238
$res = system "gzip -c \Q$dfile\E";
240
$res = system "gzip -c \Q$dfile\E >\Q$efile\E";
242
} elsif ($encoding eq "compress") {
244
$res = system "compress <\Q$dfile\E";
246
$res = system "compress <\Q$dfile\E >\Q$efile\E";
249
die "Fatal: unknown encoding \"$encoding\" at";
252
$res = int($res/256);
254
print STDERR "Error: could not encode \"$efile\" (left as \"$dfile\")\n";
255
$retcode = 2 if ($retcode < 2);
261
264
sub ExtensionMimetype {
265
unless ($donemimetypes) {
266
ReadMimetypes($usrmimetyp);
267
ReadMimetypes($locmimetyp);
268
ReadMimetypes($shrmimetyp);
269
ReadMimetypes($etcmimetyp);
273
$typ = $mimetypes{lc($ext)};
275
print STDERR " - extension \"$ext\" maps to mime-type \"$typ\"\n" if $debug;
268
unless ($donemimetypes) {
269
ReadMimetypes($usrmimetyp);
270
ReadMimetypes($locmimetyp);
271
ReadMimetypes($shrmimetyp);
272
ReadMimetypes($etcmimetyp);
276
$typ = $mimetypes{lc($ext)};
278
print STDERR " - extension \"$ext\" maps to mime-type \"$typ\"\n" if $debug;
281
284
sub PatternMimetype {
285
while (($key,$val) = each %patterntypes) {
286
if ($file =~ m!$key!i) {
287
print STDERR " - file \"$file\" maps to mime-type \"$val\"\n" if $debug;
292
print STDERR " - file \"$file\" does not conform to any known pattern\n" if $debug;
288
while (($key,$val) = each %patterntypes) {
289
if ($file =~ m!$key!i) {
290
print STDERR " - file \"$file\" maps to mime-type \"$val\"\n" if $debug;
295
print STDERR " - file \"$file\" does not conform to any known pattern\n" if $debug;
298
301
sub FileMimetype {
300
my($ext) = ($file =~ m!\.([^/\.]+)$!);
304
$type = ExtensionMimetype($ext) if $ext;
305
$type = PatternMimetype($file) unless $type;
303
my($ext) = ($file =~ m!\.([^/\.]+)$!);
307
$type = ExtensionMimetype($ext) if $ext;
308
$type = PatternMimetype($file) unless $type;
312
316
foreach (@ARGV) {
313
print STDERR " - parsing parameter \"$_\"\n" if $debug;
314
if (m!^(-h|--help)$!) {
317
} elsif (m!^--(.*?)=(.*)$!) {
318
print STDERR "Warning: definition of \"$1=$2\" overrides value \"${$1}\"\n" if ($ {$1} && $ {$1} != $2);
320
} elsif (m!^[^/:]+/[^/:]+:[^/:]+:!) {
322
} elsif (m!^([^/:]+/[^/:]+):(.*)!) {
325
my $code = EncodingForFile($file);
326
push @files,"${type}:${code}:${file}";
329
my $code = EncodingForFile($file);
333
$efile =~ s/\.[^\.]+$//;
334
$type = FileMimetype($efile);
336
$type = FileMimetype($file);
339
push @files,"${type}:${code}:${file}";
341
print STDERR "Warning: unknown mime-type for \"$file\" -- using \"$defmimetyp\"\n";
342
push @files,"${defmimetyp}:${code}:${file}";
317
print STDERR " - parsing parameter \"$_\"\n" if $debug;
318
if (m!^(-h|--help)$!) {
321
} elsif (m!^--(.*?)=(.*)$!) {
322
print STDERR "Warning: definition of \"$1=$2\" overrides value \"${$1}\"\n" if ($ {$1} && $ {$1} != $2);
324
} elsif (m!^--(.*?)$!) {
325
print STDERR "Warning: definition of \"$1=$2\" overrides value \"${$1}\"\n" if ($ {$1} && $ {$1} != 1);
327
} elsif (m!^[^/:]+/[^/:]+:[^/:]+:!) {
329
} elsif (m!^([^/:]+/[^/:]+):(.*)! && ! -e $_) {
333
my $code = EncodingForFile($file);
334
push @files,"${type}:${code}:${file}";
335
print STDERR " - file \"$file\" does not exist -- assuming mime-type specification of \"${type}\"\n" if $debug;
338
my $code = EncodingForFile($file);
342
$efile =~ s/\.[^\.]+$//;
343
$type = FileMimetype($efile);
345
$type = FileMimetype($file);
348
push @files,"${type}:${code}:${file}";
350
print STDERR "Warning: unknown mime-type for \"$file\" -- using \"$defmimetyp\"\n";
351
push @files,"${defmimetyp}:${code}:${file}";
347
356
unless ($action) {
348
if ($0 =~ m!(^|/)view$!) { $action="view"; }
349
elsif ($0 =~ m!(^|/)see$!) { $action="view"; }
350
elsif ($0 =~ m!(^|/)edit$!) { $action="edit"; }
351
elsif ($0 =~ m!(^|/)change$!) { $action="edit"; }
352
elsif ($0 =~ m!(^|/)compose$!) { $action="compose";}
353
elsif ($0 =~ m!(^|/)print$!) { $action="print"; }
354
elsif ($0 =~ m!(^|/)create$!) { $action="compose";}
355
else { $action="view"; }
357
if ($0 =~ m!(^|/)view$!) { $action="view"; }
358
elsif ($0 =~ m!(^|/)see$!) { $action="view"; }
359
elsif ($0 =~ m!(^|/)edit$!) { $action="edit"; }
360
elsif ($0 =~ m!(^|/)change$!) { $action="edit"; }
361
elsif ($0 =~ m!(^|/)compose$!) { $action="compose";}
362
elsif ($0 =~ m!(^|/)print$!) { $action="print"; }
363
elsif ($0 =~ m!(^|/)create$!) { $action="compose";}
364
else { $action="view"; }
359
368
$mailcaps = $ENV{MAILCAPS};
360
369
$mailcaps = "$ENV{HOME}/.mailcap:/etc/mailcap:/usr/local/etc/mailcap:/usr/share/etc/mailcap:/usr/etc/mailcap" unless $mailcaps;
361
370
foreach (split(/:/,$mailcaps)) {
365
374
foreach (@files) {
366
my($type,$code,$file) = m/^(.*?):(.*?):(.*)$/;
367
print STDERR "Processing file \"$file\" of type \"$type\" (encoding=",$code?$code:"none",")...\n" if $debug;
370
if ($action eq 'compose' || $action eq 'edit') {
373
print STDERR "Error: no write permission for file \"$file\"\n";
374
$retcode = 2 if ($retcode < 2);
378
if (open(TEST,">$file")) {
382
print STDERR "Error: no write permission for file \"$file\"\n";
383
$retcode = 2 if ($retcode < 2);
389
print STDERR "Error: no such file \"$file\"\n";
390
$retcode = 2 if ($retcode < 2);
394
print STDERR "Error: no read permission for file \"$file\"\n";
395
$retcode = 2 if ($retcode < 2);
401
my(@matches,$entry,$res,$efile);
404
$file = DecodeFile($efile,$code,$action);
408
foreach $entry (@mailcap) {
409
$entry =~ m/^(.*?)\s*;/;
410
$_ = "\Q$1\E"; s/\\\*/\.\*/g;
411
push @matches,$entry if ($type =~ m!^$_$!i);
413
@matches = grep(/\Q$action\E=/,@matches) unless $action eq "view";
417
foreach $match (@matches) {
419
print STDERR " - checking mailcap entry \"$match\"\n" if $debug;
420
if ($action eq "view") {
421
($comm) = ($match =~ m/^.*?;\s*(.*?)\s*($|;)/);
423
($comm) = ($match =~ m/\Q$action\E=(.*?)\s*($|;)/);
425
next if (!$comm || $comm =~ m!(^|/)false$!i);
426
print STDERR " - program to execute: $comm\n" if $debug;
428
if ($match =~ m/;\s*test=(.*?)\s*($|;)/) {
430
print STDERR " - running test: $1 " if $debug;
431
$test = system "$1 >/dev/null 2>&1";
433
print STDERR " (result=$test=",($test!=0?"false":"true"),")\n" if $debug;
440
my($tmpfile,$tmplink);
441
if ($action ne 'print' && $match =~ m/;\s*needsterminal\s*($|;)/ && ! -t STDOUT) {
443
$comm = "$xtermprgrm -T '$file ($type)' -e $0 --action=$action '${type}:%s'";
445
print STDERR " - no terminal available for rule (needsterminal)\n" if $debug;
449
} elsif ($action eq 'view' && $match =~ m/;\s*copiousoutput\s*($|;)/) {
450
$comm .= " | $0 --action=$action text/plain:-";
454
if ($comm =~ m/[^%]%s/) {
455
if ($file =~ m![^ a-z0-9,.:/@%^+=_-]!i) {
456
$match =~ m/nametemplate=(.*?)\s*($|;)/;
460
$tmplink = TempFile($prefix);
462
if ($file =~ m!^/!) {
463
$linked = symlink($file,$tmplink);
465
my $pwd = `/bin/pwd`;
467
$linked = symlink("$pwd/$file",$tmplink);
470
print STDERR " - filename contains shell meta-characters; aliased to '$tmplink'\n" if $debug;
471
$comm =~ s/([^%])%s/$1$tmplink/g;
473
$comm =~ s/([^%])%s/$1$file/g;
476
if ($comm =~ m/\|/) {
477
$comm =~ s/\|/<\Q$file\E \|/;
479
$comm .= " <\Q$file\E";
481
if ($action eq 'edit' || $action eq 'compose') {
482
$comm .= " >\Q$file\E";
486
if ($comm =~ m/[^%]%s/) {
487
$tmpfile = SaveStdin($match);
488
$comm =~ s/([^%])%s/$1$tmpfile/g;
490
# no name means same as "-"... read from stdin
494
$comm =~ s!([^%])%t!$1$type!g;
495
$comm =~ s!([^%])%F!$1!g;
496
$comm =~ s!%{(.*?)}!$_="'$ENV{$1}'";s/\`//g;$_!ge;
497
$comm =~ s!\\(.)!$1!g;
498
$comm =~ s!\'\'!\'!g;
499
$comm =~ s!$quotedsemi!;!go;
500
$comm =~ s!$quotedprct!%!go;
502
print STDERR " - executing: $comm\n" if $debug;
504
$res = int($res/256);
506
print STDERR "Warning: program returned non-zero exit code \#$res\n";
510
unlink $tmpfile if $tmpfile;
511
unlink $tmplink if $tmplink;
517
print STDERR "Error: no \"$action\" rule for type \"$type\" passed its test case\n";
518
print STDERR " (for more information, add \"--debug=1\" on the command line)\n";
519
$retcode = 3 if ($retcode < 3);
521
print STDERR "Error: no \"$action\" mailcap rules found for type \"$type\"\n";
522
$retcode = 3 if ($retcode < 3);
524
unlink $file if $code;
525
$retcode = 1 unless $retcode;
530
if ($action eq 'edit' || $action eq 'compose') {
531
my $file = EncodeFile($file,$efile,$code);
532
unlink $file if $file;
375
my($type,$code,$file) = m/^(.*?):(.*?):(.*)$/;
376
print STDERR "Processing file \"$file\" of type \"$type\" (encoding=",$code?$code:"none",")...\n" if $debug;
379
if ($action eq 'compose' || $action eq 'edit') {
382
print STDERR "Error: no write permission for file \"$file\"\n";
383
$retcode = 2 if ($retcode < 2);
387
if (open(TEST,">$file")) {
391
print STDERR "Error: no write permission for file \"$file\"\n";
392
$retcode = 2 if ($retcode < 2);
398
print STDERR "Error: no such file \"$file\"\n";
399
$retcode = 2 if ($retcode < 2);
403
print STDERR "Error: no read permission for file \"$file\"\n";
404
$retcode = 2 if ($retcode < 2);
410
my(@matches,$entry,$res,$efile);
413
$file = DecodeFile($efile,$code,$action);
417
foreach $entry (@mailcap) {
418
$entry =~ m/^(.*?)\s*;/;
419
$_ = "\Q$1\E"; s/\\\*/\.\*/g;
420
push @matches,$entry if ($type =~ m!^$_$!i);
422
@matches = grep(/\Q$action\E=/,@matches) unless $action eq "view";
426
foreach $match (@matches) {
428
print STDERR " - checking mailcap entry \"$match\"\n" if $debug;
429
if ($action eq "view") {
430
($comm) = ($match =~ m/^.*?;\s*(.*?)\s*($|;)/);
432
($comm) = ($match =~ m/\Q$action\E=(.*?)\s*($|;)/);
434
next if (!$comm || $comm =~ m!(^|/)false$!i);
435
print STDERR " - program to execute: $comm\n" if $debug;
437
if ($match =~ m/;\s*test=(.*?)\s*($|;)/) {
439
print STDERR " - running test: $1 " if $debug;
440
$test = system "$1 >/dev/null 2>&1";
442
print STDERR " (result=$test=",($test!=0?"false":"true"),")\n" if $debug;
449
my($tmpfile,$tmplink);
450
if ($action ne 'print' && $match =~ m/;\s*needsterminal\s*($|;)/ && ! -t STDOUT) {
452
$comm = "$xtermprgrm -T '$file ($type)' -e $0 --action=$action '${type}:%s'";
454
print STDERR " - no terminal available for rule (needsterminal)\n" if $debug;
458
} elsif ($action eq 'view' && $match =~ m/;\s*copiousoutput\s*($|;)/) {
459
$comm .= " | $0 --action=$action text/plain:-";
463
if ($comm =~ m/[^%]%s/) {
464
if ($file =~ m![^ a-z0-9,.:/@%^+=_-]!i) {
465
$match =~ m/nametemplate=(.*?)\s*($|;)/;
469
$tmplink = TempFile($prefix);
471
if ($file =~ m!^/!) {
472
$linked = symlink($file,$tmplink);
474
my $pwd = `/bin/pwd`;
476
$linked = symlink("$pwd/$file",$tmplink);
479
print STDERR " - filename contains shell meta-characters; aliased to '$tmplink'\n" if $debug;
480
$comm =~ s/([^%])%s/$1$tmplink/g;
482
$comm =~ s/([^%])%s/$1$file/g;
485
if ($comm =~ m/\|/) {
486
$comm =~ s/\|/<\Q$file\E \|/;
488
$comm .= " <\Q$file\E";
490
if ($action eq 'edit' || $action eq 'compose') {
491
$comm .= " >\Q$file\E";
495
if ($comm =~ m/[^%]%s/) {
496
$tmpfile = SaveStdin($match);
497
$comm =~ s/([^%])%s/$1$tmpfile/g;
499
# no name means same as "-"... read from stdin
503
$comm =~ s!([^%])%t!$1$type!g;
504
$comm =~ s!([^%])%F!$1!g;
505
$comm =~ s!%{(.*?)}!$_="'$ENV{$1}'";s/\`//g;s/\'\'//g;$_!ge;
506
$comm =~ s!\\(.)!$1!g;
507
$comm =~ s!\'\'!\'!g;
508
$comm =~ s!$quotedsemi!;!go;
509
$comm =~ s!$quotedprct!%!go;
511
print STDERR " - executing: $comm\n" if $debug;
513
$res = int($res/256);
515
print STDERR "Warning: program returned non-zero exit code \#$res\n";
519
unlink $tmpfile if $tmpfile;
520
unlink $tmplink if $tmplink;
526
print STDERR "Error: no \"$action\" rule for type \"$type\" passed its test case\n";
527
print STDERR " (for more information, add \"--debug=1\" on the command line)\n";
528
$retcode = 3 if ($retcode < 3);
530
print STDERR "Error: no \"$action\" mailcap rules found for type \"$type\"\n";
531
$retcode = 3 if ($retcode < 3);
533
unlink $file if $code;
534
$retcode = 1 unless $retcode;
539
if ($action eq 'edit' || $action eq 'compose') {
540
my $file = EncodeFile($file,$efile,$code);
541
unlink $file if $file;