validateattachment 680 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/bin/rc
  2. # exit status matching:
  3. #
  4. # *discard* - is really bad, refuse the message
  5. # *accept* - is really good, leave attachment alone
  6. # * - rewrite attachment to have .suspect extension
  7. #
  8. if(! ~ $#* 1){
  9. echo usage: validateattachment mboxfile >[1=2]
  10. exit usage
  11. }
  12. echo validating >[1=2]
  13. upas/fs -f $1
  14. cd /mail/fs/mbox/1
  15. x=`{file body}
  16. x=$"x
  17. switch($x){
  18. case *Ascii* *text* *'c program'* *'rc executable'*
  19. exit accept
  20. case *'zip archive'*
  21. if(unzip -tsf body | grep -si ' |\.(scr|exe|pif|bat|com)$'){
  22. echo executables inside zip file!
  23. exit discard
  24. }
  25. case *Microsoft* *Office*
  26. exit wrap
  27. case *MSDOS*
  28. # no executables
  29. echo $x
  30. exit discard
  31. }
  32. exit wrap