X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/e9bab734900d62af2bf2fc873dd480e7503335b9..7a5b7cbf34581a0294713ef5bb92ec5566b6be9f:/uip/msgchk.c diff --git a/uip/msgchk.c b/uip/msgchk.c index 44d93528..3e04f8f7 100644 --- a/uip/msgchk.c +++ b/uip/msgchk.c @@ -8,6 +8,8 @@ #include #include #include +#include "h/done.h" +#include #include #include @@ -59,26 +61,15 @@ DEFINE_SWITCH_ARRAY(MSGCHK, switches); */ #define MAXVEC 51 -#define NT_NONE 0x0 -#ifdef NT_NONE -#endif /* Use NT_NONE to prevent warning from gcc -Wunused-macros. */ #define NT_MAIL 0x1 #define NT_NMAI 0x2 #define NT_ALL (NT_MAIL | NT_NMAI) -#define NONEOK 0x0 -#define UUCPOLD 0x1 -#define UUCPNEW 0x2 -#define UUCPOK (UUCPOLD | UUCPNEW) -#define MMDFOLD 0x4 -#define MMDFNEW 0x8 -#define MMDFOK (MMDFOLD | MMDFNEW) - /* * static prototypes */ -static int donote (char *, int); +static int donote (char *, int) PURE; static int checkmail (char *, char *, int, int, int); static int remotemail (char *, char *, char *, char *, int, int, int, int, char *, int, const char *); @@ -153,8 +144,7 @@ main (int argc, char **argv) adios (NULL, "missing argument to %s", argp[-2]); if (vecp >= MAXVEC-1) adios (NULL, "you can only check %d users at a time", MAXVEC-1); - else - user = vec[vecp++] = cp; + user = vec[vecp++] = cp; continue; case SNOOPSW: @@ -207,8 +197,7 @@ main (int argc, char **argv) } if (vecp >= MAXVEC-1) adios (NULL, "you can only check %d users at a time", MAXVEC-1); - else - vec[vecp++] = cp; + vec[vecp++] = cp; } /* @@ -312,54 +301,39 @@ donote (char *cp, int ntflag) static int checkmail (char *user, char *home, int datesw, int notifysw, int personal) { - int mf, status; char buffer[BUFSIZ]; - struct stat st; + snprintf(buffer, sizeof buffer, "%s/%s", *mmdfldir ? mmdfldir : home, + *mmdflfil ? mmdflfil : user); - snprintf (buffer, sizeof(buffer), "%s/%s", mmdfldir[0] ? mmdfldir : home, mmdflfil[0] ? mmdflfil : user); - if (datesw) { - st.st_size = 0; - st.st_atime = st.st_mtime = 0; - } - mf = (stat (buffer, &st) == NOTOK || st.st_size == 0) ? NONEOK - : st.st_atime <= st.st_mtime ? MMDFNEW : MMDFOLD; + struct stat st; + bool statok = stat(buffer, &st) != -1; + bool empty = !statok || st.st_size == 0; - if ((mf & UUCPOK) || (mf & MMDFOK)) { - if (notifysw & NT_MAIL) { - if (personal) - printf ("You have "); - else - printf ("%s has ", user); - if (mf & UUCPOK) - printf ("%s old-style bell", mf & UUCPOLD ? "old" : "new"); - if ((mf & UUCPOK) && (mf & MMDFOK)) - printf (" and "); - if (mf & MMDFOK) - printf ("%s%s", mf & MMDFOLD ? "old" : "new", - mf & UUCPOK ? " Internet" : ""); - printf (" mail waiting"); - } else { - notifysw = 0; - } - status = 0; + if ((empty && !(notifysw & NT_NMAI)) || + (!empty && !(notifysw & NT_MAIL))) { + return empty; } - else { - if (notifysw & NT_NMAI) - printf (personal ? "You don't %s%s" : "%s doesn't %s", - personal ? "" : user, "have any mail waiting"); - else - notifysw = 0; - status = 1; + if (empty) { + if (personal) { + fputs("You don't have any mail waiting", stdout); + } else { + printf("%s doesn't have any mail waiting", user); + } + } else { + char *kind = st.st_mtime < st.st_atime ? "old" : "new"; + if (personal) { + printf("You have %s mail waiting", kind); + } else { + printf("%s has %s mail waiting", user, kind); + } } - if (notifysw) - if (datesw && st.st_atime) - printf ("; last read on %s", dtime (&st.st_atime, 1)); - if (notifysw) - putchar('\n'); + if (datesw && statok && st.st_atime) + printf("; last read on %s", dtime(&st.st_atime, 1)); + putchar('\n'); - return status; + return empty; }