]>
diplodocus.org Git - nmh/blob - docs/historical/mh-6.8.5/uip/msgchk.c
1 /* msgchk.c - check for mail */
3 static char ident
[] = "@(#)$Id: msgchk.c,v 1.14 1995/12/06 23:51:28 jromine Exp shettich $";
8 #include "../zotnet/mts.h"
9 #include "../zotnet/tws.h"
10 #include <sys/types.h>
23 #define POPminc(a) (a)
29 #define RPOPminc(a) (a)
35 #define APOPminc(a) (a)
40 static struct swit switches
[] = {
52 "host host", POPminc (-4),
54 "user user", POPminc (-4),
57 "apop", APOPminc (-4),
59 "noapop", APOPminc (-6),
62 "rpop", RPOPminc (-4),
64 "norpop", RPOPminc (-6),
77 #define NT_ALL (NT_MAIL | NT_NMAI)
83 #define UUCPOK (UUCPOLD | UUCPNEW)
86 #define MMDFOK (MMDFOLD | MMDFNEW)
91 struct passwd
*getpwuid(), *getpwnam();
92 #endif /* !__STDC__ */
95 static int donote(), checkmail(), remotemail();
122 char *user
= getusr ();
125 struct hes_postoffice
*po
;
130 setlocale(LC_ALL
, "");
132 invo_name
= r1bindex (argv
[0], '/');
133 mts_init (invo_name
);
135 if ((cp
= getenv ("MHPOPDEBUG")) && *cp
)
139 if ((cp
= m_find (invo_name
)) != NULL
) {
140 ap
= brkstring (cp
= getcpy (cp
), " ", "\n");
141 ap
= copyip (ap
, arguments
);
145 (void) copyip (argv
+ 1, ap
);
150 while (cp
= *argp
++) {
152 switch (smatch (++cp
, switches
)) {
154 ambigsw (cp
, switches
);
157 adios (NULLCP
, "-%s unknown", cp
);
159 (void) sprintf (buf
, "%s [switches] [users ...]",
161 help (buf
, switches
);
172 if (!(cp
= *argp
++) || *cp
== '-')
173 adios (NULLCP
, "missing argument to %s", argp
[-2]);
174 notifysw
|= donote (cp
, 1);
177 if (!(cp
= *argp
++) || *cp
== '-')
178 adios (NULLCP
, "missing argument to %s", argp
[-2]);
179 notifysw
&= ~donote (cp
, 0);
183 if (!(host
= *argp
++) || *host
== '-')
184 adios (NULLCP
, "missing argument to %s", argp
[-2]);
187 if (!(cp
= *argp
++) || *cp
== '-')
188 adios (NULLCP
, "missing argument to %s", argp
[-2]);
207 if (!host
|| !*host
) { /* -host not specified by user */
211 * use MAILHOST environment variable if present,
213 * If that fails, use the default (if any)
214 * provided by mtstailor in mts_init()
216 if ((tmphost
= getenv("MAILHOST")) != NULL
)
218 else if ((po
= hes_getmailhost(vecp
? vec
[0] : user
)) != NULL
&&
219 strcmp(po
->po_type
, "POP") == 0)
220 pophost
= po
->po_host
;
222 if (pophost
&& *pophost
)
227 if (!host
|| rpop
<= 0)
233 status
= remotemail (host
, user
, rpop
, notifysw
, 1, snoop
);
237 char *home
= (uid
= geteuid()) ? home
= getenv ("HOME") : NULL
;
240 pw
= getpwnam (user
);
242 adios (NULLCP
, "unable to get information about user");
246 status
= checkmail (user
, home
, datesw
, notifysw
, 1);
252 for (vecp
= 0; cp
= vec
[vecp
]; vecp
++)
255 status
+= remotemail (host
, cp
, rpop
, notifysw
, 0, snoop
);
258 if (pw
= getpwnam (cp
))
259 status
+= checkmail (pw
->pw_name
, pw
->pw_dir
, datesw
, notifysw
, 0);
261 advise (NULLCP
, "no such user as %s", cp
);
269 static struct swit ntswitches
[] = {
281 static int donote (cp
, ntflag
)
285 switch (smatch (cp
, ntswitches
)) {
287 ambigsw (cp
, ntswitches
);
290 adios (NULLCP
, "-%snotify %s unknown", ntflag
? "" : "no", cp
);
307 static int checkmail (user
, home
, datesw
, notifysw
, personal
)
308 register char *user
, *home
;
318 (void) sprintf (buffer
, "%s/%s",
319 mmdfldir
[0] ? mmdfldir
: home
,
320 mmdflfil
[0] ? mmdflfil
: user
);
324 st
.st_atime
= st
.st_mtime
= 0;
327 mf
= (stat (buffer
, &st
) == NOTOK
|| st
.st_size
== 0) ? NONEOK
328 : st
.st_atime
<= st
.st_mtime
? MMDFNEW
: MMDFOLD
;
331 if (umincproc
!= NULL
&& *umincproc
!= NULL
) {
332 (void) sprintf (buffer
, "%s/%s",
333 uucpldir
[0] ? uucpldir
: home
,
334 uucplfil
[0] ? uucplfil
: user
);
335 mf
|= (stat (buffer
, &st
) == NOTOK
|| st
.st_size
== 0) ? NONEOK
336 : st
.st_atime
<= st
.st_mtime
? UUCPNEW
: UUCPOLD
;
340 if ((mf
& UUCPOK
) || (mf
& MMDFOK
)) {
341 if (notifysw
& NT_MAIL
) {
342 printf (personal
? "You have " : "%s has ", user
);
344 printf ("%s old-style bell", mf
& UUCPOLD
? "old" : "new");
345 if ((mf
& UUCPOK
) && (mf
& MMDFOK
))
348 printf ("%s%s", mf
& MMDFOLD
? "old" : "new",
349 mf
& UUCPOK
? " Internet" : "");
350 printf (" mail waiting");
358 if (notifysw
& NT_NMAI
)
359 printf (personal
? "You don't %s%s" : "%s doesn't %s",
360 personal
? "" : user
, "have any mail waiting");
369 if (datesw
&& st
.st_atime
)
370 printf ("; last read on %s",
371 dasctime (dlocaltime ((long *) & st
.st_atime
), TW_NULL
));
382 extern char response
[];
385 static int remotemail (host
, user
, rpop
, notifysw
, personal
, snoop
)
403 ruserpass (host
, &user
, &pass
);
405 if (pop_init (host
, user
, pass
, snoop
, rpop
) == NOTOK
406 || pop_stat (&nmsgs
, &nbytes
) == NOTOK
407 || pop_quit () == NOTOK
) {
408 advise (NULLCP
, "%s", response
);
413 if (notifysw
& NT_MAIL
) {
414 printf (personal
? "You have " : "%s has ", user
);
415 printf ("%d message%s (%d bytes)",
416 nmsgs
, nmsgs
!= 1 ? "s" : "", nbytes
);
424 if (notifysw
& NT_NMAI
)
425 printf (personal
? "You don't %s%s" : "%s doesn't %s",
426 personal
? "" : user
, "have any mail waiting");
432 printf (" on %s\n", host
);