Back to index

courier  0.68.2
maildirlist.c
Go to the documentation of this file.
00001 /*
00002 ** Copyright 2002 Double Precision, Inc.
00003 ** See COPYING for distribution information.
00004 */
00005 
00006 #if HAVE_CONFIG_H
00007 #include "config.h"
00008 #endif
00009 
00010 #include <sys/types.h>
00011 #if HAVE_DIRENT_H
00012 #include <dirent.h>
00013 #define NAMLEN(dirent) strlen((dirent)->d_name)
00014 #else
00015 #define dirent direct
00016 #define NAMLEN(dirent) (dirent)->d_namlen
00017 #if HAVE_SYS_NDIR_H
00018 #include <sys/ndir.h>
00019 #endif
00020 #if HAVE_SYS_DIR_H
00021 #include <sys/dir.h>
00022 #endif
00023 #if HAVE_NDIR_H
00024 #include <ndir.h>
00025 #endif
00026 #endif
00027 #include      <sys/types.h>
00028 #include      <sys/stat.h>
00029 #include      <string.h>
00030 #include      <stdlib.h>
00031 #include      <time.h>
00032 #if    HAVE_UNISTD_H
00033 #include      <unistd.h>
00034 #endif
00035 #include      <stdio.h>
00036 #include      <ctype.h>
00037 #include      <errno.h>
00038 #include      <fcntl.h>
00039 
00040 #include      "maildirmisc.h"
00041 
00042 void maildir_list(const char *maildir,
00043                 void (*func)(const char *, void *),
00044                 void *voidp)
00045 {
00046        DIR *dirp=opendir(maildir);
00047        struct dirent *de;
00048 
00049        while (dirp && (de=readdir(dirp)) != NULL)
00050        {
00051               char *p;
00052 
00053               if (strcmp(de->d_name, "..") == 0)
00054                      continue;
00055 
00056               if (de->d_name[0] != '.')
00057                      continue;
00058 
00059               if ((p=malloc(strlen(maildir) + strlen(de->d_name)+20))
00060                   == NULL)
00061                      continue;
00062 
00063               strcat(strcat(strcat(strcpy(p, maildir), "/"), de->d_name),
00064                      "/cur/.");
00065 
00066               if (access(p, X_OK))
00067               {
00068                      free(p);
00069                      continue;
00070               }
00071 
00072               strcpy(p, INBOX);
00073 
00074               if (strcmp(de->d_name, "."))
00075                      strcat(p, de->d_name);
00076 
00077               (*func)(p, voidp);
00078               free(p);
00079        }
00080        if (dirp)
00081               closedir(dirp);
00082 }