Back to index

courier  0.68.2
Functions
maildirpath.c File Reference
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
#include <ctype.h>
#include <errno.h>
#include "maildirmisc.h"

Go to the source code of this file.

Functions

char * maildir_name2dir (const char *maildir, const char *foldername)
char * maildir_location (const char *homedir, const char *maildir)
char * maildir_folderdir (const char *maildir, const char *foldername)

Function Documentation

char* maildir_folderdir ( const char *  maildir,
const char *  foldername 
)

Definition at line 87 of file maildirpath.c.

{
char   *p;
const char *r;
size_t l;

       if (!maildir) maildir=".";
       l=strlen(maildir);

       if (foldername == 0 ||
              strcasecmp(foldername, INBOX) == 0)
       {
              if ((p=malloc(l+1)) == 0)   return (0);
              strcpy(p, maildir);
              return(p);
       }

       /* Rules: no leading/trailing periods, no /s */
       if (*foldername == '.' || strchr(foldername, '/'))
       {
              errno=EINVAL;
              return (0);
       }

       for (r=foldername; *r; r++)
       {
              if (*r != '.')       continue;
              if (r[1] == 0 || r[1] == '.')
              {
                     errno=EINVAL;
                     return (0);
              }
       }

       if ((p=malloc(l+strlen(foldername)+3)) == 0)     return (0);
       *p=0;
       if (strcmp(maildir, "."))
              strcat(strcpy(p, maildir), "/");
       
       return (strcat(strcat(p, "."), foldername));
}

Here is the caller graph for this function:

char* maildir_location ( const char *  homedir,
const char *  maildir 
)

Definition at line 71 of file maildirpath.c.

{
       char *p;

       if (*maildir == '/')
              return strdup(maildir);

       p=malloc(strlen(homedir)+strlen(maildir)+2);

       if (!p)
              return NULL;
       strcat(strcat(strcpy(p, homedir), "/"), maildir);
       return p;
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* maildir_name2dir ( const char *  maildir,
const char *  foldername 
)

Definition at line 25 of file maildirpath.c.

{
       const char *inbox=INBOX;
       int l=strlen(inbox);
       char *p;

       if (!maildir) maildir=".";

       if (foldername && strncasecmp(foldername, INBOX, l) == 0 &&
           strchr(foldername, '/') == NULL)
       {
              if (foldername[l] == 0)
                     return strdup(maildir); /* INBOX: main maildir inbox */

              if (foldername[l] == '.')
              {
                     const char *r;

                     for (r=foldername; *r; r++)
                     {
                            if (*r != '.')       continue;

                            if (r[1] == 0 || r[1] == '.')
                            {
                                   errno=EINVAL;
                                   return (0);
                            }
                     }

                     r=strchr(foldername, '.');

                     p=malloc(strlen(maildir)+strlen(r) + 2);

                     if (!p)
                            return NULL;

                     return (strcat(strcat(strcpy(p, maildir), "/"),
                                   r));
              }
       }

       errno=EINVAL;
       return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function: