9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: "Russ Cox" <rsc@swtch.com>
To: Fans of the OS Plan 9 from Bell Labs <9fans@cse.psu.edu>
Subject: Re: [9fans] acme mail on unix
Date: Wed, 18 Jan 2006 14:10:37 -0500	[thread overview]
Message-ID: <20060118191042.24E2224FC2@holo.morphisms.net> (raw)
In-Reply-To: <05f36861c20b652d1fb8127b2e9a5c7e@akira.nop.cx>

[-- Attachment #1: English text --]
[-- Type: text/plain, Size: 64 bytes --]

Mail script should be attached.  This time for sure.

Russ


[-- Attachment #2: rc executable file script --]
[-- Type: text/plain, Size: 4517 bytes --]

#!/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


  parent reply	other threads:[~2006-01-18 19:10 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-01-18 16:46 Russ Cox
2006-01-18 17:56 ` Tim Wiess
2006-01-18 18:08   ` Tim Wiess
2006-01-18 19:10   ` Russ Cox [this message]
2006-01-19 16:17     ` Aaron Griffin
2006-01-19 16:24       ` Russ Cox
2006-01-19 21:28         ` Dan Cross
2006-01-19 21:58           ` Russ Cox
2006-01-20  2:38             ` geoff
2006-01-20  5:31               ` Scott Schwartz
2006-01-20  6:04                 ` John Barham
2006-01-20 13:50                   ` erik quanstrom
2006-01-20 23:01                     ` Dave Eckhardt
2006-01-21  0:06                       ` erik quanstrom
2006-01-20 13:58           ` erik quanstrom
2006-01-20 20:02             ` erik quanstrom
2006-01-20 20:12               ` uriel
2006-01-20 20:18                 ` erik quanstrom
2006-01-20 20:41                   ` uriel
2006-01-20 20:59                     ` erik quanstrom
2006-01-20 22:58 Russ Cox

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=20060118191042.24E2224FC2@holo.morphisms.net \
    --to=rsc@swtch.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).