1 %{
2 /*
3  * addr.y -- RFC 822 address parser
4  * Ken Murchison
5  *
6  * Copyright (c) 1994-2008 Carnegie Mellon University.  All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in
17  *    the documentation and/or other materials provided with the
18  *    distribution.
19  *
20  * 3. The name "Carnegie Mellon University" must not be used to
21  *    endorse or promote products derived from this software without
22  *    prior written permission. For permission or any legal
23  *    details, please contact
24  *      Carnegie Mellon University
25  *      Center for Technology Transfer and Enterprise Creation
26  *      4615 Forbes Avenue
27  *      Suite 302
28  *      Pittsburgh, PA  15213
29  *      (412) 268-7393, fax: (412) 268-7395
30  *      innovation@andrew.cmu.edu
31  *
32  * 4. Redistributions of any form whatsoever must retain the following
33  *    acknowledgment:
34  *    "This product includes software developed by Computing Services
35  *     at Carnegie Mellon University (http://www.cmu.edu/computing/)."
36  *
37  * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
38  * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
39  * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
40  * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
41  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
42  * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
43  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
44  */
45 
46 #ifdef HAVE_CONFIG_H
47 #include <config.h>
48 #endif
49 
50 #include <stdlib.h>
51 #include <string.h>
52 
53 #include "sieve/script.h"
54 #include "sieve/addr.h"
55 #include "xstrlcpy.h"
56 
57 #define ADDRERR_SIZE 500
58 
59 void yyerror(sieve_script_t*, const char *);
60 extern int addrlex(YYSTYPE*, sieve_script_t*);
61 
62 #define YYERROR_VERBOSE /* i want better error messages! */
63 
64 /* byacc default is 500, bison default is 10000 - go with the
65    larger to support big sieve scripts (see Bug #3461) */
66 #define YYSTACKSIZE 10000
67 %}
68 
69 %token ATOM QTEXT DTEXT
70 %name-prefix "addr"
71 %defines
72 %param {sieve_script_t *parse_script}
73 %pure-parser
74 %%
75 sieve_address: addrspec                 /* simple address */
76         | phrase '<' addrspec '>'       /* name & addr-spec */
77         ;
78 
79 addrspec: localpart '@' domain          /* global-address */
80         ;
81 
82 localpart: word                         /* uninterpreted, case-preserved */
83         | word '.' localpart
84         ;
85 
86 domain: subdomain
87         | subdomain '.' domain
88         ;
89 
90 subdomain: domainref
91         | domainlit
92         ;
93 
94 domainref: ATOM                         /* symbolic reference */
95         ;
96 
97 domainlit: '[' DTEXT ']'
98         ;
99 
100 phrase: word
101         | word phrase
102         ;
103 
104 word: ATOM
105         | qstring
106         ;
107 
108 qstring: '"' QTEXT '"'
109         ;
110 
111 %%
112 
113 /* copy address error message into buffer provided by sieve parser */
114 void yyerror(sieve_script_t *parse_script, const char *s)
115 {
116     strlcpy(parse_script->addrerr, s, ADDRERR_SIZE);
117 }
118