[EXIM] Patch for quota on maildirs

Kezdőlap
Üzenet törlése
Válasz az üzenetre
Szerző: Jochen Topf
Dátum:  
Címzett: exim-users
Tárgy: [EXIM] Patch for quota on maildirs
Ok, here is my patch relative to exim 1.92 for quota on maildirs. There is a
new boolean config option "quota_on_maildir" to enable it (default is off).
I am using this here now and hope it works... :-) Any comments are welcome.
Philip: If you want to add this to the distribution, go ahead.

jochen

--- appendfile.c.orig    Tue Jun 23 18:50:35 1998
+++ appendfile.c    Tue Jun 23 20:30:31 1998
@@ -81,6 +81,8 @@
       (void *)(offsetof(appendfile_transport_options_block, prefix)) },
   { "quota",             opt_stringptr,
       (void *)(offsetof(appendfile_transport_options_block, quota)) },
+  { "quota_on_maildir",  opt_bool,
+      (void *)(offsetof(appendfile_transport_options_block, quota_on_maildir)) },
   { "require_lockfile",  opt_bool,
       (void *)(offsetof(appendfile_transport_options_block, require_lockfile)) },
   { "retry_use_local_part", opt_bool | opt_public,
@@ -116,6 +118,7 @@
   "anywhere",     /* create_file_string (string value for create_file) */
   NULL,           /* quota */
   0,              /* quota_value */
+  FALSE,       /* quota_on_maildir */
   0600,           /* mode */
   0700,           /* dirmode */
   0600,           /* lockfile_mode */
@@ -409,6 +412,42 @@
 }



+/*************************************************
+*        Check size of maildir for quota         *
+*************************************************/
+
+/* returns size 0 if it can't open the dir, which SHOULD NEVER HAPPEN(tm) */
+/* doesn't count files, which are not stat()able */
+
+int check_maildir_size(char *dirname)
+{
+DIR *dir;
+struct dirent *ent;
+struct stat statbuf;
+int sum=0;
+char filenamebuffer[80];
+
+dir = opendir(dirname);
+if (! dir) return(0);
+
+while ((ent = readdir(dir)) != NULL)
+  {
+  if (ent->d_name[0] == '.') continue;
+  snprintf(filenamebuffer, sizeof(filenamebuffer), "%s/%s", dirname, ent->d_name);
+  if (stat(filenamebuffer, &statbuf) < 0) {
+    DEBUG(9) debug_printf("check_maildir_size: stat error %d for %s\n", errno, ent->d_name);
+    continue;
+  }
+  sum += statbuf.st_size;
+  }
+
+closedir(dir);
+
+DEBUG(9) debug_printf("check_maildir_size: dir=%s sum=%d\n", dirname, sum);
+
+return(sum);
+}
+


 /*************************************************
 *              Main entry point                  *
@@ -1309,6 +1348,13 @@
       }
     }


+  /* check quota on maildir */
+  if (ob->quota_on_maildir) {
+    saved_size = check_maildir_size("new");
+    saved_size += check_maildir_size("cur");
+    DEBUG (9) debug_printf ("Size of maildir is: %d\n", saved_size);
+  }
+
   /* All relevant directories now exist. Attempt to open the temporary
   file a limited number of times. I think this rather scary-looking for
   statement is actually OK. If open succeeds, the loop is broken; if not,
@@ -1367,8 +1413,7 @@
 errno = 0;


/* If there is a local quota setting, check that we are not going to exceed it
-with this message. This of course applies only file appending, not when writing
-in a directory. */
+with this message. */

 if (ob->quota_value > 0)
   {
--- appendfile.h.orig    Tue Jun 23 20:45:25 1998
+++ appendfile.h    Tue Jun 23 20:30:38 1998
@@ -15,6 +15,7 @@
   char *create_file_string;
   char *quota;
   int   quota_value;
+  BOOL  quota_on_maildir;
   int   mode;
   int   dirmode;
   int   lockfile_mode;


--
*** Exim information can be found at http://www.exim.org/ ***