[plug] MIME Types by file contents

Bernd Felsche bernie at innovative.iinet.net.au
Mon Jul 5 01:57:57 WST 2004


I've almost finished the Python MIME mailer.

One problem I encountered was with the known MIME types having
dubious mappings to filename extensions. The code works around that
by using it's own "definitive" map of MIME type to extension.

The other problem that I've encountered and not yet resolved is with
the Python email module not liking news articles in particular.

I get a bunch of errors like:
bernie at pinion:~> python bin/maildoc.py bernie < z25 
Traceback (most recent call last):
  File "bin/maildoc.py", line 143, in ?
    if __name__ == '__main__': main()
  File "bin/maildoc.py", line 140, in main
    os.popen("/usr/sbin/sendmail -t","w").write(message.as_string())
  File "/var/tmp/python-2.2.2-build//usr/lib/python2.2/email/Message.py", line 107, in as_string
  File "/var/tmp/python-2.2.2-build//usr/lib/python2.2/email/Generator.py", line 100, in flatten
  File "/var/tmp/python-2.2.2-build//usr/lib/python2.2/email/Generator.py", line 128, in _write
  File "/var/tmp/python-2.2.2-build//usr/lib/python2.2/email/Generator.py", line 154, in _dispatch
  File "/var/tmp/python-2.2.2-build//usr/lib/python2.2/email/Generator.py", line 243, in _handle_multipart
  File "/var/tmp/python-2.2.2-build//usr/lib/python2.2/email/Generator.py", line 100, in flatten
  File "/var/tmp/python-2.2.2-build//usr/lib/python2.2/email/Generator.py", line 128, in _write
  File "/var/tmp/python-2.2.2-build//usr/lib/python2.2/email/Generator.py", line 154, in _dispatch
  File "/var/tmp/python-2.2.2-build//usr/lib/python2.2/email/Generator.py", line 302, in _handle_message
  File "/var/tmp/python-2.2.2-build//usr/lib/python2.2/email/Message.py", line 179, in get_payload
TypeError: 0

whenever I feed it a saved news item. It'll probably hiccup on email as well.

Other than that, it seems to handle any other input reliably; though
I've not done any cross-platform stuff yet.

See the attached bugfest for details.

-- 
/"\ Bernd Felsche - Innovative Reckoning, Perth, Western Australia
\ /  ASCII ribbon campaign | I'm a .signature virus!
 X   against HTML mail     | Copy me into your ~/.signature
/ \  and postings          | to help me spread!

