|
|
1.1 root 1: /* msgchk.c - check for mail */
2:
3: #include "../h/mh.h"
4: #include <stdio.h>
5: #include "../zotnet/mts.h"
6: #include <sys/types.h>
7: #include <sys/stat.h>
8: #include <pwd.h>
9:
10: /* */
11:
12: static struct swit switches[] = {
13: #define HELPSW 0
14: "help", 4,
15:
16: #ifdef POP
17: #define HOSTSW 1
18: "host host", 0,
19: #define USERSW 2
20: "user user", 0,
21:
22: #define RPOPSW 3
23: "rpop", 0,
24: #define NRPOPSW 4
25: "norpop", 0,
26: #endif POP
27:
28:
29: NULL, NULL
30: };
31:
32: /* */
33:
34: #define NONEOK 0x0
35: #define UUCPOLD 0x1
36: #define UUCPNEW 0x2
37: #define UUCPOK (UUCPOLD | UUCPNEW)
38: #define MMDFOLD 0x4
39: #define MMDFNEW 0x8
40: #define MMDFOK (MMDFOLD | MMDFNEW)
41:
42:
43: #ifdef POP
44: int snoop = 0;
45: #endif POP
46:
47:
48: #ifdef SYS5
49: struct passwd *getpwuid(), *getpwnam();
50: #endif SYS5
51:
52: /* */
53:
54: /* ARGSUSED */
55:
56: main (argc, argv)
57: int argc;
58: char *argv[];
59: {
60: int vecp = 0;
61: #ifdef POP
62: int rpop = 1;
63: #endif POP
64: char *cp,
65: #ifdef POP
66: *host = NULL,
67: #endif POP
68: buf[80],
69: **ap,
70: **argp,
71: *arguments[MAXARGS],
72: *vec[50];
73: struct passwd *pw;
74:
75: invo_name = r1bindex (argv[0], '/');
76: mts_init (invo_name);
77: #ifdef POP
78: if (pophost && *pophost)
79: host = pophost;
80: if ((cp = getenv ("MHPOPDEBUG")) && *cp)
81: snoop++;
82: #endif POP
83: if ((cp = m_find (invo_name)) != NULL) {
84: ap = brkstring (cp = getcpy (cp), " ", "\n");
85: ap = copyip (ap, arguments);
86: }
87: else
88: ap = arguments;
89: (void) copyip (argv + 1, ap);
90: argp = arguments;
91:
92: /* */
93:
94: while (cp = *argp++) {
95: if (*cp == '-')
96: switch (smatch (++cp, switches)) {
97: case AMBIGSW:
98: ambigsw (cp, switches);
99: done (1);
100: case UNKWNSW:
101: adios (NULLCP, "-%s unknown", cp);
102: case HELPSW:
103: (void) sprintf (buf, "%s [switches] [users ...]",
104: invo_name);
105: help (buf, switches);
106: done (1);
107:
108: #ifdef POP
109: case HOSTSW:
110: if (!(host = *argp++) || *host == '-')
111: adios (NULLCP, "missing argument to %s", argp[-2]);
112: continue;
113: case USERSW:
114: if (!(cp = *argp++) || *cp == '-')
115: adios (NULLCP, "missing argument to %s", argp[-2]);
116: vec[vecp++] = cp;
117: continue;
118: case RPOPSW:
119: rpop++;
120: continue;
121: case NRPOPSW:
122: rpop = 0;
123: continue;
124: #endif POP
125: }
126: vec[vecp++] = cp;
127: }
128:
129: /* */
130:
131: #ifdef POP
132: if (!*host)
133: host = NULL;
134: if (!host || !rpop)
135: (void) setuid (getuid ());
136: #endif POP
137: if (vecp == 0) {
138: #ifdef POP
139: if (host)
140: remotemail (host, NULLCP, rpop, 1);
141: else
142: #endif POP
143: if ((pw = getpwuid (getuid ())) == NULL)
144: adios (NULLCP, "you lose");
145: else
146: checkmail (pw, 1);
147: }
148: else {
149: vec[vecp] = NULL;
150:
151: for (vecp = 0; cp = vec[vecp]; vecp++)
152: #ifdef POP
153: if (host)
154: remotemail (host, cp, rpop, 0);
155: else
156: #endif POP
157: if (pw = getpwnam (cp))
158: checkmail (pw, 0);
159: else
160: advise (NULLCP, "no such user as %s", cp);
161: }
162:
163: done (0);
164: }
165:
166: /* */
167:
168: checkmail (pw, personal)
169: register struct passwd *pw;
170: int personal;
171: {
172: int mf;
173: char buffer[BUFSIZ];
174: struct stat st;
175:
176: (void) sprintf (buffer, "%s/%s",
177: mmdfldir[0] ? mmdfldir : pw -> pw_dir,
178: mmdflfil[0] ? mmdflfil : pw -> pw_name);
179: mf = (stat (buffer, &st) == NOTOK || st.st_size == 0) ? NONEOK
180: : st.st_atime <= st.st_mtime ? MMDFNEW : MMDFOLD;
181:
182: #ifdef MF
183: if (umincproc != NULL && *umincproc != NULL) {
184: (void) sprintf (buffer, "%s/%s",
185: uucpldir[0] ? uucpldir : pw -> pw_dir,
186: uucplfil[0] ? uucplfil : pw -> pw_name);
187: mf |= (stat (buffer, &st) == NOTOK || st.st_size == 0) ? NONEOK
188: : st.st_atime <= st.st_mtime ? UUCPNEW : UUCPOLD;
189: }
190: #endif MF
191:
192: if ((mf & UUCPOK) || (mf & MMDFOK)) {
193: printf (personal ? "You have " : "%s has ", pw -> pw_name);
194: if (mf & UUCPOK)
195: printf ("%s old-style bell",
196: mf & UUCPOLD ? "old" : "new");
197: if ((mf & UUCPOK) && (mf & MMDFOK))
198: printf (" and ");
199: if (mf & MMDFOK)
200: printf ("%s Internet",
201: mf & MMDFOLD ? "old" : "new");
202: printf (" mail waiting\n");
203: }
204: else
205: printf (personal ? "You don't %s%s" : "%s doesn't %s",
206: personal ? "" : pw -> pw_name, "have any mail waiting\n");
207: }
208:
209: /* */
210:
211: #ifdef POP
212: extern char response[];
213:
214:
215: remotemail (host, user, rpop, personal)
216: register char *host;
217: char *user;
218: int rpop,
219: personal;
220: {
221: int nmsgs,
222: nbytes;
223: char *pass;
224:
225: if (rpop) {
226: if (user == NULL)
227: user = getusr ();
228: pass = getusr ();
229: }
230: else
231: ruserpass (host, &user, &pass);
232:
233: if (pop_init (host, user, pass, snoop, rpop) == NOTOK
234: || pop_stat (&nmsgs, &nbytes) == NOTOK
235: || pop_quit () == NOTOK) {
236: advise (NULLCP, "%s", response);
237: return;
238: }
239:
240: if (nmsgs) {
241: printf (personal ? "You have " : "%s has ", user);
242: printf ("%d message%s (%d bytes)",
243: nmsgs, nmsgs != 1 ? "s" : "", nbytes);
244: }
245: else
246: printf (personal ? "You don't %s%s" : "%s doesn't %s",
247: personal ? "" : user, "have any mail waiting");
248: printf (" on %s\n", host);
249: }
250: #endif POP
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.