[plug] Emailing - gotchas

Craig Ringer craig at postnewspapers.com.au
Thu Jul 1 14:48:10 WST 2004


Bernd Felsche wrote:

> It assumes that the attached is a PDF so it doesn't save me any
> work.... I know that
> 	file -i 
> gives me about the MIME type. (Doffs hat) But there was no way I
> could provide that as an argument to "nail" or any other
> command-line based MUA.

OK.

> "MimeTypes" appears to do something usefully similar. But I'm not
> sure if it actually reads the file to determine content type.

If all you're worried about is PDFs, then:

def ispdf(filepath):
	return file(filepath).read(4) == '%PDF'

should do the trick nicely. It's not hard to generalise that to handle 
any other format kind enough to use magic numbers or header codes.

--
Craig Ringer




More information about the plug mailing list