summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfukachan <fukachan>2002-12-09 13:45:02 +0000
committerfukachan <fukachan>2002-12-09 13:45:02 +0000
commit149aca52e911b103206ec14e45438965d6285e2d (patch)
tree6dd5c56f47ce879d84dd9398d90eeee6cec48844
parent7e8db55ba174883607ac8380e64593c5d0f58332 (diff)
downloadfml8-149aca52e911b103206ec14e45438965d6285e2d.tar.gz
fml8-149aca52e911b103206ec14e45438965d6285e2d.tar.bz2
fml8-149aca52e911b103206ec14e45438965d6285e2d.zip
Initial revision
-rw-r--r--cpan/dist/File-MMagic/COPYING98
-rw-r--r--cpan/dist/File-MMagic/ChangeLog296
-rw-r--r--cpan/dist/File-MMagic/MANIFEST10
-rw-r--r--cpan/dist/File-MMagic/MMagic.pm1825
-rw-r--r--cpan/dist/File-MMagic/Makefile.PL14
-rw-r--r--cpan/dist/File-MMagic/README.en36
-rw-r--r--cpan/dist/File-MMagic/README.ja55
-rw-r--r--cpan/dist/File-MMagic/t/01-selfcheck.t13
-rw-r--r--cpan/dist/File-MMagic/t/02-extmagic.t14
-rw-r--r--cpan/dist/MIME-Types/ChangeLog111
-rw-r--r--cpan/dist/MIME-Types/MANIFEST11
-rw-r--r--cpan/dist/MIME-Types/MIME/Makefile.PL7
-rw-r--r--cpan/dist/MIME-Types/MIME/Type.pm320
-rw-r--r--cpan/dist/MIME-Types/MIME/Types.pm809
-rw-r--r--cpan/dist/MIME-Types/Makefile.PL12
-rw-r--r--cpan/dist/MIME-Types/README14
-rwxr-xr-xcpan/dist/MIME-Types/t/10type.t47
-rwxr-xr-xcpan/dist/MIME-Types/t/11typeol.t44
-rwxr-xr-xcpan/dist/MIME-Types/t/20types.t72
-rwxr-xr-xcpan/dist/MIME-Types/t/30export.t86
-rw-r--r--cpan/lib/File/MMagic.pm1825
-rw-r--r--cpan/lib/MIME/Type.pm320
-rw-r--r--cpan/lib/MIME/Types.pm809
23 files changed, 6848 insertions, 0 deletions
diff --git a/cpan/dist/File-MMagic/COPYING b/cpan/dist/File-MMagic/COPYING
new file mode 100644
index 00000000..04d64c14
--- /dev/null
+++ b/cpan/dist/File-MMagic/COPYING
@@ -0,0 +1,98 @@
+This program is originated from file.kulp that is a production of The
+Unix Reconstruction Projct.
+ <http://language.perl.com/ppt/index.html>
+Copyright (c) 1999 NOKUBI Takatsugu <knok@daionet.gr.jp>.
+
+There is no warranty for the program.
+
+This product includes software developed by the Apache Group
+for use in the Apache HTTP server project (http://www.apache.org/).
+
+Licence for the program is followed the original software. The licence is
+below.
+
+This program is free and open software. You may use, copy, modify, distribute
+and sell this program (and any modified variants) in any way you wish,
+provided you do not restrict others to do the same, except for the following
+consideration.
+
+I read some of Ian F. Darwin's BSD C implementation, to
+try to determine how some of this was done since the specification
+is a little vague. I don't believe that this perl version could
+be construed as an "altered version", but I did grab the tokens for
+identifying the hard-coded file types in names.h and copied some of
+the man page.
+
+Here's his notice:
+
+ * Copyright (c) Ian F. Darwin, 1987.
+ * Written by Ian F. Darwin.
+ *
+ * This software is not subject to any license of the American Telephone
+ * and Telegraph Company or of the Regents of the University of California.
+ *
+ * Permission is granted to anyone to use this software for any purpose on
+ * any computer system, and to alter it and redistribute it freely, subject
+ * to the following restrictions:
+ *
+ * 1. The author is not responsible for the consequences of use of this
+ * software, no matter how awful, even if they arise from flaws in it.
+ *
+ * 2. The origin of this software must not be misrepresented, either by
+ * explicit claim or by omission. Since few users ever read sources,
+ * credits must appear in the documentation.
+ *
+ * 3. Altered versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software. Since few users
+ * ever read sources, credits must appear in the documentation.
+ *
+ * 4. This notice may not be removed or altered.
+
+The following is the Apache License. This program contains the magic file
+that derived from the Apache HTTP Server.
+
+ * Copyright (c) 1995-1999 The Apache Group. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. All advertising materials mentioning features or use of this
+ * software must display the following acknowledgment:
+ * "This product includes software developed by the Apache Group
+ * for use in the Apache HTTP server project (http://www.apache.org/)."
+ *
+ * 4. The names "Apache Server" and "Apache Group" must not be used to
+ * endorse or promote products derived from this software without
+ * prior written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ * nor may "Apache" appear in their names without prior written
+ * permission of the Apache Group.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ * acknowledgment:
+ * "This product includes software developed by the Apache Group
+ * for use in the Apache HTTP server project (http://www.apache.org/)."
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
+ * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE GROUP OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/cpan/dist/File-MMagic/ChangeLog b/cpan/dist/File-MMagic/ChangeLog
new file mode 100644
index 00000000..9cf6281f
--- /dev/null
+++ b/cpan/dist/File-MMagic/ChangeLog
@@ -0,0 +1,296 @@
+2002-09-12 NOKUBI Takatsugu <knok@daionet.gr.jp>
+
+ * Version 1.16.
+
+ * MMagic.pm (new): Fixed binmode() place.
+ (contributed by Everton da Silva Marques, thank you.)
+
+2002-03-14 NOKUBI Takatsugu <knok@daionet.gr.jp>
+
+ * MMagic.pm (new): Added a signature for text/x-roff type.
+
+2002-02-22 NOKUBI Takatsugu <knok@daionet.gr.jp>
+
+ * Version 1.15.
+
+ * MMagic.pm: Added new funtions removeSpecials and
+ removeExts.
+ (Patch contributed by Hilko Bengen, thank you.)
+
+2001-11-13 NOKUBI Takatsugu <knok@daionet.gr.jp>
+
+ * MMagic.pm: Added binmode() in some file handles.
+ (Reported by Antony O'Sullivan, thanks.)
+
+2001-08-08 NOKUBI Takatsugu <knok@daionet.gr.jp>
+
+ * README.en : Added the notice section.
+
+ * README.ja : Ditto.
+
+2001-07-17 NOKUBI Takatsugu <knok@daionet.gr.jp>
+
+ * MANIFEST: Added t/02-extmagic.t for distribution.
+
+ * t/02-extmagic.t: Added a new file for testing.
+
+ * MANIFEST: Added t/01-selfcheck.t for distribution.
+
+ * t/01-selfcheck.t: Added a new file for testing.
+
+2001-07-05 NOKUBI Takatsugu <knok@daionet.gr.jp>
+
+ * MMagic.pm (checktype_filename): Added workaround for MSWin32
+ symlink handling probrem on ActivePerl build 626.
+ (Reported by Thomas Yengst, thank you.)
+
+ * perl-File-MMagic.spec: Removed.
+
+2001-06-20 NOKUBI Takatsugu <knok@daionet.gr.jp>
+
+ * MMagic.pm: Added some archives entry (arc, zoo, arj, rar).
+
+2001-06-19 NOKUBI Takatsugu <knok@daionet.gr.jp>
+
+ * MMagic.pm: Added ms-tnef entry.
+
+ * Version 1.14.
+
+2001-06-18 NOKUBI Takatsugu <knok@daionet.gr.jp>
+
+ * MMagic.pm: Added more comment on pod.
+
+2001-06-15 NOKUBI Takatsugu <knok@daionet.gr.jp>
+
+ * MMagic.pm (readMagicEntry): Fixed warning output probrem
+ on large magic database.
+ (Reported and patched by John R Lenton. Thanks.)
+
+ * Version 1.13.
+
+2001-02-09 NOKUBI Takatsugu <knok@daionet.gr.jp>
+
+ * MMagic.pm (checktype_data): Changed evaluation sequence of
+ binary-checking and specials-checking.
+ Version 1.12.
+
+2000-12-11 NOKUBI Takatsugu <knok@daionet.gr.jp>
+
+ * Discarded disallowEightbit().
+ Add new variable "allowEightbit".
+ Version 1.11.
+
+ * MMagic.pm (disallowEightbit): Added new entry.
+ Version 1.10.
+
+2000-10-10 NOKUBI Takatsugu <knok@daionet.gr.jp>
+
+ * MMagic.pm: Removed a text/x-info related entry.
+ Version 1.09.
+
+2000-09-12 NOKUBI Takatsugu <knok@daionet.gr.jp>
+
+ * MMagic.pm : Added image/png entry.
+ (suggested by Jamie LeTual. Thanks.)
+ Version 1.08.
+
+2000-08-09 NOKUBI Takatsugu <knok@daionet.gr.jp>
+
+ * MMagic.pm (new): Added '\.' in $self->{FILEEXTS}.
+ (reported by Yasunori Tada. Thanks.)
+ Version 1.07.
+
+2000-03-29 NOKUBI Takatsugu <knok@daionet.gr.jp>
+
+ * MMagic.pm: Removed "\v" from %ESC.
+
+2000-03-23 NOKUBI Takatsugu <knok@daionet.gr.jp>
+
+ * MMagic.pm: Added some entries.
+ (committed by kenzo-. Thanks.)
+
+2000-03-08 NOKUBI Takatsugu <knok@daionet.gr.jp>
+
+ * Version 1.03.
+
+ * MMagic.pm (addMagicEntry): Changed priority for added entry.
+
+2000-03-03 NOKUBI Takatsugu <knok@daionet.gr.jp>
+
+ * Version 1.02.
+
+ * MMagic.pm: Added the original copyrignt.
+ (I apology to the original author David Kulp, I overlook it.)
+ (magicMatchStr): Fixed short data handling probrem.
+
+2000-02-29 NOKUBI Takatsugu <knok@daionet.gr.jp>
+
+ * Fixed version number. Version 1.01.
+
+ * Version 1.00.
+
+ * MMagic.pm (checktype_filehandle): Fixed to work multiple subtests.
+
+2000-02-28 NOKUBI Takatsugu <knok@daionet.gr.jp>
+
+ * MMagic.pm: Changed URI for Namzu Project.
+ (contributed by Satoru Takabayasi)
+ Fixed to work multiple subtests.
+ Changed some entries for MicroSoft Office files.
+ Fixed addFileExts() bug.
+ Changed to check file-extends for case insensitive.
+
+ * perl-File-MMagic.spec: Created.
+ (contributed by Ryuji Abe)
+
+2000-02-24 NOKUBI Takatsugu <knok@daionet.gr.jp>
+
+ * MMagic.pm: Changed to work subtest matching.
+
+2000-02-10 NOKUBI Takatsugu <knok@daionet.gr.jp>
+
+ * Version 0.20.
+
+ * MMagic.pm: Fixed media type for RIFF format.
+ Added audio/mpeg, video/mpeg, video/quicktime format.
+ (Thanks for Mr. Perter Breton.)
+
+1999-12-02 NOKUBI Takatsugu <knok@daionet.gr.jp>
+
+ * prel-File-MMagic.spec: Renamed from File-MMagic.spec.
+
+1999-11-30 NOKUBI Takatsugu <knok@daionet.gr.jp>
+
+ * MMagic.pm: Version 0.19.
+
+1999-11-29 NOKUBI Takatsugu <knok@daionet.gr.jp>
+
+ * MMagic.pm: Changed to work with Win32 envoronment.
+ Added excel, powerpoint, ichitaro* entries.
+ (Thanks for kenzo-.)
+
+1999-11-15 NOKUBI Takatsugu <knok@daionet.gr.jp>
+
+ * MMagic.pm (new): Changed to handle specified filename for
+ magic file.
+ (Thanks for Mr. Philippe Chiasson.)
+
+1999-10-27 NOKUBI Takatsugu <knok@daionet.gr.jp>
+
+ * Added 'AUTHOR' and 'ABSTRACT' paramaters on Makefile.PL.
+
+1999-10-05 NOKUBI Takatsugu <knok@daionet.gr.jp>
+
+ * Added excluding character CR on check_binary() function.
+
+1999-09-14 NOKUBI Takatsugu <knok@daionet.gr.jp>
+
+ * Changed to return magicMatchStr function when null string is
+ specified in $str.
+
+1999-09-13 NOKUBI Takatsugu <knok@daionet.gr.jp>
+
+ * Changed `text/html' SPECIALS entry.
+ * Added empty check on checktype_data, checktype_magic.
+ * Removed non-standard type entry from %SPECIALS, %FILEEXTS, __DATA__.
+ * Added new methods addSpecials, addFileExts, addMagicEntry.
+ * Moved global %SPECIALS, %FILEEXTS variable to object.
+ * Renamed spec file.
+
+1999-09-10 NOKUBI Takatsugu <knok@daionet.gr.jp>
+
+ * Added spec file.
+ (Thanks to Mr.Abe.)
+
+1999-09-09 NOKUBI Takatsugu <knok@daionet.gr.jp>
+
+ * Fixed unescaped space in VRML magic entry.
+ (Thanks to Mr.Takaku.)
+
+1999-09-08 NOKUBI Takatsugu <knok@daionet.gr.jp>
+
+ * Changed %SPECIALS contents.
+ (Remove 'Organization:' from news,
+ add space character on rfc822/news message header,
+ add "^X-Mailer: " on rfc822,
+ add "^X-Newsreader: " on news,
+ add "^From ", "^To: " on rfc822.)
+
+ * Separated checktype_magic() from checktype_contents().
+
+1999-09-06 NOKUBI Takatsugu <knok@daionet.gr.jp>
+
+ * Added excluding character TAB on check_binary() function.
+ (Tkanks to Mr.Takaku)
+ * Added VRML magic entries. (Tkanks to Mr.Takaku)
+
+1999-08-03 NOKUBI Takatsugu <knok@daionet.gr.jp>
+
+ * Fixed flie close bug in checktype_filehandle().
+ (Thanks to Mr. Alan)
+
+1999-07-29 NOKUBI Takatsugu <knok@daionet.gr.jp>
+
+ * Fixed %SPECIALS evaluation bug.
+ * Release version 0.16.
+
+1999-07-14 NOKUBI Takatsugu <knok@daionet.gr.jp>
+
+ * Added blessing FileHandle process in new function.
+ (Thanks to Mr. majiCk)
+
+1999-07-13 NOKUBI Takatsugu <knok@daionet.gr.jp>
+
+ * Release version 0.15.
+
+1999-07-06 NOKUBI Takatsugu <knok@daionet.gr.jp>
+
+ * Fix %SPECIALS media types.
+ (text/(rfc822|news) is bad, message/* is correct.
+ Thanks to Mr.Takaku.)
+ * Changed %SPECIALS token regexp.
+
+1999-06-29 NOKUBI Takatsugu <knok@daionet.gr.jp>
+
+ * Fix truncating data processing bug in checktype_data function
+ (pack('a8192') padded "\0", it cause a probrem.)
+
+1999-06-18 NOKUBI Takatsugu <knok@daionet.gr.jp>
+
+ * Add initialize some variables code in readMagicEntry function
+ (to avoid '-w' warning).
+ * Add length check code in checktype_contents function.
+
+1999-06-17 NOKUBI Takatsugu <knok@daionet.gr.jp>
+
+ * Change %SPECIAL checking code.
+ * Add checktype_byfilename function.
+ * Add data truncation process on checktype_data function.
+
+1999-06-16 NOKUBI Takatsugu <knok@daionet.gr.jp>
+
+ * Reorder some magic entries.
+ * Fix MHonArc magic entry.
+ * Add RFC check to %SPECIALS.
+
+1999-06-15 NOKUBI Takatsugu <knok@daionet.gr.jp>
+
+ * Add 2 magic entries (MHonArc and bzip2).
+
+1999-06-14 NOKUBI Takatsugu <knok@daionet.gr.jp>
+
+ * Add the Apache License.
+ (Thanks to Ian Kluft.)
+ * Add checktype_contents() function.
+ * Add zero check routine in check_binary() funciton.
+
+1999-06-11 NOKUBI Takatsugu <knok@daionet.gr.jp>
+
+ * Change __DATA__ handling.
+ (Thanks to Mr. Inaba, Mr. Maeda, and fj.comp.lang.perl.)
+
+1999-06-10 NOKUBI Takatsugu <knok@daionet.gr.jp>
+
+ * Initial version.
+ * Branch 'classify' version.
+
diff --git a/cpan/dist/File-MMagic/MANIFEST b/cpan/dist/File-MMagic/MANIFEST
new file mode 100644
index 00000000..89712aab
--- /dev/null
+++ b/cpan/dist/File-MMagic/MANIFEST
@@ -0,0 +1,10 @@
+ChangeLog
+MMagic.pm
+MANIFEST
+COPYING
+README.ja
+README.en
+Makefile.PL
+t/01-selfcheck.t
+t/02-extmagic.t
+
diff --git a/cpan/dist/File-MMagic/MMagic.pm b/cpan/dist/File-MMagic/MMagic.pm
new file mode 100644
index 00000000..5affeaf9
--- /dev/null
+++ b/cpan/dist/File-MMagic/MMagic.pm
@@ -0,0 +1,1825 @@
+# File::MMagic
+#
+# $Id: MMagic.pm,v 1.54 2002/09/12 05:04:06 knok Exp $
+#
+# This program is originated from file.kulp that is a production of The
+# Unix Reconstruction Projct.
+# <http://language.perl.com/ppt/index.html>
+# Copyright 1999,2000,2001,2002 NOKUBI Takatsugu <knok@daionet.gr.jp>.
+#
+# This product includes software developed by the Apache Group
+# for use in the Apache HTTP server project (http://www.apache.org/).
+#
+# License for the program is followed the original software. The license is
+# below.
+#
+# This program is copyright by dkulp 1999.
+#
+# This program is free and open software. You may use, copy, modify, distribute
+# and sell this program (and any modified variants) in any way you wish,
+# provided you do not restrict others to do the same, except for the following
+# consideration.
+#
+#I read some of Ian F. Darwin's BSD C implementation, to
+#try to determine how some of this was done since the specification
+#is a little vague. I don't believe that this perl version could
+#be construed as an "altered version", but I did grab the tokens for
+#identifying the hard-coded file types in names.h and copied some of
+#the man page.
+#
+#Here's his notice:
+#
+# * Copyright (c) Ian F. Darwin, 1987.
+# * Written by Ian F. Darwin.
+# *
+# * This software is not subject to any license of the American Telephone
+# * and Telegraph Company or of the Regents of the University of California.
+# *
+# * Permission is granted to anyone to use this software for any purpose on
+# * any computer system, and to alter it and redistribute it freely, subject
+# * to the following restrictions:
+# *
+# * 1. The author is not responsible for the consequences of use of this
+# * software, no matter how awful, even if they arise from flaws in it.
+# *
+# * 2. The origin of this software must not be misrepresented, either by
+# * explicit claim or by omission. Since few users ever read sources,
+# * credits must appear in the documentation.
+# *
+# * 3. Altered versions must be plainly marked as such, and must not be
+# * misrepresented as being the original software. Since few users
+# * ever read sources, credits must appear in the documentation.
+# *
+# * 4. This notice may not be removed or altered.
+#
+# The following is the Apache License. This program contains the magic file
+# that derived from the Apache HTTP Server.
+#
+# * Copyright (c) 1995-1999 The Apache Group. All rights reserved.
+# *
+# * Redistribution and use in source and binary forms, with or without
+# * modification, are permitted provided that the following conditions
+# * are met:
+# *
+# * 1. Redistributions of source code must retain the above copyright
+# * notice, this list of conditions and the following disclaimer.
+# *
+# * 2. Redistributions in binary form must reproduce the above copyright
+# * notice, this list of conditions and the following disclaimer in
+# * the documentation and/or other materials provided with the
+# * distribution.
+# *
+# * 3. All advertising materials mentioning features or use of this
+# * software must display the following acknowledgment:
+# * "This product includes software developed by the Apache Group
+# * for use in the Apache HTTP server project (http://www.apache.org/)."
+# *
+# * 4. The names "Apache Server" and "Apache Group" must not be used to
+# * endorse or promote products derived from this software without
+# * prior written permission. For written permission, please contact
+# * apache@apache.org.
+# *
+# * 5. Products derived from this software may not be called "Apache"
+# * nor may "Apache" appear in their names without prior written
+# * permission of the Apache Group.
+# *
+# * 6. Redistributions of any form whatsoever must retain the following
+# * acknowledgment:
+# * "This product includes software developed by the Apache Group
+# * for use in the Apache HTTP server project (http://www.apache.org/)."
+# *
+# * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
+# * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE GROUP OR
+# * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+# * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+# * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+# * OF THE POSSIBILITY OF SUCH DAMAGE.
+
+package File::MMagic;
+
+=head1 NAME
+
+File::MMagic - Guess file type
+
+=head1 SYNOPSIS
+
+ use File::MMagic;
+ use FileHandle;
+
+ $mm = new File::MMagic; # use internal magic file
+ # $mm = File::MMagic::new('/etc/magic'); # use external magic file
+ # $mm = File::MMagic::new('/usr/share/etc/magic'); # if you use Debian
+ $res = $mm->checktype_filename("/somewhere/unknown/file");
+
+ $fh = new FileHandle "< /somewhere/unknown/file2";
+ $res = $mm->checktype_filehandle($fh);
+
+ $fh->read($data, 0x8564);
+ $res = $mm->checktype_contents($data);
+
+=head1 ABSTRACT
+
+This perl library uses perl5 objects to guess file type from filename
+and/or filehandle.
+
+=head1 DESCRIPTION
+
+checktype_filename(), checktype_filehandle() and checktype_contents
+returns string contains file type with MIME mediatype format.
+
+=head1 METHODS
+
+=over 4
+
+=item File::MMagic->new()
+
+=item File::MMagic->new( $filename )
+
+Initializes the module. If no filename is given, the magic numbers
+stored in File::MMagic are used.
+
+=item $mm->addSpecials
+
+If a filetype cannot be determined by magic numbers, extra checks are
+done based on extra regular expressions which can be defined here. The
+first argument should be the filetype, the remaining arguments should
+be one or more regular expressions.
+
+By default, checks are done for message/news, message/rfc822,
+text/html, text/x-roff.
+
+=item $mm->removeSpecials
+
+Removes special regular expressions. Specify one or more filetypes. If
+no filetypes are specified, all special regexps are removed.
+
+Returns a hash containing the removed entries.
+
+=item $mm->addFileExts
+
+If a filetype cannot be determined by magic numbers, extra checks can
+be done based on the file extension (actually, a regexp). Two
+arguments should be geiven: the filename pattern and the corresponding
+filetype.
+
+By default, checks are done for application/x-compress,
+application/x-bzip2, application/x-gzip, text/html, text/plain
+
+=item $mm->removeFileExts
+
+Removes filename pattern checks. Specify one or more patterns. If no
+pattern is specified, all are removed.
+
+Returns a hash containing the removed entries.
+
+=item $mm->addMagicEntry
+
+=item $mm->readMagicHandle
+
+=item $mm->checktype_filename
+
+=item $mm->checktype_magic
+
+=item $mm->checktype_contents
+
+=head1 COPYRIGHT
+
+This program is originated from file.kulp that is a production of The
+Unix Reconstruction Projct.
+ <http://language.perl.com/ppt/index.html>
+Copyright (c) 1999 NOKUBI Takatsugu <knok@daionet.gr.jp>.
+
+There is no warranty for the program.
+
+This product includes software developed by the Apache Group
+for use in the Apache HTTP server project (http://www.apache.org/).
+
+License for the program is followed the original software. The license is
+below.
+
+This program is free and open software. You may use, copy, modify, distribute
+and sell this program (and any modified variants) in any way you wish,
+provided you do not restrict others to do the same, except for the following
+consideration.
+
+I read some of Ian F. Darwin's BSD C implementation, to
+try to determine how some of this was done since the specification
+is a little vague. I don't believe that this perl version could
+be construed as an "altered version", but I did grab the tokens for
+identifying the hard-coded file types in names.h and copied some of
+the man page.
+
+Here's his notice:
+
+ * Copyright (c) Ian F. Darwin, 1987.
+ * Written by Ian F. Darwin.
+ *
+ * This software is not subject to any license of the American Telephone
+ * and Telegraph Company or of the Regents of the University of California.
+ *
+ * Permission is granted to anyone to use this software for any purpose on
+ * any computer system, and to alter it and redistribute it freely, subject
+ * to the following restrictions:
+ *
+ * 1. The author is not responsible for the consequences of use of this
+ * software, no matter how awful, even if they arise from flaws in it.
+ *
+ * 2. The origin of this software must not be misrepresented, either by
+ * explicit claim or by omission. Since few users ever read sources,
+ * credits must appear in the documentation.
+ *
+ * 3. Altered versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software. Since few users
+ * ever read sources, credits must appear in the documentation.
+ *
+ * 4. This notice may not be removed or altered.
+
+The following is the Apache License. This program contains the magic file
+that derived from the Apache HTTP Server.
+
+ * Copyright (c) 1995-1999 The Apache Group. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. All advertising materials mentioning features or use of this
+ * software must display the following acknowledgment:
+ * "This product includes software developed by the Apache Group
+ * for use in the Apache HTTP server project (http://www.apache.org/)."
+ *
+ * 4. The names "Apache Server" and "Apache Group" must not be used to
+ * endorse or promote products derived from this software without
+ * prior written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ * nor may "Apache" appear in their names without prior written
+ * permission of the Apache Group.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ * acknowledgment:
+ * "This product includes software developed by the Apache Group
+ * for use in the Apache HTTP server project (http://www.apache.org/)."
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
+ * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE GROUP OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+
+=cut
+
+use FileHandle;
+use strict;
+
+use vars qw(
+%TEMPLATES %ESC $VERSION
+$magicFile $checkMagic $followLinks $fileList
+$dataLoc $allowEightbit
+);
+
+BEGIN {
+# translation of type in magic file to unpack template and byte count
+%TEMPLATES = (byte => [ 'c', 1 ],
+ ubyte => [ 'C', 1 ],
+ char => [ 'c', 1 ],
+ uchar => [ 'C', 1 ],
+ short => [ 's', 2 ],
+ ushort => [ 'S', 2 ],
+ long => [ 'l', 4 ],
+ ulong => [ 'L', 4 ],
+ date => [ 'l', 4 ],
+ ubeshort => [ 'n', 2 ],
+ beshort => [ [ 'n', 'S', 's' ], 2 ],
+ ubelong => [ 'N', 4 ],
+ belong => [ [ 'N', 'I', 'i' ], 4 ],
+ bedate => [ 'N', 4 ],
+ uleshort => [ 'v', 2 ],
+ leshort => [ [ 'v', 'S', 's' ], 2 ],
+ ulelong => [ 'V', 4 ],
+ lelong => [ [ 'V', 'I', 'i' ], 4 ],
+ ledate => [ 'V', 4 ],
+ string => undef);
+
+# for letter escapes in magic file
+%ESC = ( n => "\n",
+ r => "\r",
+ b => "\b",
+ t => "\t",
+ f => "\f");
+
+$VERSION = "1.16";
+$allowEightbit = 1;
+undef $dataLoc;
+}
+
+sub new {
+ my $self = {};
+ my $proto = shift;
+ my $class = ref($proto) || $proto;
+ $self->{MF} = [];
+ $self->{magic} = [];
+ if (! @_) {
+ my $fh = *File::MMagic::DATA{IO};
+ binmode($fh);
+ bless $fh, 'FileHandle' if ref $fh ne 'FileHandle';
+ $dataLoc = $fh->tell() if (! defined $dataLoc);
+ $fh->seek($dataLoc, 0);
+ &readMagicHandle($self, $fh);
+ } else {
+ my $filename = shift;
+ my $fh = new FileHandle;
+ if ($fh->open("< $filename")) {
+ binmode($fh);
+ &readMagicHandle($self, $fh);
+ } else {
+ warn __PACKAGE__ . " couldn't load specified file $filename";
+ }
+ }
+
+# from the BSD names.h, some tokens for hard-coded checks of
+# different texts. This isn't rocket science. It's prone to
+# failure so these checks are only a last resort.
+
+# removSpecials() can be used to remove those afterwards.
+ $self->{SPECIALS} = {
+ "message/rfc822" => [ "^Received:",
+ "^>From ",
+ "^From ",
+ "^To: ",
+ "^Return-Path: ",
+ "^Cc: ",
+ "^X-Mailer: "],
+ "message/news" => [ "^Newsgroups: ",
+ "^Path: ",
+ "^X-Newsreader: "],
+ "text/html" => [ "<html[^>]*>",
+ "<HTML[^>]*>",
+ "<head[^>]*>",
+ "<HEAD[^>]*>",
+ "<body[^>]*>",
+ "<BODY[^>]*>",
+ "<title[^>]*>",
+ "<TITLE[^>]*>",
+ "<h1[^>]*>",
+ "<H1[^>]*>",
+ ],
+ "text/x-roff" => [
+ '^\\.\\\\"',
+ "^\\.SH",
+ "^\\.PP",
+ "^\\.TH",
+ "^\\.BR",
+ "^\\.SS",
+ "^\\.TP",
+ "^\\.IR",
+ ],
+ };
+
+ $self->{FILEEXTS} = {
+ '\.gz$' => 'application/x-gzip',
+ '\.bz2$' => 'application/x-bzip2',
+ '\.Z$' => 'application/x-compress',
+ '\.txt$' => 'text/plain',
+ '\.html$' => 'text/html',
+ '\.htm$' => 'text/html',
+ };
+ bless($self);
+ return $self;
+}
+
+sub addSpecials {
+ my $self = shift;
+ my $mtype = shift;
+ $self->{SPECIALS}->{"$mtype"} = [@_];
+ return $self;
+}
+
+sub removeSpecials {
+ my $self = shift;
+ # Remove all keys if no arguments given
+ my @mtypes = (@_ or keys %{$self->{SPECIALS}});
+ my %returnmtypes;
+ foreach my $mtype (@mtypes) {
+ $returnmtypes{"$mtype"} = delete $self->{SPECIALS}->{"$mtype"};
+ }
+ return %returnmtypes;
+}
+
+sub addFileExts {
+ my $self = shift;
+ my $filepat = shift;
+ my $mtype = shift;
+ $self->{FILEEXTS}->{"$filepat"} = $mtype;
+ return $self;
+}
+
+sub removeFileExts {
+ my $self = shift;
+ # Remove all keys if no arguments given
+ my @filepats = (@_ or keys %{$self->{FILEEXTS}});
+ my %returnfilepats;
+ foreach my $filepat (@filepats) {
+ $returnfilepats{"$filepat"} = delete $self->{FILEEXTS}->{"$filepat"};
+ }
+ return %returnfilepats;
+}
+
+sub addMagicEntry {
+ my $self = shift;
+ my $entry = shift;
+ unshift @{$self->{magic}}, [$entry, -1, []];
+ return $self;
+}
+
+sub readMagicHandle {
+ my $self = shift;
+ my $fh = shift;
+ $self->{MF}->[0] = $fh;
+ $self->{MF}->[1] = undef;
+ $self->{MF}->[2] = 0;
+ readMagicEntry($self->{magic}, $self->{MF});
+}
+
+# Not implimented.
+#
+#sub readMagicFile {
+# my $self = shift;
+# my $mfile = shift;
+#}
+
+sub checktype_filename {
+ my $self = shift;
+
+# iterate over each file explicitly so we can seek
+ my $file = shift;
+
+ # the description line. append info to this string
+ my $desc;
+ my $mtype;
+
+ # 0) check permission
+ if (! -r $file) {
+ $desc .= " can't read `$file': Permission denied.";
+ return "x-system/x-error; $desc";
+ }
+
+ # 1) check for various special files first
+ if ($^O eq 'MSWin32') {
+ stat($file);
+ } else {
+ if ($followLinks) { stat($file); } else { lstat($file); }
+ }
+ if (! -f _ or -z _) {
+ if ( $^O ne 'MSWin32' && !$followLinks && -l _ ) {
+ $desc .= " symbolic link to ".readlink($file);
+ }
+ elsif ( -d _ ) { $desc .= " directory"; }
+ elsif ( -p _ ) { $desc .= " named pipe"; }
+ elsif ( -S _ ) { $desc .= " socket"; }
+ elsif ( -b _ ) { $desc .= " block special file"; }
+ elsif ( -c _ ) { $desc .= " character special file"; }
+ elsif ( -z _ ) { $desc .= " empty"; }
+ else { $desc .= " special"; }
+
+ return "x-system/x-unix; $desc";
+ }
+
+ # current file handle. or undef if checkMagic (-c option) is true.
+ my $fh;
+
+# $fh = new FileHandle "< $file" or die "$F: $file: $!\n" ;
+ $fh = new FileHandle "< $file" or return "x-system/x-error; $file: $!\n" ;
+
+ binmode($fh); # for MSWin32
+
+ # 2) check for script
+ if (-x $file && -T _) {
+
+ # Note, some magic files include elaborate attempts
+ # to match #! header lines and return pretty responses
+ # but this slows down matching and is unnecessary.
+ my $line1 = <$fh>;
+ if ($line1 =~ /^\#!\s*(\S+)/) {
+ $desc .= " executable $1 script text";
+ }
+ else { $desc .= " commands text"; }
+
+ $fh->close();
+
+ return "x-system/x-unix; $desc";
+
+ }
+
+ my $out = checktype_filehandle($self, $fh, $desc);
+ undef $fh;
+
+ return $out;
+}
+
+sub checktype_filehandle {
+ my $self = shift;
+ my ($fh, $desc) = @_;
+ my $mtype;
+
+ binmode($fh); # for MSWin32 architecture.
+
+ # 3) iterate over each magic entry.
+ my $matchFound = 0;
+ my $m;
+ for ($m = 0; $m <= $#{$self->{magic}}; $m++) {
+
+ # check if the m-th magic entry matches
+ # if it does, then $desc will contain an updated description
+ if (magicMatch($self->{magic}->[$m],\$desc,$fh)) {
+ if (defined $desc && $desc ne '') {
+ $matchFound = 1;
+ $mtype = $desc;
+ last;
+ }
+ }
+
+ # read another entry from the magic file if we've exhausted
+ # all the entries already buffered. readMagicEntry will
+ # add to the end of the array if there are more.
+ if ($m == $#{$self->{magic}} && !$self->{MF}->[0]->eof()) {
+ readMagicEntry($self->{magic}, $self->{MF});
+ }
+ }
+
+ # 4) check if it's text or binary.
+ # if it's text, then do a bunch of searching for special tokens
+ if (!$matchFound) {
+ my $data;
+ $fh->seek(0,0);
+ $fh->read($data, 0x8564);
+ $mtype = checktype_data($self, $data);
+ }
+
+ $mtype = 'text/plain' if (! defined $mtype);
+
+ return $mtype;
+}
+
+sub checktype_contents {
+ my $self = shift;
+ my $data = shift;
+ my $mtype;
+
+ return 'application/octet-stream' if (length($data) <= 0);
+
+ $mtype = checktype_magic($self, $data);
+
+ # 4) check if it's text or binary.
+ # if it's text, then do a bunch of searching for special tokens
+ if (!defined $mtype) {
+ $mtype = checktype_data($self, $data);
+ }
+
+ $mtype = 'text/plain' if (! defined $mtype);
+
+ return $mtype;
+}
+
+sub checktype_magic {
+ my $self = shift;
+ my $data = shift;
+ my $desc;
+ my $mtype;
+
+ return 'application/octet-stream' if (length($data) <= 0);
+
+ # 3) iterate over each magic entry.
+ my $m;
+ for ($m = 0; $m <= $#{$self->{magic}}; $m++) {
+
+ # check if the m-th magic entry matches
+ # if it does, then $desc will contain an updated description
+ if (magicMatchStr($self->{magic}->[$m],\$desc,$data)) {
+ if (defined $desc && $desc ne '') {
+ $mtype = $desc;
+ last;
+ }
+ }
+
+ # read another entry from the magic file if we've exhausted
+ # all the entries already buffered. readMagicEntry will
+ # add to the end of the array if there are more.
+ if ($m == $#{$self->{magic}} && !$self->{MF}->[0]->eof()) {
+ readMagicEntry($self->{magic}, $self->{MF});
+ }
+ }
+
+ return $mtype;
+}
+
+sub checktype_data {
+ my $self = shift;
+ my $data = shift;
+ my $mtype;
+
+ return undef if (length($data) <= 0);
+
+ # truncate data
+ $data = substr($data, 0, 0x8564);
+
+ # at first, check SPECIALS
+ {
+ # in BSD's version, there's an effort to search from
+ # more specific to less, but I don't do that.
+ my ($token, %val);
+ foreach my $type (keys %{$self->{SPECIALS}}) {
+ my $token = '(' .
+ (join '|', sort {length($a) <=> length($b)} @{$self->{SPECIALS}->{$type}})
+ . ')';
+ my $tdata = $data;
+ if ($tdata =~ /$token/mg) {
+ $val{$type} = pos($tdata);
+ }
+ }
+
+ # search latest match
+ if (%val) {
+ my @skeys = sort { $val{$a} <=> $val{$b} } keys %val;
+ $mtype = $skeys[0];
+ }
+
+ ALLDONE:
+# $mtype = 'text/plain' if (! defined $mtype);
+ }
+ if (! defined $mtype && check_binary($data)) {
+ $mtype = "application/octet-stream";
+ }
+
+# $mtype = 'text/plain' if (! defined $mtype);
+ return $mtype;
+}
+
+sub checktype_byfilename {
+ my $self = shift;
+ my $fname = shift;
+ my $type;
+
+ $fname =~ s/^.*\///;
+ for my $regex (keys %{$self->{FILEEXTS}}) {
+ if ($fname =~ /$regex/i) {
+ if ((defined $type && $type !~ /;/) || (! defined $type)) {
+ $type = $self->{FILEEXTS}->{$regex}; # has no x-type param
+ }
+ }
+ }
+ $type = 'application/octet-stream' unless defined $type;
+ return $type;
+}
+
+sub check_binary {
+ my ($data) = @_;
+ my $len = length($data);
+ if ($allowEightbit) {
+ my $count = ($data =~ tr/[\x00-\x08\x0b-\x0c\x0e-\x1a\x1c-\x1f]//); # exclude TAB, ESC, nl, cr
+ return 1 if ($len <= 0); # no contents
+ return 1 if (($count/$len) > 0.1); # binary
+ } else {
+ my $count = ($data =~ tr/[\x00-\x08\x0b-\x0c\x0e-\x1a\x1c-\x1f\x80-\xff]//); # exclude TAB, ESC, nl, cr
+ return 1 if ($len <= 0); # no contents
+ return 1 if (($count/$len) > 0.3); # binary
+ }
+ return 0;
+}
+
+sub check_magic {
+ my $self = shift @_;
+ # read the whole file if we haven't already
+ while (!$self->{MF}->[0]->eof()) {
+ readMagicEntry($self->{magic}, $self->{MF});
+ }
+ dumpMagic($self->{magic});
+}
+
+####### SUBROUTINES ###########
+
+# compare the magic item with the filehandle.
+# if success, print info and return true. otherwise return undef.
+#
+# this is called recursively if an item has subitems.
+sub magicMatch {
+ my ($item, $p_desc, $fh) = @_;
+
+ # delayed evaluation. if this is our first time considering
+ # this item, then parse out its structure. @$item is just the
+ # raw string, line number, and subtests until we need the real info.
+ # this saves time otherwise wasted parsing unused subtests.
+ $item = readMagicLine(@$item) if @$item == 3;
+
+ # $item could be undef if we ran into troubles while reading
+ # the entry.
+ return unless defined($item);
+
+ # $fh is not be defined if -c. that way we always return
+ # false for every item which allows reading/checking the entire
+ # magic file.
+ return unless defined($fh);
+
+ my ($offtype, $offset, $numbytes, $type, $mask, $op, $testval,
+ $template, $message, $subtests) = @$item;
+
+ # bytes from file
+ my $data;
+
+ # set to true if match
+ my $match = 0;
+
+ # offset = [ off1, sz, template, off2 ] for indirect offset
+ if ($offtype == 1) {
+ my ($off1, $sz, $template, $off2) = @$offset;
+ $fh->seek($off1,0) or return;
+ if ($fh->read($data,$sz) != $sz) { return };
+ $off2 += unpack($template,$data);
+ $fh->seek($off2,0) or return;
+ }
+ elsif ($offtype == 2) {
+ # relative offsets from previous seek
+ $fh->seek($offset,1) or return;
+ }
+ else {
+ # absolute offset
+ $fh->seek($offset,0) or return;
+ }
+
+ if ($type eq 'string') {
+ # read the length of the match string unless the
+ # comparison is '>' ($numbytes == 0), in which case
+ # read to the next null or "\n". (that's what BSD's file does)
+ if ($numbytes > 0) {
+ if ($fh->read($data,$numbytes) != $numbytes) { return; }
+ }
+ else {
+ my $ch = $fh->getc();
+ while (defined($ch) && $ch ne "\0" && $ch ne "\n") {
+ $data .= $ch;
+ $ch = $fh->getc();
+ }
+ }
+
+ # now do the comparison
+ if ($op eq '=') {
+ $match = ($data eq $testval);
+ }
+ elsif ($op eq '<') {
+ $match = ($data lt $testval);
+ }
+ elsif ($op eq '>') {
+ $match = ($data gt $testval);
+ }
+ # else bogus op, but don't die, just skip
+
+ if ($checkMagic) {
+ print STDERR "STRING: $data $op $testval => $match\n";
+ }
+
+ }
+ else {
+ #numeric
+
+ # read up to 4 bytes
+ if ($fh->read($data,$numbytes) != $numbytes) { return; }
+
+ # If template is a ref to an array of 3 letters,
+ # then this is an endian
+ # number which must be first unpacked into an unsigned and then
+ # coerced into a signed. Is there a better way?
+ if (ref($template)) {
+ $data = unpack($$template[2],
+ pack($$template[1],
+ unpack($$template[0],$data)));
+ }
+ else {
+ $data = unpack($template,$data);
+ }
+
+ # if mask
+ if (defined($mask)) {
+ $data &= $mask;
+ }
+
+ # Now do the check
+ if ($op eq '=') {
+ $match = ($data == $testval);
+ }
+ elsif ($op eq 'x') {
+ $match = 1;
+ }
+ elsif ($op eq '!') {
+ $match = ($data != $testval);
+ }
+ elsif ($op eq '&') {
+ $match = (($data & $testval) == $testval);
+ }
+ elsif ($op eq '^') {
+ $match = ((~$data & $testval) == $testval);
+ }
+ elsif ($op eq '<') {
+ $match = ($data < $testval);
+ }
+ elsif ($op eq '>') {
+ $match = ($data > $testval);
+ }
+ # else bogus entry that we're ignoring
+
+ if ($checkMagic) {
+ print STDERR "NUMERIC: $data $op $testval => $match\n";
+ }
+
+ }
+
+ if ($match) {
+ # it's pretty common to find "\b" in the message, but
+ # sprintf doesn't insert a backspace. if it's at the
+ # beginning (typical) then don't include separator space.
+ if ($message =~ s/^\\b//) {
+ $$p_desc .= sprintf($message,$data);
+ }
+ else {
+# $$p_desc .= ' ' . sprintf($message,$data) if $message;
+ $$p_desc .= sprintf($message,$data) if $message;
+ }
+
+ my $subtest;
+ foreach $subtest (@$subtests) {
+ magicMatch($subtest,$p_desc,$fh);
+ }
+
+ return 1;
+ }
+
+}
+
+sub magicMatchStr {
+ my ($item, $p_desc, $str) = @_;
+ my $origstr = $str;
+
+ # delayed evaluation. if this is our first time considering
+ # this item, then parse out its structure. @$item is just the
+ # raw string, line number, and subtests until we need the real info.
+ # this saves time otherwise wasted parsing unused subtests.
+ $item = readMagicLine(@$item) if @$item == 3;
+
+ # $item could be undef if we ran into troubles while reading
+ # the entry.
+ return unless defined($item);
+
+ # $fh is not be defined if -c. that way we always return
+ # false for every item which allows reading/checking the entire
+ # magic file.
+ return unless defined($str);
+ return if ($str eq '');
+
+ my ($offtype, $offset, $numbytes, $type, $mask, $op, $testval,
+ $template, $message, $subtests) = @$item;
+ return unless defined $op;
+
+ # bytes from file
+ my $data;
+
+ # set to true if match
+ my $match = 0;
+
+ # offset = [ off1, sz, template, off2 ] for indirect offset
+ if ($offtype == 1) {
+ my ($off1, $sz, $template, $off2) = @$offset;
+ return if (length($str) < $off1);
+ $data = pack("a$sz", $str);
+ $off2 += unpack($template,$data);
+ return if (length($str) < $off2);
+ }
+ elsif ($offtype == 2) {
+ # can't handle relative offsets from previous seek
+ return;
+ }
+ else {
+ # absolute offset
+ return if ($offset > length($str));
+ $str = substr($str, $offset);
+ }
+
+ if ($type eq 'string') {
+ # read the length of the match string unless the
+ # comparison is '>' ($numbytes == 0), in which case
+ # read to the next null or "\n". (that's what BSD's file does)
+ if ($numbytes > 0) {
+ $data = pack("a$numbytes", $str);
+ }
+ else {
+ $str =~ /^(.*)\0|$/;
+ $data = $1;
+ }
+
+ # now do the comparison
+ if ($op eq '=') {
+ $match = ($data eq $testval);
+ }
+ elsif ($op eq '<') {
+ $match = ($data lt $testval);
+ }
+ elsif ($op eq '>') {
+ $match = ($data gt $testval);
+ }
+ # else bogus op, but don't die, just skip
+
+ if ($checkMagic) {
+ print STDERR "STRING: $data $op $testval => $match\n";
+ }
+
+ }
+ else {
+ #numeric
+
+ # read up to 4 bytes
+ $data = substr($str, 0, 4);
+
+ # If template is a ref to an array of 3 letters,
+ # then this is an endian
+ # number which must be first unpacked into an unsigned and then
+ # coerced into a signed. Is there a better way?
+ if (ref($template)) {
+ $data = unpack($$template[2],
+ pack($$template[1],
+ unpack($$template[0],$data)));
+ }
+ else {
+ $data = unpack($template,$data);
+ }
+
+ # if mask
+ if (defined($mask)) {
+ $data &= $mask;
+ }
+
+ # Now do the check
+ if ($op eq '=') {
+ $match = ($data == $testval);
+ }
+ elsif ($op eq 'x') {
+ $match = 1;
+ }
+ elsif ($op eq '!') {
+ $match = ($data != $testval);
+ }
+ elsif ($op eq '&') {
+ $match = (($data & $testval) == $testval);
+ }
+ elsif ($op eq '^') {
+ $match = ((~$data & $testval) == $testval);
+ }
+ elsif ($op eq '<') {
+ $match = ($data < $testval);
+ }
+ elsif ($op eq '>') {
+ $match = ($data > $testval);
+ }
+ # else bogus entry that we're ignoring
+
+ if ($checkMagic) {
+ print STDERR "NUMERIC: $data $op $testval => $match\n";
+ }
+
+ }
+
+ if ($match) {
+ # it's pretty common to find "\b" in the message, but
+ # sprintf doesn't insert a backspace. if it's at the
+ # beginning (typical) then don't include separator space.
+ if ($message =~ s/^\\b//) {
+ $$p_desc .= sprintf($message,$data);
+ }
+ else {
+# $$p_desc .= ' ' . sprintf($message,$data) if $message;
+ $$p_desc .= sprintf($message,$data) if $message;
+ }
+
+ my $subtest;
+ foreach $subtest (@$subtests) {
+ # finish evaluation when matched.
+ magicMatchStr($subtest,$p_desc,$origstr);
+ }
+
+ return 1;
+ }
+
+}
+
+# readMagicEntry($pa_magic, $MF, $depth)
+#
+# reads the next entry from the magic file and stores it as
+# a ref to an array at the end of @$pa_magic.
+#
+# $MF = [ filehandle, last buffered line, line count ]
+#
+# This is called recursively with increasing $depth to read in sub-clauses
+#
+# returns the depth of the current buffered line.
+#
+sub readMagicEntry {
+ my ($pa_magic, $MF, $depth) = @_;
+
+ # for some reason I need a local var because <$$MF[0]> doesn't work.(?)
+ my $magicFH = $$MF[0];
+
+ # a ref to an array containing a magic line's components
+ my ($entry, $line);
+
+ $line = $$MF[1]; # buffered last line
+ while (1) {
+ $line = '' if (! defined $line);
+ if ($line =~ /^\#/ || $line =~ /^\s*$/) {
+ last if $magicFH->eof();
+ $line = <$magicFH>;
+ $$MF[2]++;
+ next;
+ }
+
+ my ($thisDepth) = ($line =~ /^(>+)/);
+ $thisDepth = '' if (! defined $thisDepth);
+ $depth = 0 if (! defined $depth);
+
+ if (length($thisDepth) > $depth) {
+ $$MF[1] = $line;
+
+ # call ourselves recursively. will return the depth
+ # of the entry following the nested group.
+ if ((readMagicEntry($entry->[2], $MF, $depth+1) || 0) < $depth ||
+ $$MF[0]->eof())
+ {
+ return;
+ }
+ $line = $$MF[1];
+ }
+ elsif (length($thisDepth) < $depth) {
+ $$MF[1] = $line;
+ return length($thisDepth);
+ }
+ elsif (defined(@$entry)) {
+ # already have an entry. this is not a continuation.
+ # save this line for the next call and exit.
+ $$MF[1] = $line;
+ return length($thisDepth);
+ }
+ else {
+ # we're here if the number of '>' is the same as the
+ # current depth and we haven't read a magic line yet.
+
+ # create temp entry
+ # later -- if we ever get around to evaluating this condition --
+ # we'll replace @$entry with the results from readMagicLine.
+ $entry = [ $line , $$MF[2], [] ];
+
+ # add to list
+ push(@$pa_magic,$entry);
+
+ # read the next line
+ last if $magicFH->eof();
+ $line = <$magicFH>;
+ $$MF[2]++;
+ }
+ }
+}
+
+# readMagicLine($line, $line_num, $subtests)
+#
+# parses the match info out of $line. Returns a reference to an array.
+#
+# Format is:
+#
+# [ offset, bytes, type, mask, operator, testval, template, sprintf, subtests ]
+# 0 1 2 3 4 5 6 7 8
+#
+# subtests is an array like @$pa_magic.
+#
+sub readMagicLine {
+ my ($line, $line_num, $subtests) = @_;
+
+ my ($offtype, $offset, $numbytes, $type, $mask,
+ $operator, $testval, $template, $message);
+
+ # this would be easier if escaped whitespace wasn't allowed.
+
+ # grab the offset and type. offset can either be a decimal, oct,
+ # or hex offset or an indirect offset specified in parenthesis
+ # like (x[.[bsl]][+-][y]), or a relative offset specified by &.
+ # offtype : 0 = absolute, 1 = indirect, 2 = relative
+ if ($line =~ s/^>*([&\(]?[a-flsx\.\+\-\d]+\)?)\s+(\S+)\s+//) {
+ ($offset,$type) = ($1,$2);
+
+ if ($offset =~ /^\(/) {
+ # indirect offset.
+ $offtype = 1;
+
+ # store as a reference [ offset1 type template offset2 ]
+
+ my ($o1,$type,$o2);
+ if (($o1,$type,$o2) = ($offset =~ /\((\d+)(\.[bsl])?([\+\-]?\d+)?\)/))
+ {
+ $o1 = oct($o1) if $o1 =~ /^0/o;
+ $o2 = oct($o2) if $o2 =~ /^0/o;
+
+ $type =~ s/\.//;
+ if ($type eq '') { $type = 'l'; } # default to long
+ $type =~ tr/b/c/; # type will be template for unpack
+
+ my $sz = $type; # number of bytes
+ $sz =~ tr/csl/124/;
+
+ $offset = [ $o1,$sz,$type,int($o2) ];
+ } else {
+ warn "Bad indirect offset at line $line_num. '$offset'\n";
+ return;
+ }
+ }
+ elsif ($offset =~ /^&/o) {
+ # relative offset
+ $offtype = 2;
+
+ $offset = substr($offset,1);
+ $offset = oct($offset) if $offset =~ /^0/o;
+ }
+ else {
+ # normal absolute offset
+ $offtype = 0;
+
+ # convert if needed
+ $offset = oct($offset) if $offset =~ /^0/o;
+ }
+ }
+ else {
+ warn "Bad Offset/Type at line $line_num. '$line'\n";
+ return;
+ }
+
+ # check for & operator on type
+ if ($type =~ s/&(.*)//) {
+ $mask = $1;
+
+ # convert if needed
+ $mask = oct($mask) if $mask =~ /^0/o;
+ }
+
+ # check if type is valid
+ if (!exists($TEMPLATES{$type})) {
+ warn "Invalid type '$type' at line $line_num\n";
+ return;
+ }
+
+ # take everything after the first non-escaped space
+ if ($line =~ s/([^\\])\s+(.*)/$1/) {
+ $message = $2;
+ }
+ else {
+ warn "Missing or invalid test condition or message at line $line_num\n";
+ return;
+ }
+
+ # remove the return if it's still there
+ $line =~ s/\n$//o;
+
+ # get the operator. if 'x', must be alone. default is '='.
+ if ($line =~ s/^([><&^=!])//o) {
+ $operator = $1;
+ }
+ elsif ($line eq 'x') {
+ $operator = 'x';
+ }
+ else { $operator = '='; }
+
+
+ if ($type eq 'string') {
+ $testval = $line;
+
+ # do octal/hex conversion
+ $testval =~ s/\\([x0-7][0-7]?[0-7]?)/chr(oct($1))/eg;
+
+ # do single char escapes
+ $testval =~ s/\\(.)/$ESC{$1}||$1/eg;
+
+ # put the number of bytes to read in numbytes.
+ # '0' means read to \0 or \n.
+ if ($operator =~ /[>x]/o) {
+ $numbytes = 0;
+ }
+ elsif ($operator =~ /[=<]/o) {
+ $numbytes = length($testval);
+ }
+ elsif ($operator eq '!') {
+ # annoying special case. ! operator only applies to numerics so
+ # put it back.
+ $testval = $operator . $testval;
+ $numbytes = length($testval);
+ $operator = '=';
+ }
+ else {
+ # there's a bug in my magic file where there's
+ # a line that says "0 string ^!<arc..." and the BSD
+ # file program treats the argument like a numeric. To minimize
+ # hassles, complain about bad ops only if -c is set.
+ warn "Invalid operator '$operator' for type 'string' at line $line_num.\n"
+ if $checkMagic;
+ return;
+ }
+ }
+ else {
+ # numeric
+ if ($operator ne 'x') {
+ # this conversion is very forgiving. it's faster and
+ # it doesn't complain about bugs in popular magic files,
+ # but it will silently turn a string into zero.
+ if ($line =~ /^0/o) {
+ $testval = oct($line);
+ } else {
+ $testval = int($line);
+ }
+ }
+
+ ($template,$numbytes) = @{$TEMPLATES{$type}};
+
+ # unset coercion of $unsigned unless we're doing order comparison
+ if (ref($template)) {
+ $template = $$template[0]
+ unless $operator eq '>' || $operator eq '<';
+ }
+ }
+
+ return [ $offtype, $offset, $numbytes, $type, $mask,
+ $operator, $testval, $template, $message, $subtests ];
+}
+
+# recursively write the magic file to stderr. Numbers are written
+# in decimal.
+sub dumpMagic {
+ my ($magic,$depth) = @_;
+ $magic = [] unless defined $magic;
+ $depth = 0 unless defined $depth;
+
+ my $entry;
+ foreach $entry (@$magic) {
+ # delayed evaluation.
+ $entry = readMagicLine(@$entry) if @$entry == 3;
+
+ next if !defined($entry);
+
+ my ($offtype, $offset, $numbytes, $type, $mask, $op, $testval,
+ $template, $message, $subtests) = @$entry;
+
+ print STDERR '>'x$depth;
+ if ($offtype == 1) {
+ $offset->[2] =~ tr/c/b/;
+ print STDERR "($offset->[0].$offset->[2]$offset->[3])";
+ }
+ elsif ($offtype == 2) {
+ print STDERR "&",$offset;
+ }
+ else {
+ # offtype == 0
+ print STDERR $offset;
+ }
+ print STDERR "\t",$type;
+ if ($mask) { print STDERR "&",$mask; }
+ print STDERR "\t",$op,$testval,"\t",$message,"\n";
+
+ if ($subtests) {
+ dumpMagic($subtests,$depth+1);
+ }
+ }
+}
+
+1;
+__DATA__
+# Magic data for mod_mime_magic Apache module (originally for file(1) command)
+# The module is described in htdocs/manual/mod/mod_mime_magic.html
+#
+# The format is 4-5 columns:
+# Column #1: byte number to begin checking from, ">" indicates continuation
+# Column #2: type of data to match
+# Column #3: contents of data to match
+# Column #4: MIME type of result
+# Column #5: MIME encoding of result (optional)
+
+#------------------------------------------------------------------------------
+# Localstuff: file(1) magic for locally observed files
+# Add any locally observed files here.
+#
+
+# The following paramaters are created for Namazu.
+# <http://www.namazu.org/>
+#
+# 1999/08/13
+#0 string \<!--\ MHonArc text/html; x-type=mhonarc
+0 string BZh application/x-bzip2
+
+# The following paramaters are local hack.
+#
+# 1999/09/09
+# VRML (suggested by Masao Takaku)
+0 string #VRML\ V1.0\ ascii model/vrml
+0 string #VRML\ V2.0\ utf8 model/vrml
+
+#------------------------------------------------------------------------------
+# end local stuff
+#------------------------------------------------------------------------------
+
+#------------------------------------------------------------------------------
+# Java
+
+0 short 0xcafe
+>2 short 0xbabe application/java
+
+#------------------------------------------------------------------------------
+# audio: file(1) magic for sound formats
+#
+# from Jan Nicolai Langfeldt <janl@ifi.uio.no>,
+#
+
+# Sun/NeXT audio data
+0 string .snd
+>12 belong 1 audio/basic
+>12 belong 2 audio/basic
+>12 belong 3 audio/basic
+>12 belong 4 audio/basic
+>12 belong 5 audio/basic
+>12 belong 6 audio/basic
+>12 belong 7 audio/basic
+
+>12 belong 23 audio/x-adpcm
+
+# DEC systems (e.g. DECstation 5000) use a variant of the Sun/NeXT format
+# that uses little-endian encoding and has a different magic number
+# (0x0064732E in little-endian encoding).
+0 lelong 0x0064732E
+>12 lelong 1 audio/x-dec-basic
+>12 lelong 2 audio/x-dec-basic
+>12 lelong 3 audio/x-dec-basic
+>12 lelong 4 audio/x-dec-basic
+>12 lelong 5 audio/x-dec-basic
+>12 lelong 6 audio/x-dec-basic
+>12 lelong 7 audio/x-dec-basic
+# compressed (G.721 ADPCM)
+>12 lelong 23 audio/x-dec-adpcm
+
+# Bytes 0-3 of AIFF, AIFF-C, & 8SVX audio files are "FORM"
+# AIFF audio data
+8 string AIFF audio/x-aiff
+# AIFF-C audio data
+8 string AIFC audio/x-aiff
+# IFF/8SVX audio data
+8 string 8SVX audio/x-aiff
+
+# Creative Labs AUDIO stuff
+# Standard MIDI data
+0 string MThd audio/unknown
+#>9 byte >0 (format %d)
+#>11 byte >1 using %d channels
+# Creative Music (CMF) data
+0 string CTMF audio/unknown
+# SoundBlaster instrument data
+0 string SBI audio/unknown
+# Creative Labs voice data
+0 string Creative\ Voice\ File audio/unknown
+## is this next line right? it came this way...
+#>19 byte 0x1A
+#>23 byte >0 - version %d
+#>22 byte >0 \b.%d
+
+# [GRR 950115: is this also Creative Labs? Guessing that first line
+# should be string instead of unknown-endian long...]
+#0 long 0x4e54524b MultiTrack sound data
+#0 string NTRK MultiTrack sound data
+#>4 long x - version %ld
+
+# Microsoft WAVE format (*.wav)
+# [GRR 950115: probably all of the shorts and longs should be leshort/lelong]
+# Microsoft RIFF
+#0 string RIFF audio/x-msvideo
+0 string RIFF
+# - WAVE format
+>8 string WAVE audio/x-wav
+
+#------------------------------------------------------------------------------
+# c-lang: file(1) magic for C programs or various scripts
+#
+
+# XPM icons (Greg Roelofs, newt@uchicago.edu)
+# ideally should go into "images", but entries below would tag XPM as C source
+0 string /*\ XPM image/x-xbm
+
+# this first will upset you if you're a PL/1 shop... (are there any left?)
+# in which case rm it; ascmagic will catch real C programs
+# C or REXX program text
+0 string /* text/plain
+# C++ program text
+0 string // text/plain
+
+#------------------------------------------------------------------------------
+# compress: file(1) magic for pure-compression formats (no archives)
+#
+# compress, gzip, pack, compact, huf, squeeze, crunch, freeze, yabba, whap, etc.
+#
+# Formats for various forms of compressed data
+# Formats for "compress" proper have been moved into "compress.c",
+# because it tries to uncompress it to figure out what's inside.
+
+# standard unix compress
+#0 string \037\235 application/octet-stream x-compress
+0 string \037\235 application/x-compress
+
+# gzip (GNU zip, not to be confused with [Info-ZIP/PKWARE] zip archiver)
+#0 string \037\213 application/octet-stream x-gzip
+0 string \037\213 application/x-gzip
+
+# According to gzip.h, this is the correct byte order for packed data.
+0 string \037\036 application/octet-stream
+#
+# This magic number is byte-order-independent.
+#
+0 short 017437 application/octet-stream
+
+# XXX - why *two* entries for "compacted data", one of which is
+# byte-order independent, and one of which is byte-order dependent?
+#
+# compacted data
+0 short 0x1fff application/octet-stream
+0 string \377\037 application/octet-stream
+# huf output
+0 short 0145405 application/octet-stream
+
+# Squeeze and Crunch...
+# These numbers were gleaned from the Unix versions of the programs to
+# handle these formats. Note that I can only uncrunch, not crunch, and
+# I didn't have a crunched file handy, so the crunch number is untested.
+# Keith Waclena <keith@cerberus.uchicago.edu>
+#0 leshort 0x76FF squeezed data (CP/M, DOS)
+#0 leshort 0x76FE crunched data (CP/M, DOS)
+
+# Freeze
+#0 string \037\237 Frozen file 2.1
+#0 string \037\236 Frozen file 1.0 (or gzip 0.5)
+
+# lzh?
+#0 string \037\240 LZH compressed data
+
+#------------------------------------------------------------------------------
+# frame: file(1) magic for FrameMaker files
+#
+# This stuff came on a FrameMaker demo tape, most of which is
+# copyright, but this file is "published" as witness the following:
+#
+0 string \<MakerFile application/x-frame
+0 string \<MIFFile application/x-frame
+0 string \<MakerDictionary application/x-frame
+0 string \<MakerScreenFon application/x-frame
+0 string \<MML application/x-frame
+0 string \<Book application/x-frame
+0 string \<Maker application/x-frame
+
+#------------------------------------------------------------------------------
+# html: file(1) magic for HTML (HyperText Markup Language) docs
+#
+# from Daniel Quinlan <quinlan@yggdrasil.com>
+#
+0 string \<HEAD text/html
+0 string \<head text/html
+0 string \<TITLE text/html
+0 string \<title text/html
+0 string \<html text/html
+0 string \<HTML text/html
+0 string \<!-- text/html
+0 string \<h1 text/html
+0 string \<H1 text/html
+
+#------------------------------------------------------------------------------
+# images: file(1) magic for image formats (see also "c-lang" for XPM bitmaps)
+#
+# originally from jef@helios.ee.lbl.gov (Jef Poskanzer),
+# additions by janl@ifi.uio.no as well as others. Jan also suggested
+# merging several one- and two-line files into here.
+#
+# XXX - byte order for GIF and TIFF fields?
+# [GRR: TIFF allows both byte orders; GIF is probably little-endian]
+#
+
+# [GRR: what the hell is this doing in here?]
+#0 string xbtoa btoa'd file
+
+# PBMPLUS
+# PBM file
+0 string P1 image/x-portable-bitmap
+# PGM file
+0 string P2 image/x-portable-greymap
+# PPM file
+0 string P3 image/x-portable-pixmap
+# PBM "rawbits" file
+0 string P4 image/x-portable-bitmap
+# PGM "rawbits" file
+0 string P5 image/x-portable-greymap
+# PPM "rawbits" file
+0 string P6 image/x-portable-pixmap
+
+# NIFF (Navy Interchange File Format, a modification of TIFF)
+# [GRR: this *must* go before TIFF]
+0 string IIN1 image/x-niff
+
+# TIFF and friends
+# TIFF file, big-endian
+0 string MM image/tiff
+# TIFF file, little-endian
+0 string II image/tiff
+
+# possible GIF replacements; none yet released!
+# (Greg Roelofs, newt@uchicago.edu)
+#
+# GRR 950115: this was mine ("Zip GIF"):
+# ZIF image (GIF+deflate alpha)
+0 string GIF94z image/unknown
+#
+# GRR 950115: this is Jeremy Wohl's Free Graphics Format (better):
+# FGF image (GIF+deflate beta)
+0 string FGF95a image/unknown
+#
+# GRR 950115: this is Thomas Boutell's Portable Bitmap Format proposal
+# (best; not yet implemented):
+# PBF image (deflate compression)
+0 string PBF image/unknown
+
+# GIF
+0 string GIF image/gif
+
+# JPEG images
+0 beshort 0xffd8 image/jpeg
+
+# PC bitmaps (OS/2, Windoze BMP files) (Greg Roelofs, newt@uchicago.edu)
+0 string BM image/bmp
+#>14 byte 12 (OS/2 1.x format)
+#>14 byte 64 (OS/2 2.x format)
+#>14 byte 40 (Windows 3.x format)
+#0 string IC icon
+#0 string PI pointer
+#0 string CI color icon
+#0 string CP color pointer
+#0 string BA bitmap array
+
+# PNG images
+# Suggested by Jamie LeTual.
+0 string \211PNG image/png
+
+#------------------------------------------------------------------------------
+# lisp: file(1) magic for lisp programs
+#
+# various lisp types, from Daniel Quinlan (quinlan@yggdrasil.com)
+0 string ;; text/plain
+# Emacs 18 - this is always correct, but not very magical.
+0 string \012( application/x-elc
+# Emacs 19
+0 string ;ELC\023\000\000\000 application/x-elc
+
+#------------------------------------------------------------------------------
+# mail.news: file(1) magic for mail and news
+#
+# There are tests to ascmagic.c to cope with mail and news.
+0 string Relay-Version: message/rfc822
+0 string #!\ rnews message/rfc822
+0 string N#!\ rnews message/rfc822
+0 string Forward\ to message/rfc822
+0 string Pipe\ to message/rfc822
+0 string Return-Path: message/rfc822
+0 string Received: message/rfc822
+0 string Path: message/news
+0 string Xref: message/news
+0 string From: message/rfc822
+0 string Article message/news
+#------------------------------------------------------------------------------
+# msword: file(1) magic for MS Word files
+#
+# Contributor claims:
+# Reversed-engineered MS Word magic numbers
+#
+
+0 string \376\067\0\043 application/msword
+#0 string \320\317\021\340\241\261 application/msword
+0 string \333\245-\0\0\0 application/msword
+
+
+
+#------------------------------------------------------------------------------
+# printer: file(1) magic for printer-formatted files
+#
+
+# PostScript
+0 string %! application/postscript
+0 string \004%! application/postscript
+
+# Acrobat
+# (due to clamen@cs.cmu.edu)
+0 string %PDF- application/pdf
+
+#------------------------------------------------------------------------------
+# sc: file(1) magic for "sc" spreadsheet
+#
+38 string Spreadsheet application/x-sc
+
+#------------------------------------------------------------------------------
+# tex: file(1) magic for TeX files
+#
+# XXX - needs byte-endian stuff (big-endian and little-endian DVI?)
+#
+# From <conklin@talisman.kaleida.com>
+
+# Although we may know the offset of certain text fields in TeX DVI
+# and font files, we can't use them reliably because they are not
+# zero terminated. [but we do anyway, christos]
+0 string \367\002 application/x-dvi
+#0 string \367\203 TeX generic font data
+#0 string \367\131 TeX packed font data
+#0 string \367\312 TeX virtual font data
+#0 string This\ is\ TeX, TeX transcript text
+#0 string This\ is\ METAFONT, METAFONT transcript text
+
+# There is no way to detect TeX Font Metric (*.tfm) files without
+# breaking them apart and reading the data. The following patterns
+# match most *.tfm files generated by METAFONT or afm2tfm.
+#2 string \000\021 TeX font metric data
+#2 string \000\022 TeX font metric data
+#>34 string >\0 (%s)
+
+# Texinfo and GNU Info, from Daniel Quinlan (quinlan@yggdrasil.com)
+0 string \\input\ texinfo text/x-texinfo
+0 string This\ is\ Info\ file text/x-info
+#0 string This\ is\ text/x-info
+
+# correct TeX magic for Linux (and maybe more)
+# from Peter Tobias (tobias@server.et-inf.fho-emden.de)
+#
+0 leshort 0x02f7 application/x-dvi
+
+# RTF - Rich Text Format
+0 string {\\rtf application/rtf
+
+#------------------------------------------------------------------------------
+# animation: file(1) magic for animation/movie formats
+#
+# animation formats, originally from vax@ccwf.cc.utexas.edu (VaX#n8)
+# MPEG file
+0 string \000\000\001\263 video/mpeg
+#
+# The contributor claims:
+# I couldn't find a real magic number for these, however, this
+# -appears- to work. Note that it might catch other files, too,
+# so BE CAREFUL!
+#
+# Note that title and author appear in the two 20-byte chunks
+# at decimal offsets 2 and 22, respectively, but they are XOR'ed with
+# 255 (hex FF)! DL format SUCKS BIG ROCKS.
+#
+# DL file version 1 , medium format (160x100, 4 images/screen)
+0 byte 1 video/unknown
+0 byte 2 video/unknown
+
+#------------------------------------------------------------------------------
+# ichitaro456: file(1) magic for Just System Word Processor Ichitaro
+#
+# Contributor kenzo-:
+# Reversed-engineered JS Ichitaro magic numbers
+#
+
+0 string DOC
+>43 byte 0x14 application/ichitaro4
+>144 string JDASH application/ichitaro4
+
+0 string DOC
+>43 byte 0x15 application/ichitaro5
+
+0 string DOC
+>43 byte 0x16 application/ichitaro6
+
+#------------------------------------------------------------------------------
+# office97: file(1) magic for MicroSoft Office files
+#
+# Contributor kenzo-:
+# Reversed-engineered MS Office magic numbers
+#
+
+#0 string \320\317\021\340\241\261\032\341
+#>48 byte 0x1B application/excel
+
+2080 string Microsoft\ Excel\ 5.0\ Worksheet application/excel
+2114 string Biff5 application/excel
+
+0 string \224\246\056 application/msword
+
+0 belong 0x31be0000 application/msword
+
+0 string PO^Q` application/msword
+
+0 string \320\317\021\340\241\261\032\341
+>546 string bjbj application/msword
+>546 string jbjb application/msword
+
+512 string R\0o\0o\0t\0\ \0E\0n\0t\0r\0y application/msword
+
+2080 string Microsoft\ Word\ 6.0\ Document application/msword
+2080 string Documento\ Microsoft\ Word\ 6 application/msword
+2112 string MSWordDoc application/msword
+
+#0 string \320\317\021\340\241\261\032\341 application/powerpoint
+0 string \320\317\021\340\241\261\032\341 application/msword
+
+#
+# MPEG audio/video format
+# Contributer: Peter Breton
+#
+
+0 belong 0x000001b3 video/mpeg
+0 belong 0x000001ba video/mpeg
+0 beshort &0xffe0 audio/mpeg
+
+#
+# QuickTime format
+# Contributer: Peter Breton
+#
+
+0 string MOVI video/quicktime
+4 string moov video/quicktime
+4 string mdat video/quicktime
+
+# WinNT/WinCE PE files (Warner Losh, imp@village.org)
+#
+128 string PE\000\000 application/octet-stream
+0 string PE\000\000 application/octet-stream
+
+# miscellaneous formats
+0 string LZ application/octet-stream
+
+# .EXE formats (Greg Roelofs, newt@uchicago.edu)
+#
+0 string MZ
+>24 string @ application/octet-stream
+
+0 string MZ
+>30 string Copyright\ 1989-1990\ PKWARE\ Inc. application/x-zip
+
+0 string MZ
+>30 string PKLITE\ Copr. application/x-zip
+
+0 string MZ
+>36 string LHa's\ SFX application/x-lha
+
+0 string MZ
+>36 string LHA's\ SFX application/x-lha
+
+0 string MZ application/octet-stream
+
+# LHA archiver
+2 string -lh
+>6 string - application/x-lha
+
+# ZIP archiver
+0 string PK application/x-zip
+
+# POSIX tar archives
+257 string ustar\0 application/x-tar
+257 string ustar\040\040\0 application/x-gtar
+
+# TNEF file
+0 lelong 0x223E9F78 application/ms-tnef
+
+# ARC archiver
+0 lelong&0x8080ffff 0x0000081a application/x-arc
+0 lelong&0x8080ffff 0x0000091a application/x-arc
+0 lelong&0x8080ffff 0x0000021a application/x-arc
+0 lelong&0x8080ffff 0x0000031a application/x-arc
+0 lelong&0x8080ffff 0x0000041a application/x-arc
+0 lelong&0x8080ffff 0x0000061a application/x-arc
+# Zoo archiver
+20 lelong 0xfdc4a7dc application/x-zoo
+# ARJ archiver (jason@jarthur.Claremont.EDU)
+0 leshort 0xea60 application/x-arj
+# RAR archiver (Greg Roelofs, newt@uchicago.edu)
+0 string Rar! application/x-rar
diff --git a/cpan/dist/File-MMagic/Makefile.PL b/cpan/dist/File-MMagic/Makefile.PL
new file mode 100644
index 00000000..dcb1bd17
--- /dev/null
+++ b/cpan/dist/File-MMagic/Makefile.PL
@@ -0,0 +1,14 @@
+# File::MMagic Makefile.PL
+#
+# $Id: Makefile.PL,v 1.3 1999/10/27 09:44:08 knok Exp $
+
+use ExtUtils::MakeMaker;
+
+WriteMakefile(
+ 'NAME' => 'File::MMagic',
+ 'VERSION_FROM' => 'MMagic.pm',
+ ($] ge '5.005') ?
+ ('AUTHOR' => 'NOKUBI Takatsugu <knok@daionet.gr.jp>',
+ 'ABSTRACT' => 'Guess file type from contents',
+ ) : (),
+);
diff --git a/cpan/dist/File-MMagic/README.en b/cpan/dist/File-MMagic/README.en
new file mode 100644
index 00000000..a9148d6d
--- /dev/null
+++ b/cpan/dist/File-MMagic/README.en
@@ -0,0 +1,36 @@
+File::MMagic
+
+Copyright(C) 1999-2001 NOKUBI Takatsugu <knok@daionet.gr.jp>
+
+1. Abstract
+
+This module is to guess file type from its contents like file(1)
+command.
+
+2. Install
+
+Extract archive file.
+Change current directory to File-MMagic-x.xx ("x.xx" is version
+number).
+Type "perl Makefile.PL" to create Makefile.
+Type "make install" to install.
+
+3. How to use
+
+See "perldoc File::MMagic".
+
+4. Copyright
+
+See COPYING file.
+
+5. Notice
+
+If you want to use the module under mod_perl environment, you'll need
+to divide the module into module part and magic entry file part, and use
+the magic file explicitly.
+Built-in magic entry does not work correctly under mod_perl.
+
+Ex.
+
+my $magic = File::MMagic::new('/etc/mime-magic');
+ # /etc/mime-magic is separated file from MMagic.pm
diff --git a/cpan/dist/File-MMagic/README.ja b/cpan/dist/File-MMagic/README.ja
new file mode 100644
index 00000000..11bcd77f
--- /dev/null
+++ b/cpan/dist/File-MMagic/README.ja
@@ -0,0 +1,55 @@
+File::MMagic
+
+Copyright(C) 1999-2001 NOKUBI Takatsugu <knok@daionet.gr.jp>
+
+1. $B$O$8$a$K(B
+
+$B$3$N%b%8%e!<%k$O!"(Bfile(1)$B%3%^%s%I$KAjEv$9$k5!G=!"$9$J$o$A%U%!%$%k$NFb(B
+$BMF$+$i$=$N<oN`$r?dB,$9$k$?$a$N$b$N$G$9!#(B
+
+2. $B%$%s%9%H!<%k(B
+
+$B%"!<%+%$%V%U%!%$%k$rE83+$7!":n@.$5$l$?%G%#%l%/%H%j(BFile-MMagic-x.xx
+("x.xx"$B$K$O%P!<%8%g%sHV9f$,F~$j$^$9(B)$B$r%+%l%s%H%G%#%l%/%H%j$K0\$7$^$9!#(B
+$B$=$3$G!"(Bperl Makefile.PL$B$r<B9T$7$F(BMakefile$B$r@8@.$7!"(Bmake install$B$G%$%s(B
+$B%9%H!<%k$,$*$3$J$o$l$^$9!#(B
+
+3. $B;H$$J}(B
+
+$B$3$N%b%8%e!<%k$O!"(Bperl5$B$N%*%V%8%'%/%H$rMQ$$$F%U%!%$%k$N<oN`$r%U%!%$%k(B
+$BL>$d%U%!%$%k%O%s%I%k$+$i?dB,$9$k$3$H$,$G$-$^$9!#(B
+
+$B>\$7$$;H$$J}$O!"(Bperldoc File::MMagic$BEy$G3NG'$7$F$/$@$5$$!#(B
+
+4. $BCx:n8"I=<((B
+
+Copyright(C) 1999-2001 NOKUBI Takatsugu <knok@daionet.gr.jp>
+
+* Copyright (c) Ian F. Darwin, 1987.
+* Written by Ian F. Darwin.
+* Copyright (c) 1995-1999 The Apache Group. All rights reserved.
+
+$B$3$N%b%8%e!<%k$O40A4$KL5J]>c$G$9!#(B
+
+$B$^$?!"$3$N%b%8%e!<%k$O(BThe Unix Reconstruction Project$B$N@.2LJ*$G$"$k(B
+Perl Power Tools$B$N(Bfile.kulp$B$r85$K:n@.$5$l$F$$$^$9!#$5$i$K!"(BThe Apache
+HTTP server project$B$N@.2LJ*$N0lIt$G$"$k(Bmagic$B%U%!%$%k$r85$K$7$?%G!<%?$r(B
+$BFbJq$7$F$$$^$9!#$h$C$F!"Cx:n8"$O$3$l$i%*%j%8%J%k$N%=%U%H%&%'%"$K=`$8$?(B
+$B07$$$H$7$^$9!#(B
+ $B>\:Y$O!"%"!<%+%$%V$K4^$^$l$k(BCOPYING$B$H$$$&%U%!%$%k$r;2>H$7$F$/$@$5$$!#(B
+
+The Unix Reconstruction Project
+<http://language.perl.com/ppt/index.html>
+The Apache HTTP server project
+<http://www.apache.org/>
+
+5. $BCm0UE@(B
+
+$B$3$N%b%8%e!<%k$r(B mod_perl $B$GMxMQ$9$k$H$-$O!"(BMMagic.pm $B$+$i(B magic entry $BItJ,(B
+$B$rH4$-=P$7!"$=$l$r(B magic file $B$H$7$FM[$K;XDj$9$k$h$&$K$7$F2<$5$$!#(B
+$B%b%8%e!<%k$KAH$_9~$^$l$F$$$k(B magic entry $B$O(B mod_perl $B$G$O@5$7$/F0:n$7$^$;$s!#(B
+
+$BNc(B:
+
+my $magic = File::MMagic::new('/etc/mime-magic');
+ # /etc/mime-magic is separated file from MMagic.pm
diff --git a/cpan/dist/File-MMagic/t/01-selfcheck.t b/cpan/dist/File-MMagic/t/01-selfcheck.t
new file mode 100644
index 00000000..fc219422
--- /dev/null
+++ b/cpan/dist/File-MMagic/t/01-selfcheck.t
@@ -0,0 +1,13 @@
+# perl-test
+# $Id: 01-selfcheck.t,v 1.1 2001/07/17 06:51:14 knok Exp $
+
+use strict;
+use Test;
+
+BEGIN { plan tests => 1 };
+
+use File::MMagic;
+
+my $magic = File::MMagic::new();
+my $ret = $magic->checktype_filename('t/01-selfcheck.t');
+ok($ret eq 'text/plain');
diff --git a/cpan/dist/File-MMagic/t/02-extmagic.t b/cpan/dist/File-MMagic/t/02-extmagic.t
new file mode 100644
index 00000000..4343651e
--- /dev/null
+++ b/cpan/dist/File-MMagic/t/02-extmagic.t
@@ -0,0 +1,14 @@
+# perl-test
+# $Id: 02-extmagic.t,v 1.2 2001/07/17 06:57:08 knok Exp $
+
+use strict;
+use Test;
+
+BEGIN { plan tests => 1 };
+
+use File::MMagic;
+
+my $magic = File::MMagic::new();
+$magic->addMagicEntry("0\tstring\t#\\ perl-test\tapplication/x-perl-test");
+my $ret = $magic->checktype_filename('t/02-extmagic.t');
+ok($ret eq 'application/x-perl-test');
diff --git a/cpan/dist/MIME-Types/ChangeLog b/cpan/dist/MIME-Types/ChangeLog
new file mode 100644
index 00000000..dc21dedb
--- /dev/null
+++ b/cpan/dist/MIME-Types/ChangeLog
@@ -0,0 +1,111 @@
+Revision history for Perl extension MIME::Types.
+
+Unless explicitly stated differently are all changes produced by
+Mark Overmeer <mimetypes@overmeer.net>
+
+version 1.004: Tue Oct 22 19:22:43 CEST 2002
+
+ - [Dan Puro] sent a reference to a list stored at
+ http://www.indiana.edu/cgi-bin-local/mimetypes. Most differences
+ are added, but some where competing... and I won.
+
+version 1.003: Wed Oct 2 09:42:58 CEST 2002
+
+ - [Darell Fuhriman] added application/x-rar-compressed and
+ application/x-msdownload
+
+ - [Vladimir V. Kolpakov] set $/ = "\n" on parsing data from
+ inside file, which was written on UNIX and used in Windows.
+
+ - [Dan Puro] added application/wordperfect5.1 extension wpd.
+
+ - [Petri Riihikallio] added .xlt for Excel and .pps/.pot
+ for PowerPoint.
+
+version 1.002: Mon Aug 12 11:40:55 CEST 2002
+
+ - [Jan Kratochvil] added audio/amr and audio/amr-wb to the
+ set of known datatypes. Types defined by rfc3267
+
+version 1.001: Tue Jun 18 13:39:56 CEST 2002
+
+ - Brown paper-bag release. Accidentally, code was installing
+ itself as MIME::MIME::Types
+
+version 1.00: Tue Jun 18 13:27:16 CEST 2002
+
+ - No real changes for some time now, so released a stable with
+ version of 1.00
+
+ - Doc typo: MIME::Types->extension must be MIME::Types->mimeTypeOf
+
+ - Overloaded comparison of $mimetype with string now works. Before,
+ only two objects could be compared.
+
+version 0.16: Tue Feb 19 12:08:51 CET 2002
+
+ - MIME::Type->simplified('text') will return 'text/plain'
+
+ - MIME::Types->type($mime) will return undef for illegal $mime
+
+version 0.15: Wed Jan 23 21:22:26 CET 2002
+
+ - [Dirk Lutsebaeck] contributed a few mime-types. I am open
+ to receive more improvements.
+
+ - Refrased the reason for removal of import_mime_types, a
+ residual of the pre-0.10 version of this module.
+
+ - Changed MIME::Type::mainType() into MIME::Type::mediaType() to
+ follow the terminology of the RFC more closely. The old name
+ is still usable.
+
+ - Added MIME::Types::addType
+
+ - Added overloading stringify and comparison to MIME::Type objects.
+ some tests in t/11typeol.t
+
+version 0.14: Sat Dec 1 13:56:51 CET 2001
+ - Did a bad job (it's hard to support backwards compat if you run
+ 5.6) Thanks to [Tatsuhiko Miyagawa]
+
+version 0.13: Sat Dec 1 01:53:20 CET 2001
+ - [Slaven Radic] back-port to 5.005
+
+version 0.12: Wed Nov 28 09:39:44 CET 2001
+ Mark Overmeer took the namespace over from Jeff Okamoto
+ - In scalar context MIME::Types::type will return only the
+ first type that fits.
+
+version 0.10: Sat Nov 3 22:46:22 2001
+ Mark Overmeer
+ - Total redesign of the interface, object oriented with two
+ classes: the MIME::Types and the MIME::Type.
+ - No seperate mime.types file anymore, but included inside
+ MIME::Types, such that installation is much easier.
+ - Merged-in apache's mime types 1.3.14
+ - New test files.
+ - Modernized test.pl into t/30export.t
+
+version 0.06: Fri Jun 22 15:18:28 PDT 2001
+ - Repackage.
+
+version 0.05: Fri Jun 15 15:10:08 PDT 2001
+ - Added changes to import_mime_types by Antonios Christofides
+ (A.Christofides@hydro.ntua.gr)
+
+version 0.04: Thu Apr 19 15:37:23 PDT 2001
+ - Added new function import_mime_types by Mike Cramer
+ (cramer@webkist.com) to read an Apache-style mime.types file.
+
+version 0.03: Fri Feb 23 10:32:44 2001
+ - Many changes by David Wheeler (david@wheeler.net) including:
+ - substituting some regexp's with faster string calls
+ - simplifying the mapping table startup code
+ - allowing the returning of array references instead of lists
+
+version 0.02: Sat Nov 6 00:00:00 1999
+ - Fix a few bad suffix mappings and add a bit of robustness
+
+version 0.01: Tue Oct 5 14:00:18 1999
+ - original version; created by h2xs 1.18
diff --git a/cpan/dist/MIME-Types/MANIFEST b/cpan/dist/MIME-Types/MANIFEST
new file mode 100644
index 00000000..3296079d
--- /dev/null
+++ b/cpan/dist/MIME-Types/MANIFEST
@@ -0,0 +1,11 @@
+ChangeLog
+Makefile.PL
+MANIFEST
+MIME/Type.pm
+MIME/Types.pm
+MIME/Makefile.PL
+README
+t/10type.t
+t/11typeol.t
+t/20types.t
+t/30export.t
diff --git a/cpan/dist/MIME-Types/MIME/Makefile.PL b/cpan/dist/MIME-Types/MIME/Makefile.PL
new file mode 100644
index 00000000..9a125cf7
--- /dev/null
+++ b/cpan/dist/MIME-Types/MIME/Makefile.PL
@@ -0,0 +1,7 @@
+
+use ExtUtils::MakeMaker;
+
+WriteMakefile
+ ( NAME => 'MIME::Types'
+ );
+
diff --git a/cpan/dist/MIME-Types/MIME/Type.pm b/cpan/dist/MIME-Types/MIME/Type.pm
new file mode 100644
index 00000000..baec8b31
--- /dev/null
+++ b/cpan/dist/MIME-Types/MIME/Type.pm
@@ -0,0 +1,320 @@
+package MIME::Type;
+
+$VERSION = '1.004';
+
+use strict;
+use Carp;
+
+use overload '""' => 'type'
+ , cmp => 'equals'
+ ;
+
+=head1 NAME
+
+ MIME::Type - Definition of one MIME type
+
+=head1 SYNOPSIS
+
+ use MIME::Types;
+ my $mimetypes = MIME::Types->new;
+ my MIME::Type $plaintext = $mimetype->type('text/plain');
+ print $plaintext->mediaType; # text
+ print $plaintext->subType; # plain
+
+ my @ext = $plaintext->extensions;
+ print "@ext" # asc txt c cc h hh cpp
+
+ print $plaintext->encoding # 8bit
+ if($plaintext->isBinary) # false
+ if($plaintext->isAscii) # true
+ if($plaintext->equals('text/plain') {...}
+ if($plaintext eq 'text/plain') # same
+
+ print MIME::Type->simplified('x-appl/x-zip') # 'appl/zip'
+
+=head1 DESCRIPTION
+
+MIME types are used in MIME entities, for instance as part of e-mail
+and HTTP traffic. Sometimes real knowledge about a mime-type is need.
+Objects of C<MIME::Type> store the information on one such type.
+
+This module is built to conform to the MIME types of RFC's 2045 and 2231.
+It follows the collection kept at F<http://www.ltsw.se/knbase/internet/mime.htp>
+
+=cut
+
+#-------------------------------------------
+
+=head1 METHODS
+
+=over 4
+
+=cut
+
+#-------------------------------------------
+
+=item new OPTIONS
+
+Create a new C<MIME::Type> object which manages one mime type.
+
+ OPTION DEFAULT
+ type <obligatory>
+ simplified <derived from type>
+ extensions undef
+ encoding <depends on type>
+ system undef
+
+=over 4
+
+=item * type =E<gt> STRING
+
+The type which is defined here. It consists of a I<type> and a I<sub-type>,
+both case-insensitive. This module will return lower-case, but accept
+upper-case.
+
+=item * simplified =E<gt> STRING
+
+The mime types main- and sub-label can both start with C<x->, to indicate
+that is a non-registered name. Of course, after registration this flag
+can disappear which adds to the confusion. The simplified string has the
+C<x-> thingies removed and are translated to lower-case.
+
+=item * extensions =E<gt> REF-ARRAY
+
+An array of extensions which are using this mime.
+
+=item * encoding =E<gt> '7bit'|'8bit'|'base64'|'quoted-printable'
+
+How must this data be encoded to be transported safely. The default
+depends on the type: mimes with as main type C<text/> will default
+to C<quoted-printable> and all other to C<base64>.
+
+=item * system =E<gt> REGEX
+
+Regular expression which defines for which systems this rule is valid. The
+REGEX is matched on C<$^O>.
+
+=back
+
+=cut
+
+sub new(@) { (bless {}, shift)->init( {@_} ) }
+
+sub init($)
+{ my ($self, $args) = @_;
+
+ $self->{MT_type} = $args->{type}
+ or confess "Type is obligatory.";
+
+ $self->{MT_simplified} = $args->{simplified}
+ || ref($self)->simplified($args->{type});
+
+ $self->{MT_extensions} = $args->{extensions} || [];
+
+ $self->{MT_encoding}
+ = $args->{encoding} ? $args->{encoding}
+ : $self->mediaType eq 'text' ? 'quoted-printable'
+ : 'base64';
+
+ $self->{MT_system} = $args->{system}
+ if defined $args->{system};
+
+ $self;
+}
+
+#-------------------------------------------
+
+=item type
+
+Returns the long type of this object, for instance C<'text/plain'>
+
+=cut
+
+sub type() {shift->{MT_type}}
+
+#-------------------------------------------
+
+=item simplified [STRING]
+
+(Instance method or Class method)
+Returns the simplified mime type for this object or the specified STRING.
+Mime type names can get officially registered. Until then, they have to
+carry an C<x-> preamble to indicate that. Of course, after recognition,
+the C<x-> can disappear. In many cases, we prefer the simplified version
+of the type.
+
+Examples:
+
+ my $mime = MIME::Type->new(type => 'x-appl/x-zip');
+ print $mime->simplified; # 'appl/zip'
+ print $mime->simplified('text/plain'); # 'text/plain'
+ print MIME::Type->simplified('x-xyz/x-abc'); # 'xyz/abc'
+
+=cut
+
+sub simplified(;$)
+{ my $thing = shift;
+ return $thing->{MT_simplified} unless @_;
+
+ my $mime = shift;
+
+ $mime =~ m!^\s*(?:x\-)?([\w.+-]+)/(?:x\-)?([\w.+-]+)\s*$!i ? lc "$1/$2"
+ : $mime =~ m!text! ? "text/plain" # some silly mailers...
+ : undef;
+}
+
+#-------------------------------------------
+
+=item mediaType
+
+The media type of the simplified mime.
+For C<'text/plain'> it will return C<'text'>.
+
+For historical reasons, the C<'mainType'> method still can be used
+to retreive the same value. However, that method is deprecated.
+
+=cut
+
+sub mediaType() {shift->{MT_simplified} =~ m!^([\w-]+)/! ? $1 : undef}
+
+sub mainType() {shift->mediaType} # Backwards compatibility
+
+#-------------------------------------------
+
+=item subType
+
+The sub type of the simplified mime.
+For C<'text/plain'> it will return C<'plain'>.
+
+=cut
+
+sub subType() {shift->{MT_simplified} =~ m!/([\w-]+)$! ? $1 : undef}
+
+#-------------------------------------------
+
+=item isRegistered
+
+Mime-types which are not registered by IANA nor defined in RFCs shall
+start with an C<x->. This counts for as well the media-type as the
+sub-type. In case either one of the types starts with C<x-> this
+method will return false.
+
+=cut
+
+sub isRegistered()
+{ local $_ = shift->{MT_type};
+ not (m/^[xX]\-/ || m!/[xX]\-!);
+}
+
+#-------------------------------------------
+
+=item extensions
+
+Returns a list of extensions which are known to be used for this
+mime type.
+
+=cut
+
+sub extensions() { @{shift->{MT_extensions}} }
+
+#-------------------------------------------
+
+=item encoding
+
+Returns the type of encoding which is required to transport data of this
+type safely.
+
+=cut
+
+sub encoding() {shift->{MT_encoding}}
+
+#-------------------------------------------
+
+=item system
+
+Returns the regular expression which can be used to determine whether this
+type is active on the system where you are working on.
+
+=cut
+
+sub system() {shift->{MT_system}}
+
+#-------------------------------------------
+
+=item isBinary
+
+Returns true when the encoding is base64.
+
+=cut
+
+sub isBinary() { shift->{MT_encoding} eq 'base64' }
+
+#-------------------------------------------
+
+=item isAscii
+
+Returns false when the encoding is base64, and true otherwise. All encodings
+except base64 are text encodings.
+
+=cut
+
+sub isAscii() { shift->{MT_encoding} ne 'base64' }
+
+#-------------------------------------------
+
+=item isSignature
+
+Returns true when the type is in the list of known signatures.
+
+=cut
+
+# simplified names only!
+my %sigs = map { ($_ => 1) }
+ qw(application/pgp-keys application/pgp application/pgp-signature
+ application/pkcs10 application/pkcs7-mime application/pkcs7-signature
+ text/vCard);
+
+sub isSignature() { $sigs{shift->{MT_simplified}} }
+
+#-------------------------------------------
+
+=item equals STRING|MIME
+
+Compare this mime-type object with a STRING or other object. In case of
+a STRING, simplification will take place.
+
+=cut
+
+sub equals($)
+{ my ($self, $other) = @_;
+
+ my $type = ref $other
+ ? $other->simplified
+ : (ref $self)->simplified($other);
+
+ $self->simplified cmp $type;
+}
+
+#-------------------------------------------
+
+=back
+
+=head1 SEE ALSO
+
+L<MIME::Types>
+
+=head1 AUTHOR
+
+Mark Overmeer (F<mimetypes@overmeer.net>).
+
+=head1 VERSION
+
+This code is stable, version 1.003.
+
+Copyright (c) 2001-2002 Mark Overmeer. All rights reserved.
+This program is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut
+
+1;
diff --git a/cpan/dist/MIME-Types/MIME/Types.pm b/cpan/dist/MIME-Types/MIME/Types.pm
new file mode 100644
index 00000000..1240fa5d
--- /dev/null
+++ b/cpan/dist/MIME-Types/MIME/Types.pm
@@ -0,0 +1,809 @@
+package MIME::Types;
+
+$VERSION = '1.004';
+
+use strict;
+use MIME::Type;
+
+=head1 NAME
+
+ MIME::Types - Definition of MIME types
+
+=head1 SYNOPSIS
+
+ use MIME::Types;
+ my $mimetypes = MIME::Types->new;
+ my MIME::Type $plaintext = $mimetype->type('text/plain');
+ my MIME::Type $imagegif = $mimetype->mimeTypeOf('gif');
+
+=head1 DESCRIPTION
+
+MIME types are used in MIME entities, for instance as part of e-mail
+and HTTP traffic. Sometimes real knowledge about a mime-type is need.
+This module will supply it.
+
+=cut
+
+#-------------------------------------------
+
+=head1 METHODS
+
+=over 4
+
+=cut
+
+#-------------------------------------------
+
+=item new OPTIONS
+
+Create a new C<MIME::Types> object which manages the data. In the current
+implementation, it does not matter whether you create this object often
+within your program, but in the future this may change.
+
+ OPTIONS DEFAULT
+ only_complete 0
+
+=over 4
+
+=item * only_complete =E<gt> BOOLEAN
+
+Only include complete mime-type definitions: requires extension and
+encoding. This will reduce the number of entries --and with that
+the amount of memory consumed-- enormously.
+
+In your program you have to decide: the first time that you call
+the creator (C<new>) determines whether you get the full or the partial
+information.
+
+=back
+
+=cut
+
+my %list;
+sub new(@) { (bless {}, shift)->init( {@_} ) }
+
+sub init($)
+{ my ($self, $args) = @_;
+
+ unless(keys %list)
+ { local $_;
+ local $/ = "\n";
+
+ while(<MIME::Types::DATA>)
+ { s/\#.*//;
+ next if m/^$/;
+
+ my $os = s/^(\w+)\:// ? qr/$1/i : undef;
+
+ my ($type, $extensions, $encoding) = split;
+ my $extent = $extensions ? [ split /\,/, $extensions ] : undef;
+
+ next if $args->{only_complete}
+ && ! ($extensions && $encoding);
+
+ my $simplified = MIME::Type->simplified($type);
+ push @{$list{$simplified}}, MIME::Type->new
+ ( type => $type
+ , extensions => $extent
+ , encoding => $encoding
+ , system => $os
+ );
+ }
+ }
+
+ close DATA;
+ $self;
+}
+
+my %type_index;
+sub create_type_index()
+{ my $self = shift;
+
+ my @os_specific;
+ while(my ($simple, $definitions) = each %list)
+ { foreach my $def (@$definitions)
+ { if(defined $def->system && $^O =~ $def->system)
+ { # OS specific definitions will overrule the
+ # unspecific definitions, so must be postponed till
+ # the end.
+ push @os_specific, $def;
+ }
+ else
+ { $type_index{$_} = $def foreach $def->extensions;
+ }
+ }
+ }
+
+ foreach my $def (@os_specific)
+ { $type_index{$_} = $def foreach $def->extensions;
+ }
+
+ $self;
+}
+
+#-------------------------------------------
+
+=item type STRING
+
+Return the C<MIME::Type> which describes the type related to STRING. One
+type may be described more than once. Different extensions is use for
+this type, and different operating systems may cause more than one
+C<MIME::Type> object to be defined. In scalar context, only the first
+is returned.
+
+=cut
+
+sub type($)
+{ my $mime = MIME::Type->simplified($_[1]) or return;
+ return () unless exists $list{$mime};
+ wantarray ? @{$list{$mime}} : $list{$mime}[0];
+}
+
+#-------------------------------------------
+
+=item mimeTypeOf FILENAME
+
+Returns the C<MIME::Type> object which belongs to the FILENAME (or simply
+its filename extension). The extension is used, and considered
+case-insensitive.
+
+Examples:
+
+ my MIME::Types $types = MIME::Types->new;
+ my MIME::Type $mime = $types->mimeTypeOf('gif');
+
+ my MIME::Type $mime = $types->mimeTypeOf('jpg');
+ print $mime->isBinary;
+
+=cut
+
+sub mimeTypeOf($)
+{ my ($self, $name) = @_;
+ $self->create_type_index unless keys %type_index;
+ $name =~ s/.*\.//;
+ $type_index{lc $name};
+}
+
+#-------------------------------------------
+
+=item addType TYPE, ...
+
+Add one or more TYPEs to the set of known types. Each TYPE is a
+C<MIME::Type> which must be experimental: either the main-type or
+the sub-type must start with C<x->.
+
+Please inform the maintainer of this module when registered types
+are missing.
+
+=cut
+
+sub addType(@)
+{ my $self = shift;
+ foreach my $type (@_)
+ {
+ if($type->isRegistered)
+ { use Carp;
+ carp "Please report the registered type $type to the module author."
+ }
+
+ my $simplified = $type->simplified;
+ push @{$list{$simplified}}, $type;
+ }
+
+ %type_index = ();
+ $self;
+}
+
+#-------------------------------------------
+
+=back
+
+=head1 EXPORT
+
+The next methods are provided for backward compatibility with MIME::Types
+versions 0.06 and below. This code originates from Jeff Okamoto
+<F<okamoto@corp.hp.com>> and others.
+
+=over 4
+
+=cut
+
+#-------------------------------------------
+
+require Exporter;
+use vars qw/@ISA @EXPORT_OK/;
+@ISA = qw(Exporter);
+@EXPORT_OK = qw(by_suffix by_mediatype import_mime_types);
+
+#-------------------------------------------
+
+=item by_suffix FILENAME|SUFFIX
+
+Like C<mimeTypeOf> but does not return an C<MIME::Type> object.
+
+Example:
+
+ use MIME::Types 'by_suffix';
+ my ($mediatype, $encoding) = by_suffix 'image.gif';
+
+ my $refdata = by_suffix 'image.gif';
+ my ($mediatype, $encoding) = @$refdata;
+
+=cut
+
+my $mime_types;
+
+sub by_suffix($)
+{ my $filename = shift;
+ $mime_types ||= MIME::Types->new;
+ my $mime = $mime_types->mimeTypeOf($filename);
+
+ my @data = defined $mime ? ($mime->type, $mime->encoding) : ('','');
+ wantarray ? @data : \@data;
+}
+
+#-------------------------------------------
+
+=item by_mediatype TYPE
+
+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.
+
+TYPE can be a full type name (contains '/', and will be matched in full),
+a partial type (which is used as regular expression) or a real regular
+expression.
+
+=cut
+
+sub by_mediatype($)
+{ my $type = shift;
+ my @found;
+
+ if($type =~ m!/!)
+ { my $simplified = MIME::Type->simplified($type);
+ my $mime = $list{$simplified};
+ push @found, @$mime if defined $mime;
+ }
+ else
+ { my $mime = ref $type ? $type : qr/$type/i;
+ @found = map {@{$list{$_}}}
+ grep {$_ =~ $mime}
+ keys %list;
+ }
+
+ my @data;
+ foreach my $mime (@found)
+ { push @data, map { [$_, $mime->type, $mime->encoding] }
+ $mime->extensions;
+ }
+
+ wantarray ? @data : \@data;
+}
+
+#-------------------------------------------
+
+=item import_mime_types
+
+This method has been removed: mime-types are only useful if understood
+by many parties. Therefore, the IANA assigns names which can be used.
+In the table kept by this C<MIME::Types> module all these names, plus
+the most often used termporary names are kept. When names seem to be
+missing, please contact the maintainer for inclussion.
+
+=cut
+
+sub import_mime_types($)
+{ my $filename = shift;
+ use Carp;
+ croak <<'CROAK';
+import_mime_types is not supported anymore: if you have types to add
+please send them to the author.
+CROAK
+}
+
+#-------------------------------------------
+
+=back
+
+=head1 SEE ALSO
+
+L<MIME::Type>
+
+=head1 AUTHOR
+
+Original module and data collection by Jeff Okamoto and the Apache team.
+Mark Overmeer (F<mimetypes@overmeer.net>).
+
+=head1 VERSION
+
+This code is stable, version 1.003.
+
+Copyright (c) 2001-2002 by Jeff Okamoto and Mark Overmeer.
+All rights reserved. This program is free software; you can redistribute
+it and/or modify it under the same terms as Perl itself.
+
+=cut
+
+1;
+
+#-------------------------------------------
+# Internet media type registry is at
+# <ftp://ftp.iana.org/in-notes/iana/assignments/media-types/>.
+
+__DATA__
+application/access mdf
+application/activemessage
+application/andrew-inset ez
+application/applefile base64
+application/atomicmail
+application/batch-SMTP
+application/bleeper bleep base64
+application/cals-1840
+application/commonground
+application/cu-seeme csm,cu
+application/cybercash
+application/dca-rft
+application/dec-dx
+application/EDI-Consent
+application/EDIFACT
+application/EDI-X12
+application/eshop
+application/excel xls,xlt base64
+application/font-tdpfr pfr
+application/futuresplash spl
+application/ghostview
+application/hep hep
+application/http
+application/hyperstudio
+application/iges
+application/imagemap imagemap,imap 8bit
+application/index
+application/index.cmd
+application/index.obj
+application/index.response
+application/index.vnd
+application/iotp
+application/ipp
+application/lotus-123 wks
+application/mac-binhex40 hqx 8bit
+application/mac-compactpro cpt
+application/macwriteii
+application/marc
+application/mathematica
+application/mathcad mcd base64
+application/mathematica-old
+application/msword doc,dot,wrd base64
+application/news-message-id
+application/news-transmission
+application/ocsp-request
+application/ocsp-response
+application/octet-stream bin,dms,lha,lzh,exe,class,ani base64
+application/oda oda
+application/pdf pdf base64
+application/pagemaker pm5,pt5,pm
+application/pgp-encrypted
+application/pgp-keys
+application/pgp
+application/pgp-signature pgp 8bit
+application/pkcs10
+application/pkcs7-mime
+application/pkcs7-signature
+application/pkix-cert
+application/pkixcmp
+application/pkix-crl
+application/postscript ai,eps,ps 8bit
+application/postscript ps-z base64
+application/powerpoint ppt,pps,pot base64
+application/prs.alvestrand.titrax-sheet
+application/prs.cww
+application/prs.nprend
+application/remote-printing
+application/riscos
+application/rtf rtf 8bit
+application/sdp
+application/set-payment
+application/set-payment-initiation
+application/set-registration
+application/set-registration-initiation
+application/sgml
+application/sgml-open-catalog
+application/slate
+application/smil smi,smil
+application/toolbook tbk
+application/vemmi
+application/VMSBACKUP bck base64
+application/vnd.3M.Post-it-Notes
+application/vnd.accpac.simply.aso
+application/vnd.accpac.simply.imp
+application/vnd.acucobol
+application/vnd.anser-web-certificate-issue-initiation
+application/vnd.anser-web-funds-transfer-initiation
+application/vnd.audiograph
+application/vnd.bmi
+application/vnd.businessobjects
+application/vnd.canon-cpdl
+application/vnd.canon-lips
+application/vnd.claymore
+application/vnd.commerce-battelle
+application/vnd.commonspace
+application/vnd.comsocaller
+application/vnd.contact.cmsg
+application/vnd.cosmocaller
+application/vnd.ctc-posml
+application/vnd.cups-postscript
+application/vnd.cups-raster
+application/vnd.cups-raw
+application/vnd.cybank
+application/vnd.dna
+application/vnd.dpgraph
+application/vnd.dxr
+application/vnd.ecdis-update
+application/vnd.ecowin.chart
+application/vnd.ecowin.filerequest
+application/vnd.ecowin.fileupdate
+application/vnd.ecowin.series
+application/vnd.ecowin.seriesrequest
+application/vnd.ecowin.seriesupdate
+application/vnd.enliven
+application/vnd.epson.esf
+application/vnd.epson.msf
+application/vnd.epson.quickanime
+application/vnd.epson.salt
+application/vnd.epson.ssf
+application/vnd.ericsson.quickcall
+application/vnd.eudora.data
+application/vnd.fdf
+application/vnd.ffsns
+application/vnd.FloGraphIt
+application/vnd.framemaker
+application/vnd.fujitsu.oasys
+application/vnd.fujitsu.oasys2
+application/vnd.fujitsu.oasys3
+application/vnd.fujitsu.oasysgp
+application/vnd.fujitsu.oasysprs
+application/vnd.fujixerox.ddd
+application/vnd.fujixerox.docuworks
+application/vnd.fujixerox.docuworks.binder
+application/vnd.fut-misnet
+application/vnd.grafeq
+application/vnd.groove-account
+application/vnd.groove-identity-message
+application/vnd.groove-injector
+application/vnd.groove-tool-message
+application/vnd.groove-tool-template
+application/vnd.groove-vcard
+application/vnd.hp-HPGL plt,hpgl
+application/vnd.hp-hpid
+application/vnd.hp-hps
+application/vnd.hp-PCL
+application/vnd.hp-PCLXL
+application/vnd.httphone
+application/vnd.hzn-3d-crossword
+application/vnd.ibm.MiniPay
+application/vnd.ibm.modcap
+application/vnd.informix-visionary
+application/vnd.intercon.formnet
+application/vnd.intertrust.digibox
+application/vnd.intertrust.nncp
+application/vnd.intu.qbo
+application/vnd.intu.qfx
+application/vnd.is-xpr
+application/vnd.japannet-directory-service
+application/vnd.japannet-jpnstore-wakeup
+application/vnd.japannet-payment-wakeup
+application/vnd.japannet-registration
+application/vnd.japannet-registration-wakeup
+application/vnd.japannet-setstore-wakeup
+application/vnd.japannet-verification
+application/vnd.japannet-verification-wakeup
+application/vnd.koan
+application/vnd.lotus-1-2-3
+application/vnd.lotus-approach
+application/vnd.lotus-freelance
+application/vnd.lotus-notes
+application/vnd.lotus-organizer
+application/vnd.lotus-screencam
+application/vnd.lotus-wordpro
+application/vnd.mcd
+application/vnd.mediastation.cdkey
+application/vnd.meridian-slingshot
+application/vnd.mif mif
+application/vnd.minisoft-hp3000-save
+application/vnd.mitsubishi.misty-guard.trustweb
+application/vnd.mobius.daf
+application/vnd.mobius.dis
+application/vnd.mobius.msl
+application/vnd.mobius.plc
+application/vnd.mobius.txf
+application/vnd.motorola.flexsuite
+application/vnd.motorola.flexsuite.adsi
+application/vnd.motorola.flexsuite.fis
+application/vnd.motorola.flexsuite.gotap
+application/vnd.motorola.flexsuite.kmr
+application/vnd.motorola.flexsuite.ttc
+application/vnd.motorola.flexsuite.wem
+application/vnd.mozilla.xul+xml
+application/vnd.ms-artgalry
+application/vnd.ms-access mda,mdb,mde
+application/vnd.ms-asf
+application/vnd.ms-excel xls
+application/vnd.msign
+application/vnd.ms-lrm
+application/vnd.ms-powerpoint ppt
+application/vnd.ms-project mpp
+application/vnd.ms-tnef
+application/vnd.ms-works
+application/vnd.musician
+application/vnd.music-niff
+application/vnd.netfpx
+application/vnd.noblenet-directory
+application/vnd.noblenet-sealer
+application/vnd.noblenet-web
+application/vnd.novadigm.EDM
+application/vnd.novadigm.EDX
+application/vnd.novadigm.EXT
+application/vnd.osa.netdeploy
+application/vnd.pg.format
+application/vnd.pg.osasli
+application/vnd.powerbuilder6
+application/vnd.powerbuilder6-s
+application/vnd.powerbuilder7
+application/vnd.powerbuilder75
+application/vnd.powerbuilder75-s
+application/vnd.powerbuilder7-s
+application/vnd.previewsystems.box
+application/vnd.publishare-delta-tree
+application/vnd.rapid
+application/vnd.s3sms
+application/vnd.seemail
+application/vnd.shana.informed.formdata
+application/vnd.shana.informed.formtemplate
+application/vnd.shana.informed.interchange
+application/vnd.shana.informed.package
+application/vnd.street-stream
+application/vnd.svd
+application/vnd.swiftview-ics
+application/vnd.triscape.mxs
+application/vnd.trueapp
+application/vnd.truedoc
+application/vnd.ufdl
+application/vnd.uplanet.alert
+application/vnd.uplanet.alert-wbxml
+application/vnd.uplanet.bearer-choice
+application/vnd.uplanet.bearer-choi-wbxml
+application/vnd.uplanet.cacheop
+application/vnd.uplanet.cacheop-wbxml
+application/vnd.uplanet.channel
+application/vnd.uplanet.channel-wbxml
+application/vnd.uplanet.list
+application/vnd.uplanet.listcmd
+application/vnd.uplanet.listcmd-wbxml
+application/vnd.uplanet.list-wbxml
+application/vnd.uplanet.signal
+application/vnd.vcx
+application/vnd.vectorworks
+application/vnd.visio
+application/vnd.wap.sic
+application/vnd.wap.slc
+application/vnd.wap.wbxml wbxml
+application/vnd.wap.wmlc wmlc
+application/vnd.wap.wmlscriptc wmlsc
+application/vnd.webturbo
+application/vnd.wrq-hp3000-labelled
+application/vnd.wt.stf
+application/vnd.xara
+application/vnd.xfdl
+application/vnd.yellowriver-custom-menu
+application/whoispp-query
+application/whoispp-response
+application/wita
+application/wordperfect wp
+application/wordperfect5.1 wp5
+application/wordperfect6.1 wp6
+application/wordperfectd wpd
+application/x-123 wk
+application/x400-bp
+application/x-bcpio bcpio
+application/x-cdlink vcd
+application/x-chess-pgn pgn
+application/x-compress
+application/x-compress z,Z base64
+application/x-cpio cpio base64
+application/x-csh csh 8bit
+application/x-debian-package deb
+application/x-director dcr,dir,dxr
+application/x-dvi dvi base64
+application/x-futuresplash spl
+application/x-gtar gtar,tgz base64
+application/x-gunzip
+application/x-gzip gz base64
+application/x-hdf hdf
+application/x-httpd-php phtml,pht,php 8bit
+application/x-ica ica
+application/x-javascript js 8bit
+application/x-koan skp,skd,skt,skm
+application/x-latex latex 8bit
+application/x-maker frm,maker,frame,fm,fb,book,fbdoc
+application/x-mif mif
+application/xml
+application/x-msdos-program com,bat 8bit
+application/x-msdos-program exe base64
+application/x-msdownload exe base64
+application/x-netcdf nc,cdf
+application/x-ns-proxy-autoconfig pac
+application/x-perl pl,pm 8bit
+application/quicktimeplayer qtl
+application/x-rar-compressed rar base64
+application/x-shar shar 8bit
+application/x-shockwave-flash swf
+application/x-sh sh 8bit
+application/x-spss sav,spp,sbs,sps,spo
+application/x-stuffit sit base64
+application/x-sv4cpio sv4cpio base64
+application/x-sv4crc sv4crc base64
+application/x-tar tar 8bit
+application/x-tcl tcl 8bit
+application/x-texinfo texinfo,texi 8bit
+application/x-tex tex 8bit
+application/x-troff-man man 8bit
+application/x-troff-me me
+application/x-troff-ms ms
+application/x-troff t,tr,roff 8bit
+application/x-ustar ustar base64
+application/x-wais-source src
+application/x-Wingz wz
+application/x-x509-ca-cert crt base64
+application/zip zip base64
+audio/32kadpcm
+audio/amr amr base64
+audio/amr-wb awb base64
+audio/basic au,snd base64
+audio/l16
+audio/midi mid,midi,kar base64
+audio/mpeg mpga,mp2,mp3 base64
+audio/prs.sid
+audio/telephone-event
+audio/tone
+audio/vnd.cns.anp1
+audio/vnd.cns.inf1
+audio/vnd.digital-winds
+audio/vnd.everad.plj
+audio/vnd.lucent.voice
+audio/vnd.nortel.vbk
+audio/vnd.nuera.ecelp4800
+audio/vnd.nuera.ecelp7470
+audio/vnd.octel.sbc
+audio/vnd.qcelp
+audio/vnd.rhetorex.32kadpcm
+audio/vnd.vmx.cvsd
+audio/x-aiff aif,aifc,aiff base64
+audio/x-pn-realaudio-plugin rpm
+audio/x-pn-realaudio rm,ram base64
+audio/x-realaudio ra base64
+audio/x-wav wav base64
+chemical/x-pdb pdb
+chemical/x-xyz xyz
+drawing/dwf dwf
+image/bmp bmp
+image/cgm
+image/g3fax
+image/gif gif base64
+image/ief ief base64
+image/jpeg jpeg,jpg,jpe base64
+image/naplps
+image/png png base64
+image/prs.btif
+image/prs.pti
+image/tiff tiff,tif base64
+image/vnd.cns.inf2
+image/vnd.dgn dgn
+image/vnd.dwg dwg
+image/vnd.dxf
+image/vnd.fastbidsheet
+image/vnd.fpx
+image/vnd.fst
+image/vnd.fujixerox.edmics-mmr
+image/vnd.fujixerox.edmics-rlc
+image/vnd.mix
+image/vnd.net-fpx
+image/vnd.svf
+image/vnd.wap.wbmp wbmp
+image/vnd.xiff
+image/x-cmu-raster ras
+image/x-portable-anymap pnm base64
+image/x-portable-bitmap pbm base64
+image/x-portable-graymap pgm base64
+image/x-portable-pixmap ppm base64
+image/x-rgb rgb base64
+image/x-xbitmap xbm 7bit
+image/x-xpixmap xpm 8bit
+image/x-xwindowdump xwd base64
+message/delivery-status
+message/disposition-notification
+message/external-body 8bit
+message/http
+message/news 8bit
+message/partial 8bit
+message/rfc822 8bit
+message/s-http
+model/iges igs,iges
+model/mesh msh,mesh,silo
+model/vnd.dwf
+model/vnd.flatland.3dml
+model/vnd.gdl
+model/vnd.gs-gdl
+model/vnd.gtw
+model/vnd.mts
+model/vnd.vtu
+model/vrml wrl,vrml
+multipart/alternative 8bit
+multipart/appledouble 8bit
+multipart/byteranges
+multipart/digest 8bit
+multipart/encrypted
+multipart/form-data
+multipart/header-set
+multipart/mixed 8bit
+multipart/parallel 8bit
+multipart/related
+multipart/report
+multipart/signed
+multipart/voice-message
+text/calendar
+text/css css 8bit
+text/comma-separated-values csv 8bit
+text/directory
+text/enriched
+text/html html,htm,htmlx,shtml,htx 8bit
+text/plain asc,txt,c,cc,h,hh,cpp,hpp,dat,hlp 8bit
+text/prs.lines.tag
+text/rfc822-headers
+text/richtext rtx 8bit
+text/rtf rtf
+text/sgml sgml,sgm
+text/t140
+text/tab-separated-values tsv
+text/uri-list
+text/vnd.abc
+text/vnd.curl
+text/vnd.DMClientScript
+text/vnd.flatland.3dml
+text/vnd.fly
+text/vnd.fmi.flexstor
+text/vnd.in3d.3dml
+text/vnd.in3d.spot
+text/vnd.IPTC.NewsML
+text/vnd.IPTC.NITF
+text/vnd.latex-z
+text/vnd.motorola.reflex
+text/vnd.ms-mediapackage
+text/vnd.wap.si
+text/vnd.wap.sl
+text/vnd.wap.wmlscript wmls
+text/vnd.wap.wml wml
+text/xml xml,dtd 8bit
+text/x-setext etx
+text/x-sgml sgml,sgm 8bit
+text/x-vCalendar vcs 8bit
+text/x-vCard vcf 8bit
+video/dl dl base64
+video/fli fli base64
+video/gl gl base64
+video/mpeg mp2,mpe,mpeg,mpg base64
+video/pointer
+video/quicktime qt,mov base64
+video/vnd.fvt
+video/vnd.motorola.video
+video/vnd.motorola.videop
+video/vnd.vivo
+video/x-ms-asf asf,asx
+video/x-msvideo avi base64
+video/x-sgi-movie movie base64
+x-conference/x-cooltalk ice
+x-world/x-vrml wrl,vrml
+
+# Exceptions
+
+vms:text/plain doc 8bit
+mac:application/x-macbase64 bin
diff --git a/cpan/dist/MIME-Types/Makefile.PL b/cpan/dist/MIME-Types/Makefile.PL
new file mode 100644
index 00000000..c69c2873
--- /dev/null
+++ b/cpan/dist/MIME-Types/Makefile.PL
@@ -0,0 +1,12 @@
+use ExtUtils::MakeMaker;
+
+require 5.005;
+
+WriteMakefile
+ ( NAME => 'MIME::Types'
+ , VERSION_FROM => 'MIME/Types.pm'
+ , DIR => [ 'MIME' ]
+ , PREREQ_PM => {}
+ , AUTHOR => 'Mark Overmeer'
+ , ABSTRACT => 'Definition of MIME types'
+ );
diff --git a/cpan/dist/MIME-Types/README b/cpan/dist/MIME-Types/README
new file mode 100644
index 00000000..28a6cd4a
--- /dev/null
+++ b/cpan/dist/MIME-Types/README
@@ -0,0 +1,14 @@
+
+MIME::Types
+===========
+
+A start for a more detailed data-structure to keep knowledge
+about various data types are defined by MIME. Some basic
+treatments with mime types are implemented.
+
+The first special data item is whether a data type is binary
+or ascii. This is required for correctly encoding e-mail
+attachments, and implemented for the Mail::Box v2.01 module.
+
+Improvements and additions please to
+ Mark Overmeer, <mimetypes@overmeer.net>
diff --git a/cpan/dist/MIME-Types/t/10type.t b/cpan/dist/MIME-Types/t/10type.t
new file mode 100755
index 00000000..10b069d7
--- /dev/null
+++ b/cpan/dist/MIME-Types/t/10type.t
@@ -0,0 +1,47 @@
+#!/usr/bin/perl -w
+#
+# Test reporting warnings, errors and family.
+#
+
+use Test;
+use strict;
+
+use lib qw(. t);
+
+BEGIN {plan tests => 25}
+
+use MIME::Type;
+
+my $a = MIME::Type->new(type => 'x-appl/x-zip', extensions => [ 'zip', 'zp' ]);
+ok($a);
+ok($a->type eq 'x-appl/x-zip');
+ok($a->simplified eq 'appl/zip');
+ok($a->simplified('text/plain') eq 'text/plain');
+ok(MIME::Type->simplified('x-xyz/abc') eq 'xyz/abc');
+ok($a->mainType eq 'appl');
+ok($a->subType eq 'zip');
+ok(!$a->isRegistered);
+
+my @ext = $a->extensions;
+ok(@ext==2);
+ok($ext[0] eq 'zip');
+ok($ext[1] eq 'zp');
+ok($a->encoding eq 'base64');
+ok($a->isBinary);
+ok(not $a->isAscii);
+
+my $b = MIME::Type->new(type => 'TEXT/PLAIN', encoding => '8bit');
+ok($b);
+ok($b->type eq 'TEXT/PLAIN');
+ok($b->simplified eq 'text/plain');
+ok($b->mainType eq 'text');
+ok($b->subType eq 'plain');
+@ext = $b->extensions;
+ok(@ext==0);
+ok($b->encoding eq '8bit');
+ok(not $b->isBinary);
+ok($b->isAscii);
+ok($b->isRegistered);
+
+my $c = MIME::Type->new(type => 'applications/x-zip');
+ok(!$c->isRegistered);
diff --git a/cpan/dist/MIME-Types/t/11typeol.t b/cpan/dist/MIME-Types/t/11typeol.t
new file mode 100755
index 00000000..b57bd101
--- /dev/null
+++ b/cpan/dist/MIME-Types/t/11typeol.t
@@ -0,0 +1,44 @@
+#!/usr/bin/perl -w
+#
+# Test overloading on MIME::Type objects.
+#
+
+use Test;
+use strict;
+
+use lib qw(. t);
+
+BEGIN {plan tests => 21}
+
+use MIME::Type;
+
+my $a = MIME::Type->new(type => 'x-appl/x-zip');
+my $b = MIME::Type->new(type => 'appl/x-zip');
+my $c = MIME::Type->new(type => 'x-appl/zip');
+my $d = MIME::Type->new(type => 'appl/zip');
+my $e = MIME::Type->new(type => 'text/plain');
+
+ok($a eq $b);
+ok($a eq $c);
+ok($a eq $d);
+ok($b eq $c);
+ok($b eq $d);
+ok($c eq $d);
+ok($a ne $e);
+
+ok(!$a->isRegistered);
+ok(!$b->isRegistered);
+ok(!$c->isRegistered);
+ok( $d->isRegistered);
+ok( $e->isRegistered);
+
+ok("$a" eq 'x-appl/x-zip');
+ok("$b" eq 'appl/x-zip');
+ok("$c" eq 'x-appl/zip');
+ok("$d" eq 'appl/zip');
+ok("$e" eq 'text/plain');
+
+ok($a eq 'appl/zip');
+ok($b eq 'APPL/ZIP');
+ok($c eq 'x-appl/x-zip');
+ok($e eq 'text/plain');
diff --git a/cpan/dist/MIME-Types/t/20types.t b/cpan/dist/MIME-Types/t/20types.t
new file mode 100755
index 00000000..f469e616
--- /dev/null
+++ b/cpan/dist/MIME-Types/t/20types.t
@@ -0,0 +1,72 @@
+#!/usr/bin/perl -w
+#
+# Test reporting warnings, errors and family.
+#
+
+use Test;
+use strict;
+
+use lib qw(. t);
+
+BEGIN {plan tests => 19}
+
+use MIME::Types;
+
+my $a = MIME::Types->new;
+ok($a);
+
+my @t = $a->type('multipart/mixed');
+ok(@t==1);
+my $t = $t[0];
+ok(ref $t eq 'MIME::Type');
+ok($t->type eq 'multipart/mixed');
+
+@t = $a->type('TEXT/x-RTF');
+ok(@t==1);
+$t = $t[0];
+ok($t->type eq 'text/rtf');
+
+my $m = $a->mimeTypeOf('gif');
+ok($m);
+ok(ref $m eq 'MIME::Type');
+ok($m->type eq 'image/gif');
+
+my $n = $a->mimeTypeOf('GIF');
+ok($n);
+ok($n->type eq 'image/gif');
+
+my $p = $a->mimeTypeOf('my_image.gif');
+ok($p);
+ok($p->type eq 'image/gif');
+
+my $q = $a->mimeTypeOf('windows.doc');
+ok($q->type eq 'application/msword');
+ok($a->mimeTypeOf('my.lzh')->type eq 'application/octet-stream');
+
+my $r1 = MIME::Type->new(type => 'text/fake1');
+my $warn;
+{ $SIG{__WARN__} = sub {$warn = join '',@_};
+ $a->addType($r1);
+}
+ok($warn =~ m/report/);
+
+undef $warn;
+my $r2 = MIME::Type->new(type => 'text/x-fake2');
+{ $SIG{__WARN__} = sub {$warn = join '',@_};
+ $a->addType($r2);
+}
+ok(!defined $warn);
+
+undef $warn;
+my $r3 = MIME::Type->new(type => 'x-appl/x-fake3');
+{ $SIG{__WARN__} = sub {$warn = join '',@_};
+ $a->addType($r3);
+}
+ok(!defined $warn);
+
+undef $warn;
+my $r4 = MIME::Type->new(type => 'x-appl/fake4');
+{ $SIG{__WARN__} = sub {$warn = join '',@_};
+ $a->addType($r4);
+}
+ok(!defined $warn);
diff --git a/cpan/dist/MIME-Types/t/30export.t b/cpan/dist/MIME-Types/t/30export.t
new file mode 100755
index 00000000..861bfa97
--- /dev/null
+++ b/cpan/dist/MIME-Types/t/30export.t
@@ -0,0 +1,86 @@
+#!/usr/bin/perl -w
+#
+# Test exported interface.
+# Tests originally by Jeff Okamato
+#
+
+use Test;
+use strict;
+
+use lib qw(. t);
+
+BEGIN {plan tests => 34}
+
+use MIME::Types;
+
+#
+# These tests assume you want an array returned
+#
+
+my ($mt, $cte) = MIME::Types::by_suffix("Pdf");
+ok($mt eq "application/pdf");
+ok($cte eq "base64");
+
+($mt, $cte) = MIME::Types::by_suffix("foo.Pdf");
+ok($mt eq "application/pdf");
+ok($cte eq "base64");
+
+($mt, $cte) = MIME::Types::by_suffix("flurfl");
+ok($mt eq "");
+ok($cte eq "");
+
+my @c = MIME::Types::by_mediatype("pdF");
+ok(@c == 1);
+ok($c[0]->[0] eq "pdf");
+ok($c[0]->[1] eq "application/pdf");
+ok($c[0]->[2] eq "base64");
+
+@c = MIME::Types::by_mediatype("Application/pDF");
+ok(@c == 1);
+ok($c[0]->[0] eq "pdf");
+ok($c[0]->[1] eq "application/pdf");
+ok($c[0]->[2] eq "base64");
+
+@c = MIME::Types::by_mediatype("e");
+ok(@c > 1);
+
+@c = MIME::Types::by_mediatype("xyzzy");
+ok(@c == 0);
+
+#
+# These tests assume you want an array reference returned
+#
+
+my $aref = MIME::Types::by_suffix("Pdf");
+ok($aref->[0] eq "application/pdf");
+ok($aref->[1] eq "base64");
+
+$aref = MIME::Types::by_suffix("foo.Pdf");
+ok($aref->[0] eq "application/pdf");
+ok($aref->[1] eq "base64");
+
+$aref = MIME::Types::by_suffix("flurfl");
+ok($aref->[0] eq "");
+ok($aref->[1] eq "");
+
+$aref = MIME::Types::by_mediatype("pdF");
+ok(@$aref == 1);
+ok($aref->[0]->[0] eq "pdf");
+ok($aref->[0]->[1] eq "application/pdf");
+ok($aref->[0]->[2] eq "base64");
+
+$aref = MIME::Types::by_mediatype("Application/pDF");
+ok(@$aref == 1);
+ok($aref->[0]->[0] eq "pdf");
+ok($aref->[0]->[1] eq "application/pdf");
+ok($aref->[0]->[2] eq "base64");
+
+$aref = MIME::Types::by_mediatype("e");
+ok(@$aref > 1);
+
+$aref = MIME::Types::by_mediatype("xyzzy");
+ok(@$aref == 0);
+
+$aref = MIME::Types::by_suffix("foo.tsv");
+ok($aref->[0] eq "text/tab-separated-values");
+ok($aref->[1] eq "quoted-printable");
diff --git a/cpan/lib/File/MMagic.pm b/cpan/lib/File/MMagic.pm
new file mode 100644
index 00000000..5affeaf9
--- /dev/null
+++ b/cpan/lib/File/MMagic.pm
@@ -0,0 +1,1825 @@
+# File::MMagic
+#
+# $Id: MMagic.pm,v 1.54 2002/09/12 05:04:06 knok Exp $
+#
+# This program is originated from file.kulp that is a production of The
+# Unix Reconstruction Projct.
+# <http://language.perl.com/ppt/index.html>
+# Copyright 1999,2000,2001,2002 NOKUBI Takatsugu <knok@daionet.gr.jp>.
+#
+# This product includes software developed by the Apache Group
+# for use in the Apache HTTP server project (http://www.apache.org/).
+#
+# License for the program is followed the original software. The license is
+# below.
+#
+# This program is copyright by dkulp 1999.
+#
+# This program is free and open software. You may use, copy, modify, distribute
+# and sell this program (and any modified variants) in any way you wish,
+# provided you do not restrict others to do the same, except for the following
+# consideration.
+#
+#I read some of Ian F. Darwin's BSD C implementation, to
+#try to determine how some of this was done since the specification
+#is a little vague. I don't believe that this perl version could
+#be construed as an "altered version", but I did grab the tokens for
+#identifying the hard-coded file types in names.h and copied some of
+#the man page.
+#
+#Here's his notice:
+#
+# * Copyright (c) Ian F. Darwin, 1987.
+# * Written by Ian F. Darwin.
+# *
+# * This software is not subject to any license of the American Telephone
+# * and Telegraph Company or of the Regents of the University of California.
+# *
+# * Permission is granted to anyone to use this software for any purpose on
+# * any computer system, and to alter it and redistribute it freely, subject
+# * to the following restrictions:
+# *
+# * 1. The author is not responsible for the consequences of use of this
+# * software, no matter how awful, even if they arise from flaws in it.
+# *
+# * 2. The origin of this software must not be misrepresented, either by
+# * explicit claim or by omission. Since few users ever read sources,
+# * credits must appear in the documentation.
+# *
+# * 3. Altered versions must be plainly marked as such, and must not be
+# * misrepresented as being the original software. Since few users
+# * ever read sources, credits must appear in the documentation.
+# *
+# * 4. This notice may not be removed or altered.
+#
+# The following is the Apache License. This program contains the magic file
+# that derived from the Apache HTTP Server.
+#
+# * Copyright (c) 1995-1999 The Apache Group. All rights reserved.
+# *
+# * Redistribution and use in source and binary forms, with or without
+# * modification, are permitted provided that the following conditions
+# * are met:
+# *
+# * 1. Redistributions of source code must retain the above copyright
+# * notice, this list of conditions and the following disclaimer.
+# *
+# * 2. Redistributions in binary form must reproduce the above copyright
+# * notice, this list of conditions and the following disclaimer in
+# * the documentation and/or other materials provided with the
+# * distribution.
+# *
+# * 3. All advertising materials mentioning features or use of this
+# * software must display the following acknowledgment:
+# * "This product includes software developed by the Apache Group
+# * for use in the Apache HTTP server project (http://www.apache.org/)."
+# *
+# * 4. The names "Apache Server" and "Apache Group" must not be used to
+# * endorse or promote products derived from this software without
+# * prior written permission. For written permission, please contact
+# * apache@apache.org.
+# *
+# * 5. Products derived from this software may not be called "Apache"
+# * nor may "Apache" appear in their names without prior written
+# * permission of the Apache Group.
+# *
+# * 6. Redistributions of any form whatsoever must retain the following
+# * acknowledgment:
+# * "This product includes software developed by the Apache Group
+# * for use in the Apache HTTP server project (http://www.apache.org/)."
+# *
+# * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
+# * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE GROUP OR
+# * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+# * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+# * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+# * OF THE POSSIBILITY OF SUCH DAMAGE.
+
+package File::MMagic;
+
+=head1 NAME
+
+File::MMagic - Guess file type
+
+=head1 SYNOPSIS
+
+ use File::MMagic;
+ use FileHandle;
+
+ $mm = new File::MMagic; # use internal magic file
+ # $mm = File::MMagic::new('/etc/magic'); # use external magic file
+ # $mm = File::MMagic::new('/usr/share/etc/magic'); # if you use Debian
+ $res = $mm->checktype_filename("/somewhere/unknown/file");
+
+ $fh = new FileHandle "< /somewhere/unknown/file2";
+ $res = $mm->checktype_filehandle($fh);
+
+ $fh->read($data, 0x8564);
+ $res = $mm->checktype_contents($data);
+
+=head1 ABSTRACT
+
+This perl library uses perl5 objects to guess file type from filename
+and/or filehandle.
+
+=head1 DESCRIPTION
+
+checktype_filename(), checktype_filehandle() and checktype_contents
+returns string contains file type with MIME mediatype format.
+
+=head1 METHODS
+
+=over 4
+
+=item File::MMagic->new()
+
+=item File::MMagic->new( $filename )
+
+Initializes the module. If no filename is given, the magic numbers
+stored in File::MMagic are used.
+
+=item $mm->addSpecials
+
+If a filetype cannot be determined by magic numbers, extra checks are
+done based on extra regular expressions which can be defined here. The
+first argument should be the filetype, the remaining arguments should
+be one or more regular expressions.
+
+By default, checks are done for message/news, message/rfc822,
+text/html, text/x-roff.
+
+=item $mm->removeSpecials
+
+Removes special regular expressions. Specify one or more filetypes. If
+no filetypes are specified, all special regexps are removed.
+
+Returns a hash containing the removed entries.
+
+=item $mm->addFileExts
+
+If a filetype cannot be determined by magic numbers, extra checks can
+be done based on the file extension (actually, a regexp). Two
+arguments should be geiven: the filename pattern and the corresponding
+filetype.
+
+By default, checks are done for application/x-compress,
+application/x-bzip2, application/x-gzip, text/html, text/plain
+
+=item $mm->removeFileExts
+
+Removes filename pattern checks. Specify one or more patterns. If no
+pattern is specified, all are removed.
+
+Returns a hash containing the removed entries.
+
+=item $mm->addMagicEntry
+
+=item $mm->readMagicHandle
+
+=item $mm->checktype_filename
+
+=item $mm->checktype_magic
+
+=item $mm->checktype_contents
+
+=head1 COPYRIGHT
+
+This program is originated from file.kulp that is a production of The
+Unix Reconstruction Projct.
+ <http://language.perl.com/ppt/index.html>
+Copyright (c) 1999 NOKUBI Takatsugu <knok@daionet.gr.jp>.
+
+There is no warranty for the program.
+
+This product includes software developed by the Apache Group
+for use in the Apache HTTP server project (http://www.apache.org/).
+
+License for the program is followed the original software. The license is
+below.
+
+This program is free and open software. You may use, copy, modify, distribute
+and sell this program (and any modified variants) in any way you wish,
+provided you do not restrict others to do the same, except for the following
+consideration.
+
+I read some of Ian F. Darwin's BSD C implementation, to
+try to determine how some of this was done since the specification
+is a little vague. I don't believe that this perl version could
+be construed as an "altered version", but I did grab the tokens for
+identifying the hard-coded file types in names.h and copied some of
+the man page.
+
+Here's his notice:
+
+ * Copyright (c) Ian F. Darwin, 1987.
+ * Written by Ian F. Darwin.
+ *
+ * This software is not subject to any license of the American Telephone
+ * and Telegraph Company or of the Regents of the University of California.
+ *
+ * Permission is granted to anyone to use this software for any purpose on
+ * any computer system, and to alter it and redistribute it freely, subject
+ * to the following restrictions:
+ *
+ * 1. The author is not responsible for the consequences of use of this
+ * software, no matter how awful, even if they arise from flaws in it.
+ *
+ * 2. The origin of this software must not be misrepresented, either by
+ * explicit claim or by omission. Since few users ever read sources,
+ * credits must appear in the documentation.
+ *
+ * 3. Altered versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software. Since few users
+ * ever read sources, credits must appear in the documentation.
+ *
+ * 4. This notice may not be removed or altered.
+
+The following is the Apache License. This program contains the magic file
+that derived from the Apache HTTP Server.
+
+ * Copyright (c) 1995-1999 The Apache Group. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. All advertising materials mentioning features or use of this
+ * software must display the following acknowledgment:
+ * "This product includes software developed by the Apache Group
+ * for use in the Apache HTTP server project (http://www.apache.org/)."
+ *
+ * 4. The names "Apache Server" and "Apache Group" must not be used to
+ * endorse or promote products derived from this software without
+ * prior written permission. For written permission, please contact
+ * apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ * nor may "Apache" appear in their names without prior written
+ * permission of the Apache Group.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ * acknowledgment:
+ * "This product includes software developed by the Apache Group
+ * for use in the Apache HTTP server project (http://www.apache.org/)."
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
+ * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE GROUP OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+
+=cut
+
+use FileHandle;
+use strict;
+
+use vars qw(
+%TEMPLATES %ESC $VERSION
+$magicFile $checkMagic $followLinks $fileList
+$dataLoc $allowEightbit
+);
+
+BEGIN {
+# translation of type in magic file to unpack template and byte count
+%TEMPLATES = (byte => [ 'c', 1 ],
+ ubyte => [ 'C', 1 ],
+ char => [ 'c', 1 ],
+ uchar => [ 'C', 1 ],
+ short => [ 's', 2 ],
+ ushort => [ 'S', 2 ],
+ long => [ 'l', 4 ],
+ ulong => [ 'L', 4 ],
+ date => [ 'l', 4 ],
+ ubeshort => [ 'n', 2 ],
+ beshort => [ [ 'n', 'S', 's' ], 2 ],
+ ubelong => [ 'N', 4 ],
+ belong => [ [ 'N', 'I', 'i' ], 4 ],
+ bedate => [ 'N', 4 ],
+ uleshort => [ 'v', 2 ],
+ leshort => [ [ 'v', 'S', 's' ], 2 ],
+ ulelong => [ 'V', 4 ],
+ lelong => [ [ 'V', 'I', 'i' ], 4 ],
+ ledate => [ 'V', 4 ],
+ string => undef);
+
+# for letter escapes in magic file
+%ESC = ( n => "\n",
+ r => "\r",
+ b => "\b",
+ t => "\t",
+ f => "\f");
+
+$VERSION = "1.16";
+$allowEightbit = 1;
+undef $dataLoc;
+}
+
+sub new {
+ my $self = {};
+ my $proto = shift;
+ my $class = ref($proto) || $proto;
+ $self->{MF} = [];
+ $self->{magic} = [];
+ if (! @_) {
+ my $fh = *File::MMagic::DATA{IO};
+ binmode($fh);
+ bless $fh, 'FileHandle' if ref $fh ne 'FileHandle';
+ $dataLoc = $fh->tell() if (! defined $dataLoc);
+ $fh->seek($dataLoc, 0);
+ &readMagicHandle($self, $fh);
+ } else {
+ my $filename = shift;
+ my $fh = new FileHandle;
+ if ($fh->open("< $filename")) {
+ binmode($fh);
+ &readMagicHandle($self, $fh);
+ } else {
+ warn __PACKAGE__ . " couldn't load specified file $filename";
+ }
+ }
+
+# from the BSD names.h, some tokens for hard-coded checks of
+# different texts. This isn't rocket science. It's prone to
+# failure so these checks are only a last resort.
+
+# removSpecials() can be used to remove those afterwards.
+ $self->{SPECIALS} = {
+ "message/rfc822" => [ "^Received:",
+ "^>From ",
+ "^From ",
+ "^To: ",
+ "^Return-Path: ",
+ "^Cc: ",
+ "^X-Mailer: "],
+ "message/news" => [ "^Newsgroups: ",
+ "^Path: ",
+ "^X-Newsreader: "],
+ "text/html" => [ "<html[^>]*>",
+ "<HTML[^>]*>",
+ "<head[^>]*>",
+ "<HEAD[^>]*>",
+ "<body[^>]*>",
+ "<BODY[^>]*>",
+ "<title[^>]*>",
+ "<TITLE[^>]*>",
+ "<h1[^>]*>",
+ "<H1[^>]*>",
+ ],
+ "text/x-roff" => [
+ '^\\.\\\\"',
+ "^\\.SH",
+ "^\\.PP",
+ "^\\.TH",
+ "^\\.BR",
+ "^\\.SS",
+ "^\\.TP",
+ "^\\.IR",
+ ],
+ };
+
+ $self->{FILEEXTS} = {
+ '\.gz$' => 'application/x-gzip',
+ '\.bz2$' => 'application/x-bzip2',
+ '\.Z$' => 'application/x-compress',
+ '\.txt$' => 'text/plain',
+ '\.html$' => 'text/html',
+ '\.htm$' => 'text/html',
+ };
+ bless($self);
+ return $self;
+}
+
+sub addSpecials {
+ my $self = shift;
+ my $mtype = shift;
+ $self->{SPECIALS}->{"$mtype"} = [@_];
+ return $self;
+}
+
+sub removeSpecials {
+ my $self = shift;
+ # Remove all keys if no arguments given
+ my @mtypes = (@_ or keys %{$self->{SPECIALS}});
+ my %returnmtypes;
+ foreach my $mtype (@mtypes) {
+ $returnmtypes{"$mtype"} = delete $self->{SPECIALS}->{"$mtype"};
+ }
+ return %returnmtypes;
+}
+
+sub addFileExts {
+ my $self = shift;
+ my $filepat = shift;
+ my $mtype = shift;
+ $self->{FILEEXTS}->{"$filepat"} = $mtype;
+ return $self;
+}
+
+sub removeFileExts {
+ my $self = shift;
+ # Remove all keys if no arguments given
+ my @filepats = (@_ or keys %{$self->{FILEEXTS}});
+ my %returnfilepats;
+ foreach my $filepat (@filepats) {
+ $returnfilepats{"$filepat"} = delete $self->{FILEEXTS}->{"$filepat"};
+ }
+ return %returnfilepats;
+}
+
+sub addMagicEntry {
+ my $self = shift;
+ my $entry = shift;
+ unshift @{$self->{magic}}, [$entry, -1, []];
+ return $self;
+}
+
+sub readMagicHandle {
+ my $self = shift;
+ my $fh = shift;
+ $self->{MF}->[0] = $fh;
+ $self->{MF}->[1] = undef;
+ $self->{MF}->[2] = 0;
+ readMagicEntry($self->{magic}, $self->{MF});
+}
+
+# Not implimented.
+#
+#sub readMagicFile {
+# my $self = shift;
+# my $mfile = shift;
+#}
+
+sub checktype_filename {
+ my $self = shift;
+
+# iterate over each file explicitly so we can seek
+ my $file = shift;
+
+ # the description line. append info to this string
+ my $desc;
+ my $mtype;
+
+ # 0) check permission
+ if (! -r $file) {
+ $desc .= " can't read `$file': Permission denied.";
+ return "x-system/x-error; $desc";
+ }
+
+ # 1) check for various special files first
+ if ($^O eq 'MSWin32') {
+ stat($file);
+ } else {
+ if ($followLinks) { stat($file); } else { lstat($file); }
+ }
+ if (! -f _ or -z _) {
+ if ( $^O ne 'MSWin32' && !$followLinks && -l _ ) {
+ $desc .= " symbolic link to ".readlink($file);
+ }
+ elsif ( -d _ ) { $desc .= " directory"; }
+ elsif ( -p _ ) { $desc .= " named pipe"; }
+ elsif ( -S _ ) { $desc .= " socket"; }
+ elsif ( -b _ ) { $desc .= " block special file"; }
+ elsif ( -c _ ) { $desc .= " character special file"; }
+ elsif ( -z _ ) { $desc .= " empty"; }
+ else { $desc .= " special"; }
+
+ return "x-system/x-unix; $desc";
+ }
+
+ # current file handle. or undef if checkMagic (-c option) is true.
+ my $fh;
+
+# $fh = new FileHandle "< $file" or die "$F: $file: $!\n" ;
+ $fh = new FileHandle "< $file" or return "x-system/x-error; $file: $!\n" ;
+
+ binmode($fh); # for MSWin32
+
+ # 2) check for script
+ if (-x $file && -T _) {
+
+ # Note, some magic files include elaborate attempts
+ # to match #! header lines and return pretty responses
+ # but this slows down matching and is unnecessary.
+ my $line1 = <$fh>;
+ if ($line1 =~ /^\#!\s*(\S+)/) {
+ $desc .= " executable $1 script text";
+ }
+ else { $desc .= " commands text"; }
+
+ $fh->close();
+
+ return "x-system/x-unix; $desc";
+
+ }
+
+ my $out = checktype_filehandle($self, $fh, $desc);
+ undef $fh;
+
+ return $out;
+}
+
+sub checktype_filehandle {
+ my $self = shift;
+ my ($fh, $desc) = @_;
+ my $mtype;
+
+ binmode($fh); # for MSWin32 architecture.
+
+ # 3) iterate over each magic entry.
+ my $matchFound = 0;
+ my $m;
+ for ($m = 0; $m <= $#{$self->{magic}}; $m++) {
+
+ # check if the m-th magic entry matches
+ # if it does, then $desc will contain an updated description
+ if (magicMatch($self->{magic}->[$m],\$desc,$fh)) {
+ if (defined $desc && $desc ne '') {
+ $matchFound = 1;
+ $mtype = $desc;
+ last;
+ }
+ }
+
+ # read another entry from the magic file if we've exhausted
+ # all the entries already buffered. readMagicEntry will
+ # add to the end of the array if there are more.
+ if ($m == $#{$self->{magic}} && !$self->{MF}->[0]->eof()) {
+ readMagicEntry($self->{magic}, $self->{MF});
+ }
+ }
+
+ # 4) check if it's text or binary.
+ # if it's text, then do a bunch of searching for special tokens
+ if (!$matchFound) {
+ my $data;
+ $fh->seek(0,0);
+ $fh->read($data, 0x8564);
+ $mtype = checktype_data($self, $data);
+ }
+
+ $mtype = 'text/plain' if (! defined $mtype);
+
+ return $mtype;
+}
+
+sub checktype_contents {
+ my $self = shift;
+ my $data = shift;
+ my $mtype;
+
+ return 'application/octet-stream' if (length($data) <= 0);
+
+ $mtype = checktype_magic($self, $data);
+
+ # 4) check if it's text or binary.
+ # if it's text, then do a bunch of searching for special tokens
+ if (!defined $mtype) {
+ $mtype = checktype_data($self, $data);
+ }
+
+ $mtype = 'text/plain' if (! defined $mtype);
+
+ return $mtype;
+}
+
+sub checktype_magic {
+ my $self = shift;
+ my $data = shift;
+ my $desc;
+ my $mtype;
+
+ return 'application/octet-stream' if (length($data) <= 0);
+
+ # 3) iterate over each magic entry.
+ my $m;
+ for ($m = 0; $m <= $#{$self->{magic}}; $m++) {
+
+ # check if the m-th magic entry matches
+ # if it does, then $desc will contain an updated description
+ if (magicMatchStr($self->{magic}->[$m],\$desc,$data)) {
+ if (defined $desc && $desc ne '') {
+ $mtype = $desc;
+ last;
+ }
+ }
+
+ # read another entry from the magic file if we've exhausted
+ # all the entries already buffered. readMagicEntry will
+ # add to the end of the array if there are more.
+ if ($m == $#{$self->{magic}} && !$self->{MF}->[0]->eof()) {
+ readMagicEntry($self->{magic}, $self->{MF});
+ }
+ }
+
+ return $mtype;
+}
+
+sub checktype_data {
+ my $self = shift;
+ my $data = shift;
+ my $mtype;
+
+ return undef if (length($data) <= 0);
+
+ # truncate data
+ $data = substr($data, 0, 0x8564);
+
+ # at first, check SPECIALS
+ {
+ # in BSD's version, there's an effort to search from
+ # more specific to less, but I don't do that.
+ my ($token, %val);
+ foreach my $type (keys %{$self->{SPECIALS}}) {
+ my $token = '(' .
+ (join '|', sort {length($a) <=> length($b)} @{$self->{SPECIALS}->{$type}})
+ . ')';
+ my $tdata = $data;
+ if ($tdata =~ /$token/mg) {
+ $val{$type} = pos($tdata);
+ }
+ }
+
+ # search latest match
+ if (%val) {
+ my @skeys = sort { $val{$a} <=> $val{$b} } keys %val;
+ $mtype = $skeys[0];
+ }
+
+ ALLDONE:
+# $mtype = 'text/plain' if (! defined $mtype);
+ }
+ if (! defined $mtype && check_binary($data)) {
+ $mtype = "application/octet-stream";
+ }
+
+# $mtype = 'text/plain' if (! defined $mtype);
+ return $mtype;
+}
+
+sub checktype_byfilename {
+ my $self = shift;
+ my $fname = shift;
+ my $type;
+
+ $fname =~ s/^.*\///;
+ for my $regex (keys %{$self->{FILEEXTS}}) {
+ if ($fname =~ /$regex/i) {
+ if ((defined $type && $type !~ /;/) || (! defined $type)) {
+ $type = $self->{FILEEXTS}->{$regex}; # has no x-type param
+ }
+ }
+ }
+ $type = 'application/octet-stream' unless defined $type;
+ return $type;
+}
+
+sub check_binary {
+ my ($data) = @_;
+ my $len = length($data);
+ if ($allowEightbit) {
+ my $count = ($data =~ tr/[\x00-\x08\x0b-\x0c\x0e-\x1a\x1c-\x1f]//); # exclude TAB, ESC, nl, cr
+ return 1 if ($len <= 0); # no contents
+ return 1 if (($count/$len) > 0.1); # binary
+ } else {
+ my $count = ($data =~ tr/[\x00-\x08\x0b-\x0c\x0e-\x1a\x1c-\x1f\x80-\xff]//); # exclude TAB, ESC, nl, cr
+ return 1 if ($len <= 0); # no contents
+ return 1 if (($count/$len) > 0.3); # binary
+ }
+ return 0;
+}
+
+sub check_magic {
+ my $self = shift @_;
+ # read the whole file if we haven't already
+ while (!$self->{MF}->[0]->eof()) {
+ readMagicEntry($self->{magic}, $self->{MF});
+ }
+ dumpMagic($self->{magic});
+}
+
+####### SUBROUTINES ###########
+
+# compare the magic item with the filehandle.
+# if success, print info and return true. otherwise return undef.
+#
+# this is called recursively if an item has subitems.
+sub magicMatch {
+ my ($item, $p_desc, $fh) = @_;
+
+ # delayed evaluation. if this is our first time considering
+ # this item, then parse out its structure. @$item is just the
+ # raw string, line number, and subtests until we need the real info.
+ # this saves time otherwise wasted parsing unused subtests.
+ $item = readMagicLine(@$item) if @$item == 3;
+
+ # $item could be undef if we ran into troubles while reading
+ # the entry.
+ return unless defined($item);
+
+ # $fh is not be defined if -c. that way we always return
+ # false for every item which allows reading/checking the entire
+ # magic file.
+ return unless defined($fh);
+
+ my ($offtype, $offset, $numbytes, $type, $mask, $op, $testval,
+ $template, $message, $subtests) = @$item;
+
+ # bytes from file
+ my $data;
+
+ # set to true if match
+ my $match = 0;
+
+ # offset = [ off1, sz, template, off2 ] for indirect offset
+ if ($offtype == 1) {
+ my ($off1, $sz, $template, $off2) = @$offset;
+ $fh->seek($off1,0) or return;
+ if ($fh->read($data,$sz) != $sz) { return };
+ $off2 += unpack($template,$data);
+ $fh->seek($off2,0) or return;
+ }
+ elsif ($offtype == 2) {
+ # relative offsets from previous seek
+ $fh->seek($offset,1) or return;
+ }
+ else {
+ # absolute offset
+ $fh->seek($offset,0) or return;
+ }
+
+ if ($type eq 'string') {
+ # read the length of the match string unless the
+ # comparison is '>' ($numbytes == 0), in which case
+ # read to the next null or "\n". (that's what BSD's file does)
+ if ($numbytes > 0) {
+ if ($fh->read($data,$numbytes) != $numbytes) { return; }
+ }
+ else {
+ my $ch = $fh->getc();
+ while (defined($ch) && $ch ne "\0" && $ch ne "\n") {
+ $data .= $ch;
+ $ch = $fh->getc();
+ }
+ }
+
+ # now do the comparison
+ if ($op eq '=') {
+ $match = ($data eq $testval);
+ }
+ elsif ($op eq '<') {
+ $match = ($data lt $testval);
+ }
+ elsif ($op eq '>') {
+ $match = ($data gt $testval);
+ }
+ # else bogus op, but don't die, just skip
+
+ if ($checkMagic) {
+ print STDERR "STRING: $data $op $testval => $match\n";
+ }
+
+ }
+ else {
+ #numeric
+
+ # read up to 4 bytes
+ if ($fh->read($data,$numbytes) != $numbytes) { return; }
+
+ # If template is a ref to an array of 3 letters,
+ # then this is an endian
+ # number which must be first unpacked into an unsigned and then
+ # coerced into a signed. Is there a better way?
+ if (ref($template)) {
+ $data = unpack($$template[2],
+ pack($$template[1],
+ unpack($$template[0],$data)));
+ }
+ else {
+ $data = unpack($template,$data);
+ }
+
+ # if mask
+ if (defined($mask)) {
+ $data &= $mask;
+ }
+
+ # Now do the check
+ if ($op eq '=') {
+ $match = ($data == $testval);
+ }
+ elsif ($op eq 'x') {
+ $match = 1;
+ }
+ elsif ($op eq '!') {
+ $match = ($data != $testval);
+ }
+ elsif ($op eq '&') {
+ $match = (($data & $testval) == $testval);
+ }
+ elsif ($op eq '^') {
+ $match = ((~$data & $testval) == $testval);
+ }
+ elsif ($op eq '<') {
+ $match = ($data < $testval);
+ }
+ elsif ($op eq '>') {
+ $match = ($data > $testval);
+ }
+ # else bogus entry that we're ignoring
+
+ if ($checkMagic) {
+ print STDERR "NUMERIC: $data $op $testval => $match\n";
+ }
+
+ }
+
+ if ($match) {
+ # it's pretty common to find "\b" in the message, but
+ # sprintf doesn't insert a backspace. if it's at the
+ # beginning (typical) then don't include separator space.
+ if ($message =~ s/^\\b//) {
+ $$p_desc .= sprintf($message,$data);
+ }
+ else {
+# $$p_desc .= ' ' . sprintf($message,$data) if $message;
+ $$p_desc .= sprintf($message,$data) if $message;
+ }
+
+ my $subtest;
+ foreach $subtest (@$subtests) {
+ magicMatch($subtest,$p_desc,$fh);
+ }
+
+ return 1;
+ }
+
+}
+
+sub magicMatchStr {
+ my ($item, $p_desc, $str) = @_;
+ my $origstr = $str;
+
+ # delayed evaluation. if this is our first time considering
+ # this item, then parse out its structure. @$item is just the
+ # raw string, line number, and subtests until we need the real info.
+ # this saves time otherwise wasted parsing unused subtests.
+ $item = readMagicLine(@$item) if @$item == 3;
+
+ # $item could be undef if we ran into troubles while reading
+ # the entry.
+ return unless defined($item);
+
+ # $fh is not be defined if -c. that way we always return
+ # false for every item which allows reading/checking the entire
+ # magic file.
+ return unless defined($str);
+ return if ($str eq '');
+
+ my ($offtype, $offset, $numbytes, $type, $mask, $op, $testval,
+ $template, $message, $subtests) = @$item;
+ return unless defined $op;
+
+ # bytes from file
+ my $data;
+
+ # set to true if match
+ my $match = 0;
+
+ # offset = [ off1, sz, template, off2 ] for indirect offset
+ if ($offtype == 1) {
+ my ($off1, $sz, $template, $off2) = @$offset;
+ return if (length($str) < $off1);
+ $data = pack("a$sz", $str);
+ $off2 += unpack($template,$data);
+ return if (length($str) < $off2);
+ }
+ elsif ($offtype == 2) {
+ # can't handle relative offsets from previous seek
+ return;
+ }
+ else {
+ # absolute offset
+ return if ($offset > length($str));
+ $str = substr($str, $offset);
+ }
+
+ if ($type eq 'string') {
+ # read the length of the match string unless the
+ # comparison is '>' ($numbytes == 0), in which case
+ # read to the next null or "\n". (that's what BSD's file does)
+ if ($numbytes > 0) {
+ $data = pack("a$numbytes", $str);
+ }
+ else {
+ $str =~ /^(.*)\0|$/;
+ $data = $1;
+ }
+
+ # now do the comparison
+ if ($op eq '=') {
+ $match = ($data eq $testval);
+ }
+ elsif ($op eq '<') {
+ $match = ($data lt $testval);
+ }
+ elsif ($op eq '>') {
+ $match = ($data gt $testval);
+ }
+ # else bogus op, but don't die, just skip
+
+ if ($checkMagic) {
+ print STDERR "STRING: $data $op $testval => $match\n";
+ }
+
+ }
+ else {
+ #numeric
+
+ # read up to 4 bytes
+ $data = substr($str, 0, 4);
+
+ # If template is a ref to an array of 3 letters,
+ # then this is an endian
+ # number which must be first unpacked into an unsigned and then
+ # coerced into a signed. Is there a better way?
+ if (ref($template)) {
+ $data = unpack($$template[2],
+ pack($$template[1],
+ unpack($$template[0],$data)));
+ }
+ else {
+ $data = unpack($template,$data);
+ }
+
+ # if mask
+ if (defined($mask)) {
+ $data &= $mask;
+ }
+
+ # Now do the check
+ if ($op eq '=') {
+ $match = ($data == $testval);
+ }
+ elsif ($op eq 'x') {
+ $match = 1;
+ }
+ elsif ($op eq '!') {
+ $match = ($data != $testval);
+ }
+ elsif ($op eq '&') {
+ $match = (($data & $testval) == $testval);
+ }
+ elsif ($op eq '^') {
+ $match = ((~$data & $testval) == $testval);
+ }
+ elsif ($op eq '<') {
+ $match = ($data < $testval);
+ }
+ elsif ($op eq '>') {
+ $match = ($data > $testval);
+ }
+ # else bogus entry that we're ignoring
+
+ if ($checkMagic) {
+ print STDERR "NUMERIC: $data $op $testval => $match\n";
+ }
+
+ }
+
+ if ($match) {
+ # it's pretty common to find "\b" in the message, but
+ # sprintf doesn't insert a backspace. if it's at the
+ # beginning (typical) then don't include separator space.
+ if ($message =~ s/^\\b//) {
+ $$p_desc .= sprintf($message,$data);
+ }
+ else {
+# $$p_desc .= ' ' . sprintf($message,$data) if $message;
+ $$p_desc .= sprintf($message,$data) if $message;
+ }
+
+ my $subtest;
+ foreach $subtest (@$subtests) {
+ # finish evaluation when matched.
+ magicMatchStr($subtest,$p_desc,$origstr);
+ }
+
+ return 1;
+ }
+
+}
+
+# readMagicEntry($pa_magic, $MF, $depth)
+#
+# reads the next entry from the magic file and stores it as
+# a ref to an array at the end of @$pa_magic.
+#
+# $MF = [ filehandle, last buffered line, line count ]
+#
+# This is called recursively with increasing $depth to read in sub-clauses
+#
+# returns the depth of the current buffered line.
+#
+sub readMagicEntry {
+ my ($pa_magic, $MF, $depth) = @_;
+
+ # for some reason I need a local var because <$$MF[0]> doesn't work.(?)
+ my $magicFH = $$MF[0];
+
+ # a ref to an array containing a magic line's components
+ my ($entry, $line);
+
+ $line = $$MF[1]; # buffered last line
+ while (1) {
+ $line = '' if (! defined $line);
+ if ($line =~ /^\#/ || $line =~ /^\s*$/) {
+ last if $magicFH->eof();
+ $line = <$magicFH>;
+ $$MF[2]++;
+ next;
+ }
+
+ my ($thisDepth) = ($line =~ /^(>+)/);
+ $thisDepth = '' if (! defined $thisDepth);
+ $depth = 0 if (! defined $depth);
+
+ if (length($thisDepth) > $depth) {
+ $$MF[1] = $line;
+
+ # call ourselves recursively. will return the depth
+ # of the entry following the nested group.
+ if ((readMagicEntry($entry->[2], $MF, $depth+1) || 0) < $depth ||
+ $$MF[0]->eof())
+ {
+ return;
+ }
+ $line = $$MF[1];
+ }
+ elsif (length($thisDepth) < $depth) {
+ $$MF[1] = $line;
+ return length($thisDepth);
+ }
+ elsif (defined(@$entry)) {
+ # already have an entry. this is not a continuation.
+ # save this line for the next call and exit.
+ $$MF[1] = $line;
+ return length($thisDepth);
+ }
+ else {
+ # we're here if the number of '>' is the same as the
+ # current depth and we haven't read a magic line yet.
+
+ # create temp entry
+ # later -- if we ever get around to evaluating this condition --
+ # we'll replace @$entry with the results from readMagicLine.
+ $entry = [ $line , $$MF[2], [] ];
+
+ # add to list
+ push(@$pa_magic,$entry);
+
+ # read the next line
+ last if $magicFH->eof();
+ $line = <$magicFH>;
+ $$MF[2]++;
+ }
+ }
+}
+
+# readMagicLine($line, $line_num, $subtests)
+#
+# parses the match info out of $line. Returns a reference to an array.
+#
+# Format is:
+#
+# [ offset, bytes, type, mask, operator, testval, template, sprintf, subtests ]
+# 0 1 2 3 4 5 6 7 8
+#
+# subtests is an array like @$pa_magic.
+#
+sub readMagicLine {
+ my ($line, $line_num, $subtests) = @_;
+
+ my ($offtype, $offset, $numbytes, $type, $mask,
+ $operator, $testval, $template, $message);
+
+ # this would be easier if escaped whitespace wasn't allowed.
+
+ # grab the offset and type. offset can either be a decimal, oct,
+ # or hex offset or an indirect offset specified in parenthesis
+ # like (x[.[bsl]][+-][y]), or a relative offset specified by &.
+ # offtype : 0 = absolute, 1 = indirect, 2 = relative
+ if ($line =~ s/^>*([&\(]?[a-flsx\.\+\-\d]+\)?)\s+(\S+)\s+//) {
+ ($offset,$type) = ($1,$2);
+
+ if ($offset =~ /^\(/) {
+ # indirect offset.
+ $offtype = 1;
+
+ # store as a reference [ offset1 type template offset2 ]
+
+ my ($o1,$type,$o2);
+ if (($o1,$type,$o2) = ($offset =~ /\((\d+)(\.[bsl])?([\+\-]?\d+)?\)/))
+ {
+ $o1 = oct($o1) if $o1 =~ /^0/o;
+ $o2 = oct($o2) if $o2 =~ /^0/o;
+
+ $type =~ s/\.//;
+ if ($type eq '') { $type = 'l'; } # default to long
+ $type =~ tr/b/c/; # type will be template for unpack
+
+ my $sz = $type; # number of bytes
+ $sz =~ tr/csl/124/;
+
+ $offset = [ $o1,$sz,$type,int($o2) ];
+ } else {
+ warn "Bad indirect offset at line $line_num. '$offset'\n";
+ return;
+ }
+ }
+ elsif ($offset =~ /^&/o) {
+ # relative offset
+ $offtype = 2;
+
+ $offset = substr($offset,1);
+ $offset = oct($offset) if $offset =~ /^0/o;
+ }
+ else {
+ # normal absolute offset
+ $offtype = 0;
+
+ # convert if needed
+ $offset = oct($offset) if $offset =~ /^0/o;
+ }
+ }
+ else {
+ warn "Bad Offset/Type at line $line_num. '$line'\n";
+ return;
+ }
+
+ # check for & operator on type
+ if ($type =~ s/&(.*)//) {
+ $mask = $1;
+
+ # convert if needed
+ $mask = oct($mask) if $mask =~ /^0/o;
+ }
+
+ # check if type is valid
+ if (!exists($TEMPLATES{$type})) {
+ warn "Invalid type '$type' at line $line_num\n";
+ return;
+ }
+
+ # take everything after the first non-escaped space
+ if ($line =~ s/([^\\])\s+(.*)/$1/) {
+ $message = $2;
+ }
+ else {
+ warn "Missing or invalid test condition or message at line $line_num\n";
+ return;
+ }
+
+ # remove the return if it's still there
+ $line =~ s/\n$//o;
+
+ # get the operator. if 'x', must be alone. default is '='.
+ if ($line =~ s/^([><&^=!])//o) {
+ $operator = $1;
+ }
+ elsif ($line eq 'x') {
+ $operator = 'x';
+ }
+ else { $operator = '='; }
+
+
+ if ($type eq 'string') {
+ $testval = $line;
+
+ # do octal/hex conversion
+ $testval =~ s/\\([x0-7][0-7]?[0-7]?)/chr(oct($1))/eg;
+
+ # do single char escapes
+ $testval =~ s/\\(.)/$ESC{$1}||$1/eg;
+
+ # put the number of bytes to read in numbytes.
+ # '0' means read to \0 or \n.
+ if ($operator =~ /[>x]/o) {
+ $numbytes = 0;
+ }
+ elsif ($operator =~ /[=<]/o) {
+ $numbytes = length($testval);
+ }
+ elsif ($operator eq '!') {
+ # annoying special case. ! operator only applies to numerics so
+ # put it back.
+ $testval = $operator . $testval;
+ $numbytes = length($testval);
+ $operator = '=';
+ }
+ else {
+ # there's a bug in my magic file where there's
+ # a line that says "0 string ^!<arc..." and the BSD
+ # file program treats the argument like a numeric. To minimize
+ # hassles, complain about bad ops only if -c is set.
+ warn "Invalid operator '$operator' for type 'string' at line $line_num.\n"
+ if $checkMagic;
+ return;
+ }
+ }
+ else {
+ # numeric
+ if ($operator ne 'x') {
+ # this conversion is very forgiving. it's faster and
+ # it doesn't complain about bugs in popular magic files,
+ # but it will silently turn a string into zero.
+ if ($line =~ /^0/o) {
+ $testval = oct($line);
+ } else {
+ $testval = int($line);
+ }
+ }
+
+ ($template,$numbytes) = @{$TEMPLATES{$type}};
+
+ # unset coercion of $unsigned unless we're doing order comparison
+ if (ref($template)) {
+ $template = $$template[0]
+ unless $operator eq '>' || $operator eq '<';
+ }
+ }
+
+ return [ $offtype, $offset, $numbytes, $type, $mask,
+ $operator, $testval, $template, $message, $subtests ];
+}
+
+# recursively write the magic file to stderr. Numbers are written
+# in decimal.
+sub dumpMagic {
+ my ($magic,$depth) = @_;
+ $magic = [] unless defined $magic;
+ $depth = 0 unless defined $depth;
+
+ my $entry;
+ foreach $entry (@$magic) {
+ # delayed evaluation.
+ $entry = readMagicLine(@$entry) if @$entry == 3;
+
+ next if !defined($entry);
+
+ my ($offtype, $offset, $numbytes, $type, $mask, $op, $testval,
+ $template, $message, $subtests) = @$entry;
+
+ print STDERR '>'x$depth;
+ if ($offtype == 1) {
+ $offset->[2] =~ tr/c/b/;
+ print STDERR "($offset->[0].$offset->[2]$offset->[3])";
+ }
+ elsif ($offtype == 2) {
+ print STDERR "&",$offset;
+ }
+ else {
+ # offtype == 0
+ print STDERR $offset;
+ }
+ print STDERR "\t",$type;
+ if ($mask) { print STDERR "&",$mask; }
+ print STDERR "\t",$op,$testval,"\t",$message,"\n";
+
+ if ($subtests) {
+ dumpMagic($subtests,$depth+1);
+ }
+ }
+}
+
+1;
+__DATA__
+# Magic data for mod_mime_magic Apache module (originally for file(1) command)
+# The module is described in htdocs/manual/mod/mod_mime_magic.html
+#
+# The format is 4-5 columns:
+# Column #1: byte number to begin checking from, ">" indicates continuation
+# Column #2: type of data to match
+# Column #3: contents of data to match
+# Column #4: MIME type of result
+# Column #5: MIME encoding of result (optional)
+
+#------------------------------------------------------------------------------
+# Localstuff: file(1) magic for locally observed files
+# Add any locally observed files here.
+#
+
+# The following paramaters are created for Namazu.
+# <http://www.namazu.org/>
+#
+# 1999/08/13
+#0 string \<!--\ MHonArc text/html; x-type=mhonarc
+0 string BZh application/x-bzip2
+
+# The following paramaters are local hack.
+#
+# 1999/09/09
+# VRML (suggested by Masao Takaku)
+0 string #VRML\ V1.0\ ascii model/vrml
+0 string #VRML\ V2.0\ utf8 model/vrml
+
+#------------------------------------------------------------------------------
+# end local stuff
+#------------------------------------------------------------------------------
+
+#------------------------------------------------------------------------------
+# Java
+
+0 short 0xcafe
+>2 short 0xbabe application/java
+
+#------------------------------------------------------------------------------
+# audio: file(1) magic for sound formats
+#
+# from Jan Nicolai Langfeldt <janl@ifi.uio.no>,
+#
+
+# Sun/NeXT audio data
+0 string .snd
+>12 belong 1 audio/basic
+>12 belong 2 audio/basic
+>12 belong 3 audio/basic
+>12 belong 4 audio/basic
+>12 belong 5 audio/basic
+>12 belong 6 audio/basic
+>12 belong 7 audio/basic
+
+>12 belong 23 audio/x-adpcm
+
+# DEC systems (e.g. DECstation 5000) use a variant of the Sun/NeXT format
+# that uses little-endian encoding and has a different magic number
+# (0x0064732E in little-endian encoding).
+0 lelong 0x0064732E
+>12 lelong 1 audio/x-dec-basic
+>12 lelong 2 audio/x-dec-basic
+>12 lelong 3 audio/x-dec-basic
+>12 lelong 4 audio/x-dec-basic
+>12 lelong 5 audio/x-dec-basic
+>12 lelong 6 audio/x-dec-basic
+>12 lelong 7 audio/x-dec-basic
+# compressed (G.721 ADPCM)
+>12 lelong 23 audio/x-dec-adpcm
+
+# Bytes 0-3 of AIFF, AIFF-C, & 8SVX audio files are "FORM"
+# AIFF audio data
+8 string AIFF audio/x-aiff
+# AIFF-C audio data
+8 string AIFC audio/x-aiff
+# IFF/8SVX audio data
+8 string 8SVX audio/x-aiff
+
+# Creative Labs AUDIO stuff
+# Standard MIDI data
+0 string MThd audio/unknown
+#>9 byte >0 (format %d)
+#>11 byte >1 using %d channels
+# Creative Music (CMF) data
+0 string CTMF audio/unknown
+# SoundBlaster instrument data
+0 string SBI audio/unknown
+# Creative Labs voice data
+0 string Creative\ Voice\ File audio/unknown
+## is this next line right? it came this way...
+#>19 byte 0x1A
+#>23 byte >0 - version %d
+#>22 byte >0 \b.%d
+
+# [GRR 950115: is this also Creative Labs? Guessing that first line
+# should be string instead of unknown-endian long...]
+#0 long 0x4e54524b MultiTrack sound data
+#0 string NTRK MultiTrack sound data
+#>4 long x - version %ld
+
+# Microsoft WAVE format (*.wav)
+# [GRR 950115: probably all of the shorts and longs should be leshort/lelong]
+# Microsoft RIFF
+#0 string RIFF audio/x-msvideo
+0 string RIFF
+# - WAVE format
+>8 string WAVE audio/x-wav
+
+#------------------------------------------------------------------------------
+# c-lang: file(1) magic for C programs or various scripts
+#
+
+# XPM icons (Greg Roelofs, newt@uchicago.edu)
+# ideally should go into "images", but entries below would tag XPM as C source
+0 string /*\ XPM image/x-xbm
+
+# this first will upset you if you're a PL/1 shop... (are there any left?)
+# in which case rm it; ascmagic will catch real C programs
+# C or REXX program text
+0 string /* text/plain
+# C++ program text
+0 string // text/plain
+
+#------------------------------------------------------------------------------
+# compress: file(1) magic for pure-compression formats (no archives)
+#
+# compress, gzip, pack, compact, huf, squeeze, crunch, freeze, yabba, whap, etc.
+#
+# Formats for various forms of compressed data
+# Formats for "compress" proper have been moved into "compress.c",
+# because it tries to uncompress it to figure out what's inside.
+
+# standard unix compress
+#0 string \037\235 application/octet-stream x-compress
+0 string \037\235 application/x-compress
+
+# gzip (GNU zip, not to be confused with [Info-ZIP/PKWARE] zip archiver)
+#0 string \037\213 application/octet-stream x-gzip
+0 string \037\213 application/x-gzip
+
+# According to gzip.h, this is the correct byte order for packed data.
+0 string \037\036 application/octet-stream
+#
+# This magic number is byte-order-independent.
+#
+0 short 017437 application/octet-stream
+
+# XXX - why *two* entries for "compacted data", one of which is
+# byte-order independent, and one of which is byte-order dependent?
+#
+# compacted data
+0 short 0x1fff application/octet-stream
+0 string \377\037 application/octet-stream
+# huf output
+0 short 0145405 application/octet-stream
+
+# Squeeze and Crunch...
+# These numbers were gleaned from the Unix versions of the programs to
+# handle these formats. Note that I can only uncrunch, not crunch, and
+# I didn't have a crunched file handy, so the crunch number is untested.
+# Keith Waclena <keith@cerberus.uchicago.edu>
+#0 leshort 0x76FF squeezed data (CP/M, DOS)
+#0 leshort 0x76FE crunched data (CP/M, DOS)
+
+# Freeze
+#0 string \037\237 Frozen file 2.1
+#0 string \037\236 Frozen file 1.0 (or gzip 0.5)
+
+# lzh?
+#0 string \037\240 LZH compressed data
+
+#------------------------------------------------------------------------------
+# frame: file(1) magic for FrameMaker files
+#
+# This stuff came on a FrameMaker demo tape, most of which is
+# copyright, but this file is "published" as witness the following:
+#
+0 string \<MakerFile application/x-frame
+0 string \<MIFFile application/x-frame
+0 string \<MakerDictionary application/x-frame
+0 string \<MakerScreenFon application/x-frame
+0 string \<MML application/x-frame
+0 string \<Book application/x-frame
+0 string \<Maker application/x-frame
+
+#------------------------------------------------------------------------------
+# html: file(1) magic for HTML (HyperText Markup Language) docs
+#
+# from Daniel Quinlan <quinlan@yggdrasil.com>
+#
+0 string \<HEAD text/html
+0 string \<head text/html
+0 string \<TITLE text/html
+0 string \<title text/html
+0 string \<html text/html
+0 string \<HTML text/html
+0 string \<!-- text/html
+0 string \<h1 text/html
+0 string \<H1 text/html
+
+#------------------------------------------------------------------------------
+# images: file(1) magic for image formats (see also "c-lang" for XPM bitmaps)
+#
+# originally from jef@helios.ee.lbl.gov (Jef Poskanzer),
+# additions by janl@ifi.uio.no as well as others. Jan also suggested
+# merging several one- and two-line files into here.
+#
+# XXX - byte order for GIF and TIFF fields?
+# [GRR: TIFF allows both byte orders; GIF is probably little-endian]
+#
+
+# [GRR: what the hell is this doing in here?]
+#0 string xbtoa btoa'd file
+
+# PBMPLUS
+# PBM file
+0 string P1 image/x-portable-bitmap
+# PGM file
+0 string P2 image/x-portable-greymap
+# PPM file
+0 string P3 image/x-portable-pixmap
+# PBM "rawbits" file
+0 string P4 image/x-portable-bitmap
+# PGM "rawbits" file
+0 string P5 image/x-portable-greymap
+# PPM "rawbits" file
+0 string P6 image/x-portable-pixmap
+
+# NIFF (Navy Interchange File Format, a modification of TIFF)
+# [GRR: this *must* go before TIFF]
+0 string IIN1 image/x-niff
+
+# TIFF and friends
+# TIFF file, big-endian
+0 string MM image/tiff
+# TIFF file, little-endian
+0 string II image/tiff
+
+# possible GIF replacements; none yet released!
+# (Greg Roelofs, newt@uchicago.edu)
+#
+# GRR 950115: this was mine ("Zip GIF"):
+# ZIF image (GIF+deflate alpha)
+0 string GIF94z image/unknown
+#
+# GRR 950115: this is Jeremy Wohl's Free Graphics Format (better):
+# FGF image (GIF+deflate beta)
+0 string FGF95a image/unknown
+#
+# GRR 950115: this is Thomas Boutell's Portable Bitmap Format proposal
+# (best; not yet implemented):
+# PBF image (deflate compression)
+0 string PBF image/unknown
+
+# GIF
+0 string GIF image/gif
+
+# JPEG images
+0 beshort 0xffd8 image/jpeg
+
+# PC bitmaps (OS/2, Windoze BMP files) (Greg Roelofs, newt@uchicago.edu)
+0 string BM image/bmp
+#>14 byte 12 (OS/2 1.x format)
+#>14 byte 64 (OS/2 2.x format)
+#>14 byte 40 (Windows 3.x format)
+#0 string IC icon
+#0 string PI pointer
+#0 string CI color icon
+#0 string CP color pointer
+#0 string BA bitmap array
+
+# PNG images
+# Suggested by Jamie LeTual.
+0 string \211PNG image/png
+
+#------------------------------------------------------------------------------
+# lisp: file(1) magic for lisp programs
+#
+# various lisp types, from Daniel Quinlan (quinlan@yggdrasil.com)
+0 string ;; text/plain
+# Emacs 18 - this is always correct, but not very magical.
+0 string \012( application/x-elc
+# Emacs 19
+0 string ;ELC\023\000\000\000 application/x-elc
+
+#------------------------------------------------------------------------------
+# mail.news: file(1) magic for mail and news
+#
+# There are tests to ascmagic.c to cope with mail and news.
+0 string Relay-Version: message/rfc822
+0 string #!\ rnews message/rfc822
+0 string N#!\ rnews message/rfc822
+0 string Forward\ to message/rfc822
+0 string Pipe\ to message/rfc822
+0 string Return-Path: message/rfc822
+0 string Received: message/rfc822
+0 string Path: message/news
+0 string Xref: message/news
+0 string From: message/rfc822
+0 string Article message/news
+#------------------------------------------------------------------------------
+# msword: file(1) magic for MS Word files
+#
+# Contributor claims:
+# Reversed-engineered MS Word magic numbers
+#
+
+0 string \376\067\0\043 application/msword
+#0 string \320\317\021\340\241\261 application/msword
+0 string \333\245-\0\0\0 application/msword
+
+
+
+#------------------------------------------------------------------------------
+# printer: file(1) magic for printer-formatted files
+#
+
+# PostScript
+0 string %! application/postscript
+0 string \004%! application/postscript
+
+# Acrobat
+# (due to clamen@cs.cmu.edu)
+0 string %PDF- application/pdf
+
+#------------------------------------------------------------------------------
+# sc: file(1) magic for "sc" spreadsheet
+#
+38 string Spreadsheet application/x-sc
+
+#------------------------------------------------------------------------------
+# tex: file(1) magic for TeX files
+#
+# XXX - needs byte-endian stuff (big-endian and little-endian DVI?)
+#
+# From <conklin@talisman.kaleida.com>
+
+# Although we may know the offset of certain text fields in TeX DVI
+# and font files, we can't use them reliably because they are not
+# zero terminated. [but we do anyway, christos]
+0 string \367\002 application/x-dvi
+#0 string \367\203 TeX generic font data
+#0 string \367\131 TeX packed font data
+#0 string \367\312 TeX virtual font data
+#0 string This\ is\ TeX, TeX transcript text
+#0 string This\ is\ METAFONT, METAFONT transcript text
+
+# There is no way to detect TeX Font Metric (*.tfm) files without
+# breaking them apart and reading the data. The following patterns
+# match most *.tfm files generated by METAFONT or afm2tfm.
+#2 string \000\021 TeX font metric data
+#2 string \000\022 TeX font metric data
+#>34 string >\0 (%s)
+
+# Texinfo and GNU Info, from Daniel Quinlan (quinlan@yggdrasil.com)
+0 string \\input\ texinfo text/x-texinfo
+0 string This\ is\ Info\ file text/x-info
+#0 string This\ is\ text/x-info
+
+# correct TeX magic for Linux (and maybe more)
+# from Peter Tobias (tobias@server.et-inf.fho-emden.de)
+#
+0 leshort 0x02f7 application/x-dvi
+
+# RTF - Rich Text Format
+0 string {\\rtf application/rtf
+
+#------------------------------------------------------------------------------
+# animation: file(1) magic for animation/movie formats
+#
+# animation formats, originally from vax@ccwf.cc.utexas.edu (VaX#n8)
+# MPEG file
+0 string \000\000\001\263 video/mpeg
+#
+# The contributor claims:
+# I couldn't find a real magic number for these, however, this
+# -appears- to work. Note that it might catch other files, too,
+# so BE CAREFUL!
+#
+# Note that title and author appear in the two 20-byte chunks
+# at decimal offsets 2 and 22, respectively, but they are XOR'ed with
+# 255 (hex FF)! DL format SUCKS BIG ROCKS.
+#
+# DL file version 1 , medium format (160x100, 4 images/screen)
+0 byte 1 video/unknown
+0 byte 2 video/unknown
+
+#------------------------------------------------------------------------------
+# ichitaro456: file(1) magic for Just System Word Processor Ichitaro
+#
+# Contributor kenzo-:
+# Reversed-engineered JS Ichitaro magic numbers
+#
+
+0 string DOC
+>43 byte 0x14 application/ichitaro4
+>144 string JDASH application/ichitaro4
+
+0 string DOC
+>43 byte 0x15 application/ichitaro5
+
+0 string DOC
+>43 byte 0x16 application/ichitaro6
+
+#------------------------------------------------------------------------------
+# office97: file(1) magic for MicroSoft Office files
+#
+# Contributor kenzo-:
+# Reversed-engineered MS Office magic numbers
+#
+
+#0 string \320\317\021\340\241\261\032\341
+#>48 byte 0x1B application/excel
+
+2080 string Microsoft\ Excel\ 5.0\ Worksheet application/excel
+2114 string Biff5 application/excel
+
+0 string \224\246\056 application/msword
+
+0 belong 0x31be0000 application/msword
+
+0 string PO^Q` application/msword
+
+0 string \320\317\021\340\241\261\032\341
+>546 string bjbj application/msword
+>546 string jbjb application/msword
+
+512 string R\0o\0o\0t\0\ \0E\0n\0t\0r\0y application/msword
+
+2080 string Microsoft\ Word\ 6.0\ Document application/msword
+2080 string Documento\ Microsoft\ Word\ 6 application/msword
+2112 string MSWordDoc application/msword
+
+#0 string \320\317\021\340\241\261\032\341 application/powerpoint
+0 string \320\317\021\340\241\261\032\341 application/msword
+
+#
+# MPEG audio/video format
+# Contributer: Peter Breton
+#
+
+0 belong 0x000001b3 video/mpeg
+0 belong 0x000001ba video/mpeg
+0 beshort &0xffe0 audio/mpeg
+
+#
+# QuickTime format
+# Contributer: Peter Breton
+#
+
+0 string MOVI video/quicktime
+4 string moov video/quicktime
+4 string mdat video/quicktime
+
+# WinNT/WinCE PE files (Warner Losh, imp@village.org)
+#
+128 string PE\000\000 application/octet-stream
+0 string PE\000\000 application/octet-stream
+
+# miscellaneous formats
+0 string LZ application/octet-stream
+
+# .EXE formats (Greg Roelofs, newt@uchicago.edu)
+#
+0 string MZ
+>24 string @ application/octet-stream
+
+0 string MZ
+>30 string Copyright\ 1989-1990\ PKWARE\ Inc. application/x-zip
+
+0 string MZ
+>30 string PKLITE\ Copr. application/x-zip
+
+0 string MZ
+>36 string LHa's\ SFX application/x-lha
+
+0 string MZ
+>36 string LHA's\ SFX application/x-lha
+
+0 string MZ application/octet-stream
+
+# LHA archiver
+2 string -lh
+>6 string - application/x-lha
+
+# ZIP archiver
+0 string PK application/x-zip
+
+# POSIX tar archives
+257 string ustar\0 application/x-tar
+257 string ustar\040\040\0 application/x-gtar
+
+# TNEF file
+0 lelong 0x223E9F78 application/ms-tnef
+
+# ARC archiver
+0 lelong&0x8080ffff 0x0000081a application/x-arc
+0 lelong&0x8080ffff 0x0000091a application/x-arc
+0 lelong&0x8080ffff 0x0000021a application/x-arc
+0 lelong&0x8080ffff 0x0000031a application/x-arc
+0 lelong&0x8080ffff 0x0000041a application/x-arc
+0 lelong&0x8080ffff 0x0000061a application/x-arc
+# Zoo archiver
+20 lelong 0xfdc4a7dc application/x-zoo
+# ARJ archiver (jason@jarthur.Claremont.EDU)
+0 leshort 0xea60 application/x-arj
+# RAR archiver (Greg Roelofs, newt@uchicago.edu)
+0 string Rar! application/x-rar
diff --git a/cpan/lib/MIME/Type.pm b/cpan/lib/MIME/Type.pm
new file mode 100644
index 00000000..baec8b31
--- /dev/null
+++ b/cpan/lib/MIME/Type.pm
@@ -0,0 +1,320 @@
+package MIME::Type;
+
+$VERSION = '1.004';
+
+use strict;
+use Carp;
+
+use overload '""' => 'type'
+ , cmp => 'equals'
+ ;
+
+=head1 NAME
+
+ MIME::Type - Definition of one MIME type
+
+=head1 SYNOPSIS
+
+ use MIME::Types;
+ my $mimetypes = MIME::Types->new;
+ my MIME::Type $plaintext = $mimetype->type('text/plain');
+ print $plaintext->mediaType; # text
+ print $plaintext->subType; # plain
+
+ my @ext = $plaintext->extensions;
+ print "@ext" # asc txt c cc h hh cpp
+
+ print $plaintext->encoding # 8bit
+ if($plaintext->isBinary) # false
+ if($plaintext->isAscii) # true
+ if($plaintext->equals('text/plain') {...}
+ if($plaintext eq 'text/plain') # same
+
+ print MIME::Type->simplified('x-appl/x-zip') # 'appl/zip'
+
+=head1 DESCRIPTION
+
+MIME types are used in MIME entities, for instance as part of e-mail
+and HTTP traffic. Sometimes real knowledge about a mime-type is need.
+Objects of C<MIME::Type> store the information on one such type.
+
+This module is built to conform to the MIME types of RFC's 2045 and 2231.
+It follows the collection kept at F<http://www.ltsw.se/knbase/internet/mime.htp>
+
+=cut
+
+#-------------------------------------------
+
+=head1 METHODS
+
+=over 4
+
+=cut
+
+#-------------------------------------------
+
+=item new OPTIONS
+
+Create a new C<MIME::Type> object which manages one mime type.
+
+ OPTION DEFAULT
+ type <obligatory>
+ simplified <derived from type>
+ extensions undef
+ encoding <depends on type>
+ system undef
+
+=over 4
+
+=item * type =E<gt> STRING
+
+The type which is defined here. It consists of a I<type> and a I<sub-type>,
+both case-insensitive. This module will return lower-case, but accept
+upper-case.
+
+=item * simplified =E<gt> STRING
+
+The mime types main- and sub-label can both start with C<x->, to indicate
+that is a non-registered name. Of course, after registration this flag
+can disappear which adds to the confusion. The simplified string has the
+C<x-> thingies removed and are translated to lower-case.
+
+=item * extensions =E<gt> REF-ARRAY
+
+An array of extensions which are using this mime.
+
+=item * encoding =E<gt> '7bit'|'8bit'|'base64'|'quoted-printable'
+
+How must this data be encoded to be transported safely. The default
+depends on the type: mimes with as main type C<text/> will default
+to C<quoted-printable> and all other to C<base64>.
+
+=item * system =E<gt> REGEX
+
+Regular expression which defines for which systems this rule is valid. The
+REGEX is matched on C<$^O>.
+
+=back
+
+=cut
+
+sub new(@) { (bless {}, shift)->init( {@_} ) }
+
+sub init($)
+{ my ($self, $args) = @_;
+
+ $self->{MT_type} = $args->{type}
+ or confess "Type is obligatory.";
+
+ $self->{MT_simplified} = $args->{simplified}
+ || ref($self)->simplified($args->{type});
+
+ $self->{MT_extensions} = $args->{extensions} || [];
+
+ $self->{MT_encoding}
+ = $args->{encoding} ? $args->{encoding}
+ : $self->mediaType eq 'text' ? 'quoted-printable'
+ : 'base64';
+
+ $self->{MT_system} = $args->{system}
+ if defined $args->{system};
+
+ $self;
+}
+
+#-------------------------------------------
+
+=item type
+
+Returns the long type of this object, for instance C<'text/plain'>
+
+=cut
+
+sub type() {shift->{MT_type}}
+
+#-------------------------------------------
+
+=item simplified [STRING]
+
+(Instance method or Class method)
+Returns the simplified mime type for this object or the specified STRING.
+Mime type names can get officially registered. Until then, they have to
+carry an C<x-> preamble to indicate that. Of course, after recognition,
+the C<x-> can disappear. In many cases, we prefer the simplified version
+of the type.
+
+Examples:
+
+ my $mime = MIME::Type->new(type => 'x-appl/x-zip');
+ print $mime->simplified; # 'appl/zip'
+ print $mime->simplified('text/plain'); # 'text/plain'
+ print MIME::Type->simplified('x-xyz/x-abc'); # 'xyz/abc'
+
+=cut
+
+sub simplified(;$)
+{ my $thing = shift;
+ return $thing->{MT_simplified} unless @_;
+
+ my $mime = shift;
+
+ $mime =~ m!^\s*(?:x\-)?([\w.+-]+)/(?:x\-)?([\w.+-]+)\s*$!i ? lc "$1/$2"
+ : $mime =~ m!text! ? "text/plain" # some silly mailers...
+ : undef;
+}
+
+#-------------------------------------------
+
+=item mediaType
+
+The media type of the simplified mime.
+For C<'text/plain'> it will return C<'text'>.
+
+For historical reasons, the C<'mainType'> method still can be used
+to retreive the same value. However, that method is deprecated.
+
+=cut
+
+sub mediaType() {shift->{MT_simplified} =~ m!^([\w-]+)/! ? $1 : undef}
+
+sub mainType() {shift->mediaType} # Backwards compatibility
+
+#-------------------------------------------
+
+=item subType
+
+The sub type of the simplified mime.
+For C<'text/plain'> it will return C<'plain'>.
+
+=cut
+
+sub subType() {shift->{MT_simplified} =~ m!/([\w-]+)$! ? $1 : undef}
+
+#-------------------------------------------
+
+=item isRegistered
+
+Mime-types which are not registered by IANA nor defined in RFCs shall
+start with an C<x->. This counts for as well the media-type as the
+sub-type. In case either one of the types starts with C<x-> this
+method will return false.
+
+=cut
+
+sub isRegistered()
+{ local $_ = shift->{MT_type};
+ not (m/^[xX]\-/ || m!/[xX]\-!);
+}
+
+#-------------------------------------------
+
+=item extensions
+
+Returns a list of extensions which are known to be used for this
+mime type.
+
+=cut
+
+sub extensions() { @{shift->{MT_extensions}} }
+
+#-------------------------------------------
+
+=item encoding
+
+Returns the type of encoding which is required to transport data of this
+type safely.
+
+=cut
+
+sub encoding() {shift->{MT_encoding}}
+
+#-------------------------------------------
+
+=item system
+
+Returns the regular expression which can be used to determine whether this
+type is active on the system where you are working on.
+
+=cut
+
+sub system() {shift->{MT_system}}
+
+#-------------------------------------------
+
+=item isBinary
+
+Returns true when the encoding is base64.
+
+=cut
+
+sub isBinary() { shift->{MT_encoding} eq 'base64' }
+
+#-------------------------------------------
+
+=item isAscii
+
+Returns false when the encoding is base64, and true otherwise. All encodings
+except base64 are text encodings.
+
+=cut
+
+sub isAscii() { shift->{MT_encoding} ne 'base64' }
+
+#-------------------------------------------
+
+=item isSignature
+
+Returns true when the type is in the list of known signatures.
+
+=cut
+
+# simplified names only!
+my %sigs = map { ($_ => 1) }
+ qw(application/pgp-keys application/pgp application/pgp-signature
+ application/pkcs10 application/pkcs7-mime application/pkcs7-signature
+ text/vCard);
+
+sub isSignature() { $sigs{shift->{MT_simplified}} }
+
+#-------------------------------------------
+
+=item equals STRING|MIME
+
+Compare this mime-type object with a STRING or other object. In case of
+a STRING, simplification will take place.
+
+=cut
+
+sub equals($)
+{ my ($self, $other) = @_;
+
+ my $type = ref $other
+ ? $other->simplified
+ : (ref $self)->simplified($other);
+
+ $self->simplified cmp $type;
+}
+
+#-------------------------------------------
+
+=back
+
+=head1 SEE ALSO
+
+L<MIME::Types>
+
+=head1 AUTHOR
+
+Mark Overmeer (F<mimetypes@overmeer.net>).
+
+=head1 VERSION
+
+This code is stable, version 1.003.
+
+Copyright (c) 2001-2002 Mark Overmeer. All rights reserved.
+This program is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut
+
+1;
diff --git a/cpan/lib/MIME/Types.pm b/cpan/lib/MIME/Types.pm
new file mode 100644
index 00000000..1240fa5d
--- /dev/null
+++ b/cpan/lib/MIME/Types.pm
@@ -0,0 +1,809 @@
+package MIME::Types;
+
+$VERSION = '1.004';
+
+use strict;
+use MIME::Type;
+
+=head1 NAME
+
+ MIME::Types - Definition of MIME types
+
+=head1 SYNOPSIS
+
+ use MIME::Types;
+ my $mimetypes = MIME::Types->new;
+ my MIME::Type $plaintext = $mimetype->type('text/plain');
+ my MIME::Type $imagegif = $mimetype->mimeTypeOf('gif');
+
+=head1 DESCRIPTION
+
+MIME types are used in MIME entities, for instance as part of e-mail
+and HTTP traffic. Sometimes real knowledge about a mime-type is need.
+This module will supply it.
+
+=cut
+
+#-------------------------------------------
+
+=head1 METHODS
+
+=over 4
+
+=cut
+
+#-------------------------------------------
+
+=item new OPTIONS
+
+Create a new C<MIME::Types> object which manages the data. In the current
+implementation, it does not matter whether you create this object often
+within your program, but in the future this may change.
+
+ OPTIONS DEFAULT
+ only_complete 0
+
+=over 4
+
+=item * only_complete =E<gt> BOOLEAN
+
+Only include complete mime-type definitions: requires extension and
+encoding. This will reduce the number of entries --and with that
+the amount of memory consumed-- enormously.
+
+In your program you have to decide: the first time that you call
+the creator (C<new>) determines whether you get the full or the partial
+information.
+
+=back
+
+=cut
+
+my %list;
+sub new(@) { (bless {}, shift)->init( {@_} ) }
+
+sub init($)
+{ my ($self, $args) = @_;
+
+ unless(keys %list)
+ { local $_;
+ local $/ = "\n";
+
+ while(<MIME::Types::DATA>)
+ { s/\#.*//;
+ next if m/^$/;
+
+ my $os = s/^(\w+)\:// ? qr/$1/i : undef;
+
+ my ($type, $extensions, $encoding) = split;
+ my $extent = $extensions ? [ split /\,/, $extensions ] : undef;
+
+ next if $args->{only_complete}
+ && ! ($extensions && $encoding);
+
+ my $simplified = MIME::Type->simplified($type);
+ push @{$list{$simplified}}, MIME::Type->new
+ ( type => $type
+ , extensions => $extent
+ , encoding => $encoding
+ , system => $os
+ );
+ }
+ }
+
+ close DATA;
+ $self;
+}
+
+my %type_index;
+sub create_type_index()
+{ my $self = shift;
+
+ my @os_specific;
+ while(my ($simple, $definitions) = each %list)
+ { foreach my $def (@$definitions)
+ { if(defined $def->system && $^O =~ $def->system)
+ { # OS specific definitions will overrule the
+ # unspecific definitions, so must be postponed till
+ # the end.
+ push @os_specific, $def;
+ }
+ else
+ { $type_index{$_} = $def foreach $def->extensions;
+ }
+ }
+ }
+
+ foreach my $def (@os_specific)
+ { $type_index{$_} = $def foreach $def->extensions;
+ }
+
+ $self;
+}
+
+#-------------------------------------------
+
+=item type STRING
+
+Return the C<MIME::Type> which describes the type related to STRING. One
+type may be described more than once. Different extensions is use for
+this type, and different operating systems may cause more than one
+C<MIME::Type> object to be defined. In scalar context, only the first
+is returned.
+
+=cut
+
+sub type($)
+{ my $mime = MIME::Type->simplified($_[1]) or return;
+ return () unless exists $list{$mime};
+ wantarray ? @{$list{$mime}} : $list{$mime}[0];
+}
+
+#-------------------------------------------
+
+=item mimeTypeOf FILENAME
+
+Returns the C<MIME::Type> object which belongs to the FILENAME (or simply
+its filename extension). The extension is used, and considered
+case-insensitive.
+
+Examples:
+
+ my MIME::Types $types = MIME::Types->new;
+ my MIME::Type $mime = $types->mimeTypeOf('gif');
+
+ my MIME::Type $mime = $types->mimeTypeOf('jpg');
+ print $mime->isBinary;
+
+=cut
+
+sub mimeTypeOf($)
+{ my ($self, $name) = @_;
+ $self->create_type_index unless keys %type_index;
+ $name =~ s/.*\.//;
+ $type_index{lc $name};
+}
+
+#-------------------------------------------
+
+=item addType TYPE, ...
+
+Add one or more TYPEs to the set of known types. Each TYPE is a
+C<MIME::Type> which must be experimental: either the main-type or
+the sub-type must start with C<x->.
+
+Please inform the maintainer of this module when registered types
+are missing.
+
+=cut
+
+sub addType(@)
+{ my $self = shift;
+ foreach my $type (@_)
+ {
+ if($type->isRegistered)
+ { use Carp;
+ carp "Please report the registered type $type to the module author."
+ }
+
+ my $simplified = $type->simplified;
+ push @{$list{$simplified}}, $type;
+ }
+
+ %type_index = ();
+ $self;
+}
+
+#-------------------------------------------
+
+=back
+
+=head1 EXPORT
+
+The next methods are provided for backward compatibility with MIME::Types
+versions 0.06 and below. This code originates from Jeff Okamoto
+<F<okamoto@corp.hp.com>> and others.
+
+=over 4
+
+=cut
+
+#-------------------------------------------
+
+require Exporter;
+use vars qw/@ISA @EXPORT_OK/;
+@ISA = qw(Exporter);
+@EXPORT_OK = qw(by_suffix by_mediatype import_mime_types);
+
+#-------------------------------------------
+
+=item by_suffix FILENAME|SUFFIX
+
+Like C<mimeTypeOf> but does not return an C<MIME::Type> object.
+
+Example:
+
+ use MIME::Types 'by_suffix';
+ my ($mediatype, $encoding) = by_suffix 'image.gif';
+
+ my $refdata = by_suffix 'image.gif';
+ my ($mediatype, $encoding) = @$refdata;
+
+=cut
+
+my $mime_types;
+
+sub by_suffix($)
+{ my $filename = shift;
+ $mime_types ||= MIME::Types->new;
+ my $mime = $mime_types->mimeTypeOf($filename);
+
+ my @data = defined $mime ? ($mime->type, $mime->encoding) : ('','');
+ wantarray ? @data : \@data;
+}
+
+#-------------------------------------------
+
+=item by_mediatype TYPE
+
+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.
+
+TYPE can be a full type name (contains '/', and will be matched in full),
+a partial type (which is used as regular expression) or a real regular
+expression.
+
+=cut
+
+sub by_mediatype($)
+{ my $type = shift;
+ my @found;
+
+ if($type =~ m!/!)
+ { my $simplified = MIME::Type->simplified($type);
+ my $mime = $list{$simplified};
+ push @found, @$mime if defined $mime;
+ }
+ else
+ { my $mime = ref $type ? $type : qr/$type/i;
+ @found = map {@{$list{$_}}}
+ grep {$_ =~ $mime}
+ keys %list;
+ }
+
+ my @data;
+ foreach my $mime (@found)
+ { push @data, map { [$_, $mime->type, $mime->encoding] }
+ $mime->extensions;
+ }
+
+ wantarray ? @data : \@data;
+}
+
+#-------------------------------------------
+
+=item import_mime_types
+
+This method has been removed: mime-types are only useful if understood
+by many parties. Therefore, the IANA assigns names which can be used.
+In the table kept by this C<MIME::Types> module all these names, plus
+the most often used termporary names are kept. When names seem to be
+missing, please contact the maintainer for inclussion.
+
+=cut
+
+sub import_mime_types($)
+{ my $filename = shift;
+ use Carp;
+ croak <<'CROAK';
+import_mime_types is not supported anymore: if you have types to add
+please send them to the author.
+CROAK
+}
+
+#-------------------------------------------
+
+=back
+
+=head1 SEE ALSO
+
+L<MIME::Type>
+
+=head1 AUTHOR
+
+Original module and data collection by Jeff Okamoto and the Apache team.
+Mark Overmeer (F<mimetypes@overmeer.net>).
+
+=head1 VERSION
+
+This code is stable, version 1.003.
+
+Copyright (c) 2001-2002 by Jeff Okamoto and Mark Overmeer.
+All rights reserved. This program is free software; you can redistribute
+it and/or modify it under the same terms as Perl itself.
+
+=cut
+
+1;
+
+#-------------------------------------------
+# Internet media type registry is at
+# <ftp://ftp.iana.org/in-notes/iana/assignments/media-types/>.
+
+__DATA__
+application/access mdf
+application/activemessage
+application/andrew-inset ez
+application/applefile base64
+application/atomicmail
+application/batch-SMTP
+application/bleeper bleep base64
+application/cals-1840
+application/commonground
+application/cu-seeme csm,cu
+application/cybercash
+application/dca-rft
+application/dec-dx
+application/EDI-Consent
+application/EDIFACT
+application/EDI-X12
+application/eshop
+application/excel xls,xlt base64
+application/font-tdpfr pfr
+application/futuresplash spl
+application/ghostview
+application/hep hep
+application/http
+application/hyperstudio
+application/iges
+application/imagemap imagemap,imap 8bit
+application/index
+application/index.cmd
+application/index.obj
+application/index.response
+application/index.vnd
+application/iotp
+application/ipp
+application/lotus-123 wks
+application/mac-binhex40 hqx 8bit
+application/mac-compactpro cpt
+application/macwriteii
+application/marc
+application/mathematica
+application/mathcad mcd base64
+application/mathematica-old
+application/msword doc,dot,wrd base64
+application/news-message-id
+application/news-transmission
+application/ocsp-request
+application/ocsp-response
+application/octet-stream bin,dms,lha,lzh,exe,class,ani base64
+application/oda oda
+application/pdf pdf base64
+application/pagemaker pm5,pt5,pm
+application/pgp-encrypted
+application/pgp-keys
+application/pgp
+application/pgp-signature pgp 8bit
+application/pkcs10
+application/pkcs7-mime
+application/pkcs7-signature
+application/pkix-cert
+application/pkixcmp
+application/pkix-crl
+application/postscript ai,eps,ps 8bit
+application/postscript ps-z base64
+application/powerpoint ppt,pps,pot base64
+application/prs.alvestrand.titrax-sheet
+application/prs.cww
+application/prs.nprend
+application/remote-printing
+application/riscos
+application/rtf rtf 8bit
+application/sdp
+application/set-payment
+application/set-payment-initiation
+application/set-registration
+application/set-registration-initiation
+application/sgml
+application/sgml-open-catalog
+application/slate
+application/smil smi,smil
+application/toolbook tbk
+application/vemmi
+application/VMSBACKUP bck base64
+application/vnd.3M.Post-it-Notes
+application/vnd.accpac.simply.aso
+application/vnd.accpac.simply.imp
+application/vnd.acucobol
+application/vnd.anser-web-certificate-issue-initiation
+application/vnd.anser-web-funds-transfer-initiation
+application/vnd.audiograph
+application/vnd.bmi
+application/vnd.businessobjects
+application/vnd.canon-cpdl
+application/vnd.canon-lips
+application/vnd.claymore
+application/vnd.commerce-battelle
+application/vnd.commonspace
+application/vnd.comsocaller
+application/vnd.contact.cmsg
+application/vnd.cosmocaller
+application/vnd.ctc-posml
+application/vnd.cups-postscript
+application/vnd.cups-raster
+application/vnd.cups-raw
+application/vnd.cybank
+application/vnd.dna
+application/vnd.dpgraph
+application/vnd.dxr
+application/vnd.ecdis-update
+application/vnd.ecowin.chart
+application/vnd.ecowin.filerequest
+application/vnd.ecowin.fileupdate
+application/vnd.ecowin.series
+application/vnd.ecowin.seriesrequest
+application/vnd.ecowin.seriesupdate
+application/vnd.enliven
+application/vnd.epson.esf
+application/vnd.epson.msf
+application/vnd.epson.quickanime
+application/vnd.epson.salt
+application/vnd.epson.ssf
+application/vnd.ericsson.quickcall
+application/vnd.eudora.data
+application/vnd.fdf
+application/vnd.ffsns
+application/vnd.FloGraphIt
+application/vnd.framemaker
+application/vnd.fujitsu.oasys
+application/vnd.fujitsu.oasys2
+application/vnd.fujitsu.oasys3
+application/vnd.fujitsu.oasysgp
+application/vnd.fujitsu.oasysprs
+application/vnd.fujixerox.ddd
+application/vnd.fujixerox.docuworks
+application/vnd.fujixerox.docuworks.binder
+application/vnd.fut-misnet
+application/vnd.grafeq
+application/vnd.groove-account
+application/vnd.groove-identity-message
+application/vnd.groove-injector
+application/vnd.groove-tool-message
+application/vnd.groove-tool-template
+application/vnd.groove-vcard
+application/vnd.hp-HPGL plt,hpgl
+application/vnd.hp-hpid
+application/vnd.hp-hps
+application/vnd.hp-PCL
+application/vnd.hp-PCLXL
+application/vnd.httphone
+application/vnd.hzn-3d-crossword
+application/vnd.ibm.MiniPay
+application/vnd.ibm.modcap
+application/vnd.informix-visionary
+application/vnd.intercon.formnet
+application/vnd.intertrust.digibox
+application/vnd.intertrust.nncp
+application/vnd.intu.qbo
+application/vnd.intu.qfx
+application/vnd.is-xpr
+application/vnd.japannet-directory-service
+application/vnd.japannet-jpnstore-wakeup
+application/vnd.japannet-payment-wakeup
+application/vnd.japannet-registration
+application/vnd.japannet-registration-wakeup
+application/vnd.japannet-setstore-wakeup
+application/vnd.japannet-verification
+application/vnd.japannet-verification-wakeup
+application/vnd.koan
+application/vnd.lotus-1-2-3
+application/vnd.lotus-approach
+application/vnd.lotus-freelance
+application/vnd.lotus-notes
+application/vnd.lotus-organizer
+application/vnd.lotus-screencam
+application/vnd.lotus-wordpro
+application/vnd.mcd
+application/vnd.mediastation.cdkey
+application/vnd.meridian-slingshot
+application/vnd.mif mif
+application/vnd.minisoft-hp3000-save
+application/vnd.mitsubishi.misty-guard.trustweb
+application/vnd.mobius.daf
+application/vnd.mobius.dis
+application/vnd.mobius.msl
+application/vnd.mobius.plc
+application/vnd.mobius.txf
+application/vnd.motorola.flexsuite
+application/vnd.motorola.flexsuite.adsi
+application/vnd.motorola.flexsuite.fis
+application/vnd.motorola.flexsuite.gotap
+application/vnd.motorola.flexsuite.kmr
+application/vnd.motorola.flexsuite.ttc
+application/vnd.motorola.flexsuite.wem
+application/vnd.mozilla.xul+xml
+application/vnd.ms-artgalry
+application/vnd.ms-access mda,mdb,mde
+application/vnd.ms-asf
+application/vnd.ms-excel xls
+application/vnd.msign
+application/vnd.ms-lrm
+application/vnd.ms-powerpoint ppt
+application/vnd.ms-project mpp
+application/vnd.ms-tnef
+application/vnd.ms-works
+application/vnd.musician
+application/vnd.music-niff
+application/vnd.netfpx
+application/vnd.noblenet-directory
+application/vnd.noblenet-sealer
+application/vnd.noblenet-web
+application/vnd.novadigm.EDM
+application/vnd.novadigm.EDX
+application/vnd.novadigm.EXT
+application/vnd.osa.netdeploy
+application/vnd.pg.format
+application/vnd.pg.osasli
+application/vnd.powerbuilder6
+application/vnd.powerbuilder6-s
+application/vnd.powerbuilder7
+application/vnd.powerbuilder75
+application/vnd.powerbuilder75-s
+application/vnd.powerbuilder7-s
+application/vnd.previewsystems.box
+application/vnd.publishare-delta-tree
+application/vnd.rapid
+application/vnd.s3sms
+application/vnd.seemail
+application/vnd.shana.informed.formdata
+application/vnd.shana.informed.formtemplate
+application/vnd.shana.informed.interchange
+application/vnd.shana.informed.package
+application/vnd.street-stream
+application/vnd.svd
+application/vnd.swiftview-ics
+application/vnd.triscape.mxs
+application/vnd.trueapp
+application/vnd.truedoc
+application/vnd.ufdl
+application/vnd.uplanet.alert
+application/vnd.uplanet.alert-wbxml
+application/vnd.uplanet.bearer-choice
+application/vnd.uplanet.bearer-choi-wbxml
+application/vnd.uplanet.cacheop
+application/vnd.uplanet.cacheop-wbxml
+application/vnd.uplanet.channel
+application/vnd.uplanet.channel-wbxml
+application/vnd.uplanet.list
+application/vnd.uplanet.listcmd
+application/vnd.uplanet.listcmd-wbxml
+application/vnd.uplanet.list-wbxml
+application/vnd.uplanet.signal
+application/vnd.vcx
+application/vnd.vectorworks
+application/vnd.visio
+application/vnd.wap.sic
+application/vnd.wap.slc
+application/vnd.wap.wbxml wbxml
+application/vnd.wap.wmlc wmlc
+application/vnd.wap.wmlscriptc wmlsc
+application/vnd.webturbo
+application/vnd.wrq-hp3000-labelled
+application/vnd.wt.stf
+application/vnd.xara
+application/vnd.xfdl
+application/vnd.yellowriver-custom-menu
+application/whoispp-query
+application/whoispp-response
+application/wita
+application/wordperfect wp
+application/wordperfect5.1 wp5
+application/wordperfect6.1 wp6
+application/wordperfectd wpd
+application/x-123 wk
+application/x400-bp
+application/x-bcpio bcpio
+application/x-cdlink vcd
+application/x-chess-pgn pgn
+application/x-compress
+application/x-compress z,Z base64
+application/x-cpio cpio base64
+application/x-csh csh 8bit
+application/x-debian-package deb
+application/x-director dcr,dir,dxr
+application/x-dvi dvi base64
+application/x-futuresplash spl
+application/x-gtar gtar,tgz base64
+application/x-gunzip
+application/x-gzip gz base64
+application/x-hdf hdf
+application/x-httpd-php phtml,pht,php 8bit
+application/x-ica ica
+application/x-javascript js 8bit
+application/x-koan skp,skd,skt,skm
+application/x-latex latex 8bit
+application/x-maker frm,maker,frame,fm,fb,book,fbdoc
+application/x-mif mif
+application/xml
+application/x-msdos-program com,bat 8bit
+application/x-msdos-program exe base64
+application/x-msdownload exe base64
+application/x-netcdf nc,cdf
+application/x-ns-proxy-autoconfig pac
+application/x-perl pl,pm 8bit
+application/quicktimeplayer qtl
+application/x-rar-compressed rar base64
+application/x-shar shar 8bit
+application/x-shockwave-flash swf
+application/x-sh sh 8bit
+application/x-spss sav,spp,sbs,sps,spo
+application/x-stuffit sit base64
+application/x-sv4cpio sv4cpio base64
+application/x-sv4crc sv4crc base64
+application/x-tar tar 8bit
+application/x-tcl tcl 8bit
+application/x-texinfo texinfo,texi 8bit
+application/x-tex tex 8bit
+application/x-troff-man man 8bit
+application/x-troff-me me
+application/x-troff-ms ms
+application/x-troff t,tr,roff 8bit
+application/x-ustar ustar base64
+application/x-wais-source src
+application/x-Wingz wz
+application/x-x509-ca-cert crt base64
+application/zip zip base64
+audio/32kadpcm
+audio/amr amr base64
+audio/amr-wb awb base64
+audio/basic au,snd base64
+audio/l16
+audio/midi mid,midi,kar base64
+audio/mpeg mpga,mp2,mp3 base64
+audio/prs.sid
+audio/telephone-event
+audio/tone
+audio/vnd.cns.anp1
+audio/vnd.cns.inf1
+audio/vnd.digital-winds
+audio/vnd.everad.plj
+audio/vnd.lucent.voice
+audio/vnd.nortel.vbk
+audio/vnd.nuera.ecelp4800
+audio/vnd.nuera.ecelp7470
+audio/vnd.octel.sbc
+audio/vnd.qcelp
+audio/vnd.rhetorex.32kadpcm
+audio/vnd.vmx.cvsd
+audio/x-aiff aif,aifc,aiff base64
+audio/x-pn-realaudio-plugin rpm
+audio/x-pn-realaudio rm,ram base64
+audio/x-realaudio ra base64
+audio/x-wav wav base64
+chemical/x-pdb pdb
+chemical/x-xyz xyz
+drawing/dwf dwf
+image/bmp bmp
+image/cgm
+image/g3fax
+image/gif gif base64
+image/ief ief base64
+image/jpeg jpeg,jpg,jpe base64
+image/naplps
+image/png png base64
+image/prs.btif
+image/prs.pti
+image/tiff tiff,tif base64
+image/vnd.cns.inf2
+image/vnd.dgn dgn
+image/vnd.dwg dwg
+image/vnd.dxf
+image/vnd.fastbidsheet
+image/vnd.fpx
+image/vnd.fst
+image/vnd.fujixerox.edmics-mmr
+image/vnd.fujixerox.edmics-rlc
+image/vnd.mix
+image/vnd.net-fpx
+image/vnd.svf
+image/vnd.wap.wbmp wbmp
+image/vnd.xiff
+image/x-cmu-raster ras
+image/x-portable-anymap pnm base64
+image/x-portable-bitmap pbm base64
+image/x-portable-graymap pgm base64
+image/x-portable-pixmap ppm base64
+image/x-rgb rgb base64
+image/x-xbitmap xbm 7bit
+image/x-xpixmap xpm 8bit
+image/x-xwindowdump xwd base64
+message/delivery-status
+message/disposition-notification
+message/external-body 8bit
+message/http
+message/news 8bit
+message/partial 8bit
+message/rfc822 8bit
+message/s-http
+model/iges igs,iges
+model/mesh msh,mesh,silo
+model/vnd.dwf
+model/vnd.flatland.3dml
+model/vnd.gdl
+model/vnd.gs-gdl
+model/vnd.gtw
+model/vnd.mts
+model/vnd.vtu
+model/vrml wrl,vrml
+multipart/alternative 8bit
+multipart/appledouble 8bit
+multipart/byteranges
+multipart/digest 8bit
+multipart/encrypted
+multipart/form-data
+multipart/header-set
+multipart/mixed 8bit
+multipart/parallel 8bit
+multipart/related
+multipart/report
+multipart/signed
+multipart/voice-message
+text/calendar
+text/css css 8bit
+text/comma-separated-values csv 8bit
+text/directory
+text/enriched
+text/html html,htm,htmlx,shtml,htx 8bit
+text/plain asc,txt,c,cc,h,hh,cpp,hpp,dat,hlp 8bit
+text/prs.lines.tag
+text/rfc822-headers
+text/richtext rtx 8bit
+text/rtf rtf
+text/sgml sgml,sgm
+text/t140
+text/tab-separated-values tsv
+text/uri-list
+text/vnd.abc
+text/vnd.curl
+text/vnd.DMClientScript
+text/vnd.flatland.3dml
+text/vnd.fly
+text/vnd.fmi.flexstor
+text/vnd.in3d.3dml
+text/vnd.in3d.spot
+text/vnd.IPTC.NewsML
+text/vnd.IPTC.NITF
+text/vnd.latex-z
+text/vnd.motorola.reflex
+text/vnd.ms-mediapackage
+text/vnd.wap.si
+text/vnd.wap.sl
+text/vnd.wap.wmlscript wmls
+text/vnd.wap.wml wml
+text/xml xml,dtd 8bit
+text/x-setext etx
+text/x-sgml sgml,sgm 8bit
+text/x-vCalendar vcs 8bit
+text/x-vCard vcf 8bit
+video/dl dl base64
+video/fli fli base64
+video/gl gl base64
+video/mpeg mp2,mpe,mpeg,mpg base64
+video/pointer
+video/quicktime qt,mov base64
+video/vnd.fvt
+video/vnd.motorola.video
+video/vnd.motorola.videop
+video/vnd.vivo
+video/x-ms-asf asf,asx
+video/x-msvideo avi base64
+video/x-sgi-movie movie base64
+x-conference/x-cooltalk ice
+x-world/x-vrml wrl,vrml
+
+# Exceptions
+
+vms:text/plain doc 8bit
+mac:application/x-macbase64 bin