[PATCHv2 3/4] Add VACATION :seconds support

Philipp Hahn hahn at univention.de
Mon May 7 12:34:09 EDT 2012


Add support for specifying the vacation time in seconds in addition to
days.

Signed-off-by: Philipp Hahn <hahn at univention.de>
---
 lib/imapoptions                                    |    2 +-
 sieve/README                                       |    3 +++
 sieve/interp.c                                     |    3 +++
 sieve/script.c                                     |   12 ++++++++++++
 sieve/script.h                                     |    1 +
 sieve/sieve-lex.l                                  |    1 +
 sieve/sieve.y                                      |   11 +++++++++--
 sieve/test.c                                       |    5 ++++-
 .../actionExtensions/uberExtensionActionScript.key |   10 ++++++++++
 .../actionExtensions/uberExtensionActionScript.s   |   13 ++++++++++++-
 10 files changed, 56 insertions(+), 5 deletions(-)

diff --git a/lib/imapoptions b/lib/imapoptions
index 8c4f4ef..f97be2d 100644
--- a/lib/imapoptions
+++ b/lib/imapoptions
@@ -1213,7 +1213,7 @@ product version in the capabilities */
    user's scripts reside on a remote server (in a Murder).
    Otherwise, timsieved will proxy traffic to the remote server. */
 
