1*1367Sbill static char *sccsid = "@(#)prmail.c 4.1 (Berkeley) 10/10/80"; 2*1367Sbill 3*1367Sbill #include <pwd.h> 4*1367Sbill /* 5*1367Sbill * prmail 6*1367Sbill */ 7*1367Sbill struct passwd *getpwuid(); 8*1367Sbill char *getenv(); 9*1367Sbill 10*1367Sbill main(argc, argv) 11*1367Sbill int argc; 12*1367Sbill char **argv; 13*1367Sbill { 14*1367Sbill register struct passwd *pp; 15*1367Sbill 16*1367Sbill --argc, ++argv; 17*1367Sbill if (chdir("/usr/spool/mail") < 0) { 18*1367Sbill perror("/usr/spool/mail"); 19*1367Sbill exit(1); 20*1367Sbill } 21*1367Sbill if (argc == 0) { 22*1367Sbill char *user = getenv("USER"); 23*1367Sbill if (user == 0) { 24*1367Sbill pp = getpwuid(getuid()); 25*1367Sbill if (pp == 0) { 26*1367Sbill printf("Who are you?\n"); 27*1367Sbill exit(1); 28*1367Sbill } 29*1367Sbill user = pp->pw_name; 30*1367Sbill } 31*1367Sbill prmail(user, 0); 32*1367Sbill } else 33*1367Sbill while (--argc >= 0) 34*1367Sbill prmail(*argv++, 1); 35*1367Sbill exit(0); 36*1367Sbill } 37*1367Sbill 38*1367Sbill #include <sys/types.h> 39*1367Sbill #include <sys/stat.h> 40*1367Sbill 41*1367Sbill prmail(user, other) 42*1367Sbill char *user; 43*1367Sbill { 44*1367Sbill struct stat stb; 45*1367Sbill char cmdbuf[256]; 46*1367Sbill 47*1367Sbill if (stat(user, &stb) < 0) { 48*1367Sbill printf("No mail for %s.\n", user); 49*1367Sbill return; 50*1367Sbill } 51*1367Sbill if (access(user, "4") < 0) { 52*1367Sbill printf("Mailbox for %s unreadable\n", user); 53*1367Sbill return; 54*1367Sbill } 55*1367Sbill if (other) 56*1367Sbill printf(">>> %s <<<\n", user); 57*1367Sbill sprintf(cmdbuf, "more %s", user); 58*1367Sbill system(cmdbuf); 59*1367Sbill if (other) 60*1367Sbill printf("-----\n\n"); 61*1367Sbill } 62