Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!usc!snorkelwacker!bloom-beacon!athena.mit.edu!jik From: jik@athena.mit.edu (Jonathan I. Kamens) Newsgroups: comp.unix.questions Subject: Re: Checking new mail in programs Message-ID: <1990Jan15.041815.20421@athena.mit.edu> Date: 15 Jan 90 04:18:15 GMT References: <2722@draken.nada.kth.se> Sender: news@athena.mit.edu (News system) Reply-To: jik@athena.mit.edu (Jonathan I. Kamens) Organization: Massachusetts Institute of Technology Lines: 38 In article <2722@draken.nada.kth.se>, perand@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 #include /* * 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@Athena.MIT.EDU Allston, MA 02134 Office: 617-253-8495 Home: 617-782-0710