Okay images, better zip handling. [rsc] --rwxrwxr-x M 956468 rsc sys 1144 Oct 6 00:10 mail/lib/validateattachment /n/sourcesdump/2005/1006/plan9/mail/lib/validateattachment:1,4 - /n/sourcesdump/2005/1007/plan9/mail/lib/validateattachment:1,5 #!/bin/rc + rfork n # exit status matching: # /n/sourcesdump/2005/1006/plan9/mail/lib/validateattachment:13,35 - /n/sourcesdump/2005/1007/plan9/mail/lib/validateattachment:14,53 } echo validating >[1=2] + 9fs other + fn save { + d=`{date -n} + cp body /n/other/upas/tmp/$d.$1 + cp raw /n/other/upas/tmp/$d.$1.raw + whatis x >/n/other/upas/tmp/$d.$1.file + } upas/fs -f $1 cd /mail/fs/mbox/1 - x=`{file body} + x=`{file body | sed s/body://} x=$"x switch($x){ case *Ascii* *text* *'c program'* *'rc executable'* + save accept exit accept case *'zip archive'* - if(unzip -tsf body | grep -si ' |\.(scr|exe|pif|bat|com)$'){ + # >[2=1] because sometimes we get zip files we can't parse + # but the errors look like + # unzip: reading data for philw.doc.scr failed: ... + # so we can still catch these. + if(unzip -tsf body >[2=1] | grep -si ' |\.(scr|exe|pif|bat|com)$'){ echo executables inside zip file! exit discard } + case jpeg 'PNG image' bmp 'GIF image' *'plan 9 image' + save accept + exit accept + case *Microsoft* *Office* + save wrap exit wrap case *MSDOS* /n/sourcesdump/2005/1006/plan9/mail/lib/validateattachment:38,43 - /n/sourcesdump/2005/1007/plan9/mail/lib/validateattachment:56,62 exit discard } + save wrap exit wrap