-{ "sieve_extensions", "fileinto reject vacation imapflags notify envelope relational regex subaddress copy", BITFIELD("fileinto", "reject", "vacation", "imapflags", "notify", "include", "envelope", "body", "relational", "regex", "subaddress", "copy") }
+{ "sieve_extensions", "fileinto reject vacation vacation-seconds imapflags notify envelope relational regex subaddress copy", BITFIELD("fileinto", "reject", "vacation", "vacation-seconds", "imapflags", "notify", "include", "envelope", "body", "relational", "regex", "subaddress", "copy") }
 /* Space-separated list of Sieve extensions allowed to be used in
    sieve scripts, enforced at submission by timsieved(8).  Any
    previously installed script will be unaffected by this option and
diff --git a/sieve/README b/sieve/README
index 0d6e108..9eda8ac 100644
--- a/sieve/README
+++ b/sieve/README
@@ -41,6 +41,9 @@ RFC 3028, January, 2001.
 [VACATION] Showalter, T., "Sieve: Vacation Extension",
 draft-showalter-sieve-vacation-04.txt, August, 2000.
 
+[VACATION2] George, R., Leiba, B., "Sieve Vacation: Seconds parameter",
+RFC 6131, July 2011.
+
 [IMAPFLAGS] Melnikov, A., "Sieve -- IMAP flag extension",
 draft-melnikov-sieve-imapflags-03.txt, July, 2000.
 
diff --git a/sieve/interp.c b/sieve/interp.c
index 3c4b8bf..e36fe48 100644
--- a/sieve/interp.c
+++ b/sieve/interp.c
@@ -118,6 +118,9 @@ const char *sieve_listextensions(sieve_interp_t *i)
 	if (i->vacation &&
 	    (config_sieve_extensions & IMAP_ENUM_SIEVE_EXTENSIONS_VACATION))
 	    strlcat(extensions, " vacation", EXT_LEN);
+	if (i->vacation &&
+	    (config_sieve_extensions & IMAP_ENUM_SIEVE_EXTENSIONS_VACATION_SECONDS))
+	    strlcat(extensions, " vacation-seconds", EXT_LEN);
 	if (i->markflags &&
 	    (config_sieve_extensions & IMAP_ENUM_SIEVE_EXTENSIONS_IMAPFLAGS))
 	    strlcat(extensions, " imapflags", EXT_LEN);
diff --git a/sieve/script.c b/sieve/script.c
index 0b06c2f..2a8afac 100644
--- a/sieve/script.c
+++ b/sieve/script.c
@@ -119,6 +119,18 @@ int script_require(sieve_script_t *s, char *req)
 	} else {
 	    return 0;
 	}
+    } else if (!strcmp("vacation-seconds", req)) {
+	if (s->interp.vacation &&
+	    (config_sieve_extensions & IMAP_ENUM_SIEVE_EXTENSIONS_VACATION_SECONDS)) {
+	    /* Note that "vacation-seconds" implies "vacation", and a script
+	     * with "vacation-seconds" in a "require" list MAY omit "vacation"
+	     * from that list. */
+	    s->support.vacation = 1;
+	    s->support.vacation_seconds = 1;
+	    return 1;
+	} else {
+	    return 0;
+	}
     } else if (!strcmp("imapflags", req)) {
 	if (s->interp.markflags->count &&
 	    (config_sieve_extensions & IMAP_ENUM_SIEVE_EXTENSIONS_IMAPFLAGS)) {
diff --git a/sieve/script.h b/sieve/script.h
index 7fb49bf..d85793f 100644
--- a/sieve/script.h
+++ b/sieve/script.h
@@ -70,6 +70,7 @@ struct sieve_script {
 	int i_ascii_numeric: 1;
 	int include        : 1;
 	int copy           : 1;
+	int vacation_seconds: 1;
     } support;
 
     void *script_context;
diff --git a/sieve/sieve-lex.l b/sieve/sieve-lex.l
index 87145ac..c3baa57 100644
--- a/sieve/sieve-lex.l
+++ b/sieve/sieve-lex.l
@@ -136,6 +136,7 @@ CRLF		(\r\n|\r|\n)
 <INITIAL>:message	return MESSAGE;
 <INITIAL>vacation	return VACATION;
 <INITIAL>:days		return DAYS;
+<INITIAL>:seconds	return SECONDS;
 <INITIAL>:addresses	return ADDRESSES;
 <INITIAL>:subject	return SUBJECT;
 <INITIAL>:from		return FROM;
diff --git a/sieve/sieve.y b/sieve/sieve.y
index 84542d8..b7de609 100644
--- a/sieve/sieve.y
+++ b/sieve/sieve.y
@@ -200,7 +200,7 @@ extern void sieverestart(FILE *f);
 %token GT GE LT LE EQ NE
 %token ALL LOCALPART DOMAIN USER DETAIL
 %token RAW TEXT CONTENT
-%token DAYS ADDRESSES SUBJECT FROM HANDLE MIME
+%token DAYS ADDRESSES SUBJECT FROM HANDLE MIME SECONDS
 %token METHOD ID OPTIONS LOW NORMAL HIGH ANY MESSAGE
 %token INCLUDE PERSONAL GLOBAL RETURN
 %token COPY
@@ -414,8 +414,15 @@ priority: LOW                   { $$ = LOW; }
 
 vtags: /* empty */		 { $$ = new_vtags(); }
 	| vtags DAYS NUMBER	 { if ($$->seconds != -1) {
-					yyerror("duplicate :days"); YYERROR; }
+					yyerror("duplicate :days or :seconds"); YYERROR; }
 				   else { $$->seconds = $3 * DAY2SEC; } }
+	| vtags SECONDS NUMBER	 { if (!parse_script->support.vacation_seconds) {
+				     yyerror("vacation-seconds not required");
+				     YYERROR;
+				   }
+				   if ($$->seconds != -1) {
+					yyerror("duplicate :days or :seconds"); YYERROR; }
+				   else { $$->seconds = $3; } }
 	| vtags ADDRESSES stringlist { if ($$->addresses != NULL) { 
 					yyerror("duplicate :addresses"); 
 					YYERROR;
diff --git a/sieve/test.c b/sieve/test.c
index bdabc14..09ed80d 100644
--- a/sieve/test.c
+++ b/sieve/test.c
@@ -468,7 +468,10 @@ static int autorespond(void *ac, void *ic __attribute__((unused)),
     for (i = 0; i < SIEVE_HASHLEN; i++) {
 	printf("%x", arc->hash[i]);
     }
-    printf("' in %d days? ", arc->seconds / DAY2SEC);
+    if (arc->seconds % DAY2SEC)
+	printf("' in %d seconds? ", arc->seconds);
+    else
+	printf("' in %d days? ", arc->seconds / DAY2SEC);
     scanf(" %c", &yn);
     }
 
diff --git a/sieve/tests/actionExtensions/uberExtensionActionScript.key b/sieve/tests/actionExtensions/uberExtensionActionScript.key
index c39d35d..07d98d1 100644
--- a/sieve/tests/actionExtensions/uberExtensionActionScript.key
+++ b/sieve/tests/actionExtensions/uberExtensionActionScript.key
@@ -42,3 +42,13 @@ Have I already responded to '373d72afbd3cbfcb7a7922d70d5dd6e' in 5 days? no
 echo 'I'll respond in a week or two, when i get back' | mail -s 'i'm at the beach' 'me at unspecified-domain' for message '/afs/andrew/system/src/local/cyrus/046/sieve/tests/actionExtensions/testm/ueatest-vacation'
 
 keep message 
+
+'ueatest-vacation-seconds'
+
+Envelope body of 'to'? you
+Envelope body of 'from'? me
+Have I already responded to '373d72afbd3cbfcb7a7922d70d5dd6e' in 60 seconds? no
+
+echo 'I'll respond in a minute, when i get back' | mail -s 'i'm out of the room' 'me at unspecified-domain' for message '/afs/andrew/system/src/local/cyrus/046/sieve/tests/actionExtensions/testm/ueatest-vacation'
+
+keep message
diff --git a/sieve/tests/actionExtensions/uberExtensionActionScript.s b/sieve/tests/actionExtensions/uberExtensionActionScript.s
index f65c01d..9eb58f2 100644
--- a/sieve/tests/actionExtensions/uberExtensionActionScript.s
+++ b/sieve/tests/actionExtensions/uberExtensionActionScript.s
@@ -1,4 +1,4 @@
-require ["reject", "fileinto", "imapflags", "vacation", "notify"];
+require ["reject", "fileinto", "imapflags", "vacation", "notify", "vacation-seconds"];
 
 #this is for the extra thigns we have added to sieve
 
@@ -56,6 +56,17 @@ vacation :days 5
 	 "I'll respond in a week or two, when i get back";
 }
 
+#VACATION-SECONDS
+#############################################
+if header :contains "subject" "vacation-seconds"
+{
+
+vacation :seconds 60
+	 :addresses ["me at blah.com" , "me at somewhereelse.com"]
+         :subject "i'm out of the room"
+	 "I'll respond in a minute, when i get back";
+}
+
 #NOTIFY and DENOTIFY
 #############################################
 if header :contains "subject" "notify"
-- 
1.7.1



More information about the Cyrus-devel mailing list