Back to index

courier  0.68.2
Functions
dotcourier.c File Reference
#include "courier.h"
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sys/types.h>

Go to the source code of this file.

Functions

char * local_extension ()
char * local_dotcourier (const char *homedir, const char *ext, const char **defaultptr)

Function Documentation

char* local_dotcourier ( const char *  homedir,
const char *  ext,
const char **  defaultptr 
)

Definition at line 44 of file dotcourier.c.

{
char   *extbuf;
char   *x=local_extension();

       extbuf=(char *)courier_malloc(sizeof("." "--default")
                     +strlen(x) +strlen(ext));

       strcat(strcpy( extbuf, "." ), x);
       if (defaultptr)      *defaultptr=ext;

#if LOCAL_EXTENSIONS

       if (*ext)
       {
       char   *c;
       char   *filebuf=courier_malloc(sizeof("/." "--default")
                     +strlen(x) +strlen(ext)+strlen(homedir));
       int    isfirst=1;
       struct stat   stat_buf;

              strcat(strcat(extbuf, "-"), ext);
              for (c=extbuf+1; *c; c++)
                     if (*c == '.')       *c=':';

              if (defaultptr)
                     *defaultptr=0;

              while (lstat(
                     strcat(strcat(strcpy(filebuf, homedir), "/"),
                            extbuf), &stat_buf) < 0)
              {
                     /* We simply may not have the permissions to read
                     ** someone's home directory.  This can happen if
                     ** rewriting is carried out in a non-privileged
                     ** process which is submitting a mail message.
                     **
                     ** Unless we have an ENOENT at this point, assume
                     ** that this is the case, and presume that the
                     ** address is valid.  The downshot is that the
                     ** message will be accepted, and an internal bounce
                     ** is later generated.
                     */

                     if (errno != ENOENT)
                     {
                            free(extbuf);
                            free(filebuf);
                            return (0);
                     }

                     *strrchr(extbuf, '-')=0;
                     if (!isfirst)
                     {
                            if ((c=strrchr(extbuf, '-')) == 0)
                            {
                                   free(extbuf);
                                   free(filebuf);
                                   return (0);
                            }
                            *c=0;
                     }
                     isfirst=0;
                     if (defaultptr)
                            *defaultptr=ext+ (strlen(extbuf)-sizeof(".")
                                   -strlen(x)+1);
                     strcat(extbuf, "-default");
              }
              free(filebuf);
       }
#endif
       return (extbuf);
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* local_extension ( )

Definition at line 24 of file dotcourier.c.

{
static char *ext=0;

       if (!ext)
       {
       char   *f=config_localfilename("dotextension");

              ext=config_read1l(f);
              free(f);
       }

       if (!ext || !*ext)
       {
              if (ext)      free(ext);
              ext="courier";
       }
       return (ext);
}

Here is the call graph for this function:

Here is the caller graph for this function: