/*
- * Return a pointer to the active Sieve script
+ * Return a pointer to the active Sieve script.
+ * (Caller does NOT own the memory and should not free the returned pointer.)
*/
-char *get_active_script(struct ctdl_sieve *cs) {
+char *get_active_script(struct sdm_userdata *u) {
struct sdm_script *sptr;
- for (sptr=cs->u->first_script; sptr!=NULL; sptr=sptr->next) {
+ for (sptr=u->first_script; sptr!=NULL; sptr=sptr->next) {
if (sptr->script_active > 0) {
syslog(LOG_DEBUG, "get_active_script() is using script '%s'", sptr->script_name);
return(sptr->script_content);
int ctdl_getscript(sieve2_context_t *s, void *my) {
struct ctdl_sieve *cs = (struct ctdl_sieve *)my;
- char *active_script = get_active_script(cs);
+ char *active_script = get_active_script(cs->u);
if (active_script != NULL) {
sieve2_setvalue_string(s, "script", active_script);
return SIEVE2_OK;
return;
}
- /* FIXME this is where we have to check for empty scripts */
+ /*
+ * Check to see whether the script is empty and should not be processed.
+ * A script is considered non-empty if it contains at least one semicolon.
+ */
+ if (
+ (get_active_script(&u) == NULL)
+ || (strchr(get_active_script(&u), ';') == NULL)
+ ) {
+ syslog(LOG_DEBUG, "Sieve script is empty. No processing is required.");
+ return;
+ }
syslog(LOG_DEBUG, "Rules found. Performing Sieve processing for <%s>", roomname);