-
-/*
- * msgchk.c -- check for mail
+/* msgchk.c -- check for mail
*
* This code is Copyright (c) 2002, by the authors of nmh. See the
* COPYRIGHT file in the root directory of the nmh distribution for
#include <h/mh.h>
#include <h/mts.h>
#include <h/tws.h>
+#include "h/done.h"
+#include <h/utils.h>
#include <pwd.h>
#include <h/popsbr.h>
*/
#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 *);
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:
}
if (vecp >= MAXVEC-1)
adios (NULL, "you can only check %d users at a time", MAXVEC-1);
- else
- vec[vecp++] = cp;
+ vec[vecp++] = cp;
}
/*
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;
}
printf ("%s has ", user);
printf ("%d message%s (%d bytes)",
- nmsgs, nmsgs != 1 ? "s" : "", nbytes);
+ nmsgs, PLURALS(nmsgs), nbytes);
}
else
notifysw = 0;