summaryrefslogtreecommitdiffstats
path: root/maildir/maildirlist.c
diff options
context:
space:
mode:
authorSam Varshavchik2013-08-19 16:39:41 -0400
committerSam Varshavchik2013-08-25 14:43:51 -0400
commit9c45d9ad13fdf439d44d7443ae75da15ea0223ed (patch)
tree7a81a04cb51efb078ee350859a64be2ebc6b8813 /maildir/maildirlist.c
parenta9520698b770168d1f33d6301463bb70a19655ec (diff)
downloadcourier-libs-9c45d9ad13fdf439d44d7443ae75da15ea0223ed.tar.bz2
Initial checkin
Imported from subversion report, converted to git. Updated all paths in scripts and makefiles, reflecting the new directory hierarchy.
Diffstat (limited to 'maildir/maildirlist.c')
-rw-r--r--maildir/maildirlist.c82
1 files changed, 82 insertions, 0 deletions
diff --git a/maildir/maildirlist.c b/maildir/maildirlist.c
new file mode 100644
index 0000000..b334365
--- /dev/null
+++ b/maildir/maildirlist.c
@@ -0,0 +1,82 @@
+/*
+** Copyright 2002 Double Precision, Inc.
+** See COPYING for distribution information.
+*/
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+#if HAVE_DIRENT_H
+#include <dirent.h>
+#define NAMLEN(dirent) strlen((dirent)->d_name)
+#else
+#define dirent direct
+#define NAMLEN(dirent) (dirent)->d_namlen
+#if HAVE_SYS_NDIR_H
+#include <sys/ndir.h>
+#endif
+#if HAVE_SYS_DIR_H
+#include <sys/dir.h>
+#endif
+#if HAVE_NDIR_H
+#include <ndir.h>
+#endif
+#endif
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <string.h>
+#include <stdlib.h>
+#include <time.h>
+#if HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#include <stdio.h>
+#include <ctype.h>
+#include <errno.h>
+#include <fcntl.h>
+
+#include "maildirmisc.h"
+
+void maildir_list(const char *maildir,
+ void (*func)(const char *, void *),
+ void *voidp)
+{
+ DIR *dirp=opendir(maildir);
+ struct dirent *de;
+
+ while (dirp && (de=readdir(dirp)) != NULL)
+ {
+ char *p;
+
+ if (strcmp(de->d_name, "..") == 0)
+ continue;
+
+ if (de->d_name[0] != '.')
+ continue;
+
+ if ((p=malloc(strlen(maildir) + strlen(de->d_name)+20))
+ == NULL)
+ continue;
+
+ strcat(strcat(strcat(strcpy(p, maildir), "/"), de->d_name),
+ "/cur/.");
+
+ if (access(p, X_OK))
+ {
+ free(p);
+ continue;
+ }
+
+ strcpy(p, INBOX);
+
+ if (strcmp(de->d_name, "."))
+ strcat(p, de->d_name);
+
+ (*func)(p, voidp);
+ free(p);
+ }
+ if (dirp)
+ closedir(dirp);
+}