summaryrefslogtreecommitdiff
path: root/src/stmail.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/stmail.c')
-rw-r--r--src/stmail.c44
1 files changed, 23 insertions, 21 deletions
diff --git a/src/stmail.c b/src/stmail.c
index 4c66bc9..f151d4a 100644
--- a/src/stmail.c
+++ b/src/stmail.c
@@ -21,6 +21,8 @@
#include <stdio.h>
#include <unistd.h>
+#include "../lib/util.h"
+
int
newmsg(char path[1024])
{
@@ -28,11 +30,10 @@ newmsg(char path[1024])
int count;
struct dirent *entry;
- count = 0;
-
- dir = opendir(path);
- if (!dir) { return 1; }
+ if (!(dir = opendir(path)))
+ die("failed to open dir");
+ count = 0;
while ((entry = readdir(dir)) != NULL) {
if (entry->d_type == DT_REG) {
if (strcmp(entry->d_name, ".") && strcmp(entry->d_name, "..")) {
@@ -40,7 +41,6 @@ newmsg(char path[1024])
}
}
}
-
return count;
}
@@ -49,28 +49,28 @@ main(void)
{
DIR *dir;
int count;
- char *path;
- char fullpath[1024];
+ char *env;
+ char buf[1024];
+ char path[1024];
struct dirent *entry;
- path = getenv("XDG_DATA_HOME");
- if (!path) { puts("XDG_DATA_HOME is not set"); return 1; }
+ env = getenv("XDG_DATA_HOME");
+ if (!env)
+ die("XDG_DATA_HOME is not set");
- strcat(path, "/mail");
+ snprintf(buf, sizeof(buf), "%s/mail/", env);
- dir = opendir(path);
- if (!dir) { return 1; }
+ if (!(dir = opendir(buf)))
+ die("failed to open dir");
count = 0;
-
while ((entry = readdir(dir)) != NULL) {
if (entry->d_type == DT_DIR) {
if (strcmp(entry->d_name, ".") && strcmp(entry->d_name, "..") && strcmp(entry->d_name, ".notmuch")) {
- strcpy(fullpath, path);
- strcat(fullpath, "/");
- strcat(fullpath, entry->d_name);
- strcat(fullpath, "/INBOX/new/");
- count += newmsg(fullpath);
+ strcpy(path, buf);
+ strcat(path, entry->d_name);
+ strcat(path, "/INBOX/new/");
+ count += newmsg(path);
}
}
}
@@ -79,11 +79,13 @@ main(void)
if (access("/tmp/mailupdate", F_OK) != -1) {
printf("");
- if (count != 0) { printf(" "); }
+ if (count != 0)
+ printf(" ");
}
- if (count == 0) { return 0; }
- printf(" %d", count);
+ if (count == 0)
+ return 0;
+ printf(" %d", count);
return 0;
}