updated on Wed Jan 25 16:08:47 UTC 2012
[aur-mirror.git] / qmail / qmail-maildir++-universal.patch
blob68135ab6629fca7f6168899cbc452cbc1c0b1b0c
1 diff -u --new-file qmail-1.03.orig/Makefile qmail-1.03/Makefile
2 --- qmail-1.03.orig/Makefile 2005-07-05 14:15:09.105597225 -0300
3 +++ qmail-1.03/Makefile 2005-07-05 14:18:47.662764747 -0300
4 @@ -862,6 +862,38 @@
5 readwrite.h open.h headerbody.h maildir.h strerr.h
6 ./compile maildirwatch.c
8 +maildirgetquota.o: \
9 +compile maildirgetquota.c maildirgetquota.h maildirmisc.h
10 + ./compile maildirgetquota.c
12 +maildirflags.o: \
13 +compile maildirflags.c
14 + ./compile maildirflags.c
16 +maildiropen.o: \
17 +compile maildiropen.c maildirmisc.h
18 + ./compile maildiropen.c
20 +maildirparsequota.o: \
21 +compile maildirparsequota.c
22 + ./compile maildirparsequota.c
24 +maildirquota.o: \
25 +compile maildirquota.c maildirquota.h maildirmisc.h numlib.h
26 + ./compile maildirquota.c
28 +overmaildirquota.o: \
29 +compile overmaildirquota.c
30 + ./compile overmaildirquota.c
32 +strtimet.o: \
33 +compile strtimet.c
34 + ./compile strtimet.c
36 +strpidt.o: \
37 +compile strpidt.c
38 + ./compile strpidt.c
40 mailsubj: \
41 warn-auto.sh mailsubj.sh conf-qmail conf-break conf-split
42 cat warn-auto.sh mailsubj.sh \
43 @@ -1155,12 +1187,15 @@
44 load qmail-local.o qmail.o quote.o now.o gfrom.o myctime.o \
45 slurpclose.o case.a getln.a getopt.a sig.a open.a seek.a lock.a fd.a \
46 wait.a env.a stralloc.a alloc.a strerr.a substdio.a error.a str.a \
47 -fs.a datetime.a auto_qmail.o auto_patrn.o socket.lib
48 +fs.a datetime.a auto_qmail.o auto_patrn.o socket.lib maildirquota.o \
49 +maildirgetquota.o maildiropen.o maildirparsequota.o overmaildirquota.o \
50 +strtimet.o strpidt.o
51 ./load qmail-local qmail.o quote.o now.o gfrom.o myctime.o \
52 slurpclose.o case.a getln.a getopt.a sig.a open.a seek.a \
53 lock.a fd.a wait.a env.a stralloc.a alloc.a strerr.a \
54 substdio.a error.a str.a fs.a datetime.a auto_qmail.o \
55 - auto_patrn.o `cat socket.lib`
56 + auto_patrn.o `cat socket.lib` maildirquota.o maildirgetquota.o \
57 + maildiropen.o maildirparsequota.o overmaildirquota.o strtimet.o strpidt.o
59 qmail-local.0: \
60 qmail-local.8
61 @@ -1249,11 +1284,13 @@
62 qmail-pop3d: \
63 load qmail-pop3d.o commands.o case.a timeoutread.o timeoutwrite.o \
64 maildir.o prioq.o now.o env.a strerr.a sig.a open.a getln.a \
65 -stralloc.a alloc.a substdio.a error.a str.a fs.a socket.lib
66 +stralloc.a alloc.a substdio.a error.a str.a fs.a socket.lib maildirquota.o \
67 +maildirparsequota.o maildirflags.o maildiropen.o strtimet.o strpidt.o
68 ./load qmail-pop3d commands.o case.a timeoutread.o \
69 timeoutwrite.o maildir.o prioq.o now.o env.a strerr.a sig.a \
70 open.a getln.a stralloc.a alloc.a substdio.a error.a str.a \
71 - fs.a `cat socket.lib`
72 + fs.a `cat socket.lib` maildirquota.o maildirgetquota.o \
73 + maildirparsequota.o maildirflags.o maildiropen.o strtimet.o strpidt.o
75 qmail-pop3d.0: \
76 qmail-pop3d.8
77 diff -u --new-file qmail-1.03.orig/TARGETS qmail-1.03/TARGETS
78 --- qmail-1.03.orig/TARGETS 2005-07-05 14:15:09.070605844 -0300
79 +++ qmail-1.03/TARGETS 2005-07-05 14:18:47.672762284 -0300
80 @@ -15,6 +15,14 @@
81 slurpclose.o
82 make-makelib
83 makelib
84 +maildirflags.o
85 +maildirparsequota.o
86 +maildiropen.o
87 +maildirgetquota.o
88 +maildirquota.o
89 +overmaildirquota.o
90 +strtimet.o
91 +strpidt.o
92 case_diffb.o
93 case_diffs.o
94 case_lowerb.o
95 diff -u --new-file qmail-1.03.orig/maildirflags.c qmail-1.03/maildirflags.c
96 --- qmail-1.03.orig/maildirflags.c 1969-12-31 21:00:00.000000000 -0300
97 +++ qmail-1.03/maildirflags.c 2005-07-05 14:18:47.675761546 -0300
98 @@ -0,0 +1,23 @@
99 +/*
100 +** Copyright 2000 Double Precision, Inc.
101 +** See COPYING for distribution information.
104 +#include <sys/types.h>
105 +#include <string.h>
107 +static const char rcsid[]="$Id: qmail-maildir++.patch,v 1.1.1.1.2.1 2005/01/19 23:35:23 tomcollins Exp $";
109 +int maildir_hasflag(const char *filename, char flag)
111 + const char *p=strrchr(filename, '/');
113 + if (p)
114 + filename=p+1;
116 + p=strrchr(p, ':');
117 + if (p && strncmp(p, ":2,", 3) == 0 &&
118 + strchr(p+3, flag))
119 + return (1);
120 + return (0);
122 diff -u --new-file qmail-1.03.orig/maildirgetquota.c qmail-1.03/maildirgetquota.c
123 --- qmail-1.03.orig/maildirgetquota.c 1969-12-31 21:00:00.000000000 -0300
124 +++ qmail-1.03/maildirgetquota.c 2005-07-05 14:18:47.677761053 -0300
125 @@ -0,0 +1,50 @@
127 +** Copyright 1998 - 2000 Double Precision, Inc.
128 +** See COPYING for distribution information.
131 +#include "maildirgetquota.h"
132 +#include "maildirmisc.h"
133 +#if HAVE_UNISTD_H
134 +#include <unistd.h>
135 +#endif
136 +#include <stdlib.h>
137 +#include <string.h>
138 +#include <fcntl.h>
139 +#include <sys/types.h>
140 +#include <sys/stat.h>
142 +int maildir_getquota(const char *dir, char buf[QUOTABUFSIZE])
144 +char *p;
145 +struct stat stat_buf;
146 +int n;
147 +int l;
149 + p=(char *)malloc(strlen(dir)+sizeof("/maildirfolder"));
150 + if (!p) return (-1);
152 + strcat(strcpy(p, dir), "/maildirfolder");
153 + if (stat(p, &stat_buf) == 0)
155 + strcat(strcpy(p, dir), "/..");
156 + n=maildir_getquota(p, buf);
157 + free(p);
158 + return (n);
161 + strcat(strcpy(p, dir), "/maildirsize");
162 + n=maildir_safeopen(p, O_RDONLY, 0);
163 + free(p);
164 + if (n < 0) return (n);
165 + if ((l=read(n, buf, QUOTABUFSIZE-1)) < 0)
167 + close(n);
168 + return (-1);
170 + close(n);
171 + for (n=0; n<l; n++)
172 + if (buf[n] == '\n') break;
173 + buf[n]=0;
174 + return (0);
176 diff -u --new-file qmail-1.03.orig/maildirgetquota.h qmail-1.03/maildirgetquota.h
177 --- qmail-1.03.orig/maildirgetquota.h 1969-12-31 21:00:00.000000000 -0300
178 +++ qmail-1.03/maildirgetquota.h 2005-07-05 14:18:47.680760314 -0300
179 @@ -0,0 +1,30 @@
180 +#ifndef maildirgetquota_h
181 +#define maildirgetquota_h
184 +** Copyright 1998 - 1999 Double Precision, Inc.
185 +** See COPYING for distribution information.
188 +#if HAVE_CONFIG_H
189 +#include "config.h"
190 +#endif
192 +#include <sys/types.h>
193 +#include <stdio.h>
195 +#ifdef __cplusplus
196 +extern "C" {
197 +#endif
199 +static const char maildirgetquota_h_rcsid[]="$Id: qmail-maildir++.patch,v 1.1.1.1.2.1 2005/01/19 23:35:23 tomcollins Exp $";
201 +#define QUOTABUFSIZE 256
203 +int maildir_getquota(const char *, char [QUOTABUFSIZE]);
205 +#ifdef __cplusplus
207 +#endif
209 +#endif
210 diff -u --new-file qmail-1.03.orig/maildirmisc.h qmail-1.03/maildirmisc.h
211 --- qmail-1.03.orig/maildirmisc.h 1969-12-31 21:00:00.000000000 -0300
212 +++ qmail-1.03/maildirmisc.h 2005-07-05 14:18:47.683759576 -0300
213 @@ -0,0 +1,145 @@
214 +#ifndef maildirmisc_h
215 +#define maildirmisc_h
218 +** Copyright 2000 Double Precision, Inc.
219 +** See COPYING for distribution information.
222 +#if HAVE_CONFIG_H
223 +#include "config.h"
224 +#endif
226 +#ifdef __cplusplus
227 +extern "C" {
228 +#endif
230 +static const char maildirmisc_h_rcsid[]="$Id: qmail-maildir++.patch,v 1.1.1.1.2.1 2005/01/19 23:35:23 tomcollins Exp $";
234 +** Miscellaneous maildir-related code
238 +/* Some special folders */
240 +#define INBOX "INBOX"
241 +#define DRAFTS "Drafts"
242 +#define SENT "Sent"
243 +#define TRASH "Trash"
245 +#define SHAREDSUBDIR "shared-folders"
247 +char *maildir_folderdir(const char *, /* maildir */
248 + const char *); /* folder name */
249 + /* Returns the directory corresponding to foldername (foldername is
250 + ** checked to make sure that it's a valid name, else we set errno
251 + ** to EINVAL, and return (0).
252 + */
254 +char *maildir_filename(const char *, /* maildir */
255 + const char *, /* folder */
256 + const char *); /* filename */
257 + /*
258 + ** Builds the filename to this message, suitable for opening.
259 + ** If the file doesn't appear to be there, search the maildir to
260 + ** see if someone changed the flags, and return the current filename.
261 + */
263 +int maildir_safeopen(const char *, /* filename */
264 + int, /* mode */
265 + int); /* perm */
268 +** Same arguments as open(). When we're accessing a shared maildir,
269 +** prevent someone from playing cute and dumping a bunch of symlinks
270 +** in there. This function will open the indicate file only if the
271 +** last component is not a symlink.
272 +** This is implemented by opening the file with O_NONBLOCK (to prevent
273 +** a DOS attack of someone pointing the symlink to a pipe, causing
274 +** the open to hang), clearing O_NONBLOCK, then stat-int the file
275 +** descriptor, lstating the filename, and making sure that dev/ino
276 +** match.
279 +int maildir_semisafeopen(const char *, /* filename */
280 + int, /* mode */
281 + int); /* perm */
284 +** Same thing, except that we allow ONE level of soft link indirection,
285 +** because we're reading from our own maildir, which points to the
286 +** message in the sharable maildir.
289 +int maildir_mkdir(const char *); /* directory */
291 +** Create maildir including all subdirectories in the path (like mkdir -p)
294 +void maildir_purgetmp(const char *); /* maildir */
295 + /* purges old stuff out of tmp */
297 +void maildir_purge(const char *, /* directory */
298 + unsigned); /* time_t to purge */
300 +void maildir_getnew(const char *, /* maildir */
301 + const char *); /* folder */
302 + /* move messages from new to cur */
304 +int maildir_deletefolder(const char *, /* maildir */
305 + const char *); /* folder */
306 + /* deletes a folder */
308 +int maildir_mddelete(const char *); /* delete a maildir folder by path */
310 +void maildir_list_sharable(const char *, /* maildir */
311 + void (*)(const char *, void *), /* callback function */
312 + void *); /* 2nd arg to callback func */
313 + /* list sharable folders */
315 +int maildir_shared_subscribe(const char *, /* maildir */
316 + const char *); /* folder */
317 + /* subscribe to a shared folder */
319 +void maildir_list_shared(const char *, /* maildir */
320 + void (*)(const char *, void *), /* callback function */
321 + void *); /* 2nd arg to the callback func */
322 + /* list subscribed folders */
324 +int maildir_shared_unsubscribe(const char *, /* maildir */
325 + const char *); /* folder */
326 + /* unsubscribe from a shared folder */
328 +char *maildir_shareddir(const char *, /* maildir */
329 + const char *); /* folder */
330 + /*
331 + ** Validate and return a path to a shared folder. folderdir must be
332 + ** a name of a valid shared folder.
333 + */
335 +void maildir_shared_sync(const char *); /* maildir */
336 + /* "sync" the shared folder */
338 +int maildir_sharedisro(const char *); /* maildir */
339 + /* maildir is a shared read-only folder */
341 +int maildir_unlinksharedmsg(const char *); /* filename */
342 + /* Remove a message from a shared folder */
344 +/* Internal function that reads a symlink */
346 +char *maildir_getlink(const char *);
348 + /* Determine whether the maildir filename has a certain flag */
350 +int maildir_hasflag(const char *filename, char);
352 +#define MAILDIR_DELETED(f) maildir_hasflag((f), 'T')
354 +#ifdef __cplusplus
356 +#endif
358 +#endif
359 diff -u --new-file qmail-1.03.orig/maildiropen.c qmail-1.03/maildiropen.c
360 --- qmail-1.03.orig/maildiropen.c 1969-12-31 21:00:00.000000000 -0300
361 +++ qmail-1.03/maildiropen.c 2005-07-05 14:18:47.686758837 -0300
362 @@ -0,0 +1,133 @@
364 +** Copyright 2000 Double Precision, Inc.
365 +** See COPYING for distribution information.
368 +#if HAVE_CONFIG_H
369 +#include "config.h"
370 +#endif
372 +#include <sys/types.h>
373 +#include <sys/stat.h>
374 +#include <string.h>
375 +#include <stdlib.h>
376 +#include <time.h>
377 +#if HAVE_UNISTD_H
378 +#include <unistd.h>
379 +#endif
380 +#include <stdio.h>
381 +#include <ctype.h>
382 +#include <errno.h>
383 +#include <fcntl.h>
385 +#include "maildirmisc.h"
387 +static const char rcsid[]="$Id: qmail-maildir++.patch,v 1.1.1.1.2.1 2005/01/19 23:35:23 tomcollins Exp $";
389 +char *maildir_getlink(const char *filename)
391 +#if HAVE_READLINK
392 +size_t bufsiz;
393 +char *buf;
395 + bufsiz=0;
396 + buf=0;
398 + for (;;)
400 + int n;
402 + if (buf) free(buf);
403 + bufsiz += 256;
404 + if ((buf=malloc(bufsiz)) == 0)
406 + perror("malloc");
407 + return (0);
409 + if ((n=readlink(filename, buf, bufsiz)) < 0)
411 + free(buf);
412 + return (0);
414 + if (n < bufsiz)
416 + buf[n]=0;
417 + break;
420 + return (buf);
421 +#else
422 + return (0);
423 +#endif
426 +int maildir_semisafeopen(const char *path, int mode, int perm)
429 +#if HAVE_READLINK
431 +char *l=maildir_getlink(path);
433 + if (l)
435 + int f;
437 + if (*l != '/')
439 + char *q=malloc(strlen(path)+strlen(l)+2);
440 + char *s;
442 + if (!q)
444 + free(l);
445 + return (-1);
448 + strcpy(q, path);
449 + if ((s=strchr(q, '/')) != 0)
450 + s[1]=0;
451 + else *q=0;
452 + strcat(q, l);
453 + free(l);
454 + l=q;
457 + f=maildir_safeopen(l, mode, perm);
459 + free(l);
460 + return (f);
462 +#endif
464 + return (maildir_safeopen(path, mode, perm));
467 +int maildir_safeopen(const char *path, int mode, int perm)
469 +struct stat stat1, stat2;
471 +int fd=open(path, mode
472 +#ifdef O_NONBLOCK
473 + | O_NONBLOCK
474 +#else
475 + | O_NDELAY
476 +#endif
477 + , perm);
479 + if (fd < 0) return (fd);
480 + if (fcntl(fd, F_SETFL, (mode & O_APPEND)) || fstat(fd, &stat1)
481 + || lstat(path, &stat2))
483 + close(fd);
484 + return (-1);
487 + if (stat1.st_dev != stat2.st_dev || stat1.st_ino != stat2.st_ino)
489 + close(fd);
490 + errno=ENOENT;
491 + return (-1);
494 + return (fd);
496 diff -u --new-file qmail-1.03.orig/maildirparsequota.c qmail-1.03/maildirparsequota.c
497 --- qmail-1.03.orig/maildirparsequota.c 1969-12-31 21:00:00.000000000 -0300
498 +++ qmail-1.03/maildirparsequota.c 2005-07-05 14:18:47.689758098 -0300
499 @@ -0,0 +1,44 @@
501 +** Copyright 1998 - 1999 Double Precision, Inc.
502 +** See COPYING for distribution information.
505 +#if HAVE_CONFIG_H
506 +#include "config.h"
507 +#endif
508 +#include "maildirquota.h"
509 +#include <stdlib.h>
510 +#include <string.h>
512 +static const char rcsid[]="$Id: qmail-maildir++.patch,v 1.1.1.1.2.1 2005/01/19 23:35:23 tomcollins Exp $";
514 +int maildir_parsequota(const char *n, unsigned long *s)
516 +const char *o;
517 +int yes;
519 + if ((o=strrchr(n, '/')) == 0) o=n;
521 + for (; *o; o++)
522 + if (*o == ':') break;
523 + yes=0;
524 + for ( ; o >= n; --o)
526 + if (*o == '/') break;
528 + if (*o == ',' && o[1] == 'S' && o[2] == '=')
530 + yes=1;
531 + o += 3;
532 + break;
535 + if (yes)
537 + *s=0;
538 + while (*o >= '0' && *o <= '9')
539 + *s= *s*10 + (*o++ - '0');
540 + return (0);
542 + return (-1);
544 diff -u --new-file qmail-1.03.orig/maildirquota.c qmail-1.03/maildirquota.c
545 --- qmail-1.03.orig/maildirquota.c 1969-12-31 21:00:00.000000000 -0300
546 +++ qmail-1.03/maildirquota.c 2005-07-05 14:18:47.694756867 -0300
547 @@ -0,0 +1,685 @@
549 +** Copyright 1998 - 2002 Double Precision, Inc.
550 +** See COPYING for distribution information.
553 +#if HAVE_CONFIG_H
554 +#include "config.h"
555 +#endif
557 +#include <sys/types.h>
558 +/* #if HAVE_DIRENT_H */
559 +#include <dirent.h>
560 +#define NAMLEN(dirent) strlen((dirent)->d_name)
561 +/* #else
562 +#define dirent direct
563 +#define NAMLEN(dirent) (dirent)->d_namlen
564 +#if HAVE_SYS_NDIR_H
565 +#include <sys/ndir.h>
566 +#endif
567 +#if HAVE_SYS_DIR_H
568 +#include <sys/dir.h>
569 +#endif
570 +#if HAVE_NDIR_H
571 +#include <ndir.h>
572 +#endif
573 +#endif */
574 +#include <sys/types.h>
575 +/* #if HAVE_SYS_STAT_H */
576 +#include <sys/stat.h>
577 +/* #endif */
578 +#include <sys/uio.h>
580 +#include "maildirquota.h"
581 +#include "maildirmisc.h"
582 +#include <stdio.h>
583 +#include <stdlib.h>
584 +#include <string.h>
585 +#include <errno.h>
586 +/* #if HAVE_FCNTL_H */
587 +#include <fcntl.h>
588 +/* #endif */
589 +#if HAVE_UNISTD_H
590 +#include <unistd.h>
591 +#endif
592 +#include <time.h>
593 +#include "numlib.h"
595 +static const char rcsid[]="$Id: qmail-maildir++.patch,v 1.1.1.1.2.1 2005/01/19 23:35:23 tomcollins Exp $";
597 +/* Read the maildirsize file */
599 +int maildirsize_read(const char *filename, /* The filename */
600 + int *fdptr, /* Keep the file descriptor open */
601 + off_t *sizeptr, /* Grand total of maildir size */
602 + unsigned *cntptr, /* Grand total of message count */
603 + unsigned *nlines, /* # of lines in maildirsize */
604 + struct stat *statptr) /* The stats on maildirsize */
606 +char buf[5120];
607 +int f;
608 +char *p;
609 +unsigned l;
610 +int n;
611 +int first;
613 + if ((f=maildir_safeopen(filename, O_RDWR|O_APPEND, 0)) < 0)
614 + return (-1);
615 + p=buf;
616 + l=sizeof(buf);
618 + while (l)
620 + n=read(f, p, l);
621 + if (n < 0)
623 + close(f);
624 + return (-1);
626 + if (n == 0) break;
627 + p += n;
628 + l -= n;
630 + if (l == 0 || fstat(f, statptr)) /* maildir too big */
632 + close(f);
633 + return (-1);
636 + *sizeptr=0;
637 + *cntptr=0;
638 + *nlines=0;
639 + *p=0;
640 + p=buf;
641 + first=1;
642 + while (*p)
644 + long n=0;
645 + int c=0;
646 + char *q=p;
648 + while (*p)
649 + if (*p++ == '\n')
651 + p[-1]=0;
652 + break;
655 + if (first)
657 + first=0;
658 + continue;
660 + sscanf(q, "%ld %d", &n, &c);
661 + *sizeptr += n;
662 + *cntptr += c;
663 + ++ *nlines;
665 + *fdptr=f;
666 + return (0);
669 +static char *makenewmaildirsizename(const char *, int *);
670 +static int countcurnew(const char *, time_t *, off_t *, unsigned *);
671 +static int countsubdir(const char *, const char *,
672 + time_t *, off_t *, unsigned *);
673 +static int statcurnew(const char *, time_t *);
674 +static int statsubdir(const char *, const char *, time_t *);
676 +#define MDQUOTA_SIZE 'S' /* Total size of all messages in maildir */
677 +#define MDQUOTA_BLOCKS 'B' /* Total # of blocks for all messages in
678 + maildir -- NOT IMPLEMENTED */
679 +#define MDQUOTA_COUNT 'C' /* Total number of messages in maildir */
681 +static int qcalc(off_t s, unsigned n, const char *quota, int *percentage)
683 +off_t i;
684 +int spercentage=0;
685 +int npercentage=0;
687 + errno=ENOSPC;
688 + while (quota && *quota)
690 + int x=1;
692 + if (*quota < '0' || *quota > '9')
694 + ++quota;
695 + continue;
697 + i=0;
698 + while (*quota >= '0' && *quota <= '9')
699 + i=i*10 + (*quota++ - '0');
700 + switch (*quota) {
701 + default:
702 + if (i < s)
704 + *percentage=100;
705 + return (-1);
708 + /*
709 + ** For huge quotas, over 20mb,
710 + ** divide numerator & denominator by 1024 to prevent
711 + ** an overflow when multiplying by 100
712 + */
714 + x=1;
715 + if (i > 20000000) x=1024;
717 + spercentage = i ? (s/x) * 100 / (i/x):100;
718 + break;
719 + case 'C':
721 + if (i < n)
723 + *percentage=100;
724 + return (-1);
727 + /* Ditto */
729 + x=1;
730 + if (i > 20000000) x=1024;
732 + npercentage = i ? ((off_t)n/x) * 100 / (i/x):100;
733 + break;
736 + *percentage = spercentage > npercentage ? spercentage:npercentage;
737 + return (0);
740 +static int doaddquota(const char *, int, const char *, long, int, int);
742 +static int docheckquota(const char *dir,
743 + int *maildirsize_fdptr,
744 + const char *quota_type,
745 + long xtra_size,
746 + int xtra_cnt, int *percentage);
749 +int maildir_checkquota(const char *dir,
750 + int *maildirsize_fdptr,
751 + const char *quota_type,
752 + long xtra_size,
753 + int xtra_cnt)
755 +int dummy;
757 + return (docheckquota(dir, maildirsize_fdptr, quota_type,
758 + xtra_size, xtra_cnt, &dummy));
761 +int maildir_readquota(const char *dir, const char *quota_type)
763 +int percentage=0;
764 +int fd=-1;
766 + (void)docheckquota(dir, &fd, quota_type, 0, 0, &percentage);
767 + if (fd >= 0)
768 + close(fd);
769 + return (percentage);
772 +static int docheckquota(const char *dir,
773 + int *maildirsize_fdptr,
774 + const char *quota_type,
775 + long xtra_size,
776 + int xtra_cnt,
777 + int *percentage)
779 +char *checkfolder=(char *)malloc(strlen(dir)+sizeof("/maildirfolder"));
780 +char *newmaildirsizename;
781 +struct stat stat_buf;
782 +int maildirsize_fd;
783 +off_t maildirsize_size;
784 +unsigned maildirsize_cnt;
785 +unsigned maildirsize_nlines;
786 +int n;
787 +time_t tm;
788 +time_t maxtime;
789 +DIR *dirp;
790 +struct dirent *de;
792 + if (checkfolder == 0) return (-1);
793 + *maildirsize_fdptr= -1;
794 + strcat(strcpy(checkfolder, dir), "/maildirfolder");
795 + if (stat(checkfolder, &stat_buf) == 0) /* Go to parent */
797 + strcat(strcpy(checkfolder, dir), "/..");
798 + n=docheckquota(checkfolder, maildirsize_fdptr,
799 + quota_type, xtra_size, xtra_cnt, percentage);
800 + free(checkfolder);
801 + return (n);
803 + if (!quota_type || !*quota_type) return (0);
805 + strcat(strcpy(checkfolder, dir), "/maildirsize");
806 + time(&tm);
807 + if (maildirsize_read(checkfolder, &maildirsize_fd,
808 + &maildirsize_size, &maildirsize_cnt,
809 + &maildirsize_nlines, &stat_buf) == 0)
811 + n=qcalc(maildirsize_size+xtra_size, maildirsize_cnt+xtra_cnt,
812 + quota_type, percentage);
814 + if (n == 0)
816 + free(checkfolder);
817 + *maildirsize_fdptr=maildirsize_fd;
818 + return (0);
820 + close(maildirsize_fd);
822 + if (maildirsize_nlines == 1 && tm < stat_buf.st_mtime + 15*60)
823 + return (n);
826 + maxtime=0;
827 + maildirsize_size=0;
828 + maildirsize_cnt=0;
830 + if (countcurnew(dir, &maxtime, &maildirsize_size, &maildirsize_cnt))
832 + free(checkfolder);
833 + return (-1);
836 + dirp=opendir(dir);
837 + while (dirp && (de=readdir(dirp)) != 0)
839 + if (countsubdir(dir, de->d_name, &maxtime, &maildirsize_size,
840 + &maildirsize_cnt))
842 + free(checkfolder);
843 + closedir(dirp);
844 + return (-1);
847 + if (dirp)
849 +#if CLOSEDIR_VOID
850 + closedir(dirp);
851 +#else
852 + if (closedir(dirp))
854 + free(checkfolder);
855 + return (-1);
857 +#endif
860 + newmaildirsizename=makenewmaildirsizename(dir, &maildirsize_fd);
861 + if (!newmaildirsizename)
863 + free(checkfolder);
864 + return (-1);
867 + *maildirsize_fdptr=maildirsize_fd;
869 + if (doaddquota(dir, maildirsize_fd, quota_type, maildirsize_size,
870 + maildirsize_cnt, 1))
872 + unlink(newmaildirsizename);
873 + free(newmaildirsizename);
874 + close(maildirsize_fd);
875 + *maildirsize_fdptr= -1;
876 + free(checkfolder);
877 + return (-1);
880 + strcat(strcpy(checkfolder, dir), "/maildirsize");
882 + if (rename(newmaildirsizename, checkfolder))
884 + /* free(checkfolder); */
885 + unlink(newmaildirsizename);
886 + close(maildirsize_fd);
887 + *maildirsize_fdptr= -1;
889 + free(checkfolder);
890 + free(newmaildirsizename);
892 + tm=0;
894 + if (statcurnew(dir, &tm))
896 + close(maildirsize_fd);
897 + *maildirsize_fdptr= -1;
898 + return (-1);
901 + dirp=opendir(dir);
902 + while (dirp && (de=readdir(dirp)) != 0)
904 + if (statsubdir(dir, de->d_name, &tm))
906 + close(maildirsize_fd);
907 + *maildirsize_fdptr= -1;
908 + closedir(dirp);
909 + return (-1);
912 + if (dirp)
914 +#if CLOSEDIR_VOID
915 + closedir(dirp);
916 +#else
917 + if (closedir(dirp))
919 + close(maildirsize_fd);
920 + *maildirsize_fdptr= -1;
921 + return (-1);
923 +#endif
926 + if (tm != maxtime) /* Race condition, someone changed something */
928 + errno=EAGAIN;
929 + return (-1);
932 + return (qcalc(maildirsize_size+xtra_size, maildirsize_cnt+xtra_cnt,
933 + quota_type, percentage));
936 +int maildir_addquota(const char *dir, int maildirsize_fd,
937 + const char *quota_type, long maildirsize_size, int maildirsize_cnt)
939 + if (!quota_type || !*quota_type) return (0);
940 + return (doaddquota(dir, maildirsize_fd, quota_type, maildirsize_size,
941 + maildirsize_cnt, 0));
944 +static int doaddquota(const char *dir, int maildirsize_fd,
945 + const char *quota_type, long maildirsize_size, int maildirsize_cnt,
946 + int isnew)
948 +union {
949 + char buf[100];
950 + struct stat stat_buf;
951 + } u; /* Scrooge */
952 +char *newname2=0;
953 +char *newmaildirsizename=0;
954 +struct iovec iov[3];
955 +int niov;
956 +struct iovec *p;
957 +int n;
959 + niov=0;
960 + if ( maildirsize_fd < 0)
962 + newname2=(char *)malloc(strlen(dir)+sizeof("/maildirfolder"));
963 + if (!newname2) return (-1);
964 + strcat(strcpy(newname2, dir), "/maildirfolder");
965 + if (stat(newname2, &u.stat_buf) == 0)
967 + strcat(strcpy(newname2, dir), "/..");
968 + n=doaddquota(newname2, maildirsize_fd, quota_type,
969 + maildirsize_size, maildirsize_cnt,
970 + isnew);
971 + free(newname2);
972 + return (n);
975 + strcat(strcpy(newname2, dir), "/maildirsize");
977 + if ((maildirsize_fd=maildir_safeopen(newname2,
978 + O_RDWR|O_APPEND, 0644)) < 0)
980 + newmaildirsizename=makenewmaildirsizename(dir, &maildirsize_fd);
981 + if (!newmaildirsizename)
983 + free(newname2);
984 + return (-1);
987 + maildirsize_fd=maildir_safeopen(newmaildirsizename,
988 + O_CREAT|O_RDWR|O_APPEND, 0644);
990 + if (maildirsize_fd < 0)
992 + free(newname2);
993 + return (-1);
995 + isnew=1;
999 + if (isnew)
1001 + iov[0].iov_base=(caddr_t)quota_type;
1002 + iov[0].iov_len=strlen(quota_type);
1003 + iov[1].iov_base=(caddr_t)"\n";
1004 + iov[1].iov_len=1;
1005 + niov=2;
1009 + sprintf(u.buf, "%ld %d\n", maildirsize_size, maildirsize_cnt);
1010 + iov[niov].iov_base=(caddr_t)u.buf;
1011 + iov[niov].iov_len=strlen(u.buf);
1013 + p=iov;
1014 + ++niov;
1015 + n=0;
1016 + while (niov)
1018 + if (n)
1020 + if (n < p->iov_len)
1022 + p->iov_base=
1023 + (caddr_t)((char *)p->iov_base + n);
1024 + p->iov_len -= n;
1026 + else
1028 + n -= p->iov_len;
1029 + ++p;
1030 + --niov;
1031 + continue;
1035 + n=writev( maildirsize_fd, p, niov);
1037 + if (n <= 0)
1039 + if (newname2)
1041 + close(maildirsize_fd);
1042 + free(newname2);
1044 + return (-1);
1047 + if (newname2)
1049 + close(maildirsize_fd);
1051 + if (newmaildirsizename)
1053 + rename(newmaildirsizename, newname2);
1054 + free(newmaildirsizename);
1056 + free(newname2);
1058 + return (0);
1061 +/* New maildirsize is built in the tmp subdirectory */
1063 +static char *makenewmaildirsizename(const char *dir, int *fd)
1065 +char hostname[256];
1066 +struct stat stat_buf;
1067 +time_t t;
1068 +char *p;
1070 + hostname[0]=0;
1071 + hostname[sizeof(hostname)-1]=0;
1072 + gethostname(hostname, sizeof(hostname)-1);
1073 + p=(char *)malloc(strlen(dir)+strlen(hostname)+130);
1074 + if (!p) return (0);
1076 + for (;;)
1078 + char tbuf[NUMBUFSIZE];
1079 + char pbuf[NUMBUFSIZE];
1081 + time(&t);
1082 + strcat(strcpy(p, dir), "/tmp/");
1083 + sprintf(p+strlen(p), "%s.%s_NeWmAiLdIrSiZe.%s",
1084 + str_time_t(t, tbuf),
1085 + str_pid_t(getpid(), pbuf), hostname);
1087 + if (stat( (const char *)p, &stat_buf) < 0 &&
1088 + (*fd=maildir_safeopen(p,
1089 + O_CREAT|O_RDWR|O_APPEND, 0644)) >= 0)
1090 + break;
1091 + sleep(3);
1093 + return (p);
1096 +static int statcurnew(const char *dir, time_t *maxtimestamp)
1098 +char *p=(char *)malloc(strlen(dir)+5);
1099 +struct stat stat_buf;
1101 + if (!p) return (-1);
1102 + strcat(strcpy(p, dir), "/cur");
1103 + if ( stat(p, &stat_buf) == 0 && stat_buf.st_mtime > *maxtimestamp)
1104 + *maxtimestamp=stat_buf.st_mtime;
1105 + strcat(strcpy(p, dir), "/new");
1106 + if ( stat(p, &stat_buf) == 0 && stat_buf.st_mtime > *maxtimestamp)
1107 + *maxtimestamp=stat_buf.st_mtime;
1108 + free(p);
1109 + return (0);
1112 +static int statsubdir(const char *dir, const char *subdir, time_t *maxtime)
1114 +char *p;
1115 +int n;
1117 + if ( *subdir != '.' || strcmp(subdir, ".") == 0 ||
1118 + strcmp(subdir, "..") == 0 || strcmp(subdir, "." TRASH) == 0)
1119 + return (0);
1121 + p=(char *)malloc(strlen(dir)+strlen(subdir)+2);
1122 + if (!p) return (-1);
1123 + strcat(strcat(strcpy(p, dir), "/"), subdir);
1124 + n=statcurnew(p, maxtime);
1125 + free(p);
1126 + return (n);
1129 +static int docount(const char *, time_t *, off_t *, unsigned *);
1131 +static int countcurnew(const char *dir, time_t *maxtime,
1132 + off_t *sizep, unsigned *cntp)
1134 +char *p=(char *)malloc(strlen(dir)+5);
1135 +int n;
1137 + if (!p) return (-1);
1138 + strcat(strcpy(p, dir), "/new");
1139 + n=docount(p, maxtime, sizep, cntp);
1140 + if (n == 0)
1142 + strcat(strcpy(p, dir), "/cur");
1143 + n=docount(p, maxtime, sizep, cntp);
1145 + free(p);
1146 + return (n);
1149 +static int countsubdir(const char *dir, const char *subdir, time_t *maxtime,
1150 + off_t *sizep, unsigned *cntp)
1152 +char *p;
1153 +int n;
1155 + if ( *subdir != '.' || strcmp(subdir, ".") == 0 ||
1156 + strcmp(subdir, "..") == 0 || strcmp(subdir, "." TRASH) == 0)
1157 + return (0);
1159 + p=(char *)malloc(strlen(dir)+strlen(subdir)+2);
1160 + if (!p) return (2);
1161 + strcat(strcat(strcpy(p, dir), "/"), subdir);
1162 + n=countcurnew(p, maxtime, sizep, cntp);
1163 + free(p);
1164 + return (n);
1167 +static int docount(const char *dir, time_t *dirstamp,
1168 + off_t *sizep, unsigned *cntp)
1170 +struct stat stat_buf;
1171 +char *p;
1172 +DIR *dirp;
1173 +struct dirent *de;
1174 +unsigned long s;
1176 + if (stat(dir, &stat_buf)) return (0); /* Ignore */
1177 + if (stat_buf.st_mtime > *dirstamp) *dirstamp=stat_buf.st_mtime;
1178 + if ((dirp=opendir(dir)) == 0) return (0);
1179 + while ((de=readdir(dirp)) != 0)
1181 + const char *n=de->d_name;
1183 + if (*n == '.') continue;
1185 + /* PATCH - do not count msgs marked as deleted */
1187 + for ( ; *n; n++)
1189 + if (n[0] != ':' || n[1] != '2' ||
1190 + n[2] != ',') continue;
1191 + n += 3;
1192 + while (*n >= 'A' && *n <= 'Z')
1194 + if (*n == 'T') break;
1195 + ++n;
1197 + break;
1199 + if (*n == 'T') continue;
1200 + n=de->d_name;
1203 + if (maildir_parsequota(n, &s) == 0)
1204 + stat_buf.st_size=s;
1205 + else
1207 + p=(char *)malloc(strlen(dir)+strlen(n)+2);
1208 + if (!p)
1210 + closedir(dirp);
1211 + return (-1);
1213 + strcat(strcat(strcpy(p, dir), "/"), n);
1214 + if (stat(p, &stat_buf))
1216 + free(p);
1217 + continue;
1219 + free(p);
1221 + *sizep += stat_buf.st_size;
1222 + ++*cntp;
1225 +#if CLOSEDIR_VOID
1226 + closedir(dirp);
1227 +#else
1228 + if (closedir(dirp))
1229 + return (-1);
1230 +#endif
1231 + return (0);
1233 diff -u --new-file qmail-1.03.orig/maildirquota.h qmail-1.03/maildirquota.h
1234 --- qmail-1.03.orig/maildirquota.h 1969-12-31 21:00:00.000000000 -0300
1235 +++ qmail-1.03/maildirquota.h 2005-07-05 14:18:47.745744308 -0300
1236 @@ -0,0 +1,45 @@
1237 +#ifndef maildirquota_h
1238 +#define maildirquota_h
1241 +** Copyright 1998 - 1999 Double Precision, Inc.
1242 +** See COPYING for distribution information.
1245 +#if HAVE_CONFIG_H
1246 +#include "config.h"
1247 +#endif
1249 +#include <sys/types.h>
1250 +#include <stdio.h>
1252 +#ifdef __cplusplus
1253 +extern "C" {
1254 +#endif
1256 +static const char maildirquota_h_rcsid[]="$Id: qmail-maildir++.patch,v 1.1.1.1.2.1 2005/01/19 23:35:23 tomcollins Exp $";
1258 +int maildir_checkquota(const char *, /* Pointer to directory */
1259 + int *, /* Initialized to -1, or opened descriptor for maildirsize */
1260 + const char *, /* The quota */
1261 + long, /* Extra bytes planning to add/remove from maildir */
1262 + int); /* Extra messages planning to add/remove from maildir */
1264 +int maildir_addquota(const char *, /* Pointer to the maildir */
1265 + int, /* Must be the int pointed to by 2nd arg to checkquota */
1266 + const char *, /* The quota */
1267 + long, /* +/- bytes */
1268 + int); /* +/- files */
1270 +int maildir_readquota(const char *, /* Directory */
1271 + const char *); /* Quota, from getquota */
1273 +int maildir_parsequota(const char *, unsigned long *);
1274 + /* Attempt to parse file size encoded in filename. Returns 0 if
1275 + ** parsed, non-zero if we didn't parse. */
1277 +#ifdef __cplusplus
1279 +#endif
1281 +#endif
1282 diff -u --new-file qmail-1.03.orig/numlib.h qmail-1.03/numlib.h
1283 --- qmail-1.03.orig/numlib.h 1969-12-31 21:00:00.000000000 -0300
1284 +++ qmail-1.03/numlib.h 2005-07-05 14:18:47.747743816 -0300
1285 @@ -0,0 +1,45 @@
1286 +#ifndef numlib_h
1287 +#define numlib_h
1290 +** Copyright 1998 - 1999 Double Precision, Inc.
1291 +** See COPYING for distribution information.
1294 +#ifdef __cplusplus
1295 +extern "C" {
1296 +#endif
1298 +static const char numlib_h_rcsid[]="$Id: qmail-maildir++.patch,v 1.1.1.1.2.1 2005/01/19 23:35:23 tomcollins Exp $";
1300 +#if HAVE_CONFIG_H
1301 +#include "config.h"
1302 +#endif
1304 +#include <sys/types.h>
1305 +#include <time.h>
1307 +#define NUMBUFSIZE 60
1309 +/* Convert various system types to decimal */
1311 +char *str_time_t(time_t, char *);
1312 +char *str_off_t(off_t, char *);
1313 +char *str_pid_t(pid_t, char *);
1314 +char *str_ino_t(ino_t, char *);
1315 +char *str_uid_t(uid_t, char *);
1316 +char *str_gid_t(gid_t, char *);
1317 +char *str_size_t(size_t, char *);
1319 +char *str_sizekb(unsigned long, char *); /* X Kb or X Mb */
1321 +/* Convert selected system types to hex */
1323 +char *strh_time_t(time_t, char *);
1324 +char *strh_pid_t(pid_t, char *);
1325 +char *strh_ino_t(ino_t, char *);
1327 +#ifdef __cplusplus
1329 +#endif
1330 +#endif
1331 diff -u --new-file qmail-1.03.orig/overmaildirquota.c qmail-1.03/overmaildirquota.c
1332 --- qmail-1.03.orig/overmaildirquota.c 1969-12-31 21:00:00.000000000 -0300
1333 +++ qmail-1.03/overmaildirquota.c 2005-07-05 14:18:47.749743323 -0300
1334 @@ -0,0 +1,43 @@
1336 +** Copyright 1998 - 1999 Double Precision, Inc.
1337 +** See COPYING for distribution information.
1340 +#if HAVE_CONFIG_H
1341 +#include "config.h"
1342 +#endif
1343 +#include "maildirquota.h"
1344 +#include <stdlib.h>
1345 +#include <string.h>
1346 +#include <errno.h>
1347 +#include <sys/stat.h>
1349 +static const char rcsid[]="$Id: qmail-maildir++.patch,v 1.1.1.1.2.1 2005/01/19 23:35:23 tomcollins Exp $";
1353 +int user_over_maildirquota( const char *dir, const char *q)
1355 +struct stat stat_buf;
1356 +int quotafd;
1357 +int ret_value;
1359 + if (fstat(0, &stat_buf) == 0 && S_ISREG(stat_buf.st_mode) &&
1360 + stat_buf.st_size > 0 && *q)
1362 + if (maildir_checkquota(dir, &quotafd, q, stat_buf.st_size, 1)
1363 + && errno != EAGAIN)
1365 + if (quotafd >= 0) close(quotafd);
1366 + ret_value = 1;
1367 + } else {
1368 + maildir_addquota(dir, quotafd, q, stat_buf.st_size, 1);
1369 + if (quotafd >= 0) close(quotafd);
1370 + ret_value = 0;
1372 + } else {
1373 + ret_value = 0;
1376 + return(ret_value);
1378 diff -u --new-file qmail-1.03.orig/qmail-local.c qmail-1.03/qmail-local.c
1379 --- qmail-1.03.orig/qmail-local.c 2005-07-05 14:15:09.176579742 -0300
1380 +++ qmail-1.03/qmail-local.c 2005-07-05 14:18:47.759740861 -0300
1381 @@ -69,6 +69,7 @@
1383 char buf[1024];
1384 char outbuf[1024];
1385 +#define QUOTABUFSIZE 256
1387 /* child process */
1389 @@ -89,9 +90,15 @@
1390 int fd;
1391 substdio ss;
1392 substdio ssout;
1393 + char quotabuf[QUOTABUFSIZE];
1395 sig_alarmcatch(sigalrm);
1396 if (chdir(dir) == -1) { if (error_temp(errno)) _exit(1); _exit(2); }
1397 + if (maildir_getquota(dir, quotabuf) == 0) {
1398 + if (user_over_maildirquota(dir,quotabuf)==1) {
1399 + _exit(1);
1402 pid = getpid();
1403 host[0] = 0;
1404 gethostname(host,sizeof(host));
1405 @@ -102,7 +109,10 @@
1406 s += fmt_str(s,"tmp/");
1407 s += fmt_ulong(s,time); *s++ = '.';
1408 s += fmt_ulong(s,pid); *s++ = '.';
1409 - s += fmt_strn(s,host,sizeof(host)); *s++ = 0;
1410 + s += fmt_strn(s,host,sizeof(host));
1411 + s += fmt_strn(s,",S=",sizeof(",S="));
1412 + if (fstat(0,&st) == -1) if (errno == error_noent) break;
1413 + s += fmt_ulong(s,st.st_size); *s++ = 0;
1414 if (stat(fntmptph,&st) == -1) if (errno == error_noent) break;
1415 /* really should never get to this point */
1416 if (loop == 2) _exit(1);
1417 @@ -172,6 +182,7 @@
1418 switch(wait_exitcode(wstat))
1420 case 0: break;
1421 + case 1: strerr_die1x(1, "User over quota. (#5.1.1)");
1422 case 2: strerr_die1x(111,"Unable to chdir to maildir. (#4.2.1)");
1423 case 3: strerr_die1x(111,"Timeout on maildir delivery. (#4.3.0)");
1424 case 4: strerr_die1x(111,"Unable to read message. (#4.3.0)");
1425 diff -u --new-file qmail-1.03.orig/qmail-pop3d.c qmail-1.03/qmail-pop3d.c
1426 --- qmail-1.03.orig/qmail-pop3d.c 2005-07-05 14:15:09.179579003 -0300
1427 +++ qmail-1.03/qmail-pop3d.c 2005-07-05 14:20:18.731333788 -0300
1428 @@ -16,6 +16,11 @@
1429 #include "readwrite.h"
1430 #include "timeoutread.h"
1431 #include "timeoutwrite.h"
1432 +#include <errno.h>
1433 +#include "maildirquota.h"
1434 +#include "maildirmisc.h"
1436 +#define QUOTABUFSIZE 256
1438 void die() { _exit(0); }
1440 @@ -45,19 +50,15 @@
1442 substdio_put(&ssout,buf,len);
1444 -void puts(s) char *s;
1446 - substdio_puts(&ssout,s);
1448 void flush()
1450 substdio_flush(&ssout);
1452 void err(s) char *s;
1454 - puts("-ERR ");
1455 - puts(s);
1456 - puts("\r\n");
1457 + substdio_puts(&ssout,"-ERR ");
1458 + substdio_puts(&ssout,s);
1459 + substdio_puts(&ssout,"\r\n");
1460 flush();
1463 @@ -73,7 +74,7 @@
1464 void err_nosuch() { err("unable to open that message"); }
1465 void err_nounlink() { err("unable to unlink all deleted messages"); }
1467 -void okay() { puts("+OK \r\n"); flush(); }
1468 +void okay() { substdio_puts(&ssout,"+OK \r\n"); flush(); }
1470 void printfn(fn) char *fn;
1472 @@ -153,11 +154,11 @@
1474 total = 0;
1475 for (i = 0;i < numm;++i) if (!m[i].flagdeleted) { total += m[i].size; j++; }
1476 - puts("+OK ");
1477 + substdio_puts(&ssout,"+OK ");
1478 put(strnum,fmt_uint(strnum,j));
1479 - puts(" ");
1480 + substdio_puts(&ssout," ");
1481 put(strnum,fmt_ulong(strnum,total));
1482 - puts("\r\n");
1483 + substdio_puts(&ssout,"\r\n");
1484 flush();
1487 @@ -171,18 +172,41 @@
1489 void pop3_last()
1491 - puts("+OK ");
1492 + substdio_puts(&ssout,"+OK ");
1493 put(strnum,fmt_uint(strnum,last));
1494 - puts("\r\n");
1495 + substdio_puts(&ssout,"\r\n");
1496 flush();
1499 void pop3_quit()
1501 int i;
1502 + char quotabuf[QUOTABUFSIZE];
1503 + int has_quota=maildir_getquota(".", quotabuf);
1505 + long deleted_bytes=0;
1506 + long deleted_messages=0;
1508 for (i = 0;i < numm;++i)
1509 if (m[i].flagdeleted) {
1510 - if (unlink(m[i].fn) == -1) err_nounlink();
1511 + unsigned long un=0;
1512 + const char *filename=m[i].fn;
1513 + if (has_quota == 0 && !MAILDIR_DELETED(filename)) {
1514 + if (maildir_parsequota(filename, &un)) {
1515 + struct stat stat_buf;
1517 + if (stat(filename, &stat_buf) == 0)
1518 + un=stat_buf.st_size;
1521 + if (unlink(m[i].fn) == -1) {
1522 + err_nounlink();
1523 + un=0;
1525 + if (un) {
1526 + deleted_bytes -= un;
1527 + deleted_messages -= 1;
1530 else
1531 if (str_start(m[i].fn,"new/")) {
1532 @@ -192,6 +216,21 @@
1533 if (!stralloc_0(&line)) die_nomem();
1534 rename(m[i].fn,line.s); /* if it fails, bummer */
1537 + if (deleted_messages < 0) {
1538 + int quotafd;
1540 + if (maildir_checkquota(".", &quotafd, quotabuf, deleted_bytes,
1541 + deleted_messages) && errno != EAGAIN &&
1542 + deleted_bytes >= 0)
1544 + if (quotafd >= 0) close (quotafd);
1545 + } else {
1546 + maildir_addquota(".", quotafd, quotabuf,
1547 + deleted_bytes, deleted_messages);
1548 + if (quotafd >= 0) close(quotafd);
1551 okay();
1552 die();
1554 @@ -222,10 +261,10 @@
1555 int flaguidl;
1557 put(strnum,fmt_uint(strnum,i + 1));
1558 - puts(" ");
1559 + substdio_puts(&ssout," ");
1560 if (flaguidl) printfn(m[i].fn);
1561 else put(strnum,fmt_ulong(strnum,m[i].size));
1562 - puts("\r\n");
1563 + substdio_puts(&ssout,"\r\n");
1566 void dolisting(arg,flaguidl) char *arg; int flaguidl;
1567 @@ -234,7 +273,7 @@
1568 if (*arg) {
1569 i = msgno(arg);
1570 if (i == -1) return;
1571 - puts("+OK ");
1572 + substdio_puts(&ssout,"+OK ");
1573 list(i,flaguidl);
1575 else {
1576 @@ -242,7 +281,7 @@
1577 for (i = 0;i < numm;++i)
1578 if (!m[i].flagdeleted)
1579 list(i,flaguidl);
1580 - puts(".\r\n");
1581 + substdio_puts(&ssout,".\r\n");
1583 flush();
1585 Common subdirectories: qmail-1.03.orig/qmail-rhinit and qmail-1.03/qmail-rhinit
1586 diff -u --new-file qmail-1.03.orig/strpidt.c qmail-1.03/strpidt.c
1587 --- qmail-1.03.orig/strpidt.c 1969-12-31 21:00:00.000000000 -0300
1588 +++ qmail-1.03/strpidt.c 2005-07-05 14:18:47.774737167 -0300
1589 @@ -0,0 +1,26 @@
1591 +** Copyright 1998 - 2000 Double Precision, Inc.
1592 +** See COPYING for distribution information.
1595 +#if HAVE_CONFIG_H
1596 +#include "config.h"
1597 +#endif
1598 +#include "numlib.h"
1599 +#include <string.h>
1601 +static const char rcsid[]="$Id: qmail-maildir++.patch,v 1.1.1.1.2.1 2005/01/19 23:35:23 tomcollins Exp $";
1603 +char *str_pid_t(pid_t t, char *arg)
1605 +char buf[NUMBUFSIZE];
1606 +char *p=buf+sizeof(buf)-1;
1608 + *p=0;
1609 + do
1611 + *--p= '0' + (t % 10);
1612 + t=t / 10;
1613 + } while(t);
1614 + return (strcpy(arg, p));
1616 diff -u --new-file qmail-1.03.orig/strtimet.c qmail-1.03/strtimet.c
1617 --- qmail-1.03.orig/strtimet.c 1969-12-31 21:00:00.000000000 -0300
1618 +++ qmail-1.03/strtimet.c 2005-07-05 14:18:47.776736675 -0300
1619 @@ -0,0 +1,26 @@
1621 +** Copyright 1998 - 2000 Double Precision, Inc.
1622 +** See COPYING for distribution information.
1625 +#if HAVE_CONFIG_H
1626 +#include "config.h"
1627 +#endif
1628 +#include "numlib.h"
1629 +#include <string.h>
1631 +static const char rcsid[]="$Id: qmail-maildir++.patch,v 1.1.1.1.2.1 2005/01/19 23:35:23 tomcollins Exp $";
1633 +char *str_time_t(time_t t, char *arg)
1635 +char buf[NUMBUFSIZE];
1636 +char *p=buf+sizeof(buf)-1;
1638 + *p=0;
1639 + do
1641 + *--p= '0' + (t % 10);
1642 + t=t / 10;
1643 + } while(t);
1644 + return (strcpy(arg, p));