#if HAVE_CONFIG_H #include "config.h" #endif #include #include #include #if HAVE_FCNTL_H #include #endif #if HAVE_UNISTD_H #include #endif #include #if HAVE_SYS_STAT_H #include #endif #include #include #include "maildirmisc.h" #if HAVE_DIRENT_H #include #define NAMLEN(dirent) strlen((dirent)->d_name) #else #define dirent direct #define NAMLEN(dirent) (dirent)->d_namlen #if HAVE_SYS_NDIR_H #include #endif #if HAVE_SYS_DIR_H #include #endif #if HAVE_NDIR_H #include #endif #endif int maildir_make(const char *maildir, int perm, int subdirperm, int folder) { char *q=malloc(strlen(maildir)+sizeof("/maildirfolder")); int fd= -1; if (!q) return -1; if (mkdir(maildir, perm) < 0 || chmod(maildir, perm) < 0 || mkdir(strcat(strcpy(q, maildir), "/tmp"), subdirperm) < 0 || chmod(q, subdirperm) < 0 || mkdir(strcat(strcpy(q, maildir), "/new"), subdirperm) < 0 || chmod(q, subdirperm) < 0 || mkdir(strcat(strcpy(q, maildir), "/cur"), subdirperm) < 0 || chmod(q, subdirperm) < 0 || (folder && (fd=open(strcat(strcpy(q, maildir), "/maildirfolder"), O_CREAT|O_WRONLY, 0600)) < 0)) { free(q); return -1; } if (fd >= 0) close(fd); free(q); return 0; } int maildir_del_content(const char *maildir) { char *filenamebuf[100]; int n, i; DIR *dirp; struct dirent *de; do { dirp=opendir(maildir); n=0; while (dirp && (de=readdir(dirp)) != 0) { if (strcmp(de->d_name, ".") == 0 || strcmp(de->d_name, "..") == 0) continue; if ((filenamebuf[n]=malloc(strlen(maildir)+ strlen(de->d_name)+2)) == NULL) { closedir(dirp); while (n) free(filenamebuf[--n]); return -1; } strcat(strcat(strcpy(filenamebuf[n], maildir), "/"), de->d_name); if (++n >= sizeof(filenamebuf)/sizeof(filenamebuf[0])) break; } if (dirp) closedir(dirp); for (i=0; i