aboutsummaryrefslogtreecommitdiff
path: root/minc.c
diff options
context:
space:
mode:
authorChristian Neukirchen <chneukirchen@gmail.com>2016-07-21 23:17:49 +0200
committerChristian Neukirchen <chneukirchen@gmail.com>2016-07-21 23:17:49 +0200
commit98456df2cf775ab630d77e6bc9cae157333da6c4 (patch)
tree5b915f422b2c0d2a681dcef000504054364cd3f0 /minc.c
parent49b88176a067ceb6695fa7e20bb80ca8edaf5d18 (diff)
downloadmblaze-98456df2cf775ab630d77e6bc9cae157333da6c4.tar.gz
add minc
Diffstat (limited to 'minc.c')
-rw-r--r--minc.c76
1 files changed, 76 insertions, 0 deletions
diff --git a/minc.c b/minc.c
new file mode 100644
index 0000000..3788f35
--- /dev/null
+++ b/minc.c
@@ -0,0 +1,76 @@
+#include <sys/types.h>
+
+#include <dirent.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <search.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "blaze822.h"
+
+static int qflag;
+static int status;
+
+void
+inc(char *dir)
+{
+ DIR *fd;
+ struct dirent *d;
+ char src[PATH_MAX];
+ char dst[PATH_MAX];
+
+ snprintf(src, sizeof src, "%s/new", dir);
+ fd = opendir(src);
+ if (!fd) {
+ fprintf(stderr, "minc: can't open maildir '%s': %s\n",
+ dir, strerror(errno));
+ status = 2;
+ return;
+ }
+
+ while ((d = readdir(fd))) {
+ if (d->d_type != DT_REG && d->d_type != DT_UNKNOWN)
+ continue;
+ if (d->d_name[0] == '.')
+ continue;
+
+ snprintf(src, sizeof src, "%s/new/%s",
+ dir, d->d_name);
+ snprintf(dst, sizeof dst, "%s/cur/%s%s",
+ dir, d->d_name, strstr(d->d_name, ":2,") ? "" : ":2,");
+ if (rename(src, dst) < 0) {
+ fprintf(stderr, "minc: can't rename '%s' to '%s': %s\n",
+ src, dst, strerror(errno));
+ status = 3;
+ continue;
+ }
+
+ if (!qflag)
+ printf("%s\n", dst);
+ }
+
+ closedir(fd);
+}
+
+int
+main(int argc, char *argv[])
+{
+ int c, i;
+ while ((c = getopt(argc, argv, "q")) != -1)
+ switch(c) {
+ case 'q': qflag = 1; break;
+ default:
+ // XXX usage
+ exit(1);
+ }
+
+ status = 0;
+ for (i = optind; i < argc; i++)
+ inc(argv[i]);
+
+ return status;
+}