mdeutils/mbiff/mail.c

36 lines
735 B
C
Raw Normal View History

2025-11-18 20:34:20 +09:00
#include "mbiff.h"
static time_t last = 0;
2025-11-22 17:57:17 +09:00
static char* mailpath;
2025-11-18 20:34:20 +09:00
2025-11-22 17:57:17 +09:00
void init_mail(void) {
2025-11-25 11:16:05 +09:00
struct stat s;
char* name = MDEUsersGetUsername();
2025-11-18 20:34:20 +09:00
2025-11-22 17:57:17 +09:00
if(getenv("MAIL") != NULL) {
2025-11-25 11:16:05 +09:00
mailpath = malloc(strlen(getenv("MAIL")) + strlen(name) + 1);
sprintf(mailpath, getenv("MAIL"), name);
2025-11-22 17:57:17 +09:00
} else {
2025-11-25 11:16:05 +09:00
mailpath = malloc(strlen(_PATH_MAILDIR) + 1 + strlen(name) + 1);
sprintf(mailpath, _PATH_MAILDIR "/%s", name);
2025-11-18 20:34:20 +09:00
}
2025-11-25 11:16:05 +09:00
free(name);
2025-11-18 20:34:20 +09:00
2025-11-22 17:57:17 +09:00
if(stat(mailpath, &s) == 0) {
2025-11-18 20:34:20 +09:00
last = s.st_mtime;
}
}
2025-11-22 17:57:17 +09:00
void check_mail(void) {
2025-11-18 20:34:20 +09:00
struct stat s;
2025-11-18 22:51:48 +09:00
s.st_mtime = 0;
2025-11-22 17:57:17 +09:00
if(stat(mailpath, &s) == 0 || last != 0) {
if((s.st_mtime == 0 && last != 0) || s.st_mtime > last) {
2025-11-18 22:51:48 +09:00
MwVaApply(image,
2025-11-22 17:57:17 +09:00
MwNpixmap, full,
NULL);
2025-11-18 20:34:20 +09:00
}
last = s.st_mtime;
}
}