9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: rog@vitanuova.com
To: 9fans@cse.psu.edu
Subject: [9fans] spam script
Date: Tue, 29 Jul 2003 18:28:50 +0100	[thread overview]
Message-ID: <705a83eceaab3660ff85a8d46a8f96f1@vitanuova.com> (raw)
In-Reply-To: <99aa04dd7ad1d6871bf9e6c515b4f4fc@google.com>

while we're on the subject of shell scripts, if anyone is interested
in building up a spam file with a view to training a bayesian filter
or somesuch, here's a script that makes it easier.

i haven't installed a filter yet, but i've accumulated 15MB of spam in
a month and a half...

it works under acme Mail; just highlight some messages and execute
"spam" (assuming that's what you've named the script); alternatively
execute "spam" within a message window.

unfortunately it's unable to delete the messages automatically and
currently it assumes it's dealing with /mail/fs/mbox.

  cheers,
    rog.

PS. it was a bit of an effort to get the current selection of an acme
window from within a script; it would make things easier if:
- the id of the current acme window was available as well as its tag filename;
- the addr file didn't revert back to its default state when the ctl file was closed;
- the data file provided only the number of characters selected by the address.
... but maybe these are important properties, i dunno.

#!/bin/rc
rfork n
fn save {
	{echo From spam; cat $1; echo} >> $home/spam
}
fn saveselected {
	cd $1
	{echo 'addr=dot' > ctl; x=`{cat}} < addr
	msgs=`{>[2] /dev/null dd -count 1 -bs `{echo $x(2) $x(1) -p | dc} < data |
		sed -e '/^	/d' -e 's/^\(deleted\)-//'  -e 's:/.*::'}
	for(i in $msgs)
		save /mail/fs/mbox/$i/raw
}

if(~ $#* 0 && ~ $#% 1){
	if(~ $% /mail/fs/mbox/){
		poss=`{awk '{print $1, $6}' < /mnt/acme/index | grep '^[0-9]+ /mail/fs/mbox/$'}
		if(! ~ $#poss 2){
			echo no acme window found
			exit nope
		}
		saveselected /mnt/acme/$poss(1)
	}

	if not
	if(test -f $%/raw)
		save $%/raw
}

if not
for(i in $*){
	save /mail/fs/mbox/$i/raw
}



      parent reply	other threads:[~2003-07-29 17:28 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-07-29 14:47 [9fans] sig Rob 'Commander' Pike
2003-07-29 16:02 ` Dan Cross
2003-07-29 20:49   ` boyd, rounin
2003-07-29 17:28 ` rog [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=705a83eceaab3660ff85a8d46a8f96f1@vitanuova.com \
    --to=rog@vitanuova.com \
    --cc=9fans@cse.psu.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).