Back to index

courier  0.68.2
maildirquota.h
Go to the documentation of this file.
00001 #ifndef       maildirquota_h
00002 #define       maildirquota_h
00003 
00004 /*
00005 ** Copyright 1998 - 2010 Double Precision, Inc.
00006 ** See COPYING for distribution information.
00007 */
00008 
00009 #if    HAVE_CONFIG_H
00010 #include      "config.h"
00011 #endif
00012 
00013 #include      <sys/types.h>
00014 #include      <sys/stat.h>
00015 #include      <stdio.h>
00016 
00017 #include      "numlib/numlib.h"
00018 
00019 #ifdef  __cplusplus
00020 extern "C" {
00021 #endif
00022 
00023 
00024 #define       MDQUOTA_SIZE  'S'    /* Total size of all messages in maildir */
00025 #define       MDQUOTA_BLOCKS       'B'    /* Total # of blocks for all messages in
00026                             maildir -- NOT IMPLEMENTED */
00027 #define       MDQUOTA_COUNT 'C'    /* Total number of messages in maildir */
00028 
00029 struct maildirquota {
00030        int64_t nbytes;      /* # of bytes, 0 - unlimited */
00031        int nmessages;       /* # of messages, 0 - unlimited */
00032 };
00033 
00034        /*
00035        ** The maildirsize file
00036        */
00037 
00038 struct maildirsize {
00039 
00040        int fd;       /* Opened file descriptor for the maildirsize file */
00041 
00042        char *maildir;                     /* Pathname to the maildir */
00043        char *maildirsizefile;             /* The name of the maildirsize file */
00044 
00045        struct maildirquota quota;  /* 1st line in maildirsize */
00046 
00047        struct maildirquota size;   /* Actual counts 2+ line */
00048 
00049        int recalculation_needed;   /* size is not calculated */
00050 
00051        struct stat   statbuf;      /* The stat on the maidlirsize file */
00052        unsigned nlines;     /* # of lines in the maildirsize file */
00053 };
00054 
00055 
00056 /*
00057 ** maildir_openquotafile initializes a maildirsize structure from a maildirsize
00058 ** file.  This is really an internal, undocumented, function.
00059 **
00060 ** return 0 for success, -1 if the file could not be opened
00061 */
00062 
00063 int maildir_openquotafile(struct maildirsize *info,     /* Initialized */
00064                        const char *                     /* maildir */
00065                        );
00066 
00067 /*
00068 ** maildir_closequotafile releases all resources allocated by maildirsize
00069 ** struct.
00070 */
00071 
00072 void maildir_closequotafile(struct maildirsize *info);
00073 
00074 
00075 
00076 
00077 int maildir_checkquota(struct maildirsize *, /* Opened maildir */
00078                      int64_t,  /* Extra bytes planning to add/remove from
00079                              maildir */
00080                      int);  /* Extra messages planning to add/remove from
00081                              maildir */
00082 
00083 int maildir_addquota(struct maildirsize *, /* Opened maildir */
00084                    int64_t, /* +/- bytes */
00085                    int);    /* +/- files */
00086 
00087 int maildir_readquota(struct maildirsize *);     /* Directory */
00088 
00089 int maildir_parsequota(const char *, unsigned long *);
00090        /* Attempt to parse file size encoded in filename.  Returns 0 if
00091        ** parsed, non-zero if we didn't parse. */
00092 
00093 
00094        /* Here are some high-level functions that call the above */
00095 
00096        /* Adding messages to the maildir, in two easy steps: */
00097 
00098 int maildir_quota_add_start(const char *maildir,
00099                          struct maildirsize *info,
00100                          int64_t msgsize, int nmsgs,
00101                          const char *newquota);
00102 
00103 void maildir_quota_add_end(struct maildirsize *info,
00104                         int64_t msgsize, int nmsgs);
00105 
00106 /* When we're deleting messages, we want an unconditional quota update */
00107 
00108 void maildir_quota_deleted(const char *maildir,
00109                         int64_t nbytes,   /* Must be negative */
00110                         int nmsgs);       /* Must be negative */
00111 
00112 
00113 /* Can we delete or undelete messages?  This is like maildir_quota_add_start
00114 ** and maildir_quota_add_end, except that if deleted messages are included in
00115 ** the quota, they are compiled to no-ops
00116 */
00117 
00118 int maildir_quota_delundel_start(const char *maildir,
00119                              struct maildirsize *info,
00120                              int64_t msgsize, int nmsgs);
00121 
00122 void maildir_quota_delundel_end(struct maildirsize *info,
00123                             int64_t msgsize, int nmsgs);
00124 
00125        /* Set a new quota on the maildir; */
00126 
00127 void maildir_quota_set(const char *dir, const char *quota);
00128 
00129        /* Forcibly recalculate the maildir's quota */
00130 
00131 void maildir_quota_recalculate(const char *maildir);
00132 
00133 
00134        /*
00135        ** Should the following folder/file be included in the quota?
00136        ** (excludes TRASH and deleted files, if configured to do so)
00137        */
00138 
00139 int maildirquota_countfolder(const char *folder);
00140 int maildirquota_countfile(const char *filename);
00141 
00142 void maildir_deliver_quota_warning(const char *dir, const int percent,
00143                                const char *msgquotafile);
00144 
00145 #ifdef  __cplusplus
00146 }
00147 #endif
00148 
00149 #endif