Back to index

courier  0.68.2
Defines | Functions
maildirpurgetmp.c File Reference
#include "maildirquota.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include "maildirmisc.h"

Go to the source code of this file.

Defines

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

Functions

static void dopurge (const char *m, unsigned nage, int *nfiles, long *nbytes)
void maildir_purgetmp (const char *maildir)
void maildir_purge (const char *maildir, unsigned nage)

Define Documentation

#define dirent   direct

Definition at line 16 of file maildirpurgetmp.c.

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

Definition at line 17 of file maildirpurgetmp.c.


Function Documentation

static void dopurge ( const char *  m,
unsigned  nage,
int *  nfiles,
long *  nbytes 
) [static]

Definition at line 39 of file maildirpurgetmp.c.

{
time_t current_time;
DIR    *dirp;
struct dirent *de;

       time (&current_time);
       dirp=opendir(m);
       *nfiles=0;
       *nbytes=0;

       while (dirp && (de=readdir(dirp)) != 0)
       {
       char   *z;
       struct stat   stat_buf;

              if (de->d_name[0] == '.')   continue;
              z=malloc(strlen(m)+strlen(de->d_name)+2);
              if (!z)       continue;

              strcat(strcat(strcpy(z, m), "/"), de->d_name);

              if (stat(z, &stat_buf) == 0
                     && stat_buf.st_ctime < current_time - nage)
              {
                     if (maildirquota_countfile(de->d_name))
                     {
                            ++ *nfiles;
                            *nbytes += stat_buf.st_size;
                     }
                     unlink(z);
              }
              free(z);
       }
       if (dirp)     closedir(dirp);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void maildir_purge ( const char *  maildir,
unsigned  nage 
)

Definition at line 90 of file maildirpurgetmp.c.

{
       char   *m=malloc(strlen(maildir)+sizeof("/cur"));
       char   *p;
       int adjustquota;
       int nfiles;
       long nbytes;

       int nfiles2;
       long nbytes2;

       p=strrchr(maildir, '/');
       if (p)
              ++p;
       else
              p=".";

       adjustquota=maildirquota_countfolder(p);

       if (!m)       return;
       strcat(strcpy(m, maildir), "/cur");
       dopurge(m, nage, &nfiles, &nbytes);
       strcat(strcpy(m, maildir), "/new");
       dopurge(m, nage, &nfiles2, &nbytes2);
       free(m);

       nfiles += nfiles2;
       nbytes += nbytes2;

       if (adjustquota && nfiles > 0)
              maildir_quota_deleted(maildir, -nbytes, -nfiles);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void maildir_purgetmp ( const char *  maildir)

Definition at line 78 of file maildirpurgetmp.c.

{
       char   *m=malloc(strlen(maildir)+sizeof("/tmp"));
       int nfiles;
       long nbytes;

       if (!m)       return;
       strcat(strcpy(m, maildir), "/tmp");
       dopurge(m, 60 * 60 * 36, &nfiles, &nbytes);
       free(m);
}

Here is the call graph for this function:

Here is the caller graph for this function: