Back to index

courier  0.68.2
Defines | Functions
maildirmake2.c File Reference
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <ctype.h>
#include <errno.h>
#include "maildirmisc.h"

Go to the source code of this file.

Defines

#define dirent   direct
#define NAMLEN(dirent)   (dirent)->d_namlen

Functions

int maildir_make (const char *maildir, int perm, int subdirperm, int folder)
int maildir_del_content (const char *maildir)
int maildir_del (const char *maildir)

Define Documentation

#define dirent   direct

Definition at line 26 of file maildirmake2.c.

#define NAMLEN (   dirent)    (dirent)->d_namlen

Definition at line 27 of file maildirmake2.c.


Function Documentation

int maildir_del ( const char *  maildir)

Definition at line 135 of file maildirmake2.c.

{
       int rc;
       if ((rc=maildir_del_content(maildir)) == -1)
           return rc;
       return rmdir(maildir) < 0 && errno != ENOENT ? -1:0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int maildir_del_content ( const char *  maildir)

Definition at line 67 of file maildirmake2.c.

{
       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<n; i++)
              {
                     struct stat s_buf;

                     if (lstat(filenamebuf[i], &s_buf) < 0)
                            continue;

                     if (S_ISDIR(s_buf.st_mode))
                     {
                            if (maildir_del(filenamebuf[i]) < 0)
                            {
                                   while (n)
                                          free(filenamebuf[--n]);
                                   return -1;
                            }
                     }
                     else if (unlink(filenamebuf[i]) < 0)
                     {
                            if (errno != ENOENT)
                            {
                                   while (n)
                                          free(filenamebuf[--n]);
                                   return -1;

                            }
                     }
              }

              for (i=0; i<n; i++)
                     free(filenamebuf[i]);
       } while (n);
       return 0; 
}

Here is the call graph for this function:

Here is the caller graph for this function:

int maildir_make ( const char *  maildir,
int  perm,
int  subdirperm,
int  folder 
)

Definition at line 39 of file maildirmake2.c.

{
       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;
}

Here is the caller graph for this function: