Checking new mail in programs
Jonathan I. Kamens
jik at athena.mit.edu
Mon Jan 15 15:18:15 AEST 1990
In article <2722 at draken.nada.kth.se>, perand at nada.kth.se (Per Andersson)
writes:
> I am writing a program similar to 'finger'. In fact I took finger and
> ripped out the parts I didn't need. But I don't know how to check if
> the user has mail/new mail. The SunOS finger program does this, but
> I only have source to BSD4.3. Also I have a system V variant, but that
> has to be setuid to root, and that is out of the question. Suns is an
> ordinary program so it can be done. What approach should I take ?
This code is untested, but should do just about the right thing, or at
least show you how to do it. I got the general idea of how to do this
from the sources to our login program.
#include <sys/types.h>
#include <sys/stat.h>
/*
* assumes that mail directory is /usr/spool/mail, and that usernames are never
* longer than eight characters.
*/
char mailfile[25];
struct stat statbuf;
char *username;
/*
* somewhere above this code fragment, the variable username should be set.
*/
sprintf(mailfile, "/usr/spool/mail/%s", username);
if ((stat(mailfile, &statbuf) == 0) && statbuf.st_size != 0)
printf("You have %smail.\n",
(statbuf.st_mtime > statbuf.st_atime) ? "new " : "");
Jonathan Kamens USnail:
MIT Project Athena 11 Ashford Terrace
jik at Athena.MIT.EDU Allston, MA 02134
Office: 617-253-8495 Home: 617-782-0710
More information about the Comp.unix.questions
mailing list