4 define(
'APACHE_MIME_TYPES_URL',
'http://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types');
5 define(
'FREEDESKTOP_XML_URL',
'https://raw2.github.com/minad/mimemagic/master/script/freedesktop.org.xml');
9 $preamble =
"<?php\n\n";
11 $preamble .=
" * This file is part of SwiftMailer.\n";
12 $preamble .=
" * (c) 2004-2009 Chris Corbyn\n *\n";
13 $preamble .=
" * For the full copyright and license information, please view the LICENSE\n";
14 $preamble .=
" * file that was distributed with this source code.\n *\n";
15 $preamble .=
" * autogenerated using http://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types\n";
16 $preamble .=
" * and https://raw.github.com/minad/mimemagic/master/script/freedesktop.org.xml\n";
17 $preamble .=
" */\n\n";
19 $preamble .=
" * List of MIME type automatically detected in Swift Mailer.\n";
20 $preamble .=
" */\n\n";
21 $preamble .=
"// You may add or take away what you like (lowercase required)\n\n";
28 $valid_mime_types = array();
31 if (preg_match_all(
'/^#?([a-z0-9\-\+\/\.]+)[\t]+(.*)$/miu', $mime_types, $matches) !==
false) {
33 $valid_mime_types_preset = array(
34 'php' =>
'application/x-php',
35 'php3' =>
'application/x-php',
36 'php4' =>
'application/x-php',
37 'php5' =>
'application/x-php',
38 'zip' =>
'application/zip',
42 'js' =>
'text/javascript',
43 'txt' =>
'text/plain',
44 'aif' =>
'audio/x-aiff',
45 'aiff' =>
'audio/x-aiff',
48 'bz2' =>
'application/x-bz2',
50 'dmg' =>
'application/x-apple-diskimage',
51 'doc' =>
'application/msword',
52 'docx' =>
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
53 'eml' =>
'message/rfc822',
54 'aps' =>
'application/postscript',
55 'exe' =>
'application/x-ms-dos-executable',
56 'flv' =>
'video/x-flv',
57 'gz' =>
'application/x-gzip',
58 'hqx' =>
'application/stuffit',
60 'html' =>
'text/html',
61 'jar' =>
'application/x-java-archive',
62 'jpeg' =>
'image/jpeg',
63 'jpg' =>
'image/jpeg',
64 'm3u' =>
'audio/x-mpegurl',
66 'mdb' =>
'application/x-msaccess',
67 'mid' =>
'audio/midi',
68 'midi' =>
'audio/midi',
69 'mov' =>
'video/quicktime',
70 'mp3' =>
'audio/mpeg',
72 'mpeg' =>
'video/mpeg',
73 'mpg' =>
'video/mpeg',
74 'odg' =>
'vnd.oasis.opendocument.graphics',
75 'odp' =>
'vnd.oasis.opendocument.presentation',
76 'odt' =>
'vnd.oasis.opendocument.text',
77 'ods' =>
'vnd.oasis.opendocument.spreadsheet',
79 'pdf' =>
'application/pdf',
80 'ppt' =>
'application/vnd.ms-powerpoint',
81 'pptx' =>
'application/vnd.openxmlformats-officedocument.presentationml.presentation',
82 'ps' =>
'application/postscript',
83 'rar' =>
'application/x-rar-compressed',
84 'rtf' =>
'application/rtf',
85 'tar' =>
'application/x-tar',
86 'sit' =>
'application/x-stuffit',
87 'svg' =>
'image/svg+xml',
88 'tif' =>
'image/tiff',
89 'tiff' =>
'image/tiff',
90 'ttf' =>
'application/x-font-truetype',
91 'vcf' =>
'text/x-vcard',
93 'wma' =>
'audio/x-ms-wma',
94 'wmv' =>
'audio/x-ms-wmv',
95 'xls' =>
'application/excel',
96 'xlsx' =>
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
97 'xml' =>
'application/xml',
101 foreach ($valid_mime_types_preset as $extension => $mime_type) {
103 $valid_mime_types[$extension] =
"'{$extension}' => '{$mime_type}'";
107 $valid_extensions = array();
110 foreach ($matches[2] as $i => $extensions) {
112 $extensions = explode(
' ', strtolower($extensions));
115 if (!is_array($extensions)) {
116 $extensions = array($extensions);
119 foreach ($extensions as $extension) {
121 $mime_type = $matches[1][$i];
124 if (strlen($extension) < 10) {
126 $valid_extensions[] = $extension;
128 if (!isset($valid_mime_types[$mime_type])) {
130 $valid_mime_types[$extension] =
"'{$extension}' => '{$mime_type}'";
137 $xml = simplexml_load_string($mime_xml);
139 foreach ($xml as $node) {
141 if (!isset($node->glob[
'pattern'])) {
146 foreach ((array) $node->glob[
'pattern'] as $extension) {
148 if (strpos($extension,
'.') ===
false) {
153 $extension = explode(
'.', strtolower($extension));
154 $extension = end($extension);
157 if (strlen($extension) <= 9) {
158 $valid_extensions[] = $extension;
162 if (isset($node->glob[
'pattern'][0])) {
164 $mime_type = strtolower((
string) $node[
'type']);
167 $extension = strtolower(trim($node->glob[
'ddpattern'][0],
'*.'));
170 if (strpos($extension,
'.') !==
false || strlen($extension) < 1 || strlen($extension) > 9) {
175 if (!isset($valid_mime_types[$mime_type])) {
177 $valid_mime_types[$extension] =
"'{$extension}' => '{$mime_type}'";
183 $valid_mime_types = array_unique($valid_mime_types);
184 ksort($valid_mime_types);
187 $output =
"$preamble\$swift_mime_types = array(\n ".implode($valid_mime_types,
",\n ").
"\n);";
190 @file_put_contents(
'./mime_types.php', $output);