* new version 2.19.9999
[alpine.git] / pico / osdep / newmail.c
blob4695b13f2032c3a187b6e76c71cc010dfd39296c
1 #if !defined(lint) && !defined(DOS)
2 static char rcsid[] = "$Id: newmail.c 769 2007-10-24 00:15:40Z hubert@u.washington.edu $";
3 #endif
5 /*
6 * ========================================================================
7 * Copyright 2006-2007 University of Washington
8 * Copyright 2013-2015 Eduardo Chappa
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * ========================================================================
19 #include <system.h>
20 #include <general.h>
22 #include "../estruct.h"
23 #include "../mode.h"
24 #include "../pico.h"
25 #include "../edef.h"
26 #include "../efunc.h"
27 #include "../keydefs.h"
29 #include "../../pith/charconv/filesys.h"
31 #include "newmail.h"
37 * pico_new_mail - just checks mtime and atime of mail file and notifies user
38 * if it's possible that they have new mail.
40 int
41 pico_new_mail(void)
43 #ifndef _WINDOWS
44 int ret = 0;
45 static time_t lastchk = 0;
46 struct stat sbuf;
47 char inbox[256], *p;
49 if((p = (char *)getenv("MAIL")) != NULL)
50 /* fix unsafe sprintf - noticed by petter wahlman <petter@bluezone.no> */
51 snprintf(inbox, sizeof(inbox), "%s", p);
52 else
53 snprintf(inbox, sizeof(inbox), "%s/%s", MAILDIR, (char *) getlogin());
55 if(our_stat(inbox, &sbuf) == 0){
56 ret = sbuf.st_atime <= sbuf.st_mtime &&
57 (lastchk < sbuf.st_mtime && lastchk < sbuf.st_atime);
58 lastchk = sbuf.st_mtime;
59 return(ret);
61 else
62 return(ret);
63 #else /* _WINDOWS */
64 return(0);
65 #endif