-------------- next part --------------
A non-text attachment was scrubbed...
Name: maildoc.py
Type: text/x-python
Size: 3602 bytes
Desc: not available
URL: <http://lists.plug.org.au/pipermail/plug/attachments/20040705/c03f6c5b/attachment.py>
-------------- next part --------------
application/EDI-Consent	edi
application/EDI-X12	edix12
application/EDIFACT	edifact
application/andrew-inset	ez
application/cu-seeme	csm
application/excel	xls
application/mac-binhex40	hqx
application/mac-compactpro	cpt
application/msword	doc
application/netscape-ps	ps
application/octet-stream	bin
application/oda	oda
application/pdf	pdf
application/pgp-signature	pgp
application/postscript	ps
application/powerpoint	ppt
application/rtf	rtf
application/sdp	sdp
application/sgml	sgml
application/sieve	sieve
application/smil	smil
application/vnd.hp-HPGL	hpgl
application/vnd.hp-PCL	pcl
application/vnd.hp-PCLXL	pclxl
application/vnd.mif	mif
application/vnd.ms-excel	xls
application/vnd.ms-powerpoint	ppt
application/vnd.ms-tnef	tnef
application/vnd.rn-realmedia	rm
application/vnd.visio	visio
application/vnd.wap.wbxml	wbxml
application/vnd.wap.wmlc	wmlc
application/vnd.wap.wmlscriptc	wmlsc
application/wordperfect5.1	wp5
application/x-123	wk
application/x-Wingz	wz
application/x-bcpio	bcpio
application/x-bzip2	bz2
application/x-cdlink	vcd
application/x-chess-pgn	pgn
application/x-compress	z
application/x-cpio	cpio
application/x-csh	csh
application/x-cshell	csh
application/x-debian-package	deb
application/x-director	dir
application/x-dvi	dvi
application/x-futuresplash	spl
application/x-gtar	gtar
application/x-gunzip	gz
application/x-gzip	gz
application/x-hdf	hdf
application/x-httpd-php	phtml
application/x-javascript	js
application/x-kchart	chrt
application/x-koan	skp
application/x-kpresenter	kpr
application/x-kspread	ksp
application/x-kword	kwd
application/x-latex	latex
application/x-maker	frm
application/x-mif	mif
application/x-msdos-program	com
application/x-netcdf	cdf
application/x-ns-proxy-autoconfig	pac
application/x-perl	pl
application/x-rad	rad
application/x-rpm	rpm
application/x-sdp	sdp
application/x-sh	sh
application/x-shar	shar
application/x-shell	sh
application/x-shockwave-flash	swf
application/x-shockwave-flash2-preview	swf
application/x-stuffit	sit
application/x-sv4cpio	sv4cpio
application/x-sv4crc	sv4crc
application/x-tar	tar
application/x-tcl	tcl
application/x-texinfo	texi
application/x-troff	t
application/x-troff-man	man
application/x-troff-me	me
application/x-troff-ms	ms
application/x-ustar	ustar
application/x-wais-source	src
application/xhtml+xml	xhtml
application/xml	xml
application/xml-dtd	dtd
application/zip	zip
audio/basic	au
audio/midi	midi
audio/mpeg	mpga
audio/vnd.rn-realaudio	ra
audio/x-aiff	aiff
audio/x-mpegurl	m3u
audio/x-pn-realaudio	ram
audio/x-pn-realaudio-plugin	rpm
audio/x-realaudio	ra
audio/x-wav	wav
chemical/x-pdb	pdb
chemical/x-xyz	xyz
image/bmp	bmp
image/cgm	cgn
image/fpx	fpx
image/g3fax	g3
image/gif	gif
image/ief	ief
image/jpeg	jpeg
image/png	png
image/tiff	tiff
image/vnd.djvu	djvu
image/vnd.dwg	dwg
image/vnd.dxf	dxf
image/vnd.fpx	fpx
image/vnd.fst	fst
image/vnd.net-fpx	fpx
image/vnd.rn-realflash	swf
image/vnd.rn-realpix	rp
image/vnd.svf	svf
image/vnd.wap.wbmp	wbmp
image/vnd.xiff	xiff
image/x-alias	pix
image/x-bitmap	bmp
image/x-cmu-raster	ras
image/x-photocd	pcd
image/x-portable-anymap	pnm
image/x-portable-bitmap	pbm
image/x-portable-graymap	pgm
image/x-portable-pixmap	ppm
image/x-rgb	rgb
image/x-sgi-rgb	rgb
image/x-sun-raster	ras
image/x-xbitmap	xbm
image/x-xpixmap	xpm
image/x-xwindowdump	xwd
message/news	news
message/rfc822	rfc822
message/s-http	shttp
model/iges	iges
model/mesh	mesh
model/vnd.dwf	dwf
model/vnd.flatland.3dml	3dml
model/vnd.gdl	gdl
model/vnd.gtw	gtw
model/vnd.mts	mts
model/vnd.vtu	vtu
model/vrml	vrml
text/calendar	cal
text/css	css
text/html	html
text/plain	txt
text/rfc822-headers .rfc822
text/richtext	rtx
text/rtf	rtf
text/sgml	sgml
text/tab-separated-values	tsv
text/vnd.rn-realtext	rt
text/vnd.wap.wml	wml
text/vnd.wap.wmlscript	wmls
text/x-setext	etx
text/x-vCalendar	vcs
text/x-vCard	vcf
text/xml	xml
video/dl	dl
video/fli	fli
video/gl	gl
video/mpeg	mpeg
video/quicktime	qt
video/vnd.fvt	fvt
video/vnd.mpegurl	mxu
video/vnd.rn-realvideo	rv
video/vnd.vivo	vivo
video/x-msvideo	avi
video/x-sgi-movie	movie
x-conference/x-cooltalk	ice
x-world/x-vrml	vrml


More information about the plug mailing list