9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] Mg (Mail grep)
@ 2008-11-18 22:29 a
  2008-11-18 22:54 ` erik quanstrom
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: a @ 2008-11-18 22:29 UTC (permalink / raw)
  To: 9fans

A few days ago, someone in #plan9 asked how to search for all
messages with a certain string in Acme Mail. The provided answer
was "grep(1)", which has the advantage of being concise and
maybe nominally correct, but the disadvantage of being totally
useless as a practical answer.

Today I found myself needing the same thing again, so I wrote Mg.
I can't remember who wanted this, and it might be more widely
useful, so I've put it at /n/sources/contrib/anothy/bin/rc/Mg. It's
intended to be put in an Acme Mail tag line and invoked as
	Mg foo bar
although all it really cares about is being run from within a
/mail/fs/foo directory. For each argument, it will search the
subject and body of every message in that mailbox and ask the
plumber to open any matching messages.

Right now it does no error checking, always folds case, checks
body and subject always/only, has been only trivially tested, and
I'm somewhat skeptical of the multipart handling, but it's already
saved me more time than it took to write (which, except for the
suspect multipart handling, was less than the time it took to write
this note).

Mg depends on Dan Cross' 'walk' (/n/sources/contrib/cross/walk.c).




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [9fans] Mg (Mail grep)
  2008-11-18 22:29 [9fans] Mg (Mail grep) a
@ 2008-11-18 22:54 ` erik quanstrom
  2008-11-19  5:16 ` Skip Tavakkolian
  2008-11-19  6:00 ` akumar
  2 siblings, 0 replies; 5+ messages in thread
From: erik quanstrom @ 2008-11-18 22:54 UTC (permalink / raw)
  To: 9fans

> A few days ago, someone in #plan9 asked how to search for all
> messages with a certain string in Acme Mail. The provided answer
> was "grep(1)", which has the advantage of being concise and
> maybe nominally correct, but the disadvantage of being totally
> useless as a practical answer.

just to add to that.  if Mail is not a requirement, ned has some
interesting possibilities

for messages with Mg in the "h" line, execute the h command
	g/Mg/h
same thing for matches in the whole message
	g%Mg%h

nupas ned allows you to search any file that upas/fs provides
for a message.  for example, if you want to print out all messages
that reference a given message
	25: p references
	d6dea0d153e3a5b9afac72c15318644e@coraid.com
	25: g#references#d6dea0d153e3a5b9afac72c15318644e@coraid.com#h
	 25       1208   9/04 10:23 quanstro@coraid.com          Re: sata
	 57       1706   9/04 10:01 example@coraid.com          Re: sata

countdown to requests for threading in 3..2..1..

- erik




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [9fans] Mg (Mail grep)
  2008-11-18 22:29 [9fans] Mg (Mail grep) a
  2008-11-18 22:54 ` erik quanstrom
@ 2008-11-19  5:16 ` Skip Tavakkolian
  2008-11-19 12:01   ` a
  2008-11-19  6:00 ` akumar
  2 siblings, 1 reply; 5+ messages in thread
From: Skip Tavakkolian @ 2008-11-19  5:16 UTC (permalink / raw)
  To: 9fans

this is what i use:

cpue% cat bin/rc/mgrep
#! /bin/rc

if (test ($#* -lt 1) -o ($#* -gt 2)) {
	echo 'usage: mgrep [from] regex'
	exit
}

if (test ! -d /mail/fs/mbox) {
	echo '/mail/fs/mbox does not exist'
	exit
}

if (~ $#* 1) {
	grep $1 /mail/fs/mbox/*/body
	exit $?
}

for (i in `{grep $1 /mail/fs/mbox/*/from}) {
	d=`{basename -d $i}
	if (grep $2 $d/body) {
		echo $d
	}
}


also, i just looked at Mg. i'm not sure why i would do 'Mg foo bar
baz' when i can do grep '(foo|bar|baz)'

> A few days ago, someone in #plan9 asked how to search for all
> messages with a certain string in Acme Mail. The provided answer
> was "grep(1)", which has the advantage of being concise and
> maybe nominally correct, but the disadvantage of being totally
> useless as a practical answer.
>
> Today I found myself needing the same thing again, so I wrote Mg.
> I can't remember who wanted this, and it might be more widely
> useful, so I've put it at /n/sources/contrib/anothy/bin/rc/Mg. It's
> intended to be put in an Acme Mail tag line and invoked as
> 	Mg foo bar
> although all it really cares about is being run from within a
> /mail/fs/foo directory. For each argument, it will search the
> subject and body of every message in that mailbox and ask the
> plumber to open any matching messages.
>
> Right now it does no error checking, always folds case, checks
> body and subject always/only, has been only trivially tested, and
> I'm somewhat skeptical of the multipart handling, but it's already
> saved me more time than it took to write (which, except for the
> suspect multipart handling, was less than the time it took to write
> this note).
>
> Mg depends on Dan Cross' 'walk' (/n/sources/contrib/cross/walk.c).




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [9fans] Mg (Mail grep)
  2008-11-18 22:29 [9fans] Mg (Mail grep) a
  2008-11-18 22:54 ` erik quanstrom
  2008-11-19  5:16 ` Skip Tavakkolian
@ 2008-11-19  6:00 ` akumar
  2 siblings, 0 replies; 5+ messages in thread
From: akumar @ 2008-11-19  6:00 UTC (permalink / raw)
  To: 9fans

- Mg eris - (highlight, middle click)
... Delmesg, Delmesg, Delmesg, ...


Ah,
Thanks




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [9fans] Mg (Mail grep)
  2008-11-19  5:16 ` Skip Tavakkolian
@ 2008-11-19 12:01   ` a
  0 siblings, 0 replies; 5+ messages in thread
From: a @ 2008-11-19 12:01 UTC (permalink / raw)
  To: 9fans

> also, i just looked at Mg. i'm not sure why i would do 'Mg foo bar
> baz' when i can do grep '(foo|bar|baz)'

I started off wanting to do "Mg foo bar baz". It was sort of a happy
implementation accident that foo et al get to be regexps. "Mg foo
bar baz" is easier to type when they're simple strings.




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2008-11-19 12:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-11-18 22:29 [9fans] Mg (Mail grep) a
2008-11-18 22:54 ` erik quanstrom
2008-11-19  5:16 ` Skip Tavakkolian
2008-11-19 12:01   ` a
2008-11-19  6:00 ` akumar

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).