[net.unix-wizards] Checking for new mail ?

dan@rna.UUCP (01/16/84)

	I must be missing something, but I can't see any surefire way of
checking if any new mail has come into a mail file without understanding
the mail file format and crunching it.
	I'm not up on all the mail systems, but take the example of a mail
program like /bin/mail with a single mail file, along with a program like
the shell which wants to check quickly from time to time.
	You definitely check for atime greater than mtime, since that means
the user has scanned the mail file.
	If you check for size increases, that doesn't account for the chance
that the user has read some of his mail, has deleted a few items and a
short new item has been added since the last time you've checked.
	Unfortunately, UNIX doesn't seem to have a way of checking if only
a write has occurred, since atime, ctime and mtime all get updated with
a write().
	I've checked /bin/sh and /bin/csh code and am not convinced they
solve the previous situation. Perhaps if all mail programs did a final
read after each session to make atime greater than mtime.
	What am I missing ?

						Cheers,
						Dan Ts'o
						...cmcl2!rna!dan
P.S.
	One other possibility: some mail programs create a new file at
the end of a session and copy over messages which has not been deleted,
then unlink the original and link in the new file. In this situation
ctime != mtime since the last operation will be the link() rather than
the write().

guy@rlgvax.UUCP (Guy Harris) (01/16/84)

They don't solve the problem completely, but then they never intended to.
A mail checking algorithm which is 99% accurate is good enough; the cost
of making one that never gives a false alarm is sufficiently great that
it really isn't worth it.

	Guy Harris
	{seismo,ihnp4,allegra}!rlgvax!guy

gwyn%brl-vld@sri-unix.UUCP (01/17/84)

From:      Doug Gwyn (VLD/VMB) <gwyn@brl-vld>

The st_atime of a file is NOT supposed to be changed by a write(2).