[comp.mail.misc] mail notification at login

allen@nntp-server.caltech.edu (Scott R. Allen) (02/07/91)

Hello -

I am experiencing an anomoly with mail that I don't quite
understand and I would greatly appreciate it if someone could
explain this to me.  Here is the scenario:

Sun workstation --SunOS version 4.1

1.  Root sends mail to user1.
2.  User1 logs in and gets the 'you have new mail' message.
3.  User1 logs out.
4.  User1 logs in again and gets the same 'you have new mail' message.
5.  User1 logs out.
6.  Root executes the command 'cat /var/spool/mail/user1' and the
    all of the mail in user1's folder scrolls on the screen, the
    message that root sent being the last.
7.  User1 logs in again and this time gets the message 'you
    have mail' rather than 'you have new mail'.

The only thing that has happened between step 4 and step 7 is 
that root has done a cat on user1's mail folder.  My question is:
WHY does this happen?  How does it now that the file has been
read by someone and why does it change the message from 'you have
new mail' to 'you have mail'?  

It is my understanding that this test for mail is internal to
the 'login' program.

Note:  A probably unrelated detail -- If this is the first time
that user1 has ever gotton mail (when root sends it in step 1)
and therefore user1 doesn't have a /var/spool/mail/user1 file
then it is created at step 1.  Oddly enough, if this is the case
then in step 2 when user1 logs in the message only says 'you
have mail' rather than 'you have new mail'.  I assume that this
is a bug.  To get around this, root sends user1 two mail messages
or someone else has previously sent user1 mail.

If someone can explain how 'login' decides between 'you have mail'
and 'you have new mail' I would really appreciate it.

thanks

Scott Allen
allen@tybalt.caltech.edu

rickert@mp.cs.niu.edu (Neil Rickert) (02/07/91)

In article <1991Feb6.233621.16164@nntp-server.caltech.edu> allen@nntp-server.caltech.edu (Scott R. Allen) writes:
>
>Sun workstation --SunOS version 4.1
>
>1.  Root sends mail to user1.
>2.  User1 logs in and gets the 'you have new mail' message.
>3.  User1 logs out.
>4.  User1 logs in again and gets the same 'you have new mail' message.
>5.  User1 logs out.
>6.  Root executes the command 'cat /var/spool/mail/user1' and the
>    all of the mail in user1's folder scrolls on the screen, the
>    message that root sent being the last.
>7.  User1 logs in again and this time gets the message 'you
>    have mail' rather than 'you have new mail'.

 I bet you have an NFS mounted mail spool directory.

 What happens is that the shell (or is it 'login') compares the last modified
and last accessed dates of your mailbox.  If modified since the last access
it reports the 'new mail' message.

 The mail command, on saving your mailbox, is careful to ensure that the
last accessed date is updated after the save, so that the mailbox does not
appear to have new mail.  But something happens between the saving on your
host and the actual saving on the server host which owns the real spool
directory.  I have seen various explanations such as clocks not completely
synchronized between the two.  I have not yet seen a fully convincing
explanation.

-- 
=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
  Neil W. Rickert, Computer Science               <rickert@cs.niu.edu>
  Northern Illinois Univ.
  DeKalb, IL 60115                                   +1-815-753-6940

barmar@think.com (Barry Margolin) (02/07/91)

In article <1991Feb6.233621.16164@nntp-server.caltech.edu> allen@nntp-server.caltech.edu (Scott R. Allen) writes:
>If someone can explain how 'login' decides between 'you have mail'
>and 'you have new mail' I would really appreciate it.

If the modification time of the mail file is more recent than the access
time, it adds the word "new".
--
Barry Margolin, Thinking Machines Corp.

barmar@think.com
{uunet,harvard}!think!barmar

prg@mgweed.UUCP (Gunsul) (02/07/91)

In article <1991Feb6.233621.16164@nntp-server.caltech.edu>, allen@nntp-server.caltech.edu (Scott R. Allen) writes:
> Hello -
> 
> I am experiencing an anomoly with mail that I don't quite
> understand and I would greatly appreciate it if someone could
> explain this to me.  Here is the scenario:
> 
> It is my understanding that this test for mail is internal to
> the 'login' program.
> 
> Scott Allen
> allen@tybalt.caltech.edu

I don't know much about Sun systems, but on our 3B's, the check for
mail is done in the /etc/profile, with an "if mail -e then echo
you have mail".

It also sounds like your check on the mail uses the "access" time
on the file rather than the "creation" time, or some combination of
the two...

There is no reference to the mail command in "login" as far as I
can see.

Phil

allen@nntp-server.caltech.edu (Scott R. Allen) (02/07/91)

Thanks for the replies -- I understand now.

Scott