I'm not saying that it is 100% safe (can you ever be 100% safe?), But here is something you can try:
Suppose you have an alias for your postfix (or any other mail system) that redirects incoming messages to a php / bash / python script for further processing.
The first thing I would like to do is use the image manipulation library (say imagemagick) and convert all incoming files to .png format or something else, and just continue your logic if the conversion is successful.
Thus, if someone sends you any malicious attachments (php exploit, jar's, swf's, anything), the conversion will fail and, therefore, it will be ignored by your system.
Edit: ImageMagick has an "ident" command that does exactly what you want.
Iraklis
source share