Plan 9 from Bell Labs’s /usr/web/sources/contrib/anothy/bin/rc/Mg

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#!/bin/rc

#TODO:
# make case folding (grep -i) optional.
# make what to search (from/to/cc/subject/body) optional?

rfork e
msgs=()

# find a text part of a multipart message (or punt)
fn findbody {
	for (subpart in `{walk | grep '/type$'}) {
		if (~ `{cat $subpart} text/*)
			multipart=($multipart `{basename -d $subpart}^/body)
	}
	if (~ $#multipart 0)
		echo body
	if not
		echo $multipart
}

# for each argument, find matching message numbers.
for (arg in $*)
	for (i in *) {
		body=body
		multipart=()
		if (~ `{cat $i/type >[2] /dev/null} multipart/*)
			body=`{cd $i && findbody}
		if (grep -is $arg $i/$body $i/subject >[2] /dev/null)
			msgs=($msgs $i)
	}


if (! ~ $#msgs 0) {
	plumb `{pwd}^/$msgs
}

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].