date and time created 87/02/05 15:19:02 by slatteng
[unix-history] / usr / src / old / prmail / prmail.c
CommitLineData
22e155fc
DF
1/*
2 * Copyright (c) 1980 Regents of the University of California.
3 * All rights reserved. The Berkeley software License Agreement
4 * specifies the terms and conditions for redistribution.
5 */
6
7#ifndef lint
8char copyright[] =
9"@(#) Copyright (c) 1980 Regents of the University of California.\n\
10 All rights reserved.\n";
11#endif not lint
12
13#ifndef lint
14static char sccsid[] = "@(#)prmail.c 5.1 (Berkeley) %G%";
15#endif not lint
750a6622
BJ
16
17#include <pwd.h>
18/*
19 * prmail
20 */
21struct passwd *getpwuid();
22char *getenv();
23
24main(argc, argv)
25 int argc;
26 char **argv;
27{
28 register struct passwd *pp;
29
30 --argc, ++argv;
31 if (chdir("/usr/spool/mail") < 0) {
32 perror("/usr/spool/mail");
33 exit(1);
34 }
35 if (argc == 0) {
36 char *user = getenv("USER");
37 if (user == 0) {
38 pp = getpwuid(getuid());
39 if (pp == 0) {
40 printf("Who are you?\n");
41 exit(1);
42 }
43 user = pp->pw_name;
44 }
45 prmail(user, 0);
46 } else
47 while (--argc >= 0)
48 prmail(*argv++, 1);
49 exit(0);
50}
51
52#include <sys/types.h>
53#include <sys/stat.h>
54
55prmail(user, other)
56 char *user;
57{
58 struct stat stb;
59 char cmdbuf[256];
60
61 if (stat(user, &stb) < 0) {
62 printf("No mail for %s.\n", user);
63 return;
64 }
e32b0050 65 if (access(user, 4) < 0) {
750a6622
BJ
66 printf("Mailbox for %s unreadable\n", user);
67 return;
68 }
69 if (other)
70 printf(">>> %s <<<\n", user);
71 sprintf(cmdbuf, "more %s", user);
72 system(cmdbuf);
73 if (other)
74 printf("-----\n\n");
75}