Back to index

courier  0.68.2
Classes | Defines | Functions
maildirquota.h File Reference
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include "numlib/numlib.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  maildirquota
struct  maildirsize

Defines

#define MDQUOTA_SIZE   'S' /* Total size of all messages in maildir */
#define MDQUOTA_BLOCKS
#define MDQUOTA_COUNT   'C' /* Total number of messages in maildir */

Functions

int maildir_openquotafile (struct maildirsize *info, const char *)
void maildir_closequotafile (struct maildirsize *info)
int maildir_checkquota (struct maildirsize *, int64_t, int)
int maildir_addquota (struct maildirsize *, int64_t, int)
int maildir_readquota (struct maildirsize *)
int maildir_parsequota (const char *, unsigned long *)
int maildir_quota_add_start (const char *maildir, struct maildirsize *info, int64_t msgsize, int nmsgs, const char *newquota)
void maildir_quota_add_end (struct maildirsize *info, int64_t msgsize, int nmsgs)
void maildir_quota_deleted (const char *maildir, int64_t nbytes, int nmsgs)
int maildir_quota_delundel_start (const char *maildir, struct maildirsize *info, int64_t msgsize, int nmsgs)
void maildir_quota_delundel_end (struct maildirsize *info, int64_t msgsize, int nmsgs)
void maildir_quota_set (const char *dir, const char *quota)
void maildir_quota_recalculate (const char *maildir)
int maildirquota_countfolder (const char *folder)
int maildirquota_countfile (const char *filename)
void maildir_deliver_quota_warning (const char *dir, const int percent, const char *msgquotafile)

Class Documentation

struct maildirquota

Definition at line 28 of file maildirquota.h.

Class Members
int64_t nbytes
int nmessages
struct maildirsize

Definition at line 37 of file maildirquota.h.

Class Members
int fd
char * maildir
char * maildirsizefile
unsigned nlines
int recalculation_needed

Define Documentation

#define MDQUOTA_BLOCKS
Value:
'B'    /* Total # of blocks for all messages in
                            maildir -- NOT IMPLEMENTED */

Definition at line 25 of file maildirquota.h.

#define MDQUOTA_COUNT   'C' /* Total number of messages in maildir */

Definition at line 26 of file maildirquota.h.

#define MDQUOTA_SIZE   'S' /* Total size of all messages in maildir */

Definition at line 24 of file maildirquota.h.


Function Documentation

int maildir_addquota ( struct maildirsize ,
int64_t  ,
int   
)

Definition at line 561 of file maildirquota.c.

{
       if (info->fd < 0)
              return (0);

       return (doaddquota(info, info->fd, maildirsize_size,
                        maildirsize_cnt, 0));
}

Here is the call graph for this function:

Here is the caller graph for this function:

int maildir_checkquota ( struct maildirsize ,
int64_t  ,
int   
)

Definition at line 385 of file maildirquota.c.

{
       int    dummy;

       return (docheckquota(info, xtra_size, xtra_cnt, &dummy));
}

Here is the call graph for this function:

Here is the caller graph for this function:

void maildir_closequotafile ( struct maildirsize info)

Definition at line 304 of file maildirquota.c.

{
       if (info->maildir)
              free (info->maildir);
       info->maildir=NULL;

       if (info->maildirsizefile)
              free (info->maildirsizefile);
       info->maildirsizefile=NULL;

       if (info->fd >= 0)
              close(info->fd);
       info->fd= -1;
}

Here is the caller graph for this function:

void maildir_deliver_quota_warning ( const char *  dir,
const int  percent,
const char *  msgquotafile 
)

Definition at line 1116 of file maildirquota.c.

