commit 531c239673c159514ba6035b670a1e650d7ef2a0 from: Caleb Stein date: Sat Jun 20 00:29:16 2026 UTC allow up to 8 mailboxes to be monitored commit - 0952df4dba1fa6bfa901a43dbe2f173d9c1bd5f7 commit + 531c239673c159514ba6035b670a1e650d7ef2a0 blob - f1cb02e9b387ed768122a486ebac75a9cb33c85e blob + 4012d5ff7fc8d537bd7a071745f16b5298bc13c2 --- include/statbar.h +++ include/statbar.h @@ -24,7 +24,6 @@ extern void close_display(void); /* FS */ extern bool weather_loc_valid; -extern bool mail_path_valid; extern void read_config(void); extern int open_command_interface(void); @@ -67,8 +66,8 @@ extern void close_weather(void); /* Mail */ extern char mail_string[7]; -extern bool get_mail(void); -extern char **get_mail_path_ptr(void); +extern void get_mail(void); +extern char **get_append_mail_path_ptr(void); extern void close_mail(void); /* Network */ blob - 831622e305ba0930a787c90c60cc59b6d52f954a blob + a12a3dc312ce17805a89431f02c513fdbdc46287 --- modules/mail.c +++ modules/mail.c @@ -1,4 +1,3 @@ -#include #include #include #include @@ -7,46 +6,69 @@ #include "statbar.h" +#define MAX_MAILDIRS 8 + char mail_string[7]; -static char *mail_path; +static char *mail_path[MAX_MAILDIRS]; char ** -get_mail_path_ptr(void) +get_append_mail_path_ptr(void) { - return &mail_path; + int i; + + for (i = 0; i < MAX_MAILDIRS; i++) + { + if (mail_path[i] == NULL) return &mail_path[i]; + } + + return NULL; } -bool +void get_mail(void) { DIR *dir; struct dirent *dp; + int new_mail = 0; + int i = 0; - dir = opendir(mail_path); - if (dir == NULL) + while (mail_path[i]) { - perror("opendir"); + dir = opendir(mail_path[i]); + if (dir == NULL) + { + perror("opendir"); - return false; - } - for (;;) - { - dp = readdir(dir); + continue; + } + for (;;) + { + dp = readdir(dir); - if (dp == NULL || - (strcmp(dp->d_name, ".") != 0 - && strcmp(dp->d_name, "..") != 0)) break; - } - (void)snprintf(mail_string, 7, "%s ", dp ? MAIL : ""); - (void)closedir(dir); + if (dp == NULL || + (strcmp(dp->d_name, ".") != 0 + && strcmp(dp->d_name, "..") != 0)) break; + } + if (dp) new_mail = 1; + (void)closedir(dir); - return true; + if (new_mail || ++i == MAX_MAILDIRS) break; + } + + (void)snprintf(mail_string, 7, "%s ", new_mail ? MAIL : ""); } void close_mail(void) { - free(mail_path); + int i = 0; + + while (mail_path[i]) + { + free(mail_path[i]); + + if (++i == MAX_MAILDIRS) break; + } } blob - 69fa60c0842cd0e65676319e03802e91134cdb44 blob + cc7751e57650ee33fa7bbd84596ce844f64b7149 --- src/fs.c +++ src/fs.c @@ -44,6 +44,7 @@ read_config(void) time_t battery_ms; time_t cputemp_ms; char **weather_location; + char **mail_ptr; uid_t uid; struct passwd *pw; FILE *file; @@ -113,13 +114,17 @@ read_config(void) } if (strncmp(line, "inbox directory", strlen("inbox directory")) == 0) { - if (mail_path_valid && *get_mail_path_ptr() != NULL) close_mail(); + mail_ptr = get_append_mail_path_ptr(); + if (mail_ptr == NULL) + { + (void)printf("Config error line %d: Too many mailboxes specified\n", i); + + continue; + } delim++; while (*delim == ' ') delim++; - if (asprintf(get_mail_path_ptr(), "%s/new", delim) == -1) + if (asprintf(mail_ptr, "%s/new", delim) == -1) perror("asprintf"); - else - mail_path_valid = true; continue; } blob - 91ed0768eda2efa5c651da097817dda010c5a390 blob + 92680bf0f31b186e21edb4298305a38a480d615f --- src/main.c +++ src/main.c @@ -34,7 +34,6 @@ static int reload_mail = 0; static int reload_battery = 0; bool weather_loc_valid = false; -bool mail_path_valid = false; void sig_handler(int sig) @@ -156,7 +155,7 @@ main(void) weather_pfd->events = POLLIN; get_weather(weather_pipe[1]); } - if (mail_path_valid) mail_path_valid = get_mail(); + get_mail(); display = XOpenDisplay(NULL); if (display == NULL) @@ -175,9 +174,6 @@ main(void) } while (!should_quit) { - if (mail_path_valid == false) - close_mail(); - (void)clock_gettime(CLOCK_BOOTTIME, &now); next_event = NULL; for (i = 0; i < CLOCKS_COUNT; i++) @@ -247,10 +243,10 @@ main(void) (void)clock_gettime(CLOCK_BOOTTIME, &now); /* Mail */ - if (mail_path_valid && reload_mail) + if (reload_mail) { reload_mail = 0; - mail_path_valid = get_mail(); + get_mail(); dirty = true; } @@ -320,7 +316,7 @@ cleanup: if (vol_pid > 0) (void)kill(vol_pid, SIGTERM); if (network_pid > 0) (void)kill(network_pid, SIGTERM); if (weather_loc_valid) close_weather(); - if (mail_path_valid) close_mail(); + close_mail(); (void)XCloseDisplay(display); if (weather_pfd) {