[prev in list] [next in list] [prev in thread] [next in thread]
List: cyrus-devel
Subject: patch for more fine grained date in cyr_expire
From: Kjetil Torgrim Homme <kjetilho () ifi ! uio ! no>
Date: 2005-12-01 11:53:49
Message-ID: 1133438029.31641.166.camel () mattugur ! ifi ! uio ! no
[Download RAW message or body]
we make a shadow delivery of all e-mail, so when users screw up and
delete all their e-mail, we can resend the messages and they're happy.
unfortunately, the duplicate suppression will often kick in, and so we
need to use cyr_expire to prune the database prior to reinjecting the
e-mail. the minimum ttl allowed by cyr_expire is 24 hours, and this is
a long wait for those users.
so, this simple patch makes it possible to specify a duration shorter
than that, e.g. cyr_expire -E 2h or cyr_expire -e 0.5d
the behaviour should be backwards compatible.
the patch is against 2.2.12, please consider it for inclusion. I
haven't checked CVS HEAD, if integration is problematic, please let me
know and I'll rework the patch.
--
thanks,
Kjetil T.
["patch.cyr_expire" (patch.cyr_expire)]
diff -ru cyrus-imapd-2.2.12.orig/imap/cyr_expire.c cyrus-imapd-2.2.12/imap/cyr_expire.c
--- cyrus-imapd-2.2.12.orig/imap/cyr_expire.c Sat May 22 05:45:48 2004
+++ cyrus-imapd-2.2.12/imap/cyr_expire.c Wed Nov 9 04:39:13 2005
@@ -193,10 +193,47 @@
mailbox_close(&mailbox);
}
+static double parse_duration(const char *str)
+{
+ /* Convert "23.5m" to fractional days. Accepts the suffixes "d"
+ (day), "h" (hour), "m" (minute) and "s" (second). If no
+ suffix, assume days.
+ If the suffix is unknown or the number can't be parsed, return 0.
+ */
+ int seconds = 1;
+ if (*str == '\0')
+ return 0.0;
+ switch (str[strlen(str)-1]) {
+ case '0':
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ case '8':
+ case '9':
+ case 'd':
+ seconds *= 24;
+ case 'h':
+ seconds *= 60;
+ case 'm':
+ seconds *= 60;
+ case 's':
+ break;
+ default:
+ /* unknown syntax */
+ return 0.0;
+ }
+ return (seconds * atof(str) / 86400.0);
+}
+
int main(int argc, char *argv[])
{
extern char *optarg;
- int opt, r = 0, days = 0;
+ int opt, r = 0;
+ double days = 0.0;
char *alt_config = NULL;
char buf[100];
struct hash_table expire_table;
@@ -215,7 +250,7 @@
case 'E':
if (days) usage();
- days = atoi(optarg);
+ days = parse_duration(optarg);
break;
case 'v':
diff -ru cyrus-imapd-2.2.12.orig/imap/duplicate.c cyrus-imapd-2.2.12/imap/duplicate.c
--- cyrus-imapd-2.2.12.orig/imap/duplicate.c Thu Mar 11 19:36:42 2004
+++ cyrus-imapd-2.2.12/imap/duplicate.c Wed Nov 9 04:18:01 2005
@@ -311,7 +311,7 @@
return 0;
}
-int duplicate_prune(int days, struct hash_table *expire_table)
+int duplicate_prune(double days, struct hash_table *expire_table)
{
struct prunerock prock;
@@ -320,7 +320,7 @@
prock.count = prock.deletions = 0;
prock.expmark = time(NULL) - (days * 60 * 60 * 24);
prock.expire_table = expire_table;
- syslog(LOG_NOTICE, "duplicate_prune: pruning back %d days", days);
+ syslog(LOG_NOTICE, "duplicate_prune: pruning back %.3f days", days);
/* check each entry in our database */
prock.db = dupdb;
diff -ru cyrus-imapd-2.2.12.orig/imap/duplicate.h cyrus-imapd-2.2.12/imap/duplicate.h
--- cyrus-imapd-2.2.12.orig/imap/duplicate.h Thu Feb 12 03:32:22 2004
+++ cyrus-imapd-2.2.12/imap/duplicate.h Wed Nov 9 04:18:17 2005
@@ -56,7 +56,7 @@
unsigned long uid);
int duplicate_find(char *msgid, int (*proc)(), void *rock);
-int duplicate_prune(int days, struct hash_table *expire_table);
+int duplicate_prune(double days, struct hash_table *expire_table);
int duplicate_dump(FILE *f);
int duplicate_done(void);
diff -ru cyrus-imapd-2.2.12.orig/man/cyr_expire.8 cyrus-imapd-2.2.12/man/cyr_expire.8
--- cyrus-imapd-2.2.12.orig/man/cyr_expire.8 2003-10-22 20:03:08.000000000 +0200
+++ cyrus-imapd-2.2.12/man/cyr_expire.8 2005-12-01 07:54:12.000000000 +0100
@@ -78,8 +78,11 @@
.BI \-C " config-file"
Read configuration options from \fIconfig-file\fR.
.TP
-\fB\-E \fIdays\fR
-Prune the duplicate database of entries older than \fIdays\fR. This
+\fB\-E \fIduration\fR
+Prune the duplicate database of entries older than \fIduration\fR
+days. The value can be a floating point number, and may have a suffix
+to use a unit other than days. Valid suffixes are \fBd\fR (days),
+\fBh\fR (hours), \fBm\fR (minutes) and \fBs\fR (seconds). This
value is only used for entries which do not have a corresponding
\fB/vendor/cmu/cyrus-imapd/expire\fR mailbox annotation.
.TP
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic