#!/usr/bin/perl -w # only run as root exit(0) if $>; my %hash = (); my %prio = (); while (<STDIN>) { chomp($_); if (/.*mimetypes="([^"]+)"\s+.*/ ) { my $mimetypes = $1; if (/.*command="([^"]+)"\s+.*/ ) { my $command = $1; next if ($command =~ /%/); my $priority = 0; if (/.*InitialPreference=([0-9]+)/ ) { $priority = $1; } foreach my $m (split(",|;", $mimetypes)) { my $cmd = $hash{$m}; my $pri = $prio{$m}; if ((!$cmd) || ($pri < $priority)) { $hash{$m} = $command; $prio{$m} = $priority; } } } } } open(MAILCAP, ">/etc/mailcap"); print MAILCAP "# AUTOGENERATED FILE, don't modify this file,\n# modify mailcap.base instead and run update-menus afterward.\n\n"; close(MAILCAP); system("cat /etc/mailcap.base >> /etc/mailcap; chmod 644 /etc/mailcap"); open(MAILCAP, ">>/etc/mailcap"); print MAILCAP "#\n# Automatically generated part from update-menus\n#\n"; foreach my $m (sort keys %hash) { my $cmd = $hash{$m}; my $pri = $prio{$m}; print MAILCAP "$m; $cmd %s\n"; } close(MAILCAP);