perand@nada.kth.se (Per Andersson) (01/14/90)
Hello. 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 ? Per -- --- Per Andersson Royal Institute of Technology, Stockholm, Sweden perand@admin.kth.se, @nada.kth.se
jik@athena.mit.edu (Jonathan I. Kamens) (01/15/90)
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 <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@Athena.MIT.EDU Allston, MA 02134 Office: 617-253-8495 Home: 617-782-0710