blob: 74018d0e3e9f889be49d929296b0b3626c1ee9cc [file] [log] [blame]
rsc0e6fee12006-04-09 00:24:14 +00001#!/usr/local/plan9/bin/rc
2rfork n
3
4. 9.rc
5
6# exit status matching:
7#
rscfc46abd2006-04-12 13:10:08 +00008# $discard - is really bad, refuse the message
9# $accept - is really good, leave attachment alone
10# anything else - rewrite attachment to have .suspect extension
rsc0e6fee12006-04-09 00:24:14 +000011#
12
13# magic exit statuses known to vf
14accept=10
15discard=13
16
17wrap=123 # anything but 10, 13
18
19if(! ~ $#* 1){
20 echo usage: validateattachment mboxfile >[1=2]
21 exit usage
22}
23
rscfc46abd2006-04-12 13:10:08 +000024# some idiot virus is sending around attachments marked as .zip
25# that are completely bogus and just say %TS_ZIP_ATTACH%
26# as the base64 encoding of the zip file. gmail rejects all zip
27# attachments when we forward them, so nip this one here.
28if(grep -s '^%TS_ZIP_ATTACH%$' $1 && ~ `{wc -l <$1} 1 2 3 4 5 6 7 8 9 10){
29 echo bogus zip file!
30 exit $discard
31}
32
rsc0e6fee12006-04-09 00:24:14 +000033upas/unvf < $1 >$1.unvf
34file=$1.unvf
35fn sigexit { rm $file }
36
37fn save {
38# d=`{date -n}
39# cp $file /n/other/upas/tmp/$d.$1
40# cp raw /n/other/upas/tmp/$d.$1.raw
41# whatis x >/n/other/upas/tmp/$d.$1.file
42}
43
44x=`{file <$file | sed s/stdin://}
45x=$"x
46switch($x){
47case *Ascii* *text* *'c program'* *'rc executable'*
48 save accept
49 exit $accept
50
51case *'zip archive'*
rscfc46abd2006-04-12 13:10:08 +000052
rsc0e6fee12006-04-09 00:24:14 +000053 # >[2=1] because sometimes we get zip files we can't parse
54 # but the errors look like
55 # unzip: reading data for philw.doc.scr failed: ...
56 # so we can still catch these.
Russ Cox83ab7d82007-11-27 15:39:06 -050057 if(! unzip -tsf $file >[2=1] >/dev/null){
58 echo corrupt zip file!
59 exit $discard
60 }
rsc0e6fee12006-04-09 00:24:14 +000061 if(unzip -tsf $file >[2=1] | grep -si ' |\.(scr|exe|pif|bat|com)$'){
62 echo executables inside zip file!
63 exit $discard
64 }
65
66case jpeg 'PNG image' bmp 'GIF image' *'plan 9 image'
67 save accept
68 exit $accept
69
70case *Microsoft* *Office*
71 save wrap
72 exit $wrap
73
74case *MSDOS*
75 # no executables
76 echo $x
77 exit $discard
78}
79
80save wrap
81exit $wrap
82
83