10 date 95.12.06.23.51.28; author jromine; state Exp;
15 date 93.09.01.21.44.19; author jromine; state Exp;
20 date 93.08.20.15.52.41; author jromine; state Exp;
25 date 92.12.15.00.20.22; author jromine; state Exp;
30 date 92.11.04.00.49.17; author jromine; state Exp;
35 date 92.10.16.16.51.48; author jromine; state Exp;
40 date 92.02.04.21.58.40; author jromine; state Exp;
45 date 92.02.04.21.54.20; author jromine; state Exp;
50 date 92.02.03.16.35.46; author jromine; state Exp;
55 date 92.01.31.22.49.20; author jromine; state Exp;
60 date 92.01.31.22.16.47; author jromine; state Exp;
65 date 90.04.05.15.01.32; author sources; state Exp;
70 date 90.02.06.13.21.51; author sources; state Exp;
75 date 90.02.06.13.21.36; author sources; state Exp;
89 @/* msgchk.c - check for mail */
91 static char ident[] = "@@(#)$Id: msgchk.c,v 1.13 1993/09/01 21:44:19 jromine Exp jromine $";
96 #include "../zotnet/mts.h"
97 #include "../zotnet/tws.h"
98 #include <sys/types.h>
111 #define POPminc(a) (a)
117 #define RPOPminc(a) (a)
119 #define RPOPminc(a) 0
123 #define APOPminc(a) (a)
125 #define APOPminc(a) 0
128 static struct swit switches[] = {
140 "host host", POPminc (-4),
142 "user user", POPminc (-4),
145 "apop", APOPminc (-4),
147 "noapop", APOPminc (-6),
150 "rpop", RPOPminc (-4),
152 "norpop", RPOPminc (-6),
165 #define NT_ALL (NT_MAIL | NT_NMAI)
171 #define UUCPOK (UUCPOLD | UUCPNEW)
174 #define MMDFOK (MMDFOLD | MMDFNEW)
179 struct passwd *getpwuid(), *getpwnam();
180 #endif /* !__STDC__ */
183 static int donote(), checkmail(), remotemail();
206 char *user = getusr ();
209 struct hes_postoffice *po;
214 setlocale(LC_ALL, "");
216 invo_name = r1bindex (argv[0], '/');
217 mts_init (invo_name);
219 if ((cp = getenv ("MHPOPDEBUG")) && *cp)
223 if ((cp = m_find (invo_name)) != NULL) {
224 ap = brkstring (cp = getcpy (cp), " ", "\n");
225 ap = copyip (ap, arguments);
229 (void) copyip (argv + 1, ap);
234 while (cp = *argp++) {
236 switch (smatch (++cp, switches)) {
238 ambigsw (cp, switches);
241 adios (NULLCP, "-%s unknown", cp);
243 (void) sprintf (buf, "%s [switches] [users ...]",
245 help (buf, switches);
256 if (!(cp = *argp++) || *cp == '-')
257 adios (NULLCP, "missing argument to %s", argp[-2]);
258 notifysw |= donote (cp, 1);
261 if (!(cp = *argp++) || *cp == '-')
262 adios (NULLCP, "missing argument to %s", argp[-2]);
263 notifysw &= ~donote (cp, 0);
267 if (!(host = *argp++) || *host == '-')
268 adios (NULLCP, "missing argument to %s", argp[-2]);
271 if (!(cp = *argp++) || *cp == '-')
272 adios (NULLCP, "missing argument to %s", argp[-2]);
291 if (!host || !*host) { /* -host not specified by user */
295 * use MAILHOST environment variable if present,
297 * If that fails, use the default (if any)
298 * provided by mtstailor in mts_init()
300 if ((tmphost = getenv("MAILHOST")) != NULL)
302 else if ((po = hes_getmailhost(vecp ? vec[0] : user)) != NULL &&
303 strcmp(po->po_type, "POP") == 0)
304 pophost = po->po_host;
306 if (pophost && *pophost)
311 if (!host || rpop <= 0)
317 status = remotemail (host, user, rpop, notifysw, 1, snoop);
321 char *home = (uid = geteuid()) ? home = getenv ("HOME") : NULL;
324 pw = getpwnam (user);
326 adios (NULLCP, "unable to get information about user");
330 status = checkmail (user, home, datesw, notifysw, 1);
336 for (vecp = 0; cp = vec[vecp]; vecp++)
339 status += remotemail (host, cp, rpop, notifysw, 0, snoop);
342 if (pw = getpwnam (cp))
343 status += checkmail (pw->pw_name, pw->pw_dir, datesw, notifysw, 0);
345 advise (NULLCP, "no such user as %s", cp);
353 static struct swit ntswitches[] = {
365 static int donote (cp, ntflag)
369 switch (smatch (cp, ntswitches)) {
371 ambigsw (cp, ntswitches);
374 adios (NULLCP, "-%snotify %s unknown", ntflag ? "" : "no", cp);
391 static int checkmail (user, home, datesw, notifysw, personal)
392 register char *user, *home;
402 (void) sprintf (buffer, "%s/%s",
403 mmdfldir[0] ? mmdfldir : home,
404 mmdflfil[0] ? mmdflfil : user);
408 st.st_atime = st.st_mtime = 0;
411 mf = (stat (buffer, &st) == NOTOK || st.st_size == 0) ? NONEOK
412 : st.st_atime <= st.st_mtime ? MMDFNEW : MMDFOLD;
415 if (umincproc != NULL && *umincproc != NULL) {
416 (void) sprintf (buffer, "%s/%s",
417 uucpldir[0] ? uucpldir : home,
418 uucplfil[0] ? uucplfil : user);
419 mf |= (stat (buffer, &st) == NOTOK || st.st_size == 0) ? NONEOK
420 : st.st_atime <= st.st_mtime ? UUCPNEW : UUCPOLD;
424 if ((mf & UUCPOK) || (mf & MMDFOK)) {
425 if (notifysw & NT_MAIL) {
426 printf (personal ? "You have " : "%s has ", user);
428 printf ("%s old-style bell", mf & UUCPOLD ? "old" : "new");
429 if ((mf & UUCPOK) && (mf & MMDFOK))
432 printf ("%s%s", mf & MMDFOLD ? "old" : "new",
433 mf & UUCPOK ? " Internet" : "");
434 printf (" mail waiting");
442 if (notifysw & NT_NMAI)
443 printf (personal ? "You don't %s%s" : "%s doesn't %s",
444 personal ? "" : user, "have any mail waiting");
453 if (datesw && st.st_atime)
454 printf ("; last read on %s",
455 dasctime (dlocaltime ((long *) & st.st_atime), TW_NULL));
466 extern char response[];
469 static int remotemail (host, user, rpop, notifysw, personal, snoop)
487 ruserpass (host, &user, &pass);
489 if (pop_init (host, user, pass, snoop, rpop) == NOTOK
490 || pop_stat (&nmsgs, &nbytes) == NOTOK
491 || pop_quit () == NOTOK) {
492 advise (NULLCP, "%s", response);
497 if (notifysw & NT_MAIL) {
498 printf (personal ? "You have " : "%s has ", user);
499 printf ("%d message%s (%d bytes)",
500 nmsgs, nmsgs != 1 ? "s" : "", nbytes);
508 if (notifysw & NT_NMAI)
509 printf (personal ? "You don't %s%s" : "%s doesn't %s",
510 personal ? "" : user, "have any mail waiting");
516 printf (" on %s\n", host);
526 @don't override -host value with pophost
531 static char ident[] = "@@(#)$Id: msgchk.c,v 1.12 1993/08/20 15:52:41 jromine Exp jromine $";
540 @better user defaulting on rpop/apop
541 should check to make sure this works OK
546 static char ident[] = "@@(#)$Id: msgchk.c,v 1.11 1992/12/15 00:20:22 jromine Exp jromine $";
552 * use MAILHOST environment variable if present,
554 * If that fails, use the default (if any)
555 * provided by mtstailor in mts_init()
557 if (pophost == NULL || pophost[0] == '\0')
564 strcmp(po->po_type, "POP") == 0)
565 pophost = po->po_host;
569 if (pophost && *pophost)
581 static char ident[] = "@@(#)$Id: msgchk.c,v 1.10 1992/11/04 00:49:17 jromine Exp jromine $";
599 static char ident[] = "@@(#)$Id: msgchk.c,v 1.9 1992/10/16 16:51:48 jromine Exp jromine $";
641 static char ident[] = "@@(#)$Id: msgchk.c,v 1.8 1992/02/04 21:58:40 jromine Exp jromine $";
649 @don't call getusr() unless needed
654 static char ident[] = "@@(#)$Id: msgchk.c,v 1.7 1992/02/04 21:54:20 jromine Exp jromine $";
671 static char ident[] = "@@(#)$Id: msgchk.c,v 1.6 1992/02/03 16:35:46 jromine Exp jromine $";
685 static char ident[] = "@@(#)$Id: msgchk.c,v 1.5 1992/01/31 22:49:20 jromine Exp jromine $";
721 static char ident[] = "@@(#)$Id: msgchk.c,v 1.4 1992/01/31 22:16:47 jromine Exp jromine $";
734 static char ident[] = "@@(#)$Id: msgchk.c,v 1.3 1990/04/05 15:01:32 sources Exp jromine $";
747 static char ident[] = "@@(#)$Id:$";
757 if (pophost && *pophost)
767 (void) setuid (getuid ());
771 status = remotemail (host, NULLCP, rpop, notifysw, 1, snoop);
775 if ((pw = getpwuid (getuid ())) == NULL)
776 adios (NULLCP, "you lose");
778 status = checkmail (pw, datesw, notifysw, 1);
784 status += checkmail (pw, datesw, notifysw, 0);
790 static int checkmail (pw, datesw, notifysw, personal)
791 register struct passwd *pw;
794 mmdfldir[0] ? mmdfldir : pw -> pw_dir,
795 mmdflfil[0] ? mmdflfil : pw -> pw_name);
798 uucpldir[0] ? uucpldir : pw -> pw_dir,
799 uucplfil[0] ? uucplfil : pw -> pw_name);
802 printf (personal ? "You have " : "%s has ", pw -> pw_name);
805 personal ? "" : pw -> pw_name, "have any mail waiting");