*** qmail-local.c	Mon Jun 15 13:53:16 1998
--- qmail-local.c.quota	Sun May  6 18:22:36 2001
***************
*** 1,4 ****
--- 1,6 ----
  #include <sys/types.h>
  #include <sys/stat.h>
+ #include <stdio.h>
+ #include <dirent.h>
  #include "readwrite.h"
  #include "sig.h"
***************
*** 30,33 ****
--- 32,40 ----
  #include "auto_patrn.h"
  
+ #define MY_QUOTA 8192 /* total number of blocks/bytes */
+ #define MY_BYTES 0    /* default is to calculate quota by bytes */
+ 		      /* 0 - bytes */
+ 		      /* 1 - blocks */
+ 
  void usage() { strerr_die1x(100,"qmail-local: usage: qmail-local [ -nN ] user homedir local dash ext domain sender aliasempty"); }
  
***************
*** 42,45 ****
--- 49,54 ----
  { strerr_die5x(111,"Unable to open ",fn,": ",error_str(errno),". (#4.3.0)"); }
  
+ void myreaddir(char *myhomedir);
+ 
  int flagdoit;
  int flag99;
***************
*** 53,56 ****
--- 62,68 ----
  char *sender;
  char *aliasempty;
+ long total_bytes;
+ long total_blocks;
+ stralloc myuser_tmp = {0};
  
  stralloc safeext = {0};
***************
*** 460,463 ****
--- 472,478 ----
   char *x;
  
+ total_bytes=0;
+ total_blocks=0;
+ 
   umask(077);
   sig_pipeignore();
***************
*** 489,495 ****
   if (homedir[0] != '/') usage();
   if (chdir(homedir) == -1)
!    strerr_die5x(111,"Unable to switch to ",homedir,": ",error_str(errno),". (#4.3.0)");
   checkhome();
! 
   if (!env_put2("HOST",host)) temp_nomem();
   if (!env_put2("HOME",homedir)) temp_nomem();
--- 504,514 ----
   if (homedir[0] != '/') usage();
   if (chdir(homedir) == -1)
!    strerr_die5x(100,"Unable to switch to ",homedir,": ",error_str(errno),". (#4.3.0)");
   checkhome();
! if (!stralloc_copys(&myuser_tmp,homedir)) temp_nomem();
! if (!stralloc_cats(&myuser_tmp,"/Maildir")) temp_nomem();
! if (!stralloc_0(&myuser_tmp)) temp_nomem(); 
! myreaddir(myuser_tmp.s);
! if (total_bytes >= MY_QUOTA ) {strerr_die5x(100,"This user exceeds quota !!!!!",homedir,":"," ","");}
   if (!env_put2("HOST",host)) temp_nomem();
   if (!env_put2("HOME",homedir)) temp_nomem();
***************
*** 697,698 ****
--- 716,772 ----
   _exit(0);
  }
+ 
+ void myreaddir(char *myhomedir) {
+ {
+ /*
+ qmail-quota patch
+ written by Levent Serinol 
+ May 6 2001
+ lserinol@yahoo.com
+ 
+ NOTE: change MY_QUOTA definition's value to set quota limit in bytes or blocks
+ */
+ 
+  int mystatus;
+  DIR *mydir;
+  struct stat mystat;
+  struct dirent *mydirent;
+  char mytmp[255];
+  char mytmp_file[255];
+  mydir=opendir(myhomedir);
+  if (mydir == NULL) { strerr_die3x(111,"Unable to stat home directory: ",error_str(mydir),". (#4.3.0)"); };
+  mydirent=readdir(mydir);
+  while ( mydirent != NULL )
+  {
+        if (!strcpy(mytmp_file,myhomedir)) temp_nomem();
+        if (!strcat(mytmp_file,"/")) temp_nomem();
+        if (!strcat(mytmp_file,mydirent->d_name)) temp_nomem();
+  	mystatus=lstat(mytmp_file,&mystat);
+  	if (mystatus != 0) {  strerr_die3x(111,"Unable to stat home directory: ",error_str(mystatus),". (#4.3.0)"); }; 
+  
+  	if ( S_ISDIR(mystat.st_mode) )
+ 	        {	
+ 		if ( strcmp(mydirent->d_name,".") && strcmp(mydirent->d_name,"..") )  {
+  		      if (!strcpy(mytmp,myhomedir)) temp_nomem();
+  		      if (!strcat(mytmp,"/")) temp_nomem();
+  		      if (!strcat(mytmp,mydirent->d_name)) temp_nomem();
+  		      myreaddir(mytmp);
+  		 }
+  	} else
+              { 
+          	if (MY_BYTES == 0 ) {
+  			/*Calculate size by file bytes*/
+  			total_bytes=total_bytes+mystat.st_size; 
+  	 			}
+          			 else
+             				 {
+  				/*Calculate size by file blocks */
+  				total_blocks=total_blocks+mystat.st_blksize;
+                				}
+              }
+  	mydirent=readdir(mydir); 
+  } 
+  closedir(mydir);
+  }
+  return;
+  } /* end of myreaddir function */

