aboutsummaryrefslogtreecommitdiff
path: root/bin/upas
diff options
context:
space:
mode:
authorrsc <devnull@localhost>2006-05-21 18:39:29 +0000
committerrsc <devnull@localhost>2006-05-21 18:39:29 +0000
commitf1007ee0c6a2dfdc5512a1be3dada65cbc5d5391 (patch)
tree2a2b6aae68d2caa2d102fc2acc2d5f429dea02ce /bin/upas
parent38c7eb9bd22e05ef32998858b178edaf8269cbab (diff)
downloadplan9port-f1007ee0c6a2dfdc5512a1be3dada65cbc5d5391.tar.gz
plan9port-f1007ee0c6a2dfdc5512a1be3dada65cbc5d5391.tar.bz2
plan9port-f1007ee0c6a2dfdc5512a1be3dada65cbc5d5391.zip
new
Diffstat (limited to 'bin/upas')
-rw-r--r--bin/upas/.cvsignore11
-rwxr-xr-xbin/upas/isspam35
-rwxr-xr-xbin/upas/msgcat61
-rwxr-xr-xbin/upas/spam19
-rwxr-xr-xbin/upas/spambox14
-rwxr-xr-xbin/upas/unspam19
-rwxr-xr-xbin/upas/unspambox14
7 files changed, 173 insertions, 0 deletions
diff --git a/bin/upas/.cvsignore b/bin/upas/.cvsignore
index e69de29b..b370701d 100644
--- a/bin/upas/.cvsignore
+++ b/bin/upas/.cvsignore
@@ -0,0 +1,11 @@
+aliasmail
+filter
+marshal
+nedmail
+qer
+runq
+send
+smtp
+smtpd
+unvf
+vf
diff --git a/bin/upas/isspam b/bin/upas/isspam
new file mode 100755
index 00000000..03be23f7
--- /dev/null
+++ b/bin/upas/isspam
@@ -0,0 +1,35 @@
+#!/usr/local/plan9/bin/rc
+
+rfork en
+
+if (~ $#* 0)
+ echo usage: isspam mesg && exit 'usage'
+
+TMP=/tmp/isspam.$USER.$pid
+{
+ echo '# hash table'
+ msgcat $1|sed '/^$/,$ s/^From / From /'|upas/msgtok|
+ grep -v '^....................(.*) '|
+ sed 's/$/ 1/'
+} >$TMP.tok
+
+x=`{upas/bayes -k $HOME/mail/_prof.mbox $HOME/mail/_prof.spam ~ $TMP.tok}
+where=$x(1)
+prob=$x(2)
+echo $where $prob
+*=($x)
+shift 2
+while(! ~$#* 0){
+ echo ' ' $1 $2
+ shift 2
+}
+
+rm -f $TMP.tok
+if (~ $where *spam*){
+ echo spam
+ exit ''
+}
+if not {
+ echo ok
+ exit 'is ok'
+}
diff --git a/bin/upas/msgcat b/bin/upas/msgcat
new file mode 100755
index 00000000..7067a435
--- /dev/null
+++ b/bin/upas/msgcat
@@ -0,0 +1,61 @@
+#!/usr/local/plan9/bin/rc
+
+fn read9p {
+ srv=$1; shift
+ 9p read $srv >[2=1]|grep -v '^9p\:'
+}
+
+fn dir9p {
+ srv=$1; shift
+ 9p ls $srv >[2=1]|grep -v '^9p\:'
+}
+
+
+fn catmesg {
+ # hold on for a second
+ TMP=/tmp/$USER.`{date -n}; sleep 1
+ msg=$1;
+ read9p $msg/body >$TMP.body
+ t=`{read9p $msg/type}
+ switch($t){
+ case text/html
+ echo '
+ ,x/<!--(-?[^\-]|--[^>]|\n)*-->/ c//
+ ,x/<[^>]+>/d
+ ,p
+ u
+ ,y/<[^>]+>/d
+ ,p
+ '| sam -d $TMP.body|[2] sed '1d;/^\?/d'
+ case text/*
+ cat $TMP.body
+ case message/*
+ cat $TMP.body
+ case multipart/related
+ if (~ `{read9p $msg/1/type} text/plain)
+ catmesg $msg/1
+ if not if (~ `{read9p $msg/2/type} text/plain)
+ catmesg $msg/2
+ if not {
+ for (i in `{dir9p $msg|awk '$10 ~ /[0-9][0-9]*/ {print $10}'})
+ catmesg $msg/$i
+ }
+ case *
+ echo $t
+ # should there be more?
+ }
+ rm -f $TMP.body
+}
+
+if (~ $#* 0)
+ echo usage: msgcat mail/mbox/msgn && exit 1
+
+mesg=$1
+if (~ `{read9p $mesg/lines} '')
+ echo no such message $mesg && exit 2
+
+
+read9p $mesg/unixheader; read9p $mesg/header
+echo
+catmesg $mesg
+echo
diff --git a/bin/upas/spam b/bin/upas/spam
new file mode 100755
index 00000000..d7d44852
--- /dev/null
+++ b/bin/upas/spam
@@ -0,0 +1,19 @@
+#!/usr/local/plan9/bin/rc
+
+rfork en
+
+if (~ $#* 0)
+ echo usage: spam mesg && exit 1
+
+TMP=/tmp/spam.$USER.$pid
+{
+ echo '# hash table'
+ msgcat $1|sed '/^$/,$ s/^From / From /'|upas/msgtok|
+ grep -v '^....................(.*) '|
+ sed 's/$/ 1/'
+} >$TMP.tok
+
+cd $home/mail
+upas/addhash -o _prof.mbox _prof.mbox 1 $TMP.tok -1
+upas/addhash -o _prof.spam _prof.spam 1 $TMP.tok 1
+rm -f $TMP.*
diff --git a/bin/upas/spambox b/bin/upas/spambox
new file mode 100755
index 00000000..b34cd300
--- /dev/null
+++ b/bin/upas/spambox
@@ -0,0 +1,14 @@
+#!/usr/local/plan9/bin/rc
+
+if (~ $#* 0)
+ echo usage: spambox mailfs/mbox && exit "usage"
+box=$1
+msgs=(`{9p ls $box>[2=1]|awk '$10 ~ /[0-9][0-9]*/{print $10}'})
+if (~ $#msgs 0)
+ echo no messages in $box && exit "none"
+
+echo -n adding
+for (m in $msgs){
+ echo -n ' '$m
+ spam $box/$m
+}
diff --git a/bin/upas/unspam b/bin/upas/unspam
new file mode 100755
index 00000000..1d056d52
--- /dev/null
+++ b/bin/upas/unspam
@@ -0,0 +1,19 @@
+#!/usr/local/plan9/bin/rc
+
+rfork en
+
+if (~ $#* 0)
+ echo usage: unspam mesg && exit 1
+
+TMP=/tmp/unspam.$USER.$pid
+{
+ echo '# hash table'
+ msgcat $1|sed '/^$/,$ s/^From / From /'|upas/msgtok|
+ grep -v '^....................(.*) '|
+ sed 's/$/ 1/'
+} >$TMP.tok
+
+cd $home/mail
+upas/addhash -o _prof.mbox _prof.mbox 1 $TMP.tok 1
+upas/addhash -o _prof.spam _prof.spam 1 $TMP.tok -1
+rm -f $TMP.*
diff --git a/bin/upas/unspambox b/bin/upas/unspambox
new file mode 100755
index 00000000..bfa70531
--- /dev/null
+++ b/bin/upas/unspambox
@@ -0,0 +1,14 @@
+#!/usr/local/plan9/bin/rc
+
+if (~ $#* 0)
+ echo usage: unspambox mailfs/mbox && exit "usage"
+box=$1
+msgs=(`{9p ls $box>[2=1]|awk '$10 ~ /[0-9][0-9]*/{print $10}'})
+if (~ $#msgs 0)
+ echo no messages in $box && exit "none"
+
+echo -n adding
+for (m in $msgs){
+ echo -n ' '$m
+ unspam $box/$m
+}