Commit | Line | Data |
---|---|---|
86530b38 AT |
1 | ##---------------------------------------------------------------------------## |
2 | ## File: | |
3 | ## $Id: mhmimetypes.pl,v 1.11 2002/09/26 02:52:53 ehood Exp $ | |
4 | ## Author: | |
5 | ## Earl Hood mhonarc@mhonarc.org | |
6 | ## Description: | |
7 | ## MIME type mappings. | |
8 | ##---------------------------------------------------------------------------## | |
9 | ## MHonArc -- Internet mail-to-HTML converter | |
10 | ## Copyright (C) 1998,1999 Earl Hood, mhonarc@mhonarc.org | |
11 | ## | |
12 | ## This program is free software; you can redistribute it and/or modify | |
13 | ## it under the terms of the GNU General Public License as published by | |
14 | ## the Free Software Foundation; either version 2 of the License, or | |
15 | ## (at your option) any later version. | |
16 | ## | |
17 | ## This program is distributed in the hope that it will be useful, | |
18 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 | ## GNU General Public License for more details. | |
21 | ## | |
22 | ## You should have received a copy of the GNU General Public License | |
23 | ## along with this program; if not, write to the Free Software | |
24 | ## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | |
25 | ## 02111-1307, USA | |
26 | ##---------------------------------------------------------------------------## | |
27 | ||
28 | package mhonarc; | |
29 | ||
30 | $UnknownExt = 'bin'; | |
31 | ||
32 | %CTExt = ( | |
33 | ##----------------------------------------------------------------------- | |
34 | ## Content-Type Extension:Description | |
35 | ##----------------------------------------------------------------------- | |
36 | ||
37 | 'application/astound', 'asd:Astound presentation', | |
38 | 'application/envoy', 'evy:Envoy file', | |
39 | 'application/fastman', 'lcc:fastman file', | |
40 | 'application/fractals', 'fif:Fractal Image Format', | |
41 | 'application/iges', 'iges:IGES file', | |
42 | 'application/mac-binhex40', 'hqx:Mac BinHex archive', | |
43 | 'application/mathematica', 'ma:Mathematica Notebook document', | |
44 | 'application/mbedlet', 'mbd:mbedlet file', | |
45 | 'application/ms-excel', 'xls:MS-Excel spreadsheet', | |
46 | 'application/ms-powerpoint', 'ppt:MS-Powerpoint presentation', | |
47 | 'application/ms-project', 'mpp:MS-Project file', | |
48 | 'application/msword', 'doc:MS-Word document', | |
49 | 'application/octet-stream', 'bin:Binary data', | |
50 | 'application/oda', 'oda:ODA file', | |
51 | 'application/pdf', 'pdf:Adobe PDF document', | |
52 | 'application/pgp', 'pgp:PGP message', | |
53 | 'application/pgp-signature', 'pgp:PGP signature', | |
54 | 'application/postscript', 'ps,eps,ai:PostScript document', | |
55 | 'application/rtf', 'rtf:RTF file', | |
56 | 'application/sgml', 'sgml:SGML document', | |
57 | 'application/studiom', 'smp:Studio M file', | |
58 | 'application/timbuktu', 'tbt:timbuktu file', | |
59 | 'application/vis5d', 'v5d:Vis5D dataset', | |
60 | 'application/vnd.framemaker', 'fm:FrameMaker document', | |
61 | 'application/vnd.hp-hpgl', 'hpg,hpgl:HPGL file', | |
62 | 'application/vnd.lotus-1-2-3', '123,wk4,wk3,wk1:Lotus 1-2-3', | |
63 | 'application/vnd.lotus-approach', 'apr,vew:Lotus Approach', | |
64 | 'application/vnd.lotus-freelance', 'prz,pre:Lotus Freelance', | |
65 | 'application/vnd.lotus-organizer', 'org,or3,or2:Lotus Organizer', | |
66 | 'application/vnd.lotus-screencam', 'scm:Lotus Screencam', | |
67 | 'application/vnd.lotus-wordpro', 'lwp,sam:Lotus WordPro', | |
68 | 'application/vnd.mif', 'mif:Frame MIF document', | |
69 | 'application/vnd.ms-excel', 'xls:MS-Excel spreadsheet', | |
70 | 'application/vnd.ms-powerpoint', 'ppt:MS-Powerpoint presentation', | |
71 | 'application/vnd.ms-project', 'mpp:MS-Project file', | |
72 | 'application/vnd.stardivision.calc', 'sdc:StarCalc spreadsheet', | |
73 | 'application/vnd.stardivision.chart', 'sds:StarChart document', | |
74 | 'application/vnd.stardivision.draw', 'sda:StarDraw document', | |
75 | 'application/vnd.stardivision.impress-packed', 'sdp:StarImpress packed file', | |
76 | 'application/vnd.stardivision.impress', 'sdd:StarImpress presentation', | |
77 | 'application/vnd.stardivision.mail', 'smd:StarMail mail file', | |
78 | 'application/vnd.stardivision.math', 'smf:StarMath document', | |
79 | 'application/vnd.stardivision.writer-global', 'sgl:StarWriter global document', | |
80 | 'application/vnd.stardivision.writer', 'sdw:StarWriter document', | |
81 | 'application/vnd.sun.xml.calc', 'sxc:OpenOffice Calc spreadsheet', | |
82 | 'application/vnd.sun.xml.calc.template', 'stc:OpenOffice Calc template', | |
83 | 'application/vnd.sun.xml.draw', 'sxd:OpenOffice Draw document', | |
84 | 'application/vnd.sun.xml.draw.template', 'std:OpenOffice Draw Template', | |
85 | 'application/vnd.sun.xml.impress', 'sxi:OpenOffice Impress presentation', | |
86 | 'application/vnd.sun.xml.impress.template', 'sti:OpenOffice Impress template', | |
87 | 'application/vnd.sun.xml.math', 'sxm:OpenOffice Math documents', | |
88 | 'application/vnd.sun.xml.writer.global', 'sxg:OpenOffice Writer global document', | |
89 | 'application/vnd.sun.xml.writer', 'sxw:OpenOffice Writer document', | |
90 | 'application/vnd.sun.xml.writer.template', 'stw:OpenOffice Write template', | |
91 | 'application/winhlp', 'hlp:WinHelp document', | |
92 | 'application/wordperfect5.1', 'wp:WordPerfect 5.1 document', | |
93 | 'application/x-asap', 'asp:asap file', | |
94 | 'application/x-bcpio', 'bcpio:BCPIO file', | |
95 | 'application/x-bzip2', 'bz2:BZip2 compressed data', | |
96 | 'application/x-compress', 'Z:Unix compressed data', | |
97 | 'application/x-cpio', 'cpio:CPIO file', | |
98 | 'application/x-csh', 'csh:C-Shell script', | |
99 | 'application/x-dot', 'dot:dot file', | |
100 | 'application/x-dvi', 'dvi:TeX dvi file', | |
101 | 'application/x-earthtime', 'etc:Earthtime file', | |
102 | 'application/x-envoy', 'evy:Envoy file', | |
103 | 'application/x-excel', 'xls:MS-Excel spreadsheet', | |
104 | 'application/x-gtar', 'gtar:GNU Unix tar archive', | |
105 | 'application/x-gzip', 'gz:GNU Zip compressed data', | |
106 | 'application/x-hdf', 'hdf:HDF file', | |
107 | 'application/x-javascript', 'js:JavaScript source', | |
108 | 'application/x-ksh', 'ksh:Korn Shell script', | |
109 | 'application/x-latex', 'latex:LaTeX document', | |
110 | 'application/x-maker', 'fm:FrameMaker document', | |
111 | 'application/x-mif', 'mif:Frame MIF document', | |
112 | 'application/x-mocha', 'moc:mocha file', | |
113 | 'application/x-msaccess', 'mdb:MS-Access database', | |
114 | 'application/x-mscardfile', 'crd:MS-CardFile', | |
115 | 'application/x-msclip', 'clp:MS-Clip file', | |
116 | 'application/x-msmediaview', 'm14:MS-Media View file', | |
117 | 'application/x-msmetafile', 'wmf:MS-Metafile', | |
118 | 'application/x-msmoney', 'mny:MS-Money file', | |
119 | 'application/x-mspublisher', 'pub:MS-Publisher document', | |
120 | 'application/x-msschedule', 'scd:MS-Schedule file', | |
121 | 'application/x-msterminal', 'trm:MS-Terminal', | |
122 | 'application/x-mswrite', 'wri:MS-Write document', | |
123 | 'application/x-netcdf', 'cdf:Cdf file', | |
124 | 'application/x-net-install', 'ins:Net Install file', | |
125 | 'application/x-ns-proxy-autoconfig','proxy:Netscape Proxy Auto Config', | |
126 | 'application/x-patch', 'patch:Source code patch', | |
127 | 'application/x-perl', 'pl:Perl program', | |
128 | 'application/x-pointplus', 'css:pointplus file', | |
129 | 'application/x-salsa', 'slc:salsa file', | |
130 | 'application/x-script', 'script:A script file', | |
131 | 'application/x-shar', 'shar:Unix shell archive', | |
132 | 'application/x-sh', 'sh:Bourne shell script', | |
133 | 'application/x-sprite', 'spr:sprite file', | |
134 | 'application/x-stuffit', 'sit:Macintosh archive', | |
135 | 'application/x-sv4cpio', 'sv4cpio:SV4Cpio file', | |
136 | 'application/x-sv4crc', 'sv4crc:SV4Crc file', | |
137 | 'application/x-tar', 'tar:Unix tar archive', | |
138 | 'application/x-tcl', 'tcl:Tcl script', | |
139 | 'application/x-texinfo', 'texinfo:TeXInfo document', | |
140 | 'application/x-tex', 'tex:TeX document', | |
141 | 'application/x-timbuktu', 'tbp:timbuktu file', | |
142 | 'application/x-tkined', 'tki:tkined file', | |
143 | 'application/x-troff-man', 'man:Unix manual page', | |
144 | 'application/x-troff-me', 'me:Troff ME-macros document', | |
145 | 'application/x-troff-ms', 'ms:Troff MS-macros document', | |
146 | 'application/x-troff', 'roff:Troff document', | |
147 | 'application/x-ustar', 'ustar:UStar file', | |
148 | 'application/x-wais-source', 'src:WAIS Source', | |
149 | 'application/x-zip-compressed', 'zip:Zip compressed data', | |
150 | 'application/zip', 'zip:Zip archive', | |
151 | ||
152 | 'audio/basic', 'snd:Basic audio', | |
153 | 'audio/echospeech', 'es:Echospeech audio', | |
154 | 'audio/microsoft-wav', 'wav:Wave audio', | |
155 | 'audio/midi', 'midi:MIDI audio', | |
156 | 'audio/wav', 'wav:Wave audio', | |
157 | 'audio/x-aiff', 'aif,aiff,aifc:AIF audio', | |
158 | 'audio/x-epac', 'pae:epac audio', | |
159 | 'audio/x-midi', 'midi:MIDI audio', | |
160 | 'audio/x-mpeg', 'mp2:MPEG audio', | |
161 | 'audio/x-pac', 'pac:pac audio', | |
162 | 'audio/x-pn-realaudio', 'ra,ram:PN Realaudio', | |
163 | 'audio/x-wav', 'wav:Wave audio', | |
164 | ||
165 | 'chemical/chem3d', 'c3d:Chem3d chemical test', | |
166 | 'chemical/chemdraw', 'chm:Chemdraw chemical test', | |
167 | 'chemical/cif', 'cif:CIF chemical test', | |
168 | 'chemical/cml', 'cml:CML chemical test', | |
169 | 'chemical/cmsl', 'cml:Chemical Structure Markup', | |
170 | 'chemical/cxf', 'cxf:Chemical Exhange Format file', | |
171 | 'chemical/daylight-smiles', 'smi:SMILES format file', | |
172 | 'chemical/embl-dl-nucleotide', 'emb,embl:EMBL nucleotide format file', | |
173 | 'chemical/gaussian', 'gau:Gaussian data', | |
174 | 'chemical/gaussian-input', 'gau:Gaussian input data', | |
175 | 'chemical/gaussian-log', 'gal:Gaussian log', | |
176 | 'chemical/gcg8-sequence', 'gcg:GCG format file', | |
177 | 'chemical/genbank', 'gen:GENbank data', | |
178 | 'chemical/jcamp-dx', 'jdx:Jcamp chemical spectra test', | |
179 | 'chemical/kinemage', 'kin:Kinemage', | |
180 | 'chemical/macromodel-input', 'mmd,mmod:Macromodel chemical test', | |
181 | 'chemical/mopac-input', 'gau:Mopac chemical test', | |
182 | 'chemical/mdl-molfile', 'mol:MOL mdl chemical test', | |
183 | 'chemical/mdl-rdf', 'rdf:RDF chemical test', | |
184 | 'chemical/mdl-rxn', 'rxn:RXN chemical test', | |
185 | 'chemical/mdl-sdf', 'sdf:SDF chemical test', | |
186 | 'chemical/mdl-tgf', 'tgf:TGF chemical test', | |
187 | 'chemical/mif', 'mif:MIF chemical test', | |
188 | 'chemical/mmd', 'mmd:Macromodel data', | |
189 | 'chemical/mopac-input', 'mop:MOPAC data ', | |
190 | 'chemical/ncbi-asn1', 'asn:NCBI data', | |
191 | 'chemical/pdb', 'pdb:Protein Databank data', | |
192 | 'chemical/rosdal', 'ros:Rosdal data', | |
193 | 'chemical/xyz', 'xyz:Xmol XYZ data', | |
194 | ||
195 | 'image/bmp', 'bmp:Windows bitmap', | |
196 | 'image/cgm', 'cgm:Computer Graphics Metafile', | |
197 | 'image/fif', 'fif:Fractal Image Format image', | |
198 | 'image/g3fax', 'g3f:Group III FAX image', | |
199 | 'image/gif', 'gif:GIF image', | |
200 | 'image/ief', 'ief:IEF image', | |
201 | 'image/ifs', 'ifs:IFS image', | |
202 | 'image/jpeg', 'jpg,jpeg,jpe:JPEG image', | |
203 | 'image/pbm', 'pbm:Portable bitmap', | |
204 | 'image/pgm', 'pgm:Portable graymap', | |
205 | 'image/png', 'png:PNG image', | |
206 | 'image/tiff', 'tif,tiff:TIFF image', | |
207 | 'image/vnd', 'dwg:VND image', | |
208 | 'image/wavelet', 'wi:Wavelet image', | |
209 | 'image/x-cmu-raster', 'ras:CMU raster', | |
210 | 'image/x-pbm', 'pbm:Portable bitmap', | |
211 | 'image/x-pcx', 'pcx:PCX image', | |
212 | 'image/x-pgm', 'pgm:Portable graymap', | |
213 | 'image/x-pict', 'pict:Mac PICT image', | |
214 | 'image/x-pnm', 'pnm:Portable anymap', | |
215 | 'image/x-portable-anymap', 'pnm:Portable anymap', | |
216 | 'image/x-portable-bitmap', 'pbm:Portable bitmap', | |
217 | 'image/x-portable-graymap', 'pgm:Portable graymap', | |
218 | 'image/x-portable-pixmap', 'ppm:Portable pixmap', | |
219 | 'image/x-ppm', 'ppm:Portable pixmap', | |
220 | 'image/x-rgb', 'rgb:RGB image', | |
221 | 'image/x-xbitmap', 'xbm:X bitmap', | |
222 | 'image/x-xbm', 'xbm:X bitmap', | |
223 | 'image/x-xpixmap', 'xpm:X pixmap', | |
224 | 'image/x-xpm', 'xpm:X pixmap', | |
225 | 'image/x-xwd', 'xwd:X window dump', | |
226 | 'image/x-xwindowdump', 'xwd:X window dump', | |
227 | ||
228 | 'message/rfc822', '822:Mail message', | |
229 | 'message/news', '822:News post', | |
230 | ||
231 | 'model/iges', 'iges:IGES model', | |
232 | 'model/vrml', 'wrl:VRML model', | |
233 | 'model/mesh', 'mesh:Mesh model', | |
234 | ||
235 | 'text/enriched', 'rtx:Text-enriched document', | |
236 | 'text/html', 'html:HTML document', | |
237 | 'text/plain', 'txt:Text document', | |
238 | 'text/richtext', 'rtx:Richtext document', | |
239 | 'text/setext', 'stx:Setext document', | |
240 | 'text/sgml', 'sgml:SGML document', | |
241 | 'text/tab-separated-values', 'tsv:Tab separated values', | |
242 | 'text/x-speech', 'talk:Speech document', | |
243 | ||
244 | 'video/isivideo', 'fvi:isi video', | |
245 | 'video/mpeg', 'mpg,mpeg,mpe:MPEG movie', | |
246 | 'video/msvideo', 'avi:MS Video', | |
247 | 'video/quicktime', 'mov,qt:QuickTime movie', | |
248 | 'video/vivo', 'viv:vivo video', | |
249 | 'video/wavelet', 'wv:Wavelet video', | |
250 | 'video/x-sgi-movie', 'movie:SGI movie', | |
251 | ||
252 | ); | |
253 | ||
254 | ##--------------------------------------------------------------------------- | |
255 | ## get_mime_ext(): Get the prefered filename extension and a | |
256 | ## a brief description of a given mime type. | |
257 | ## | |
258 | sub get_mime_ext { | |
259 | my $ctype = lc shift; | |
260 | my($ext, $desc) = (undef, undef); | |
261 | ||
262 | if (defined($CTExt{$ctype})) { | |
263 | ($ext, $desc) = split(/:/, $CTExt{$ctype}, 2); | |
264 | } elsif (($ctype =~ s|/x-|/|) && defined($CTExt{$ctype})) { | |
265 | ($ext, $desc) = split(/:/, $CTExt{$ctype}, 2); | |
266 | } | |
267 | if (defined($ext)) { | |
268 | $ext = (split(/,/, $ext))[0]; | |
269 | } elsif ($ctype =~ /^text\//) { | |
270 | $ext = 'txt'; | |
271 | $desc = 'Text Data'; | |
272 | } else { | |
273 | $ext = $UnknownExt; | |
274 | $desc = $ctype; | |
275 | } | |
276 | ($ext, $desc); | |
277 | } | |
278 | ||
279 | ##--------------------------------------------------------------------------- | |
280 | ## write_attachment(): Write data to a file with a given content-type. | |
281 | ## Function can be used by content-type filters for writing data | |
282 | ## to a file. | |
283 | ## | |
284 | sub write_attachment { | |
285 | my $content = lc shift; | |
286 | my $sref = shift; | |
287 | my $path = shift; | |
288 | my $fname = shift; | |
289 | my $inext = shift; | |
290 | my($ctype, $cnt, $pre, $ext, $pathname); | |
291 | ||
292 | ($ctype) = $content =~ m%^\s*([\w\-\./]+)%; # Extract content-type | |
293 | ||
294 | local(*OUTFILE); | |
295 | ||
296 | $pathname = $OUTDIR; | |
297 | if ($path) { | |
298 | $pathname .= $DIRSEP . $path; | |
299 | mkdir($pathname, 0777); | |
300 | } | |
301 | ||
302 | ## If no filename specified, generate it | |
303 | if (!$fname) { | |
304 | ($cnt, $pre, $ext) = get_cnt($ctype, $pathname, $inext); | |
305 | $fname = $pre . $cnt . '.' . $ext; | |
306 | ||
307 | ## Else, filename given | |
308 | } else { | |
309 | $fname =~ tr/ \t\n\r/_/; # Convert spaces to underscore | |
310 | } | |
311 | ||
312 | ## Set pathname for file | |
313 | $pathname .= $DIRSEP . $fname; | |
314 | ||
315 | if (open(OUTFILE, "> $pathname")) { | |
316 | binmode(OUTFILE); # For WinDog | |
317 | print OUTFILE $$sref; | |
318 | close(OUTFILE); | |
319 | } else { | |
320 | warn qq/Warning: Unable to create "$pathname": $!\n/; | |
321 | } | |
322 | ||
323 | join("", | |
324 | ($mhonarc::SINGLE ? $mhonarc::OUTDIR.$mhonarc::DIRSEP : ""), | |
325 | ($path ? join($mhonarc::DIRSEP,$path,$fname) : $fname)); | |
326 | } | |
327 | ||
328 | ##--------------------------------------------------------------------------- | |
329 | ## get_cnt(): Function that returns a list which can be used to | |
330 | ## generate a unique filename for a given content-type. | |
331 | ## | |
332 | sub get_cnt { | |
333 | my $ctype = shift; # content-type | |
334 | my $dir = shift || $CURDIR; # directory | |
335 | my $inext = shift; # passed in extension (optional) | |
336 | ||
337 | my(@files) = (); | |
338 | my $ext = $inext || (get_mime_ext($ctype))[0]; | |
339 | my $pre = $ext; | |
340 | my $cnt = -1; | |
341 | local(*DIR); | |
342 | ||
343 | substr($pre, 3) = "" if length($pre) > 3; | |
344 | ||
345 | if (!opendir(DIR, $dir)) { | |
346 | warn qq/Warning: Unable to open "$dir": $!\n/; | |
347 | } else { | |
348 | my($file, $num); | |
349 | foreach $file (grep(/^$pre\d+\.$ext$/i, readdir(DIR))) { | |
350 | $num = substr($file, length($pre)); | |
351 | $num = substr($num, 0, length($num)-(length($ext)+1)); | |
352 | $cnt = $num if $num > $cnt; | |
353 | } | |
354 | close(DIR); | |
355 | } | |
356 | ++$cnt; | |
357 | (sprintf("%05d", $cnt), $pre, $ext); | |
358 | } | |
359 | ||
360 | ##--------------------------------------------------------------------------- | |
361 | ||
362 | sub dump_ctext_hash { | |
363 | local($_); | |
364 | foreach (sort keys %CTExt) { | |
365 | print STDERR $_,":",$CTExt{$_},"\n"; | |
366 | } | |
367 | } | |
368 | ||
369 | ##--------------------------------------------------------------------------- | |
370 | 1; |