File: mailcap.pl

package info (click to toggle)
links2 2.1pre37-1.1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 16,556 kB
  • ctags: 6,227
  • sloc: ansic: 115,566; sh: 3,335; cpp: 530; makefile: 116; awk: 47; perl: 34
file content (51 lines) | stat: -rwxr-xr-x 1,216 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/perl -w
# mailcap to links.cfg converter (aka quick hack)
# version 1.00 by <grin@tolna.net>
# Released under GPLv2 or later
#
# Usage: mailcap-convert.pl /etc/mailcap >> ~/.links2/links.cfg
#

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";
}