Excerpts from John Bent's message of Tue Jan 22 09:40:05 -0700 2008:
> I saw some earlier discussion in the list archives about a missing run-mailcap
> script. I had this same problem too on my mac (10.4.11 Power PC). It's sort
> of a kluge but I dealt with this by writing my own /usr/bin/run-mailcap which
> just does a simple hash lookup of mime type to rename the file with an
> appropriate extension and then uses the mac 'open' command. I haven't fully
> populated the hash table yet; I'll do that lazily. If the 'file' command
> could return an extension, I'd be tempted to use it and avoid the hash table
> but the best it can do is return the mime-type which we already know. Or if
> there was some way to pass the mime-type to the 'open' command, that'd be
> better too. But at least this works...
>
Here's a cleaner version that doesn't have anything hard-coded but relies
on the 'find' command and the MIME::Types perl module:
============================================================================
#! /opt/local/bin/perl
use MIME::Types;
my ( $type, $file ) = split( /:/, $ARGV[1] );
if ( $type eq 'application/octet-stream' ) {
$type = findType( $file );
}
my $extension = findExtension( $type );
my $newfile = "$file.$extension";
my $command = "open $newfile";
rename( $file, $newfile );
Log( "Extension for $type is $extension -> $command\n" );
system( $command );
#######################################################################
sub
findExtension {
my $mimetypes = MIME::Types->new;
my MIME::Type $mimetype = $mimetypes->type($type);
my @extensions = $mimetype->extensions;
return $extensions[0];
}
sub
findType {
my $file = shift;
my $type = `file -i -b $file`;
chomp( $type );
return $type;
}
my $log_fd;
sub
Log {
if ( ! defined $log_fd ) {
open LOG, ">>/tmp/mailcap.log" or warn "open log: $!\n";
$log_fd = \*LOG;
}
#print "@_";
print LOG "@_";
}
_______________________________________________
sup-talk mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/sup-talk