validateattachment 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/bin/rc
  2. rfork n
  3. # exit status matching:
  4. #
  5. # *discard* - is really bad, refuse the message
  6. # *accept* - is really good, leave attachment alone
  7. # * - rewrite attachment to have .suspect extension
  8. #
  9. if(! ~ $#* 1){
  10. echo usage: validateattachment mboxfile >[1=2]
  11. exit usage
  12. }
  13. echo validating >[1=2]
  14. 9fs other
  15. fn save {
  16. d=`{date -n}
  17. cp body /n/other/upas/tmp/$d.$1
  18. cp raw /n/other/upas/tmp/$d.$1.raw
  19. whatis x >/n/other/upas/tmp/$d.$1.file
  20. }
  21. upas/fs -f $1
  22. cd /mail/fs/mbox/1
  23. x=`{file body | sed s/body://}
  24. x=$"x
  25. switch($x){
  26. case *Ascii* *text* *'c program'* *'rc executable'*
  27. save accept
  28. exit accept
  29. case *'zip archive'*
  30. # >[2=1] because sometimes we get zip files we can't parse
  31. # but the errors look like
  32. # unzip: reading data for philw.doc.scr failed: ...
  33. # so we can still catch these.
  34. if(unzip -tsf body >[2=1] | grep -si ' |\.(scr|exe|pif|bat|com)$'){
  35. echo executables inside zip file!
  36. exit discard
  37. }
  38. case jpeg 'PNG image' bmp 'GIF image' *'plan 9 image'
  39. save accept
  40. exit accept
  41. case *Microsoft* *Office*
  42. save wrap
  43. exit wrap
  44. case *MSDOS*
  45. # no executables
  46. echo $x
  47. exit discard
  48. }
  49. save wrap
  50. exit wrap