Hi Sam,
Here's a patch I wrote to permit the control of inbound SMTP only for
under quota accounts.
In my mail system, when a maildrop throw an overquota status
(EXITCODE=77) I flag in a database that no more mail can be accepted
into the account until customer clean his mailbox. SMTP servers query
this flag on each RCPT and gracefully (deferral) deny if associated
account is overquota.
It drastically reduces the spools !
With this patch a mailbox can fill beyond 100%, but we need it else a
message in the spool can block an account.
What do you think about this solution ?
Regards,
Alain
diff -ruN courier-imap-4.0.6.20051004.orig/imap/configure.in
courier-imap-4.0.6.20051004/imap/configure.in
--- courier-imap-4.0.6.20051004.orig/imap/configure.in 2005-09-24
02:46:23.000000000 +0200
+++ courier-imap-4.0.6.20051004/imap/configure.in 2006-02-09
11:56:49.000000000 +0100
@@ -331,6 +331,15 @@
MAKECHECKBROKEN=Y
fi
+AC_ARG_WITH(trashquota, [ --with-quota-until-last-byte Accept messages
until the quota's last byte is reached],
+ quotalastbyte="$withval",
+ quotalastbyte="no")
+
+if test "$quotalastbyte" = "yes"
+then
+ MAKECHECKBROKEN=Y
+fi
+
AC_SUBST(MAKECHECKBROKEN)
AC_OUTPUT(Makefile imapd.dist imapd-ssl.dist pop3d.dist pop3d-ssl.dist
diff -ruN courier-imap-4.0.6.20051004.orig/maildir/configure.in
courier-imap-4.0.6.20051004/maildir/configure.in
--- courier-imap-4.0.6.20051004.orig/maildir/configure.in 2005-09-24
02:42:46.000000000 +0200
+++ courier-imap-4.0.6.20051004/maildir/configure.in 2006-02-09
11:46:41.000000000 +0100
@@ -133,6 +133,16 @@
[ Whether to count deleted messages towards the maildir quota ])
fi
+AC_ARG_WITH(quota-until-last-byte, [ --with-quota-until-last-byte
Accept messages until the quota's last byte is reached],
+ quotalastbyte="$withval",
+ quotalastbyte="no")
+
+if test "$quotalastbyte" = "yes"
+then
+ AC_DEFINE_UNQUOTED(QUOTA_UNTIL_LAST_BYTE,1,
+ [ Whether to accept messages until the quota's last byte is reached ])
+fi
+
test "x$prefix" = xNONE && prefix=$ac_default_prefix
test "x$exec_prefix" = xNONE && exec_prefix='${prefix}'
eval "prefix=$prefix"
diff -ruN courier-imap-4.0.6.20051004.orig/maildir/maildirquota.c
courier-imap-4.0.6.20051004/maildir/maildirquota.c
--- courier-imap-4.0.6.20051004.orig/maildir/maildirquota.c 2005-02-17
00:42:54.000000000 +0100
+++ courier-imap-4.0.6.20051004/maildir/maildirquota.c 2006-02-09
11:46:41.000000000 +0100
@@ -350,6 +350,7 @@
static int checkOneQuota(off_t size, off_t quota, int *percentage)
{
int x=1;
+ int ret=0;
if (quota == 0) /* No quota */
{
@@ -359,15 +360,14 @@
if (size > quota)
{
- *percentage=100;
- return (-1);
+ ret=-1;
}
if (quota > 20000000)
x=1024;
*percentage= quota > 0 ? (size/x) * 100 / (quota/x):0;
- return 0;
+ return ret;
}
static char *makenewmaildirsizename(const char *, int *);
@@ -415,20 +415,27 @@
DIR *dirp;
struct dirent *de;
+#ifndef QUOTA_UNTIL_LAST_BYTE
struct maildirquota new_quota;
-
+#endif
*percentage=0;
if (info->fd < 0) /* No quota */
return (0);
+#ifndef QUOTA_UNTIL_LAST_BYTE
new_quota=info->size;
new_quota.nbytes += xtra_size;
new_quota.nmessages += xtra_cnt;
+#endif
if (!info->recalculation_needed &&
+#ifdef QUOTA_UNTIL_LAST_BYTE
+ checkQuota(&info->size, &info->quota, percentage) == 0)
+#else
checkQuota(&new_quota, &info->quota, percentage) == 0)
+#endif
return (0); /* New size is under quota */
/*
@@ -551,12 +558,16 @@
*percentage=0;
+#ifndef QUOTA_UNTIL_LAST_BYTE
new_quota=info->size;
new_quota.nbytes += xtra_size;
new_quota.nmessages += xtra_cnt;
return checkQuota(&new_quota, &info->quota, percentage);
+#else
+ return checkQuota(&info->size, &info->quota, percentage);
+#endif
}
int maildir_addquota(struct maildirsize *info,