1*21568Sdist /*
2*21568Sdist * Copyright (c) 1980 Regents of the University of California.
3*21568Sdist * All rights reserved. The Berkeley software License Agreement
4*21568Sdist * specifies the terms and conditions for redistribution.
5*21568Sdist */
61367Sbill
7*21568Sdist #ifndef lint
8*21568Sdist char copyright[] =
9*21568Sdist "@(#) Copyright (c) 1980 Regents of the University of California.\n\
10*21568Sdist All rights reserved.\n";
11*21568Sdist #endif not lint
12*21568Sdist
13*21568Sdist #ifndef lint
14*21568Sdist static char sccsid[] = "@(#)prmail.c 5.1 (Berkeley) 05/31/85";
15*21568Sdist #endif not lint
16*21568Sdist
171367Sbill #include <pwd.h>
181367Sbill /*
191367Sbill * prmail
201367Sbill */
211367Sbill struct passwd *getpwuid();
221367Sbill char *getenv();
231367Sbill
main(argc,argv)241367Sbill main(argc, argv)
251367Sbill int argc;
261367Sbill char **argv;
271367Sbill {
281367Sbill register struct passwd *pp;
291367Sbill
301367Sbill --argc, ++argv;
311367Sbill if (chdir("/usr/spool/mail") < 0) {
321367Sbill perror("/usr/spool/mail");
331367Sbill exit(1);
341367Sbill }
351367Sbill if (argc == 0) {
361367Sbill char *user = getenv("USER");
371367Sbill if (user == 0) {
381367Sbill pp = getpwuid(getuid());
391367Sbill if (pp == 0) {
401367Sbill printf("Who are you?\n");
411367Sbill exit(1);
421367Sbill }
431367Sbill user = pp->pw_name;
441367Sbill }
451367Sbill prmail(user, 0);
461367Sbill } else
471367Sbill while (--argc >= 0)
481367Sbill prmail(*argv++, 1);
491367Sbill exit(0);
501367Sbill }
511367Sbill
521367Sbill #include <sys/types.h>
531367Sbill #include <sys/stat.h>
541367Sbill
prmail(user,other)551367Sbill prmail(user, other)
561367Sbill char *user;
571367Sbill {
581367Sbill struct stat stb;
591367Sbill char cmdbuf[256];
601367Sbill
611367Sbill if (stat(user, &stb) < 0) {
621367Sbill printf("No mail for %s.\n", user);
631367Sbill return;
641367Sbill }
6510824Ssam if (access(user, 4) < 0) {
661367Sbill printf("Mailbox for %s unreadable\n", user);
671367Sbill return;
681367Sbill }
691367Sbill if (other)
701367Sbill printf(">>> %s <<<\n", user);
711367Sbill sprintf(cmdbuf, "more %s", user);
721367Sbill system(cmdbuf);
731367Sbill if (other)
741367Sbill printf("-----\n\n");
751367Sbill }
76