1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-10-08 05:04:16 -04:00
elinks/contrib/conv/mailcap.pl
Petr Baudis 0f6d4310ad Initial commit of the HEAD branch of the ELinks CVS repository, as of
Thu Sep 15 15:57:07 CEST 2005. The previous history can be added to this
by grafting.
2005-09-15 15:58:31 +02:00

50 lines
1.2 KiB
Perl
Executable File

#!/usr/bin/perl -w
# mailcap to elinks.conf converter (aka quick hack)
# version 1.00 by <grin@tolna.net>
# Released under GPLv2 or later
#
# Usage: mailcap-convert.pl /etc/mailcap >> ~/.elinks/elinks.conf
#
print "association \"-=BEGIN DEBIAN CONVERT=-\" \"\" \"\" 23 1\n";
while( <> ) {
chomp;
next if /^\s*(#|$)/;
@fields = split /;\s*/;
# change %s to % in the command
$fields[1] =~ s/%s/%/g;
my @out = ( "External association", $fields[0], $fields[1] );
for( my $i=2; $i<=$#fields; $i++ ) {
if( $fields[$i] =~ m/description="?([^"]+)"?/ ) {
# description
$out[0] = $1;
} elsif( $fields[$i] =~ m/nametemplate=(.+)/ ) {
# extension for the mime type
my $ext = $1;
$ext =~ s/%s\.(.+)$/$1/;
&new_ext($ext,$fields[0]);
}
}
&new_assoc( \@out );
}
print "association \"-=END DEBIAN CONVERT=-\" \"\" \"\" 23 1\n";
sub new_assoc {
my $aref = shift;
print "association ";
for my $i (0..2) {
print "\"$aref->[$i]\" ";
}
print "23 1\n";
}
sub new_ext {
print "extension";
for my $i (0..1) {
print " \"$_[$i]\"";
}
print "\n";
}