2014-04-01 18:34:29 +00:00
|
|
|
|
#!/bin/rc
|
2014-10-28 04:38:58 +00:00
|
|
|
|
# NEWT, their six-year-old daughter, yells from the back...
|
|
|
|
|
# use with nntpfs
|
2014-04-01 18:34:29 +00:00
|
|
|
|
rfork en
|
|
|
|
|
ramfs
|
|
|
|
|
argv0=$0
|
|
|
|
|
if(~ $#editor 0)
|
|
|
|
|
editor=hold
|
|
|
|
|
group=alt/test
|
|
|
|
|
maxposts=30
|
|
|
|
|
mnt=/mnt/news
|
|
|
|
|
if(~ $#newtname 0)
|
|
|
|
|
newtname=newt@dont-email.me
|
2014-10-28 04:38:58 +00:00
|
|
|
|
fn e{
|
2014-04-01 18:34:29 +00:00
|
|
|
|
{
|
|
|
|
|
echo From: $"newtname
|
|
|
|
|
echo Newsgroups: `{echo $group | sed 's/\//\./g'}
|
|
|
|
|
echo Subject: $"subject
|
|
|
|
|
echo
|
|
|
|
|
} >/tmp/post
|
|
|
|
|
eval $editor /tmp/post
|
2014-10-28 04:38:58 +00:00
|
|
|
|
yn send
|
|
|
|
|
if(~ $yn y)
|
|
|
|
|
cat /tmp/post >$mnt/$group/post
|
2014-04-01 18:34:29 +00:00
|
|
|
|
}
|
|
|
|
|
fn f { du -a $* | sed 's/^.* //g' }
|
|
|
|
|
fn fmtd{
|
|
|
|
|
date=`{cat}
|
|
|
|
|
if(! ~ $date(1) [0-9]*)
|
|
|
|
|
date=`{nshift $date}
|
|
|
|
|
da=$date(1)
|
2014-04-10 01:26:43 +00:00
|
|
|
|
if(~ $da [0-9])
|
|
|
|
|
da=0^$da
|
2014-04-01 18:34:29 +00:00
|
|
|
|
switch($date(2)){
|
|
|
|
|
case Jan; mo=1
|
|
|
|
|
case Feb; mo=2
|
|
|
|
|
case Mar; mo=3
|
|
|
|
|
case Apr; mo=4
|
|
|
|
|
case May; mo=5
|
|
|
|
|
case Jun; mo=6
|
|
|
|
|
case Jul; mo=7
|
|
|
|
|
case Aug; mo=8
|
|
|
|
|
case Sep; mo=9
|
|
|
|
|
case Oct; mo=10
|
|
|
|
|
case Nov; mo=11
|
|
|
|
|
case Dec; mo=12
|
|
|
|
|
}
|
|
|
|
|
if(! ~ $date(3) `{date | awk '{print $6;}'})
|
|
|
|
|
ti=$date(3)
|
|
|
|
|
if not
|
|
|
|
|
ti=`{echo $date(4) | awk '{print substr($0,0,5);}'}
|
2014-10-29 16:03:32 +00:00
|
|
|
|
if(! ~ $#mo 0 && ! ~ $#da 0 && ! ~ $#ti 0)
|
|
|
|
|
echo $mo/$da $ti
|
|
|
|
|
if not
|
|
|
|
|
echo nil
|
2014-04-01 18:34:29 +00:00
|
|
|
|
}
|
|
|
|
|
fn geth{
|
|
|
|
|
for(i in $*){
|
2014-10-28 04:38:58 +00:00
|
|
|
|
from=`{awk -F ' ' '{print $3;}' $rposts($i)^/xover >[2]/dev/null}
|
2014-04-01 18:34:29 +00:00
|
|
|
|
if(! ~ $#from 0 && ! ~ $#from 1){
|
|
|
|
|
nfrom=`{
|
|
|
|
|
for(i in $from){
|
|
|
|
|
if(~ $i *@*)
|
|
|
|
|
echo $i | sed 's/(<|>)//g'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(! ~ $#nfrom 0)
|
|
|
|
|
from=$nfrom
|
|
|
|
|
}
|
2014-10-28 04:38:58 +00:00
|
|
|
|
if(~ $#from 0)
|
|
|
|
|
from=nil
|
|
|
|
|
date=`{awk -F ' ' '{print $4;}' $rposts($i)^/xover >[2]/dev/null | fmtd}
|
|
|
|
|
if(~ $#date 0)
|
|
|
|
|
date=nil
|
|
|
|
|
subject=`{awk -F ' ' '{print substr($2,0,50);}' $rposts($i)^/xover >[2]/dev/null}
|
|
|
|
|
if(~ $#subject 0)
|
|
|
|
|
subject=nil
|
|
|
|
|
# unicode 00a0 divides message number from headline.
|
|
|
|
|
# command input ignores everything after unicode 00a0.
|
|
|
|
|
# these lines may be selected and sent to the prompt.
|
|
|
|
|
echo ' '$"i' '$"date' '$"from' '$"subject
|
2014-04-01 18:34:29 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fn getposts{ ls | grep -e '^[0-9]+$' | sort -n | tail -$maxposts }
|
2014-10-28 04:38:58 +00:00
|
|
|
|
fn getr{
|
|
|
|
|
switch($*){
|
|
|
|
|
case ,; echo $posts
|
|
|
|
|
case ,*; seq 1 `{echo $* | sed 's/,//g'}
|
|
|
|
|
case *,; seq `{echo $* | sed 's/,//g'} $posts($#posts)
|
|
|
|
|
case *,*; seq `{echo $* | sed 's/,/ /g'}
|
|
|
|
|
case *; echo $*
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fn h{ sed -n $1^p /tmp/h }
|
2014-04-01 18:34:29 +00:00
|
|
|
|
fn k{
|
|
|
|
|
kmnt=`{echo $mnt | sed 's/\//\\\//g'}
|
|
|
|
|
f $mnt/$* |
|
2014-04-02 19:49:24 +00:00
|
|
|
|
grep -v -e '\/([0-9]+|article|body|header|post|xover)$' |
|
2014-04-11 17:19:18 +00:00
|
|
|
|
sed 's/^'$"kmnt'\// g /g' |
|
2014-04-01 18:34:29 +00:00
|
|
|
|
sort
|
|
|
|
|
}
|
|
|
|
|
fn nshift{ shift; echo $* }
|
|
|
|
|
fn printhelp{
|
2014-10-28 04:38:58 +00:00
|
|
|
|
echo 'Commands are of the form [<range>] <command> [args]
|
|
|
|
|
<range> := <addr> | <addr>','<addr>
|
|
|
|
|
<command> :=
|
|
|
|
|
b print the next ten headers
|
2014-04-01 18:34:29 +00:00
|
|
|
|
e enter message
|
|
|
|
|
g ... go to specified group
|
2014-10-28 04:38:58 +00:00
|
|
|
|
h print message headline (,h for all)
|
2014-04-01 18:34:29 +00:00
|
|
|
|
help print this help message
|
|
|
|
|
k ... list sub-groups under specified group
|
2014-04-11 17:19:18 +00:00
|
|
|
|
kf ... grep $home/lib/newsgroups for regexp
|
2014-04-01 18:34:29 +00:00
|
|
|
|
p print message with minimal headers
|
|
|
|
|
P print message with full headers
|
|
|
|
|
q quit
|
|
|
|
|
r reply to message
|
|
|
|
|
y synchronize message list with server
|
|
|
|
|
" print message in quoted form, suitable for reply
|
|
|
|
|
|cmd pipe message body to a command
|
|
|
|
|
||cmd pipe raw message to a command
|
|
|
|
|
? print debug information'
|
|
|
|
|
}
|
2014-10-28 04:38:58 +00:00
|
|
|
|
fn p{
|
|
|
|
|
if(test $1 -le $#rposts && test -f $mnt/$group/$rposts($1)^/body){
|
2014-04-25 13:25:08 +00:00
|
|
|
|
{ # don't stutter
|
2014-10-28 04:38:58 +00:00
|
|
|
|
grep -e '(^From|^Newsgroups|^Subject|^Date)' $rposts($1)^/header
|
2014-04-25 13:25:08 +00:00
|
|
|
|
echo
|
2014-10-28 04:38:58 +00:00
|
|
|
|
cat $rposts($1)^/body
|
2014-04-25 13:25:08 +00:00
|
|
|
|
} >/tmp/p
|
|
|
|
|
cat /tmp/p
|
2014-04-01 18:34:29 +00:00
|
|
|
|
}
|
|
|
|
|
echo
|
2014-10-30 02:49:08 +00:00
|
|
|
|
go=1
|
2014-10-28 04:38:58 +00:00
|
|
|
|
r=$1
|
|
|
|
|
post=$1
|
2014-04-01 18:34:29 +00:00
|
|
|
|
prompt=$group/$1
|
|
|
|
|
}
|
2014-10-28 04:38:58 +00:00
|
|
|
|
fn P{
|
|
|
|
|
if(test $1 -le $#rposts && test -f $mnt/$group/$rposts($1)^/article)
|
|
|
|
|
cat $rposts($1)^/article
|
2014-04-01 18:34:29 +00:00
|
|
|
|
echo
|
2014-10-30 02:49:08 +00:00
|
|
|
|
go=1
|
2014-10-28 04:38:58 +00:00
|
|
|
|
r=$1
|
|
|
|
|
post=$1
|
2014-04-01 18:34:29 +00:00
|
|
|
|
prompt=$group/$1
|
|
|
|
|
}
|
2014-10-28 04:38:58 +00:00
|
|
|
|
fn r{
|
|
|
|
|
if(test $1 -le $#rposts && test -f $mnt/$group/$rposts($1)^/header){
|
|
|
|
|
subject=`{grep -e '^Subject: ' $mnt/$group/$rposts($1)^/header | sed 's/^Subject: //g'}
|
|
|
|
|
if(! ~ $subject RE:* Re:* re:*)
|
|
|
|
|
subject=(Re: $subject)
|
|
|
|
|
e
|
|
|
|
|
}
|
|
|
|
|
if not
|
|
|
|
|
echo !message missing
|
|
|
|
|
}
|
|
|
|
|
fn y{
|
|
|
|
|
go=()
|
|
|
|
|
r=$post
|
|
|
|
|
if(! ~ $q 1){
|
|
|
|
|
rposts=`{getposts}
|
|
|
|
|
posts=`{seq 1 $#rposts}
|
|
|
|
|
post=$posts(1)
|
|
|
|
|
prompt=$post
|
|
|
|
|
geth $posts >/tmp/h
|
|
|
|
|
echo $#posts messages
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fn yn{
|
|
|
|
|
echo
|
|
|
|
|
echo -n $* ' (y, n) '
|
|
|
|
|
yn=`{read}
|
|
|
|
|
switch($yn){
|
|
|
|
|
case y n
|
|
|
|
|
;
|
|
|
|
|
case *
|
|
|
|
|
yn
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fn '"' {{p $1 | sed 1d | sed 's/^/> /g' | sed 's/^> >/>>/g' | sed '$d'; echo}}
|
2014-04-01 18:34:29 +00:00
|
|
|
|
fn usage{
|
|
|
|
|
echo usage: $argv0 '[ -f newsgroup ] [ -m mountpoint ] [ -p maxposts ]' >[1=2]
|
|
|
|
|
exit usage
|
|
|
|
|
}
|
|
|
|
|
while(~ $1 -*){
|
|
|
|
|
switch($1){
|
|
|
|
|
case -f
|
|
|
|
|
group=`{echo $2 | sed 's/\./\//g'}
|
|
|
|
|
shift
|
|
|
|
|
case -m
|
|
|
|
|
mnt=$2
|
|
|
|
|
shift
|
|
|
|
|
case -p
|
|
|
|
|
maxposts=$2
|
|
|
|
|
shift
|
|
|
|
|
case *
|
|
|
|
|
usage
|
|
|
|
|
}
|
|
|
|
|
shift
|
|
|
|
|
}
|
|
|
|
|
if(! ~ $#* 0)
|
|
|
|
|
usage
|
|
|
|
|
prompt=$group
|
|
|
|
|
if(! test -d $mnt/$group){
|
|
|
|
|
echo !$mnt/$group does not exist >[1=2]
|
|
|
|
|
exit
|
|
|
|
|
}
|
|
|
|
|
builtin cd $mnt/$group
|
2014-10-28 04:38:58 +00:00
|
|
|
|
y
|
2014-04-01 18:34:29 +00:00
|
|
|
|
while(){
|
|
|
|
|
echo -n $"prompt': '
|
2014-10-28 04:38:58 +00:00
|
|
|
|
# command input ignores everything after unicode 00a0.
|
|
|
|
|
rcmd=`{read | sed 's/[ ].*$//g' | sed 's/^([0-9]+)?(,)?([0-9]+)?/& /g'}
|
|
|
|
|
switch($rcmd){
|
|
|
|
|
case ,* [0-9]*
|
|
|
|
|
r=`{getr $rcmd(1)}
|
|
|
|
|
cmd=`{nshift $rcmd}
|
|
|
|
|
if(~ $#cmd 0)
|
|
|
|
|
cmd=p
|
|
|
|
|
case *
|
|
|
|
|
r=$post
|
|
|
|
|
cmd=$rcmd
|
|
|
|
|
}
|
2014-04-01 18:34:29 +00:00
|
|
|
|
switch($cmd){
|
|
|
|
|
case b
|
2014-10-28 04:38:58 +00:00
|
|
|
|
r=`{seq $r(1) `{echo $r(1)^+10|bc}}
|
|
|
|
|
if(test $r($#r) -gt $posts($#posts))
|
|
|
|
|
r=`{seq $r(1) $posts($#posts)}
|
|
|
|
|
if(! ~ $#r 0 && test $r(1) -le $posts($#posts)){
|
|
|
|
|
sed -n $r(1)^,$r($#r)^p /tmp/h
|
|
|
|
|
post=$r($#r)
|
|
|
|
|
prompt=$post
|
2014-04-01 18:34:29 +00:00
|
|
|
|
}
|
2014-10-28 04:38:58 +00:00
|
|
|
|
if not
|
|
|
|
|
echo !address
|
2014-04-01 18:34:29 +00:00
|
|
|
|
case e
|
2014-10-28 04:38:58 +00:00
|
|
|
|
subject=() e
|
2014-04-01 18:34:29 +00:00
|
|
|
|
case g' '*
|
|
|
|
|
ngroup=`{nshift $cmd | sed 's/\./\//g'}
|
|
|
|
|
if(test -d $mnt/$ngroup){
|
|
|
|
|
if(grep -s -e '^[0-9]+$' <{ls -p $mnt/$ngroup}){
|
|
|
|
|
group=$ngroup
|
|
|
|
|
builtin cd $mnt/$group
|
2014-10-28 04:38:58 +00:00
|
|
|
|
y
|
2014-04-01 18:34:29 +00:00
|
|
|
|
}
|
|
|
|
|
if not
|
|
|
|
|
echo !$ngroup contains no messages
|
|
|
|
|
}
|
|
|
|
|
if not
|
|
|
|
|
echo !$ngroup does not exist
|
|
|
|
|
case h
|
2014-10-28 04:38:58 +00:00
|
|
|
|
for(i in $r)
|
|
|
|
|
h $i
|
|
|
|
|
post=$r($#r)
|
|
|
|
|
prompt=$post
|
2014-04-01 18:34:29 +00:00
|
|
|
|
case help
|
|
|
|
|
printhelp
|
|
|
|
|
case k
|
|
|
|
|
k $group
|
|
|
|
|
case k' '*
|
|
|
|
|
k `{nshift $cmd | sed 's/\./\//g'}
|
2014-04-11 17:19:18 +00:00
|
|
|
|
case kf' '*
|
|
|
|
|
grep -e `{nshift $cmd} $home/lib/newsgroups |
|
|
|
|
|
sed 's/^/ g /g'
|
2014-04-01 18:34:29 +00:00
|
|
|
|
case p
|
2014-10-28 04:38:58 +00:00
|
|
|
|
for(i in $r)
|
|
|
|
|
p $i
|
2014-04-01 18:34:29 +00:00
|
|
|
|
case P
|
2014-10-28 04:38:58 +00:00
|
|
|
|
for(i in $r)
|
|
|
|
|
P $i
|
2014-04-01 18:34:29 +00:00
|
|
|
|
case q
|
2014-10-28 04:38:58 +00:00
|
|
|
|
q=1 y # BUP STOP
|
2014-04-01 18:34:29 +00:00
|
|
|
|
exit
|
|
|
|
|
case r
|
2014-10-28 04:38:58 +00:00
|
|
|
|
for(i in $r)
|
|
|
|
|
r $i
|
|
|
|
|
post=$r($#r)
|
|
|
|
|
prompt=$post
|
2014-04-01 18:34:29 +00:00
|
|
|
|
case y
|
2014-10-28 04:38:58 +00:00
|
|
|
|
y
|
2014-04-01 18:34:29 +00:00
|
|
|
|
case '"'
|
2014-10-28 04:38:58 +00:00
|
|
|
|
for(i in $r)
|
|
|
|
|
'"' $i
|
|
|
|
|
post=$r($#r)
|
|
|
|
|
prompt=$post
|
2014-04-01 18:34:29 +00:00
|
|
|
|
case '||'*
|
|
|
|
|
cmd=`{echo $"cmd | sed 's/^\|\|//g'}
|
2014-10-28 04:38:58 +00:00
|
|
|
|
cat $mnt/$group/^$rposts($post)^/article | eval $cmd
|
2014-04-01 18:34:29 +00:00
|
|
|
|
case '|'*
|
|
|
|
|
cmd=`{echo $"cmd | sed 's/^\|//g'}
|
2014-10-28 04:38:58 +00:00
|
|
|
|
cat $mnt/$group/^$rposts($post)^/body | eval $cmd
|
2014-04-01 18:34:29 +00:00
|
|
|
|
case '?'
|
|
|
|
|
echo mnt: $mnt
|
|
|
|
|
echo group: $group
|
|
|
|
|
echo maxposts: $maxposts
|
2014-10-30 02:49:08 +00:00
|
|
|
|
echo '#go': $#go
|
2014-10-28 04:38:58 +00:00
|
|
|
|
echo rposts: $rposts
|
|
|
|
|
echo 'rposts(r):' $rposts($r)
|
2014-04-01 18:34:29 +00:00
|
|
|
|
echo posts: $posts
|
2014-10-28 04:38:58 +00:00
|
|
|
|
echo post: $post
|
|
|
|
|
echo r: $r
|
|
|
|
|
case *
|
2014-10-29 04:20:41 +00:00
|
|
|
|
if(~ $post $posts(1) && ~ $#go 0)
|
2014-10-28 04:38:58 +00:00
|
|
|
|
p $post
|
2014-04-01 18:34:29 +00:00
|
|
|
|
if not if(! ~ $post $posts($#posts)){
|
|
|
|
|
post=`{echo $post^+1 | bc}
|
|
|
|
|
if(test $post -gt $posts($#posts))
|
|
|
|
|
post=$posts($#posts)
|
2014-10-28 04:38:58 +00:00
|
|
|
|
p $post
|
2014-04-01 18:34:29 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|