Sieve will now only process messages that are newer than its script.
authorDave West <davew@uncensored.citadel.org>
Fri, 16 May 2008 22:07:46 +0000 (22:07 +0000)
committerDave West <davew@uncensored.citadel.org>
Fri, 16 May 2008 22:07:46 +0000 (22:07 +0000)
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.

citadel/control.c
citadel/include/ctdl_module.h
citadel/modules/sieve/serv_sieve.c

index ea0865d49fd5db46243e0427d70ff76783a466b9..671a9cc741d84433d0ea011ee623f67e6ed78c34 100644 (file)
@@ -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.
  */
index e554783f58cad5d5e208babd2d244223f098c60e..d17a9861bcc91b5eb37b2034465adb14ec42131c 100644 (file)
@@ -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 */
index 46957b5971740a6f02ee7c06962eef7cc9b53841..0006604f32b040d017ccb8a68a07e5ded3aa8351 100644 (file)
@@ -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);
 }