1*10824Ssam static char *sccsid = "@(#)prmail.c 4.2 (Berkeley) 02/09/83"; 21367Sbill 31367Sbill #include <pwd.h> 41367Sbill /* 51367Sbill * prmail 61367Sbill */ 71367Sbill struct passwd *getpwuid(); 81367Sbill char *getenv(); 91367Sbill 101367Sbill main(argc, argv) 111367Sbill int argc; 121367Sbill char **argv; 131367Sbill { 141367Sbill register struct passwd *pp; 151367Sbill 161367Sbill --argc, ++argv; 171367Sbill if (chdir("/usr/spool/mail") < 0) { 181367Sbill perror("/usr/spool/mail"); 191367Sbill exit(1); 201367Sbill } 211367Sbill if (argc == 0) { 221367Sbill char *user = getenv("USER"); 231367Sbill if (user == 0) { 241367Sbill pp = getpwuid(getuid()); 251367Sbill if (pp == 0) { 261367Sbill printf("Who are you?\n"); 271367Sbill exit(1); 281367Sbill } 291367Sbill user = pp->pw_name; 301367Sbill } 311367Sbill prmail(user, 0); 321367Sbill } else 331367Sbill while (--argc >= 0) 341367Sbill prmail(*argv++, 1); 351367Sbill exit(0); 361367Sbill } 371367Sbill 381367Sbill #include <sys/types.h> 391367Sbill #include <sys/stat.h> 401367Sbill 411367Sbill prmail(user, other) 421367Sbill char *user; 431367Sbill { 441367Sbill struct stat stb; 451367Sbill char cmdbuf[256]; 461367Sbill 471367Sbill if (stat(user, &stb) < 0) { 481367Sbill printf("No mail for %s.\n", user); 491367Sbill return; 501367Sbill } 51*10824Ssam if (access(user, 4) < 0) { 521367Sbill printf("Mailbox for %s unreadable\n", user); 531367Sbill return; 541367Sbill } 551367Sbill if (other) 561367Sbill printf(">>> %s <<<\n", user); 571367Sbill sprintf(cmdbuf, "more %s", user); 581367Sbill system(cmdbuf); 591367Sbill if (other) 601367Sbill printf("-----\n\n"); 611367Sbill } 62