Mail script should be attached. This time for sure.
Russ
#!/usr/local/plan9/bin/rc
. 9.rc
. $PLAN9/lib/acme.rc
mh=/usr/bin/mh # directory with mh binaries
fn event {
# $1 - c1 origin of event
# $2 - c2 type of action
# $3 - q0 beginning of selection
# $4 - q1 end of selection
# $5 - eq0 beginning of expanded selection
# $6 - eq1 end of expanded selection
# $7 - flag
# $8 - nr number of runes in $7
# $9 - text
# $10 - chorded argument
# $11 - origin of chorded argument
switch($1$2){
case E* # write to body or tag
case F* # generated by ourselves; ignore
case K* # type away we do not care
case Mi # mouse: text inserted in tag
case MI # mouse: text inserted in body
case Md # mouse: text deleted from tag
case MD # mouse: text deleted from body
case Mx MX # button 2 in tag or body
$x $*
case Ml ML # button 3 in tag or body
$l $* &
}
}
listfmt='%(msg)/ %<(mymbox{from})%<{to}To:
%(decode(friendly{to}))%>%>%<(zero)%(decode(friendly{from}))%>
%(day{date}) %(month{date}) %(mday{date}) %02(hour{date}):%02(min{date})\n
%(decode{subject})'
fn boxexec {
switch($9){
case Get
echo -n , | winwrite addr
$mh/scan +^$boxname -reverse -format $listfmt | winwrite data
winctl clean
case Mail*
postwin `{echo $9 | sed 's/Mail *//'} &
case *
winwriteevent $*
}
}
fn boxload {
switch($9){
case [0-9]*
msgwin $boxname $9 &
case */Mail/*
f=`{echo $9 | sed 's;/+$;;'}
if(test -d $f){
boxwin $f &
}
if not if(test -f $f){
echo reloading msg
box=`{echo $f | sed 's;/[^/]+$;;'}
num=`{echo $f | sed 's;.*/;;'}
msgwin $box $num &
}
if not
winwriteevent $*
case *
winwriteevent $*
}
}
fn cmd {
$1 - - - - - - - - $2
}
fn boxwin {
newwindow
boxname=$1
winname $boxname
x=boxexec
l=boxload
cmd $x Get
echo -n 'Get Mail ' | winwrite tag
wineventloop
}
fn msgexec {
switch($9){
case Get
echo -n , | winwrite addr
$mh/mhshow -nopause +^$boxname $msgnum | 9 grep -v '^part
[0-9]? +text' | 9 fmt -j | winwrite data
winctl clean
case Mail*
postwin `{echo $9 | sed 's/^Mail *//'} &
case Reply*
postwin `{echo $9 | sed 's/^Reply *//'} &
case Delmesg
if(~ $boxname */*){
x=`{echo $boxname | sed 's;.*/;;'}
$mh/refile -src +$x $msgnum +d
winctl del
}
case Spam
if(~ $boxname */*){
x=`{echo $boxname | sed 's;.*/;;'}
$mh/refile -src +$x $msgnum +spam
winctl del
}
case *
winwriteevent $*
}
}
fn msgwin {
newwindow
boxname=$1
msgnum=$2
winname $boxname/$msgnum
shift
shift
x=msgexec
l=boxload
if(~ $boxname */draft){
x=postexec
echo -n 'Post ' | winwrite tag
}
if not
echo -n 'Reply Delmesg ' | winwrite tag
cmd $x Get
wineventloop
}
fn postexec {
switch($9){
case Get
winctl get
case Post
switch($boxname){
case */draft
if(winctl put)
$mh/send -attach Attach -push -draftmessage
$boxname/$msgnum
case *
# should copy body into draft file and post it
# can't put - would overwrite good message
echo cannot post from non-draft
}
case Del
# check that window is clean!
winwriteevent $*
case *
winwriteevent $*
}
}
nl='
'
fn postwin {
if(~ $#msgnum 1){
# prepare a reply
winread body | 9 grep -i '^(Reply-To|Subject|From|Message-Id):'
>/tmp/mail.$pid
winread body | sed '1,/^$/d' | sed 's/^/> /' >/tmp/body.$pid
oifs=$ifs
ifs=$nl
subject=`{9 grep -i '^Subject:' /tmp/mail.$pid | sed
's/^Subject: *//'}
from=`{9 grep -i '^From:' /tmp/mail.$pid | sed 's/^From: *//'}
msgid=`{9 grep -i '^Message-Id:' $boxname/$msgnum | sed
's/^[Mm][Ee][Ss][Ss][Aa][Gg][Ee]-[Ii][Dd]: *//'}
replyto=`{9 grep -i '^Reply-To:' $boxname/$msgnum | sed
's/^[Rr][Ee][Pp][Ll][Yy]-[Tt][Oo]: *//'}
rm -f /tmp/mail.$pid
ifs=$oifs
if(~ $#* 0){
if(! ~ $#replyto 0)
*=($replyto)
if not
*=($from)
}
if(! echo $subject | 9 grep -si 're:')
subject='Re: ' ^ $"subject
}
newwindow
n=1
while(test -f $home/Mail/draft/$n)
n=`{echo 1+$n|hoc}
name=$home/Mail/draft/$n
msgnum=$n
boxname=$home/Mail/draft
{
echo 'To:' $*
if(! ~ $#subject 0)
echo 'Subject: '^$subject
cat $home/Mail/headers
if(! ~ $#msgid 0)
echo 'In-Reply-To: '^$msgid
echo
if(test -f /tmp/body.$pid){
cat /tmp/body.$pid
rm /tmp/body.$pid
}
} >$name
winname $name
winctl get
echo -n 'Post' | winwrite tag
x=postexec
l=boxload
wineventloop
}
boxwin $home/Mail/inbox; exit