* New version 2.26
[alpine.git] / pico / osdep / newmail.c
blob8708ddbeed444ccde60034dc1663bfc0dfb6f558
1 /*
2 * ========================================================================
3 * Copyright 2006-2007 University of Washington
4 * Copyright 2013-2022 Eduardo Chappa
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * ========================================================================
15 #include <system.h>
16 #include <general.h>
18 #include "../estruct.h"
19 #include "../mode.h"
20 #include "../pico.h"
21 #include "../edef.h"
22 #include "../efunc.h"
23 #include "../keydefs.h"
25 #include "../../pith/charconv/filesys.h"
27 #include "newmail.h"
33 * pico_new_mail - just checks mtime and atime of mail file and notifies user
34 * if it's possible that they have new mail.
36 int
37 pico_new_mail(void)
39 #ifndef _WINDOWS
40 int ret = 0;
41 static time_t lastchk = 0;
42 struct stat sbuf;
43 char inbox[256], *p;
45 if((p = (char *)getenv("MAIL")) != NULL)
46 /* fix unsafe sprintf - noticed by petter wahlman <petter@bluezone.no> */
47 snprintf(inbox, sizeof(inbox), "%s", p);
48 else
49 snprintf(inbox, sizeof(inbox), "%s/%s", MAILDIR, (char *) getlogin());
51 if(our_stat(inbox, &sbuf) == 0){
52 ret = sbuf.st_atime <= sbuf.st_mtime &&
53 (lastchk < sbuf.st_mtime && lastchk < sbuf.st_atime);
54 lastchk = sbuf.st_mtime;
55 return(ret);
57 else
58 return(ret);
59 #else /* _WINDOWS */
60 return(0);
61 #endif