NAME
MIME::Types - Perl extension for determining MIME types and Transfer Encoding
SYNOPSIS
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);
DESCRIPTION
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.
INTERFACE
The following functions are avilable:
- by_suffix
-
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.
- by_mediatype
-
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.
- import_mime_types
-
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.
AUTHOR
Jeff Okamoto <okamoto@corp.hp.com>.
Updated by David Wheeler <david@wheeler.net>.
import_mime_types added by Mike Cramer <cramer@webkist.com> with fixes by Antonios Christofides <A.Christofides@hydro.ntua.gr>.
Inspired by the mail_attach.pl program by Dan Sugalski <dan@sidhe.org>.