summaryrefslogtreecommitdiffstats
path: root/maildir/maildirquota.h
diff options
context:
space:
mode:
authorSam Varshavchik2013-08-19 16:39:41 -0400
committerSam Varshavchik2013-08-25 14:43:51 -0400
commit9c45d9ad13fdf439d44d7443ae75da15ea0223ed (patch)
tree7a81a04cb51efb078ee350859a64be2ebc6b8813 /maildir/maildirquota.h
parenta9520698b770168d1f33d6301463bb70a19655ec (diff)
downloadcourier-libs-9c45d9ad13fdf439d44d7443ae75da15ea0223ed.tar.bz2
Initial checkin
Imported from subversion report, converted to git. Updated all paths in scripts and makefiles, reflecting the new directory hierarchy.
Diffstat (limited to 'maildir/maildirquota.h')
-rw-r--r--maildir/maildirquota.h149
1 files changed, 149 insertions, 0 deletions
diff --git a/maildir/maildirquota.h b/maildir/maildirquota.h
new file mode 100644
index 0000000..400de4f
--- /dev/null
+++ b/maildir/maildirquota.h
@@ -0,0 +1,149 @@
+#ifndef maildirquota_h
+#define maildirquota_h
+
+/*
+** Copyright 1998 - 2010 Double Precision, Inc.
+** See COPYING for distribution information.
+*/
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <stdio.h>
+
+#include "numlib/numlib.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+#define MDQUOTA_SIZE 'S' /* Total size of all messages in maildir */
+#define MDQUOTA_BLOCKS 'B' /* Total # of blocks for all messages in
+ maildir -- NOT IMPLEMENTED */
+#define MDQUOTA_COUNT 'C' /* Total number of messages in maildir */
+
+struct maildirquota {
+ int64_t nbytes; /* # of bytes, 0 - unlimited */
+ int nmessages; /* # of messages, 0 - unlimited */
+};
+
+ /*
+ ** The maildirsize file
+ */
+
+struct maildirsize {
+
+ int fd; /* Opened file descriptor for the maildirsize file */
+
+ char *maildir; /* Pathname to the maildir */
+ char *maildirsizefile; /* The name of the maildirsize file */
+
+ struct maildirquota quota; /* 1st line in maildirsize */
+
+ struct maildirquota size; /* Actual counts 2+ line */
+
+ int recalculation_needed; /* size is not calculated */
+
+ struct stat statbuf; /* The stat on the maidlirsize file */
+ unsigned nlines; /* # of lines in the maildirsize file */
+};
+
+
+/*
+** maildir_openquotafile initializes a maildirsize structure from a maildirsize
+** file. This is really an internal, undocumented, function.
+**
+** return 0 for success, -1 if the file could not be opened
+*/
+
+int maildir_openquotafile(struct maildirsize *info, /* Initialized */
+ const char * /* maildir */
+ );
+
+/*
+** maildir_closequotafile releases all resources allocated by maildirsize
+** struct.
+*/
+
+void maildir_closequotafile(struct maildirsize *info);
+
+
+
+
+int maildir_checkquota(struct maildirsize *, /* Opened maildir */
+ int64_t, /* Extra bytes planning to add/remove from
+ maildir */
+ int); /* Extra messages planning to add/remove from
+ maildir */
+
+int maildir_addquota(struct maildirsize *, /* Opened maildir */
+ int64_t, /* +/- bytes */
+ int); /* +/- files */
+
+int maildir_readquota(struct maildirsize *); /* Directory */
+
+int maildir_parsequota(const char *, unsigned long *);
+ /* Attempt to parse file size encoded in filename. Returns 0 if
+ ** parsed, non-zero if we didn't parse. */
+
+
+ /* Here are some high-level functions that call the above */
+
+ /* Adding messages to the maildir, in two easy steps: */
+
+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);
+
+/* When we're deleting messages, we want an unconditional quota update */
+
+void maildir_quota_deleted(const char *maildir,
+ int64_t nbytes, /* Must be negative */
+ int nmsgs); /* Must be negative */
+
+
+/* Can we delete or undelete messages? This is like maildir_quota_add_start
+** and maildir_quota_add_end, except that if deleted messages are included in
+** the quota, they are compiled to no-ops
+*/
+
+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);
+
+ /* Set a new quota on the maildir; */
+
+void maildir_quota_set(const char *dir, const char *quota);
+
+ /* Forcibly recalculate the maildir's quota */
+
+void maildir_quota_recalculate(const char *maildir);
+
+
+ /*
+ ** Should the following folder/file be included in the quota?
+ ** (excludes TRASH and deleted files, if configured to do so)
+ */
+
+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);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif