summaryrefslogtreecommitdiff
path: root/src/maildir.c
diff options
context:
space:
mode:
authorJannis Hoffmann <jannis@fehcom.de>2024-07-03 15:52:39 +0200
committerJannis Hoffmann <jannis@fehcom.de>2024-07-03 15:52:39 +0200
commita6a7d6ce079cabdaf2fa502b2e2cf15e5428ac6f (patch)
treeb88cc7a8457658d67e0321718556ac807f6bccf3 /src/maildir.c
parent00be7622c428f279872f84569f098ce16150f8a8 (diff)
format files
Diffstat (limited to 'src/maildir.c')
-rw-r--r--src/maildir.c62
1 files changed, 31 insertions, 31 deletions
diff --git a/src/maildir.c b/src/maildir.c
index 8832d75..c360bc2 100644
--- a/src/maildir.c
+++ b/src/maildir.c
@@ -1,15 +1,18 @@
-#include <unistd.h>
-#include <sys/types.h>
+#include "maildir.h"
+
#include <sys/stat.h>
-#include "prioq.h"
+#include <sys/types.h>
+#include <unistd.h>
+
+#include "direntry.h"
#include "env.h"
+#include "logmsg.h"
+#include "str.h"
#include "stralloc.h"
-#include "direntry.h"
+
#include "datetime.h"
#include "now.h"
-#include "str.h"
-#include "maildir.h"
-#include "logmsg.h"
+#include "prioq.h"
#define WHO "maildir"
@@ -17,10 +20,8 @@ int maildir_chdir()
{
char *maildir;
maildir = env_get("MAILDIR");
- if (!maildir)
- logmsg(WHO,111,ERROR,"MAILDIR not set");
- if (chdir(maildir) == -1)
- logmsg(WHO,110,FATAL,B("unable to chdir to: ",maildir));
+ if (!maildir) logmsg(WHO, 111, ERROR, "MAILDIR not set");
+ if (chdir(maildir) == -1) logmsg(WHO, 110, FATAL, B("unable to chdir to: ", maildir));
return 0;
}
@@ -37,13 +38,12 @@ void maildir_clean(stralloc *tmpname)
if (!dir) return;
while ((d = readdir(dir))) {
- if (d->d_name[0] == '.') continue;
- if (!stralloc_copys(tmpname,"tmp/")) break;
- if (!stralloc_cats(tmpname,d->d_name)) break;
- if (!stralloc_0(tmpname)) break;
- if (stat(tmpname->s,&st) == 0)
- if (time > st.st_atime + 129600)
- unlink(tmpname->s);
+ if (d->d_name[0] == '.') continue;
+ if (!stralloc_copys(tmpname, "tmp/")) break;
+ if (!stralloc_cats(tmpname, d->d_name)) break;
+ if (!stralloc_0(tmpname)) break;
+ if (stat(tmpname->s, &st) == 0)
+ if (time > st.st_atime + 129600) unlink(tmpname->s);
}
closedir(dir);
}
@@ -57,26 +57,25 @@ static int append(prioq *pq, stralloc *filenames, char *subdir, datetime_sec tim
struct stat st;
dir = opendir(subdir);
- if (!dir)
- logmsg(WHO,112,FATAL,B("unable to scan $MAILDIR/:",subdir));
+ if (!dir) logmsg(WHO, 112, FATAL, B("unable to scan $MAILDIR/:", subdir));
while ((d = readdir(dir))) {
if (d->d_name[0] == '.') continue;
pos = filenames->len;
- if (!stralloc_cats(filenames,subdir)) break;
- if (!stralloc_cats(filenames,"/")) break;
- if (!stralloc_cats(filenames,d->d_name)) break;
+ if (!stralloc_cats(filenames, subdir)) break;
+ if (!stralloc_cats(filenames, "/")) break;
+ if (!stralloc_cats(filenames, d->d_name)) break;
if (!stralloc_0(filenames)) break;
- if (stat(filenames->s + pos,&st) == 0)
+ if (stat(filenames->s + pos, &st) == 0)
if (st.st_mtime < time) { /* don't want to mix up the order */
pe.dt = st.st_mtime;
pe.id = pos;
- if (!prioq_insert(pq,&pe)) break;
+ if (!prioq_insert(pq, &pe)) break;
}
}
closedir(dir);
- if (d) logmsg(WHO,112,FATAL,B("unable to read $MAILDIR/:",subdir));
+ if (d) logmsg(WHO, 112, FATAL, B("unable to read $MAILDIR/:", subdir));
return 0;
}
@@ -85,13 +84,14 @@ int maildir_scan(prioq *pq, stralloc *filenames, int flagnew, int flagcur)
struct prioq_elt pe;
datetime_sec time;
- if (!stralloc_copys(filenames,"")) return 0;
- while (prioq_min(pq,&pe))
- prioq_delmin(pq);
+ if (!stralloc_copys(filenames, "")) return 0;
+ while (prioq_min(pq, &pe)) prioq_delmin(pq);
time = now();
- if (flagnew) if (append(pq,filenames,"new",time) == -1) return -1;
- if (flagcur) if (append(pq,filenames,"cur",time) == -1) return -1;
+ if (flagnew)
+ if (append(pq, filenames, "new", time) == -1) return -1;
+ if (flagcur)
+ if (append(pq, filenames, "cur", time) == -1) return -1;
return 0;
}