Commit fa5efdb3 fa5efdb30791b8a00904d9f379638aee211a5169 by Alain Magloire

First try at implementing seive with lex/yacc.

1 parent dfe52103
...@@ -533,8 +533,14 @@ imap_scan (mailbox_t mailbox, size_t msgno, size_t *pcount) ...@@ -533,8 +533,14 @@ imap_scan (mailbox_t mailbox, size_t msgno, size_t *pcount)
533 if (mailbox->observable == NULL) 533 if (mailbox->observable == NULL)
534 return 0; 534 return 0;
535 for (i = msgno; i <= *pcount; i++) 535 for (i = msgno; i <= *pcount; i++)
536 if (observable_notify (mailbox->observable, MU_EVT_MESSAGE_ADD) != 0) 536 {
537 break; 537 if (observable_notify (mailbox->observable, MU_EVT_MESSAGE_ADD) != 0)
538 break;
539 if (((i + 1) % 10) == 0)
540 {
541 observable_notify (mailbox->observable, MU_EVT_MAILBOX_PROGRESS);
542 }
543 }
538 return 0; 544 return 0;
539 } 545 }
540 546
......
1 %{
2 %}
3
4 %token SIEVE_ADDRESS SIEVE_ALL SIEVE_ALLOF SIEVE_ANYOF SIEVE_COMPARATOR
5 %token SIEVE_CONTAINS SIEVE_DISCARD SIEVE_DOMAIN SIEVE_ELSE SIEVE_ELSIF
6 %token SIEVE_ENVELOPE SIEVE_EXISTS SIEVE_FALSE SIEVE_FILEINTO SIEVE_HEADER
7 %token SIEVE_IF SIEVE_IS SIEVE_KEEP SIEVE_LOCALPART SIEVE_MATCHES
8 %token SIEVE_NOT SIEVE_NUMBER SIEVE_OVER SIEVE_STRING
9 %token SIEVE_REDIRECT SIEVE_REJECT SIEVE_REQUIRE SIEVE_SIZE SIEVE_STOP
10 %token SIEVE_TEST SIEVE_TRUE SIEVE_UNDER
11
12 %%
13
14 commands : command | command commands ;
15
16 command : action_command | control_command | test_command ;
17
18 block : '{' commands '}' | '{' /* Empty block. */ '}' ;
19
20 action_command : action ';' ;
21
22 action : discard | fileinto | keep | redirect | require | reject | stop ;
23
24 control_command : SIEVE_IF test_command block else_part
25 | SIEVE_IF test_command block
26 ;
27 else_part : SIEVE_ELSIF test_command block else_part
28 | SIEVE_ELSE block
29
30 test_command : test_address | test_allof | test_anyof | test_envelope
31 | test_exists | test_false | test_header | test_not
32 | test_size | test_true ;
33
34 fileinto : SIEVE_FILEINTO string_list ;
35
36 stop : SIEVE_STOP ;
37
38 discard : SIEVE_DISCARD ;
39
40 keep : SIEVE_KEEP ;
41
42 redirect : SIEVE_REDIRECT string_list ;
43
44 reject : SIEVE_REJECT SIEVE_STRING ;
45
46 require : SIEVE_REQUIRE string_list ;
47
48 test_list : '(' test ')' | '(' test ',' test ')' | test;
49
50 test : test_address | test_anyof | test_envelope | test_false | test_exists
51 | test_header | test_not | test_size | test_true ;
52
53 test_address : SIEVE_ADDRESS address_part match_type
54 | SIEVE_ADDRESS address_part string_list ;
55
56 test_allof : SIEVE_ALLOF test_list ;
57
58 test_anyof : SIEVE_ANYOF test_list ;
59
60 test_envelope : SIEVE_ENVELOPE ':' comparator | SIEVE_ENVELOPE ':' match_type ;
61
62 test_exists : SIEVE_EXISTS string_list ;
63
64 test_false : SIEVE_FALSE ;
65
66 test_header : SIEVE_HEADER comparator
67 | SIEVE_HEADER match_type
68 | SIEVE_HEADER string_list ;
69
70 test_not : SIEVE_NOT test | SIEVE_NOT '(' test ')' ;
71
72 test_size : SIEVE_SIZE ':' SIEVE_OVER SIEVE_NUMBER
73 | SIEVE_SIZE ':' SIEVE_UNDER SIEVE_NUMBER ;
74
75 test_true : SIEVE_TRUE ;
76
77 comparator : ':' SIEVE_COMPARATOR SIEVE_STRING SIEVE_STRING
78
79 match_type : ':' SIEVE_IS string_list string_list
80 | ':' SIEVE_CONTAINS string_list string_list
81 | ':' SIEVE_MATCHES string_list string_list ;
82
83 address_part : ':' SIEVE_DOMAIN ;
84 | ':' SIEVE_LOCALPART ;
85 | ':' SIEVE_ALL ;
86
87 strings : SIEVE_STRING | SIEVE_STRING ',' strings
88
89 string_list : '[' strings ']' | SIEVE_STRING ;
1 /* Scanner for Sieve
2 created : Alain Magloire
3 ref: RFC 3028 */
4
5 %{
6 #include <stdio.h>
7 #include "y.tab.h"
8
9 void count ();
10 %}
11
12 DIGIT [0-9]
13 WHITE_SPACE [ \r\t]
14 QUANTIFIER [KMG]
15 DELIM [ \t\v\f\n]
16 LETTER [A-Za-z_]
17 ID [A-Za-z_][A-Za-z0-9_]*
18 TAG {ID}:
19
20 %x COMMENT
21 %x MULTILINE
22 %%
23
24 "/*" { BEGIN COMMENT; count (); } /* Switch to comment state. */
25 <COMMENT>.|\n /* Throw away text. */;
26 <COMMENT>"*/" { BEGIN INITIAL; count (); }
27
28 "text:"\n { BEGIN MULTILINE; count (); }
29 <MULTILINE>.|\n { count (); }
30 <MULTILINE>^\.\n { BEGIN INITIAL; count (); return SIEVE_STRING; }
31
32 #.* /* Throw away. */;
33
34 {DIGIT}+[QUANTIFIER]? { count (); return SIEVE_NUMBER; }
35 \"[^\n"]+\" { /* " */ count (); return SIEVE_STRING; }
36
37 address { count (); return SIEVE_ADDRESS; }
38 all { count (); return SIEVE_ALL; }
39 allof { count (); return SIEVE_ALLOF; }
40 anyof { count (); return SIEVE_ANYOF; }
41 comparator { count (); return SIEVE_COMPARATOR; }
42 contains { count (); return SIEVE_CONTAINS; }
43 discard { count (); return SIEVE_DISCARD; }
44 domain { count (); return SIEVE_DOMAIN; }
45 else { count (); return SIEVE_ELSE; }
46 elsif { count (); return SIEVE_ELSIF; }
47 envelope { count (); return SIEVE_ENVELOPE; }
48 exists { count (); return SIEVE_EXISTS; }
49 false { count (); return SIEVE_FALSE; }
50 fileinto { count (); return SIEVE_FILEINTO; }
51 header { count (); return SIEVE_HEADER; }
52 if { count (); return SIEVE_IF; }
53 is { count (); return SIEVE_IS; }
54 keep { count (); return SIEVE_KEEP; }
55 localpart { count (); return SIEVE_LOCALPART; }
56 matches { count (); return SIEVE_MATCHES; }
57 not { count (); return SIEVE_NOT; }
58 over { count (); return SIEVE_OVER; }
59 redirect { count (); return SIEVE_REDIRECT; }
60 reject { count (); return SIEVE_REJECT; }
61 require { count (); return SIEVE_REQUIRE; }
62 size { count (); return SIEVE_SIZE; }
63 stop { count (); return SIEVE_STOP; }
64 true { count (); return SIEVE_TRUE; }
65 \: { count (); return ':'; }
66 \; { count (); return ';'; }
67 \, { count (); return ','; }
68 \( { count (); return '('; }
69 \) { count (); return ')'; }
70 \[ { count (); return '['; }
71 \] { count (); return ']'; }
72 \{ { count (); return '{'; }
73 \} { count (); return '}'; }
74
75 %%
76
77 int
78 yywrap ()
79 {
80 return (1);
81 }
82
83 void
84 count ()
85 {
86 ECHO;
87 }
88
89 int
90 yyerror (char *s)
91 {
92 fflush(stdout);
93 printf ("\n^ Syntax error.\n");
94 }