-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Aaron
this is a first attempt at updating notify syntax in libsieve to:
http://ietfreport.isoc.org/idref/draft-ietf-sieve-notify/
http://ietfreport.isoc.org/idref/draft-ietf-sieve-notify-mailto/
changes made are:
- - priority parameter becomes :importance keyword followed by string
parameter ("1" / "2" / "3") default "2",
- - removal of :id tag
- - addition of :from tag + address (currently validate email address, but
this needs to become method specific)
- - default message changed from "$from$: $subject$" to "${from}:
${subject}" This is only a temporary measure to remove old syntax,
let's leave the final solution on this for when variable extension is done
- - removal of :method keyword and substitution by method URI parameter.
Currently supported mailto: valid email address
I'm submitting this for a review, since I want to check I'm moving in
the right direction. I was unsure what I needed to do
about supported notify methods, beyond mailto: which is mandatory.
Should the parser know about all supported methods and
validate the method name and URI format, or leave this to the
application that uses the library?
Methods may be only locally supported, so I would guess it does not make
sense to put every possible method and URI type into the library.
here's a test script that I used to validate:
require
["fileinto","envelope","reject","vacation","relational","comparator-i;ascii-numeric","regex","notify"];
if
header :contains "Subject" "test notify"
{
keep;
notify :importance "1" :from "[EMAIL PROTECTED]" :message "test notify
script" "mailto:[EMAIL PROTECTED]" ;
}
John
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.4-svn0 (GNU/Linux)
Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org
iD8DBQFHwBlgd4I3jTtt9EIRAhwnAJ4jD4LyjAYTl5fYVUeUrVLJrCAkUwCgkhTS
6BN4hJScSWDGGT0qnV5uHVo=
=wkxt
-----END PGP SIGNATURE-----
diff -ur libsieve-2.2.6/src/sv_interface/callbacks2.c
libsieve-2.2.6-patch/src/sv_interface/callbacks2.c
--- libsieve-2.2.6/src/sv_interface/callbacks2.c 2007-10-10
10:04:28.000000000 +0200
+++ libsieve-2.2.6-patch/src/sv_interface/callbacks2.c 2008-02-23
12:02:36.000000000 +0100
@@ -188,9 +188,9 @@
/* Notify is incompatible with:
* nothing
*/
-int libsieve_do_notify(struct sieve2_context *c, char *id,
+int libsieve_do_notify(struct sieve2_context *c, char *from,
char *method, stringlist_t *options,
- char *priority, char *message)
+ char *importance, char *message)
{
char **optionstring;
@@ -200,9 +200,9 @@
optionstring = libsieve_stringlist_to_chararray(options);
libsieve_setvalue_stringlist(c, "options", optionstring);
- libsieve_setvalue_string(c, "id", id);
+ libsieve_setvalue_string(c, "from", from);
libsieve_setvalue_string(c, "method", method);
- libsieve_setvalue_string(c, "priority", priority);
+ libsieve_setvalue_string(c, "importance", importance);
libsieve_setvalue_string(c, "message", message);
libsieve_callback_do(c, SIEVE2_ACTION_NOTIFY);
diff -ur libsieve-2.2.6/src/sv_interface/callbacks2.h
libsieve-2.2.6-patch/src/sv_interface/callbacks2.h
--- libsieve-2.2.6/src/sv_interface/callbacks2.h 2007-10-10
10:04:28.000000000 +0200
+++ libsieve-2.2.6-patch/src/sv_interface/callbacks2.h 2008-02-23
12:01:44.000000000 +0100
@@ -44,9 +44,9 @@
int libsieve_do_vacation(struct sieve2_context *c, char *addr, char *fromaddr,
char *subj, char *msg, char *handle,
int days, int mime);
-int libsieve_do_notify(struct sieve2_context *c, char *id,
+int libsieve_do_notify(struct sieve2_context *c, char *from,
char *method, stringlist_t *options,
- char *priority, char *message);
+ char *importance, char *message);
/* Reporting parse and runtime errors. */
int libsieve_do_error_parse(struct sieve2_context *c, int lineno, char *msg);
diff -ur libsieve-2.2.6/src/sv_interface/script.c
libsieve-2.2.6-patch/src/sv_interface/script.c
--- libsieve-2.2.6/src/sv_interface/script.c 2007-10-10 09:58:51.000000000
+0200
+++ libsieve-2.2.6-patch/src/sv_interface/script.c 2008-02-23
12:01:29.000000000 +0100
@@ -561,8 +561,8 @@
}
break;
case NOTIFY:
- res = libsieve_do_notify(context, c->u.n.id, c->u.n.method,
- c->u.n.options, c->u.n.priority, c->u.n.message);
+ res = libsieve_do_notify(context, c->u.n.from, c->u.n.method,
+ c->u.n.options, c->u.n.importance, c->u.n.message);
TRACE_DEBUG("Doing a notify");
break;
}
diff -ur libsieve-2.2.6/src/sv_interface/tree.c
libsieve-2.2.6-patch/src/sv_interface/tree.c
--- libsieve-2.2.6/src/sv_interface/tree.c 2007-09-26 09:40:57.000000000
+0200
+++ libsieve-2.2.6-patch/src/sv_interface/tree.c 2008-02-23
12:38:07.000000000 +0100
@@ -248,7 +248,8 @@
case NOTIFY:
if (cl->u.n.method) libsieve_free(cl->u.n.method);
- if (cl->u.n.id) libsieve_free(cl->u.n.id);
+ if (cl->u.n.from) libsieve_free(cl->u.n.from);
+ if (cl->u.n.importance) libsieve_free(cl->u.n.importance);
if (cl->u.n.options) libsieve_free_sl(cl->u.n.options);
if (cl->u.n.message) libsieve_free(cl->u.n.message);
break;
diff -ur libsieve-2.2.6/src/sv_interface/tree.h
libsieve-2.2.6-patch/src/sv_interface/tree.h
--- libsieve-2.2.6/src/sv_interface/tree.h 2007-09-26 09:40:57.000000000
+0200
+++ libsieve-2.2.6-patch/src/sv_interface/tree.h 2008-02-23
12:00:41.000000000 +0100
@@ -124,16 +124,16 @@
} v;
struct { /* it's a notify action */
char *method;
- char *id;
+ char *from;
stringlist_t *options;
- char *priority;
+ char *importance;
char *message;
} n;
struct { /* it's a denotify action */
int comptag;
comparator_t *comp;
void *pattern;
- char *priority;
+ int importance;
} d;
} u;
struct Commandlist *next;
diff -ur libsieve-2.2.6/src/sv_parser/sieveinc.h
libsieve-2.2.6-patch/src/sv_parser/sieveinc.h
--- libsieve-2.2.6/src/sv_parser/sieveinc.h 2007-09-26 09:35:13.000000000
+0200
+++ libsieve-2.2.6-patch/src/sv_parser/sieveinc.h 2008-02-23
12:58:35.000000000 +0100
@@ -32,9 +32,9 @@
struct ntags {
char *method;
- char *id;
+ char *from;
stringlist_t *options;
- char *priority;
+ char * importance;
char *message;
};
@@ -45,7 +45,7 @@
static test_t *static_build_header(int t, struct htags *h,
stringlist_t *sl, patternlist_t *pl);
static commandlist_t *static_build_vacation(int t, struct vtags *h, char *s);
-static commandlist_t *static_build_notify(int t, struct ntags *n);
+static commandlist_t *static_build_notify(int t, struct ntags *n, char *
method);
static commandlist_t *static_build_validnotif(int t, stringlist_t *sl);
static struct aetags *static_new_aetags(void);
static struct aetags *static_canon_aetags(struct aetags *ae);
@@ -63,6 +63,8 @@
static int static_verify_stringlist(stringlist_t *sl, int (*verify)(const char
*));
static int static_verify_mailbox(const char *s);
+static int static_verify_importance(const char *s);
+static int static_verify_notify_method(const char *s);
static int static_verify_address(const char *s);
static int static_verify_header(const char *s);
static int static_verify_flag(const char *s);
diff -ur libsieve-2.2.6/src/sv_parser/sieve-lex.l
libsieve-2.2.6-patch/src/sv_parser/sieve-lex.l
--- libsieve-2.2.6/src/sv_parser/sieve-lex.l 2007-10-09 09:22:14.000000000
+0200
+++ libsieve-2.2.6-patch/src/sv_parser/sieve-lex.l 2008-02-23
11:43:23.000000000 +0100
@@ -130,13 +130,9 @@
<INITIAL>:flags return FLAGS;
<INITIAL>notify return NOTIFY;
<INITIAL>valid_notif_method return VALIDNOTIF;
-<INITIAL>:id return ID;
-<INITIAL>:method return METHOD;
<INITIAL>:options return OPTIONS;
-<INITIAL>:low return LOW;
-<INITIAL>:normal return NORMAL;
-<INITIAL>:high return HIGH;
<INITIAL>:message return MESSAGE;
+<INITIAL>:importance return IMPORTANCE;
<INITIAL>vacation return VACATION;
<INITIAL>:days return DAYS;
<INITIAL>:addresses return ADDRESSES;
diff -ur libsieve-2.2.6/src/sv_parser/sieve.y
libsieve-2.2.6-patch/src/sv_parser/sieve.y
--- libsieve-2.2.6/src/sv_parser/sieve.y 2007-10-10 10:04:28.000000000
+0200
+++ libsieve-2.2.6-patch/src/sv_parser/sieve.y 2008-02-23 13:02:09.000000000
+0100
@@ -86,7 +86,7 @@
%token COMPARATOR IS CONTAINS MATCHES REGEX OVER UNDER COUNT VALUE
%token ALL LOCALPART DOMAIN USER DETAIL
%token DAYS ADDRESSES SUBJECT MIME FROM HANDLE
-%token METHOD ID OPTIONS LOW NORMAL HIGH MESSAGE
+%token OPTIONS MESSAGE IMPORTANCE
%type <cl> commands command action elsif block
%type <sl> stringlist strings
@@ -98,7 +98,6 @@
%type <aetag> aetags
%type <vtag> vtags
%type <ntag> ntags
-%type <sval> priority
%%
@@ -246,14 +245,15 @@
}
$$ = libsieve_new_command(REMOVEFLAG);
$$->u.sl = $2; }
- | NOTIFY ntags { if
(!libsieve_parse_context->require.notify) {
+ | NOTIFY ntags STRING { if
(!libsieve_parse_context->require.notify) {
libsieve_sieveerror("notify not required");
$$ = libsieve_new_command(NOTIFY);
YYERROR;
- } else {
- $$ = static_build_notify(NOTIFY,
- static_canon_ntags($2));
- } }
+ } else { if (!static_verify_notify_method($3))
{
+ libsieve_sieveerror("invalid notify URI");
YYERROR;
+ } else { $$ = static_build_notify(NOTIFY,
+ static_canon_ntags($2),$3);
+ } } }
| VALIDNOTIF stringlist { if
(!libsieve_parse_context->require.notify) {
libsieve_sieveerror("notify not
required");
$$ = libsieve_new_command(VALIDNOTIF);
@@ -264,23 +264,23 @@
;
ntags: /* empty */ { $$ = static_new_ntags(); }
- | ntags ID STRING { if ($$->id != NULL) {
- libsieve_sieveerror("duplicate
:method"); YYERROR; }
- else { $$->id = $3; } }
- | ntags METHOD STRING { if ($$->method != NULL) {
+ | ntags FROM STRING { if ($$->from != NULL) {
libsieve_sieveerror("duplicate
:method"); YYERROR; }
- else { $$->method = $3; } }
+ else { if(!static_verify_address($3))
{libsieve_sieveerror("invalid :from address"); YYERROR;}
+ else {$$->from = $3; } } }
| ntags OPTIONS stringlist { if ($$->options != NULL) {
libsieve_sieveerror("duplicate
:options"); YYERROR; }
else { $$->options = $3; } }
- | ntags priority { if ($$->priority != NULL) {
- libsieve_sieveerror("duplicate
:priority"); YYERROR; }
- else { $$->priority = $2; } }
+ | ntags IMPORTANCE STRING { if ($$->importance != NULL) {
+ libsieve_sieveerror("duplicate
:importance"); YYERROR; }
+ else { if(!static_verify_importance($3))
{libsieve_sieveerror(":importance invalid range"); YYERROR;}
+ else {$$->importance = $3;} } }
| ntags MESSAGE STRING { if ($$->message != NULL) {
libsieve_sieveerror("duplicate
:message"); YYERROR; }
else { $$->message = $3; } }
;
+
hftags: /*empty */ { $$ = static_new_hftags(); }
| hftags comptag { $$->comptag = $2; }
| hftags COMPARATOR STRING { if ($$->comparator != NULL) {
@@ -288,11 +288,6 @@
else { $$->comparator = $3; } }
;
-priority: LOW { $$ = "low"; }
- | NORMAL { $$ = "normal"; }
- | HIGH { $$ = "high"; }
- ;
-
vtags: /* empty */ { $$ = static_new_vtags(); }
| vtags DAYS NUMBER { if ($$->days != -1) {
libsieve_sieveerror("duplicate :days");
@@ -583,17 +578,17 @@
return ret;
}
-static commandlist_t *static_build_notify(int t, struct ntags *n)
+static commandlist_t *static_build_notify(int t, struct ntags *n, char *
method)
{
commandlist_t *ret = libsieve_new_command(t);
libsieve_assert(t == NOTIFY);
if (ret) {
- ret->u.n.method = n->method; n->method = NULL;
- ret->u.n.id = n->id; n->id = NULL;
+ ret->u.n.method = method;
+ ret->u.n.from = n->from; n->from = NULL;
ret->u.n.options = n->options; n->options = NULL;
- ret->u.n.priority = n->priority;
+ ret->u.n.importance = n->importance; n->importance = NULL;
ret->u.n.message = n->message; n->message = NULL;
static_free_ntags(n);
}
@@ -612,7 +607,7 @@
ret->u.d.comptag = d->comptag;
ret->u.d.comp = libsieve_comparator_lookup("i;ascii-casemap",
d->comptag);
ret->u.d.pattern = d->pattern; d->pattern = NULL;
- ret->u.d.priority = d->priority;
+ ret->u.d.importance = d->importance; d->importance = NULL;
static_free_dtags(d);
}*/
return ret;
@@ -718,19 +713,19 @@
{
struct ntags *r = (struct ntags *) libsieve_malloc(sizeof(struct ntags));
- r->method = NULL;
- r->id = NULL;
+ r->from = NULL;
r->options = NULL;
- r->priority = NULL;
+ r->importance = NULL;
r->message = NULL;
+ r->method = NULL;
return r;
}
static struct ntags *static_canon_ntags(struct ntags *n)
{
- char *from = "$from$: $subject$";
- if (n->priority == NULL) { n->priority = "normal"; }
+ char *from = "${from}: ${subject}";
+ if (n->importance == NULL) { n->importance = libsieve_strdup("2"); }
if (n->message == NULL) { n->message = libsieve_strdup(from); }
return n;
@@ -739,9 +734,10 @@
static void static_free_ntags(struct ntags *n)
{
libsieve_free(n->method);
- libsieve_free(n->id);
+ libsieve_free(n->from);
if (n->options) libsieve_free_sl(n->options);
libsieve_free(n->message);
+ libsieve_free(n->importance);
libsieve_free(n);
}
@@ -777,6 +773,21 @@
return 1;
}
+static int static_verify_importance(const char *s )
+{
+ if (strcmp(s,"1")==0 || strcmp(s,"2")==0 || strcmp(s,"3")==0)
+ return 1;
+ return 0;
+}
+// mailto: is mandatory, other methods may be implementation specific
+static int static_verify_notify_method(const char *s )
+{
+#define MAILTO "mailto:"
+ if (strncmp(s,MAILTO,strlen(MAILTO))==0 &&
static_verify_address(s+strlen(MAILTO)))
+ return 1;
+ return 0;
+}
+
static int static_verify_header(const char *hdr)
{
const char *h = hdr;
diff -ur libsieve-2.2.6/src/sv_test/example.c
libsieve-2.2.6-patch/src/sv_test/example.c
--- libsieve-2.2.6/src/sv_test/example.c 2007-10-10 10:04:28.000000000
+0200
+++ libsieve-2.2.6-patch/src/sv_test/example.c 2008-02-23 12:07:29.000000000
+0100
@@ -92,13 +92,13 @@
int i;
printf( "Action is NOTIFY: \n" );
- printf( " ID \"%s\" is %s\n",
- sieve2_getvalue_string(s, "id"),
+ printf( " from is %s\n",
+ sieve2_getvalue_string(s, "from"),
sieve2_getvalue_string(s, "active"));
printf( " Method is %s\n",
sieve2_getvalue_string(s, "method"));
- printf( " Priority is %s\n",
- sieve2_getvalue_string(s, "priority"));
+ printf( " Importance is %s\n",
+ sieve2_getvalue_string(s, "importance"));
printf( " Message is %s\n",
sieve2_getvalue_string(s, "message"));
_______________________________________________
Dbmail-dev mailing list
[email protected]
http://twister.fastxs.net/mailman/listinfo/dbmail-dev