MIME::Types - Perl extension for determining MIME types and Transfer Encoding
use MIME::Types qw(by_suffix by_mediatype import_mime_types); import_mime_types("/www/mime.types"); my ($mime_type, $encoding) = by_suffix(FILENAME); my $aref = by_suffix(FILENAME); my @list = by_mediatype(MEDIATYPE); my $aref = by_mediatype(MEDIATYPE);
NOTE: This is ALPHA code. There are no guarantees that any of the subroutines described here will not have their names or return values changed.
This module is built to conform to the MIME types standard defined in RFC 1341 and updated by RFC's 1521 and 1522. It follows the collection kept at http://www.ltsw.se/knbase/internet/mime.htp.
The following functions are avilable:
This function takes either a file name suffix or a complete file name. It returns a two-element list or an anonymous array if the suffix can be found: the media type and a content encoding. An empty list is returned if the suffix could not be found.
This function takes a media type and returns a list or anonymous array of anonymous three-element arrays whose values are the file name suffix used to identify it, the media type, and a content encoding.
If the media type contains a slash (/), it is assumed to be a complete media type and must exactly match against the internal table. Otherwise the value is compared to all the values in the table via a regular expression. All regular expression codes are supported (except, of course, any string with a slash in it). Thus, calling by_mediatype("application") will return a large list.
This function takes a filename as argument and returns the number of filename extensions imported. The file should be similar in format to the mime.types file distributed with the Apache webserver. Each MIME type should be at the start of a line followed by whitespace separated extensions (without the "."). For example:
text/tab-separated-values tab tsv
If an extension in the mime.types file conflicts with an extension built into the MIME::Types package, it will be ignored. The encoding assigned to each type is "quoted-printable" for "text/*" types and "base64" for everything else.
Jeff Okamoto <firstname.lastname@example.org>.
Updated by David Wheeler <email@example.com>.
import_mime_types added by Mike Cramer <firstname.lastname@example.org> with fixes by Antonios Christofides <A.Christofides@hydro.ntua.gr>.
Inspired by the mail_attach.pl program by Dan Sugalski <email@example.com>.