147124Sbostic /*- 260718Sbostic * Copyright (c) 1991, 1993 360718Sbostic * The Regents of the University of California. All rights reserved. 447124Sbostic * 547124Sbostic * This code is derived from software contributed to Berkeley by 647124Sbostic * Kenneth Almquist. 747124Sbostic * 847124Sbostic * %sccs.include.redist.c% 947124Sbostic */ 1047124Sbostic 1147124Sbostic #ifndef lint 12*69272Schristos static char sccsid[] = "@(#)mail.c 8.2 (Berkeley) 05/04/95"; 1347124Sbostic #endif /* not lint */ 1447124Sbostic 1547124Sbostic /* 1647124Sbostic * Routines to check for mail. (Perhaps make part of main.c?) 1747124Sbostic */ 1847124Sbostic 1947124Sbostic #include "shell.h" 2047124Sbostic #include "exec.h" /* defines padvance() */ 2147124Sbostic #include "var.h" 2247124Sbostic #include "output.h" 2347124Sbostic #include "memalloc.h" 2447124Sbostic #include "error.h" 2547124Sbostic #include <sys/types.h> 2647124Sbostic #include <sys/stat.h> 2747124Sbostic 2847124Sbostic 2947124Sbostic #define MAXMBOXES 10 3047124Sbostic 3147124Sbostic 3247124Sbostic STATIC int nmboxes; /* number of mailboxes */ 3347124Sbostic STATIC time_t mailtime[MAXMBOXES]; /* times of mailboxes */ 3447124Sbostic 3547124Sbostic 3647124Sbostic 3747124Sbostic /* 3847124Sbostic * Print appropriate message(s) if mail has arrived. If the argument is 3947124Sbostic * nozero, then the value of MAIL has changed, so we just update the 4047124Sbostic * values. 4147124Sbostic */ 4247124Sbostic 4347124Sbostic void chkmail(silent)44*69272Schristoschkmail(silent) 45*69272Schristos int silent; 46*69272Schristos { 4747124Sbostic register int i; 4847124Sbostic char *mpath; 4947124Sbostic char *p; 5047124Sbostic register char *q; 5147124Sbostic struct stackmark smark; 5247124Sbostic struct stat statb; 5347124Sbostic 5447124Sbostic if (silent) 5547124Sbostic nmboxes = 10; 5647124Sbostic if (nmboxes == 0) 5747124Sbostic return; 5847124Sbostic setstackmark(&smark); 5947124Sbostic mpath = mpathset()? mpathval() : mailval(); 6047124Sbostic for (i = 0 ; i < nmboxes ; i++) { 6147124Sbostic p = padvance(&mpath, nullstr); 6247124Sbostic if (p == NULL) 6347124Sbostic break; 6447124Sbostic if (*p == '\0') 6547124Sbostic continue; 6647124Sbostic for (q = p ; *q ; q++); 6747124Sbostic if (q[-1] != '/') 6847124Sbostic abort(); 6947124Sbostic q[-1] = '\0'; /* delete trailing '/' */ 7047124Sbostic #ifdef notdef /* this is what the System V shell claims to do (it lies) */ 7147124Sbostic if (stat(p, &statb) < 0) 7247124Sbostic statb.st_mtime = 0; 7347124Sbostic if (statb.st_mtime > mailtime[i] && ! silent) { 7447124Sbostic out2str(pathopt? pathopt : "you have mail"); 7547124Sbostic out2c('\n'); 7647124Sbostic } 7747124Sbostic mailtime[i] = statb.st_mtime; 7847124Sbostic #else /* this is what it should do */ 7947124Sbostic if (stat(p, &statb) < 0) 8047124Sbostic statb.st_size = 0; 8147124Sbostic if (statb.st_size > mailtime[i] && ! silent) { 8247124Sbostic out2str(pathopt? pathopt : "you have mail"); 8347124Sbostic out2c('\n'); 8447124Sbostic } 8547124Sbostic mailtime[i] = statb.st_size; 8647124Sbostic #endif 8747124Sbostic } 8847124Sbostic nmboxes = i; 8947124Sbostic popstackmark(&smark); 9047124Sbostic } 91