[comp.unix.questions] Programmatic Mail reader

peters@mips2.cr.bull.com (Dan Peters) (07/26/90)

	This is my first post to this newsgroup, I hope it is appropriate.
What is the easiest way to programmaticly do the following:

	read mail,
	dump it to a file (i.e. log)
	delete the messages read (so they arn't logged again),
	quit mail


I have tried to programmaticly read mail with MAILX on a Hewlett Packard
machine running HP-UX (BSD 4.3 based i believe) with the following .mailrc
file:
	if r
	set autoprint
	save * dlog
	delete *
	quit
	endif

This is my first attempt to programmaticly read mail, log it to file dlog and
then delete the mail from the mailbox and exit mailx.
Mailx is called form this script:

	if mailx -e
	then
		echo :Logging please wait.."
		mails
		/usr/bin/pg dlog
	fi

Why won't mailx exit programmatically via the .mailrc file (it does everything
else)?
I must be doing this the hard way (you usually do until you learn the easy
way :-) any help out there?
Thanks for you time.

Dan

kseshadr@quasar.intel.com (Kishore Seshadri) (07/27/90)

In article <1990Jul26.155303.15563@mips2.cr.bull.com>, peters@mips2 (Dan Peters) writes:
>
>	This is my first post to this newsgroup, I hope it is appropriate.
>What is the easiest way to programmaticly do the following:
>
>	read mail,
>	dump it to a file (i.e. log)
>	delete the messages read (so they arn't logged again),
>	quit mail
>
>
>I have tried to programmaticly read mail with MAILX on a Hewlett Packard
>machine running HP-UX (BSD 4.3 based i believe) with the following .mailrc

I know nothing whatsoever about HP/UX but using Berkeley mail you can
direct your mail to a file using the .forward file mechanism. If this works
on your system it may be a viable solution.

Kishore Seshadri

===============================================================================
Kishore Seshadri (Speaking for myself)      Intel Corp., Santa Clara, CA
CSNET: kseshadr@mipos3.intel.com ARPA: kseshadr%mipos3.intel.com@relay.cs.net
UUCP:{amdcad,decwrl,hplabs,oliveb,pur-ee,qantel}!intelca!mipos3!kseshadr

schaefer@ogicse.ogc.edu (Barton E. Schaefer) (07/29/90)

In article <1990Jul26.155303.15563@mips2.cr.bull.com> peters@mips2.cr.bull.com (Dan Peters) writes:
} 
} 	This is my first post to this newsgroup, I hope it is appropriate.
} What is the easiest way to programmaticly do the following:
} 
} 	read mail,
} 	dump it to a file (i.e. log)
} 	delete the messages read (so they arn't logged again),
} 	quit mail

I'm not sure what you mean by the first step ("read mail") -- does that
mean you want to see each message before it gets saved?

If you have mush 7.1 available, that would be:

    #!/usr/local/bin/mush -F!
    unset hold
    set alwaysignore = pipe
    pipe * /usr/bin/pg
    save * dlog
    quit

You could also get a little fancier:

    #!/usr/local/bin/mush -F!
    unset hold
    if redirect		# Don't display if stdin is not a tty
	:n | save dlog		# save new mail only
    else
	set alwaysignore = pipe
	:n | /usr/bin/pg | save dlog	# print & save new mail only
    endif
    quit

Mush is available from the comp.sources.misc archives.
-- 
Bart Schaefer						schaefer@cse.ogi.edu