147124Sbostic /*- 2*60718Sbostic * Copyright (c) 1991, 1993 3*60718Sbostic * 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*60718Sbostic static char sccsid[] = "@(#)mail.c 8.1 (Berkeley) 05/31/93"; 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 4447124Sbostic chkmail(silent) { 4547124Sbostic register int i; 4647124Sbostic char *mpath; 4747124Sbostic char *p; 4847124Sbostic register char *q; 4947124Sbostic struct stackmark smark; 5047124Sbostic struct stat statb; 5147124Sbostic 5247124Sbostic if (silent) 5347124Sbostic nmboxes = 10; 5447124Sbostic if (nmboxes == 0) 5547124Sbostic return; 5647124Sbostic setstackmark(&smark); 5747124Sbostic mpath = mpathset()? mpathval() : mailval(); 5847124Sbostic for (i = 0 ; i < nmboxes ; i++) { 5947124Sbostic p = padvance(&mpath, nullstr); 6047124Sbostic if (p == NULL) 6147124Sbostic break; 6247124Sbostic if (*p == '\0') 6347124Sbostic continue; 6447124Sbostic for (q = p ; *q ; q++); 6547124Sbostic if (q[-1] != '/') 6647124Sbostic abort(); 6747124Sbostic q[-1] = '\0'; /* delete trailing '/' */ 6847124Sbostic #ifdef notdef /* this is what the System V shell claims to do (it lies) */ 6947124Sbostic if (stat(p, &statb) < 0) 7047124Sbostic statb.st_mtime = 0; 7147124Sbostic if (statb.st_mtime > mailtime[i] && ! silent) { 7247124Sbostic out2str(pathopt? pathopt : "you have mail"); 7347124Sbostic out2c('\n'); 7447124Sbostic } 7547124Sbostic mailtime[i] = statb.st_mtime; 7647124Sbostic #else /* this is what it should do */ 7747124Sbostic if (stat(p, &statb) < 0) 7847124Sbostic statb.st_size = 0; 7947124Sbostic if (statb.st_size > mailtime[i] && ! silent) { 8047124Sbostic out2str(pathopt? pathopt : "you have mail"); 8147124Sbostic out2c('\n'); 8247124Sbostic } 8347124Sbostic mailtime[i] = statb.st_size; 8447124Sbostic #endif 8547124Sbostic } 8647124Sbostic nmboxes = i; 8747124Sbostic popstackmark(&smark); 8847124Sbostic } 89