From: Dave West Date: Fri, 16 May 2008 22:07:46 +0000 (+0000) Subject: Sieve will now only process messages that are newer than its script. X-Git-Tag: v7.86~2246 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=f89c5f3027859b19fc935ff76a958e1ec26c620a Sieve will now only process messages that are newer than its script. This fixes bug #297 To impliment this I created a new API call CtdlGetCurrentMessageNumber() this returns the message number currently in use IE the last one allocated. This is good enough for Sieve in this case and probably good enough for other things too. --- diff --git a/citadel/control.c b/citadel/control.c index ea0865d49..671a9cc74 100644 --- a/citadel/control.c +++ b/citadel/control.c @@ -213,6 +213,23 @@ long get_new_message_number(void) } +/* + * CtdlGetCurrentMessageNumber() - Obtain the current highest message number in the system + * This provides a quick way to initialise a variable that might be used to indicate + * messages that should not be processed. EG. a new Sieve script will use this + * to record determine that messages older than this should not be processed. + */ +long CtdlGetCurrentMessageNumber(void) +{ + long retval = 0L; + begin_critical_section(S_CONTROL); + get_control(); + retval = CitControl.MMhighest; + end_critical_section(S_CONTROL); + return(retval); +} + + /* * get_new_user_number() - Obtain a new, unique ID to be used for a user. */ diff --git a/citadel/include/ctdl_module.h b/citadel/include/ctdl_module.h index e554783f5..d17a9861b 100644 --- a/citadel/include/ctdl_module.h +++ b/citadel/include/ctdl_module.h @@ -150,4 +150,13 @@ struct CitContext *CtdlGetContextArray (int *count); +/* + * CtdlGetCurrentMessageNumber() - Obtain the current highest message number in the system + * This provides a quick way to initialise a variable that might be used to indicate + * messages that should not be processed. EG. a new Sieve script will use this + * to record determine that messages older than this should not be processed. + * This function is defined in control.c + */ +long CtdlGetCurrentMessageNumber(void); + #endif /* CTDL_MODULE_H */ diff --git a/citadel/modules/sieve/serv_sieve.c b/citadel/modules/sieve/serv_sieve.c index 46957b597..0006604f3 100644 --- a/citadel/modules/sieve/serv_sieve.c +++ b/citadel/modules/sieve/serv_sieve.c @@ -988,6 +988,15 @@ void msiv_load(struct sdm_userdata *u) { } void msiv_store(struct sdm_userdata *u, int yes_write_to_disk) { +/* + * Initialise the sieve configs last processed message number. + * We don't need to get the highest message number for the users inbox since the systems + * highest message number will be higher than that and loer than this scripts message number + * This prevents this new script from processing any old messages in the inbox. + * Most importantly it will prevent vacation messages being sent to lots of old messages + * in the inbox. + */ + u->lastproc = CtdlGetCurrentMessageNumber(); rewrite_ctdl_sieve_config(u, yes_write_to_disk); }