From: jamesd@techbook.com (James Deibele)
Subject: Re: .QWK mail reader for Waffle (part 3)
Keywords: waffle, qwk, mail, offline
Organization: TECHbooks of Beaverton Oregon - Public Access Unix
Date: Sat, 12 Dec 1992 04:09:50 GMT

OK, so we've handled the host side of things for our reader.  Well, I
ducked the mail side, but let's keep ignoring that temporarily.  Let's
move to the caller's side of things. 

We need an installation program.  The program needs to ask what your
name is, what your e-mail address is, what your "Organization" line to
read, what communications program you're using, which word-processor,
and which directory is the "base" directory.  Then we need:

MAIL_OUT	- Mail to be sent
MAIL_IN		- Mail that's coming in
NEWS_OUT	- News articles to be sent
NEWS_IN		- Guess.
BULLETIN	- Bulletins from host system 
DOWNLOAD	- Downloaded files from host
UPLOAD		- Files to send to host (Ha!)
NEWSGRP.LST	- Newsgroups name, last message received, directory
MAILER.CFG	- Where name, organization, etc. go
ACTIVE		- Host system's active file (optional)
NEWSGROU	- "newsgroups" from host (optional)
IMPORT.EXE	- Maintains NEWSGRP.LST
READER.EXE	- How we look at messages
INSTALL.EXE	- Sets up the rest of the system

There'll be one script ending in the appropriate magic extension for
Procomm, Telix, or whatever.  And there'll be directories for each
newsgroup, which the import program will need to create as necessary.

Specifications for script (one each for Procomm, Telix, etc.)
(1) Call host and login successfully.
(2) Drop off mail by calling "mail_in" and then sending all files in
	~/MAIL_OUT.  If files are sent successfully, delete.
(3) Drop off news by calling "news_in" and then sending all files in
	~/NEWS_OUT.  If files are sent successfully, delete.
(4) Pick up mail by calling "mail_out".  If host sends all mail
	successfully, it will delete mail.
(5) Pick up news by calling "news_out", sending newsgroup.lst, then go
	into receive mode.  
(6) Disconnect.

The way we testing successful sending/receiving was to pass a "token".
Using mail_in as example: the host goes into "rz/rb" mode and the caller
sends the contents of MAIL_OUT.  The caller then goes into receive mode,
and waits for the host to send some small (only a few bytes) file with a
magic name, like RECEIVED.OK.  When the caller script sees the existence
of the magic file, it knows that it can delete the contents of MAIL_OUT.
This would be repeated for news_in.

It would be possible to do a loop, where each file in the outgoing
directory was sent, a token file received, then the sent message would
be deleted.  But I don't think many people are going to have that many
large messages, so just send the whole directory.  If there's a problem,
the host could throw everything away (sending *.*) or keep everything
but the last file (since it's likely to be damaged).

Flow chart of our script:

wait until magic time
while !successful
do
	call host
	if connected
	{
	login
	cd ~/MAIL_OUT
	if exist *.*
		{
		send "mail_in" /* Yes, it's confusing.  Whether it's in or out
						depends on whether or not you're the host, just
						like uploading varies on whether you're getting
						or taking the file.  We probably should call this
						"mail_out" since there are more callers than
						sysadmins.  Around these parts, anyway. */
		send files
		receive file
		if RECEIVED.OK exists
			delete *.*
		else
			{
			hangup /* We're probably already disconnected */
			resume loop
			}
		}
	cd ~/NEWS_OUT
	if exist *.*
		send "news_in"
		send files
		receive file
		if RECEIVED.OK exists
			delete *.*
		else
			{
			hangup /* We're probably already disconnected */
			resume loop
			}
		}
	cd ~/MAIL_IN
	send "mail_out"
	receive file(s) 
	if RECEIVED.OK exists
		send RECEIVED.OK
		/* Let the host know it can delete mail */
	else
		{
		delete *.* /* Do we try to salvage partial transfer?  */
		hangup /* We're probably already disconnected */
		resume loop
		}
	remove RECEIVED.OK
	cd ~/NEWS_IN
	send "news_in"
	receive files(s)
	if RECEIVED.OK exists
		send RECEIVED.OK
		/* Let the host know it can delete news */
	else
		{
		delete *.* /* Do we try to salvage partial transfer?  */
		hangup /* We're probably already disconnected */
		resume loop
		}
	remove RECEIVED.OK
	send "logout"
	successful is set to true
done