{
       size_t l;
       char *p;
       struct stat   sb;

       /* If we delivered to a folder, dump the warning message into INBOX */

       l = strlen(dir)+sizeof("/maildirfolder");
       if ((p = malloc(l)) == 0)
              return;

       strcat(strcpy(p, dir), "/maildirfolder");

       /* If delivering to a folder, find quotawarn in its parent directory */

       if (stat(p, &sb) == 0)
       {
              strcat(strcpy(p, dir), "/..");
              maildir_deliver_quota_warning(p, percent, msgquotafile);
              free(p);
              return;
       }
       free(p);

       if (percent >= 0)
       {
              struct maildirsize info;

              if (maildir_openquotafile(&info, dir) == 0)
              {
                     if (maildir_readquota(&info) >= percent)
                     {
                            maildir_closequotafile(&info);
                            do_deliver_warning(msgquotafile, dir);
                            return;
                     }
                     maildir_closequotafile(&info);
              }
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

int maildir_openquotafile ( struct maildirsize info,
const char *   
)

Definition at line 66 of file maildirquota.c.

{
       return (maildir_openquotafile_init(info, maildir, NULL));
}

Here is the call graph for this function:

Here is the caller graph for this function:

int maildir_parsequota ( const char *  ,
unsigned long *   
)

Definition at line 14 of file maildirparsequota.c.

{
const char *o;
int    yes;

       if ((o=strrchr(n, '/')) == 0)      o=n;

       for (; *o; o++)
              if (*o == MDIRSEP[0])       break;
       yes=0;
       for ( ; o >= n; --o)
       {
              if (*o == '/')       break;

              if (*o == ',' && o[1] == 'S' && o[2] == '=')
              {
                     yes=1;
                     o += 3;
                     break;
              }
       }
       if (yes)
       {
              *s=0;
              while (*o >= '0' && *o <= '9')
                     *s= *s*10 + (*o++ - '0');
              return (0);
       }
       return (-1);
}

Here is the caller graph for this function:

void maildir_quota_add_end ( struct maildirsize info,
int64_t  msgsize,
int  nmsgs 
)

Definition at line 906 of file maildirquota.c.

{
       maildir_addquota(info, msgsize, nmsgs);
       maildir_closequotafile(info);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int maildir_quota_add_start ( const char *  maildir,
struct maildirsize info,
int64_t  msgsize,
int  nmsgs,
const char *  newquota 
)

Definition at line 850 of file maildirquota.c.

{
       struct maildirquota mq;
       int i;

       if ( maildir_openquotafile(info, maildir))
              info->fd= -1;

       if (newquota != NULL)
       {
              parsequotastr(newquota, &mq);

              if ((mq.nbytes > 0 || mq.nmessages > 0) &&
                  (info->fd < 0 || info->quota.nbytes != mq.nbytes ||
                   info->quota.nmessages != mq.nmessages))
              {
                     if (info->fd < 0)
                     {
                            maildir_quota_set(maildir, newquota);
                            if (maildir_openquotafile(info, maildir))
                                   info->fd= -1;
                     }
                     else
                     {
                            info->quota=mq;
                            info->recalculation_needed=1;
                     }
              }
       }
       if (info->fd < 0)
              return (0);   /* No quota set on this maildir */

       for (i=0; i<5; i++)
       {
              int rc;

              rc=maildir_checkquota(info, msgsize, nmsgs);
              if (rc == 0)
                     return (0);

              if (errno != EAGAIN)
              {
                     maildir_closequotafile(info);
                     return (-1);
              }
       }
       maildir_closequotafile(info);

       /* Cannot recover from a race condition, just punt */

       return (0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void maildir_quota_deleted ( const char *  maildir,
int64_t  nbytes,
int  nmsgs 
)

Definition at line 913 of file maildirquota.c.

{
       struct maildirsize info;

       if ( maildir_openquotafile(&info, maildir))
              return;

       maildir_checkquota(&info, nbytes, nmsgs); /* Cleanup */
       maildir_addquota(&info, nbytes, nmsgs);
       maildir_closequotafile(&info);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void maildir_quota_delundel_end ( struct maildirsize info,
int64_t  msgsize,
int  nmsgs 
)

Definition at line 956 of file maildirquota.c.

{
#if TRASHQUOTA
       return;
#else
       if (nmsgs < 0)
              return;

       maildir_quota_add_end(info, msgsize, nmsgs);
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

int maildir_quota_delundel_start ( const char *  maildir,
struct maildirsize info,
int64_t  msgsize,
int  nmsgs 
)

Definition at line 939 of file maildirquota.c.

{
#if TRASHQUOTA
       return (0);
#else
       if (nmsgs < 0)
       {
              maildir_quota_deleted(maildir, msgsize, nmsgs);
              return (0);   /* Always allowed */
       }

       return maildir_quota_add_start(maildir, info, msgsize, nmsgs, NULL);
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

void maildir_quota_recalculate ( const char *  maildir)

Definition at line 927 of file maildirquota.c.

{
       struct maildirsize info;

       if (maildir_openquotafile(&info, maildir))
              return;
       info.recalculation_needed=1;

       maildir_readquota(&info);
       maildir_closequotafile(&info);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void maildir_quota_set ( const char *  dir,
const char *  quota 
)

Definition at line 970 of file maildirquota.c.

Here is the call graph for this function:

Here is the caller graph for this function:

int maildir_readquota ( struct maildirsize )

Definition at line 394 of file maildirquota.c.

{
       int    percentage=0;

       (void)docheckquota(info, 0, 0, &percentage);
       return (percentage);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int maildirquota_countfile ( const char *  filename)

Definition at line 818 of file maildirquota.c.

{
#ifdef TRASHQUOTA

#else
       const char *nn=strrchr(n, '/');

       if (nn != NULL)
              n=nn+1;

       /* do not count msgs marked as deleted */

       for ( ; *n; n++)
       {
              if (n[0] != MDIRSEP[0] || n[1] != '2' ||
                  n[2] != ',')     continue;
              n += 3;
              while (*n >= 'A' && *n <= 'Z')
              {
                     if (*n == 'T')       return (0);
                     ++n;
              }
              break;
       }
#endif
       return (1);
}

Here is the caller graph for this function:

int maildirquota_countfolder ( const char *  folder)

Definition at line 799 of file maildirquota.c.

{
#ifdef TRASHQUOTA

#else

       if (strcmp(folder, "." TRASH) == 0 ||
           strcmp(folder, "." TRASH "/") == 0)
              return (0);

       for ( ; *folder; folder++)
              if (*folder == '/' &&
                  (strcmp(folder+1, "." TRASH) == 0 ||
                   strcmp(folder+1, "." TRASH "/") == 0))
                     return (0);
#endif
       return (1);
}

Here is the caller graph for this function: