?? qmail-maildir++.patch
字號:
+ n=docount(p, maxtime, sizep, cntp);+ }+ free(p);+ return (n);+ }+ + static int countsubdir(const char *dir, const char *subdir, time_t *maxtime,+ off_t *sizep, unsigned *cntp)+ {+ char *p;+ int n;+ + if ( *subdir != '.' || strcmp(subdir, ".") == 0 ||+ strcmp(subdir, "..") == 0 || strcmp(subdir, "." TRASH) == 0)+ return (0);+ + p=(char *)malloc(strlen(dir)+strlen(subdir)+2);+ if (!p) return (2);+ strcat(strcat(strcpy(p, dir), "/"), subdir);+ n=countcurnew(p, maxtime, sizep, cntp);+ free(p);+ return (n);+ }+ + static int docount(const char *dir, time_t *dirstamp,+ off_t *sizep, unsigned *cntp)+ {+ struct stat stat_buf;+ char *p;+ DIR *dirp;+ struct dirent *de;+ unsigned long s;+ + if (stat(dir, &stat_buf)) return (0); /* Ignore */+ if (stat_buf.st_mtime > *dirstamp) *dirstamp=stat_buf.st_mtime;+ if ((dirp=opendir(dir)) == 0) return (0);+ while ((de=readdir(dirp)) != 0)+ {+ const char *n=de->d_name;+ + if (*n == '.') continue;+ + /* PATCH - do not count msgs marked as deleted */+ + for ( ; *n; n++)+ {+ if (n[0] != ':' || n[1] != '2' ||+ n[2] != ',') continue;+ n += 3;+ while (*n >= 'A' && *n <= 'Z')+ {+ if (*n == 'T') break;+ ++n;+ }+ break;+ }+ if (*n == 'T') continue;+ n=de->d_name;+ + + if (maildir_parsequota(n, &s) == 0)+ stat_buf.st_size=s;+ else+ {+ p=(char *)malloc(strlen(dir)+strlen(n)+2);+ if (!p)+ {+ closedir(dirp);+ return (-1);+ }+ strcat(strcat(strcpy(p, dir), "/"), n);+ if (stat(p, &stat_buf))+ {+ free(p);+ continue;+ }+ free(p);+ }+ *sizep += stat_buf.st_size;+ ++*cntp;+ }+ + #if CLOSEDIR_VOID+ closedir(dirp);+ #else+ if (closedir(dirp))+ return (-1);+ #endif+ return (0);+ }diff -crN ../qmail-1.03/maildirquota.h ./maildirquota.h*** ../qmail-1.03/maildirquota.h Wed Dec 31 18:00:00 1969--- ./maildirquota.h Mon Jun 10 13:25:46 2002****************** 0 ****--- 1,45 ----+ #ifndef maildirquota_h+ #define maildirquota_h+ + /*+ ** Copyright 1998 - 1999 Double Precision, Inc.+ ** See COPYING for distribution information.+ */+ + #if HAVE_CONFIG_H+ #include "config.h"+ #endif+ + #include <sys/types.h>+ #include <stdio.h>+ + #ifdef __cplusplus+ extern "C" {+ #endif+ + static const char maildirquota_h_rcsid[]="$Id: qmail-maildir++.patch,v 1.1.1.1 2003/09/10 20:43:16 tomcollins Exp $";+ + int maildir_checkquota(const char *, /* Pointer to directory */+ int *, /* Initialized to -1, or opened descriptor for maildirsize */+ const char *, /* The quota */+ long, /* Extra bytes planning to add/remove from maildir */+ int); /* Extra messages planning to add/remove from maildir */+ + int maildir_addquota(const char *, /* Pointer to the maildir */+ int, /* Must be the int pointed to by 2nd arg to checkquota */+ const char *, /* The quota */+ long, /* +/- bytes */+ int); /* +/- files */+ + int maildir_readquota(const char *, /* Directory */+ const char *); /* Quota, from getquota */+ + 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. */+ + #ifdef __cplusplus+ }+ #endif+ + #endifdiff -crN ../qmail-1.03/numlib.h ./numlib.h*** ../qmail-1.03/numlib.h Wed Dec 31 18:00:00 1969--- ./numlib.h Mon Jun 10 13:25:46 2002****************** 0 ****--- 1,45 ----+ #ifndef numlib_h+ #define numlib_h+ + /*+ ** Copyright 1998 - 1999 Double Precision, Inc.+ ** See COPYING for distribution information.+ */+ + #ifdef __cplusplus+ extern "C" {+ #endif+ + static const char numlib_h_rcsid[]="$Id: qmail-maildir++.patch,v 1.1.1.1 2003/09/10 20:43:16 tomcollins Exp $";+ + #if HAVE_CONFIG_H+ #include "config.h"+ #endif+ + #include <sys/types.h>+ #include <time.h>+ + #define NUMBUFSIZE 60+ + /* Convert various system types to decimal */+ + char *str_time_t(time_t, char *);+ char *str_off_t(off_t, char *);+ char *str_pid_t(pid_t, char *);+ char *str_ino_t(ino_t, char *);+ char *str_uid_t(uid_t, char *);+ char *str_gid_t(gid_t, char *);+ char *str_size_t(size_t, char *);+ + char *str_sizekb(unsigned long, char *); /* X Kb or X Mb */+ + /* Convert selected system types to hex */+ + char *strh_time_t(time_t, char *);+ char *strh_pid_t(pid_t, char *);+ char *strh_ino_t(ino_t, char *);+ + #ifdef __cplusplus+ }+ #endif+ #endifdiff -crN ../qmail-1.03/overmaildirquota.c ./overmaildirquota.c*** ../qmail-1.03/overmaildirquota.c Wed Dec 31 18:00:00 1969--- ./overmaildirquota.c Mon Jun 10 13:25:46 2002****************** 0 ****--- 1,43 ----+ /*+ ** Copyright 1998 - 1999 Double Precision, Inc.+ ** See COPYING for distribution information.+ */+ + #if HAVE_CONFIG_H+ #include "config.h"+ #endif+ #include "maildirquota.h"+ #include <stdlib.h>+ #include <string.h>+ #include <errno.h>+ #include <sys/stat.h>+ + static const char rcsid[]="$Id: qmail-maildir++.patch,v 1.1.1.1 2003/09/10 20:43:16 tomcollins Exp $";+ + + + int user_over_maildirquota( const char *dir, const char *q)+ {+ struct stat stat_buf;+ int quotafd;+ int ret_value;+ + if (fstat(0, &stat_buf) == 0 && S_ISREG(stat_buf.st_mode) &&+ stat_buf.st_size > 0 && *q)+ {+ if (maildir_checkquota(dir, "afd, q, stat_buf.st_size, 1)+ && errno != EAGAIN)+ {+ if (quotafd >= 0) close(quotafd);+ ret_value = 1;+ } else {+ maildir_addquota(dir, quotafd, q, stat_buf.st_size, 1);+ if (quotafd >= 0) close(quotafd);+ ret_value = 0;+ }+ } else {+ ret_value = 0;+ }+ + return(ret_value);+ }diff -crN ../qmail-1.03/qmail-local.c ./qmail-local.c*** ../qmail-1.03/qmail-local.c Mon Jun 15 05:53:16 1998--- ./qmail-local.c Mon Jun 10 13:54:19 2002****************** 66,71 ****--- 66,72 ---- char buf[1024]; char outbuf[1024];+ #define QUOTABUFSIZE 256 /* child process */ ****************** 86,94 ****--- 87,101 ---- int fd; substdio ss; substdio ssout;+ char quotabuf[QUOTABUFSIZE]; sig_alarmcatch(sigalrm); if (chdir(dir) == -1) { if (error_temp(errno)) _exit(1); _exit(2); }+ if (maildir_getquota(dir, quotabuf) == 0) {+ if (user_over_maildirquota(dir,quotabuf)==1) {+ _exit(1);+ }+ } pid = getpid(); host[0] = 0; gethostname(host,sizeof(host));****************** 99,105 **** s += fmt_str(s,"tmp/"); s += fmt_ulong(s,time); *s++ = '.'; s += fmt_ulong(s,pid); *s++ = '.';! s += fmt_strn(s,host,sizeof(host)); *s++ = 0; if (stat(fntmptph,&st) == -1) if (errno == error_noent) break; /* really should never get to this point */ if (loop == 2) _exit(1);--- 106,115 ---- s += fmt_str(s,"tmp/"); s += fmt_ulong(s,time); *s++ = '.'; s += fmt_ulong(s,pid); *s++ = '.';! s += fmt_strn(s,host,sizeof(host));! s += fmt_strn(s,",S=",sizeof(",S="));! if (fstat(0,&st) == -1) if (errno == error_noent) break;! s += fmt_ulong(s,st.st_size); *s++ = 0; if (stat(fntmptph,&st) == -1) if (errno == error_noent) break; /* really should never get to this point */ if (loop == 2) _exit(1);****************** 159,164 ****--- 169,175 ---- switch(wait_exitcode(wstat)) { case 0: break;+ case 1: strerr_die1x(1, "User over quota. (#5.1.1)"); case 2: strerr_die1x(111,"Unable to chdir to maildir. (#4.2.1)"); case 3: strerr_die1x(111,"Timeout on maildir delivery. (#4.3.0)"); case 4: strerr_die1x(111,"Unable to read message. (#4.3.0)");diff -crN ../qmail-1.03/qmail-pop3d.c ./qmail-pop3d.c*** ../qmail-1.03/qmail-pop3d.c Mon Jun 15 05:53:16 1998--- ./qmail-pop3d.c Mon Jun 10 13:25:46 2002****************** 16,21 ****--- 16,26 ---- #include "readwrite.h" #include "timeoutread.h" #include "timeoutwrite.h"+ #include <errno.h>+ #include "maildirquota.h"+ #include "maildirmisc.h"+ + #define QUOTABUFSIZE 256 void die() { _exit(0); } ****************** 45,63 **** { substdio_put(&ssout,buf,len); }- void puts(s) char *s;- {- substdio_puts(&ssout,s);- } void flush() { substdio_flush(&ssout); } void err(s) char *s; {! puts("-ERR ");! puts(s);! puts("\r\n"); flush(); } --- 50,64 ---- { substdio_put(&ssout,buf,len); } void flush() { substdio_flush(&ssout); } void err(s) char *s; {! substdio_puts(&ssout,"-ERR ");! substdio_puts(&ssout,s);! substdio_puts(&ssout,"\r\n"); flush(); } ****************** 73,79 **** void err_nosuch() { err("unable to open that message"); } void err_nounlink() { err("unable to unlink all deleted messages"); } ! void okay() { puts("+OK \r\n"); flush(); } void printfn(fn) char *fn; {--- 74,80 ---- void err_nosuch() { err("unable to open that message"); } void err_nounlink() { err("unable to unlink all deleted messages"); } ! void okay() { substdio_puts(&ssout,"+OK \r\n"); flush(); } void printfn(fn) char *fn; {****************** 153,163 **** total = 0; for (i = 0;i < numm;++i) if (!m[i].flagdeleted) total += m[i].size;! puts("+OK "); put(strnum,fmt_uint(strnum,numm));! puts(" "); put(strnum,fmt_ulong(strnum,total));! puts("\r\n"); flush(); } --- 154,164 ---- total = 0; for (i = 0;i < numm;++i) if (!m[i].flagdeleted) total += m[i].size;! substdio_puts(&ssout,"+OK "); put(strnum,fmt_uint(strnum,numm));! substdio_puts(&ssout," "); put(strnum,fmt_ulong(strnum,total));! substdio_puts(&ssout,"\r\n"); flush(); } ****************** 171,188 **** void pop3_last() {! puts("+OK "); put(strnum,fmt_uint(strnum,last));! puts("\r\n"); flush(); } void pop3_quit() { int i; for (i = 0;i < numm;++i) if (m[i].flagdeleted) {! if (unlink(m[i].fn) == -1) err_nounlink(); } else if (str_start(m[i].fn,"new/")) {--- 172,212 ---- void pop3_last() {! substdio_puts(&ssout,"+OK "); put(strnum,fmt_uint(strnum,last));! substdio_puts(&ssout,"\r\n"); flush(); } void pop3_quit() { int i;+ char quotabuf[QUOTABUFSIZE];+ int has_quota=maildir_getquota(".", quotabuf);+ + long deleted_bytes=0;+ long deleted_messages=0;+ for (i = 0;i < numm;++i) if (m[i].flagdeleted) {! unsigned long un=0;! const char *filename=m[i].fn;! if (has_quota == 0 && !MAILDIR_DELETED(filename)) {! if (maildir_parsequota(filename, &un)) {! struct stat stat_buf;! ! if (stat(filename, &stat_buf) == 0)! un=stat_buf.st_size;! }! }! if (unlink(m[i].fn) == -1) {! err_nounlink();! un=0;! }! if (un) {! deleted_bytes -= un;! deleted_messages -= 1;! } } else if (str_start(m[i].fn,"new/")) {****************** 192,197 ****--- 216,236 ---- if (!stralloc_0(&line)) die_nomem(); rename(m[i].fn,line.s); /* if it fails, bummer */ }+ + if (deleted_messages < 0) {+ int quotafd;+ + if (maildir_checkquota(".", "afd, quotabuf, deleted_bytes,+ deleted_messages) && errno != EAGAIN &&+ deleted_bytes >= 0)+ {+ if (quotafd >= 0) close (quotafd);+ } else {+ maildir_addquota(".", quotafd, quotabuf,+ deleted_bytes, deleted_messages);+ if (quotafd >= 0) close(quotafd);+ }+ } okay(); die(); }****************** 222,231 **** int flaguidl; { put(strnum,fmt_uint(strnum,i + 1));! puts(" "); if (flaguidl) printfn(m[i].fn); else put(strnum,fmt_ulong(strnum,m[i].size));! puts("\r\n"); } void dolisting(arg,flaguidl) char *arg; int flaguidl;--- 261,270 ---- int flaguidl; { put(strnum,fmt_uint(strnum,i + 1));! substdio_puts(&ssout," "); if (flaguidl) printfn(m[i].fn); else put(strnum,fmt_ulong(strnum,m[i].size));! substdio_puts(&ssout,"\r\n"); } void dolisting(arg,flaguidl) char *arg; int flaguidl;****************** 234,240 **** if (*arg) { i = msgno(arg); if (i == -1) return;! puts("+OK "); list(i,flaguidl); } else {--- 273,279 ---- if (*arg) { i = msgno(arg); if (i == -1) return;! substdio_puts(&ssout,"+OK "); list(i,flaguidl); } else {****************** 242,248 **** for (i = 0;i < numm;++i) if (!m[i].flagdeleted) list(i,flaguidl);! puts(".\r\n"); } flush(); }--- 281,287 ---- for (i = 0;i < numm;++i) if (!m[i].flagdeleted) list(i,flaguidl);! substdio_puts(&ssout,".\r\n"); } flush(); }diff -crN ../qmail-1.03/strpidt.c ./strpidt.c*** ../qmail-1.03/strpidt.c Wed Dec 31 18:00:00 1969--- ./strpidt.c Mon Jun 10 13:25:46 2002****************** 0 ****--- 1,26 ----+ /*+ ** Copyright 1998 - 2000 Double Precision, Inc.+ ** See COPYING for distribution information.+ */+ + #if HAVE_CONFIG_H+ #include "config.h"+ #endif+ #include "numlib.h"+ #include <string.h>+ + static const char rcsid[]="$Id: qmail-maildir++.patch,v 1.1.1.1 2003/09/10 20:43:16 tomcollins Exp $";+ + char *str_pid_t(pid_t t, char *arg)+ {+ char buf[NUMBUFSIZE];+ char *p=buf+sizeof(buf)-1;+ + *p=0;+ do+ {+ *--p= '0' + (t % 10);+ t=t / 10;+ } while(t);+ return (strcpy(arg, p));+ }diff -crN ../qmail-1.03/strtimet.c ./strtimet.c*** ../qmail-1.03/strtimet.c Wed Dec 31 18:00:00 1969--- ./strtimet.c Mon Jun 10 13:25:46 2002****************** 0 ****--- 1,26 ----+ /*+ ** Copyright 1998 - 2000 Double Precision, Inc.+ ** See COPYING for distribution information.+ */+ + #if HAVE_CONFIG_H+ #include "config.h"+ #endif+ #include "numlib.h"+ #include <string.h>+ + static const char rcsid[]="$Id: qmail-maildir++.patch,v 1.1.1.1 2003/09/10 20:43:16 tomcollins Exp $";+ + char *str_time_t(time_t t, char *arg)+ {+ char buf[NUMBUFSIZE];+ char *p=buf+sizeof(buf)-1;+ + *p=0;+ do+ {+ *--p= '0' + (t % 10);+ t=t / 10;+ } while(t);+ return (strcpy(arg, p));+ }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -