/* A Bison parser, made by GNU Bison 3.8.2.  */

/* Bison implementation for Yacc-like parsers in C

   Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2021 Free Software Foundation,
   Inc.

   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */

/* As a special exception, you may create a larger work that contains
   part or all of the Bison parser skeleton and distribute that work
   under terms of your choice, so long as that work isn't itself a
   parser generator using the skeleton or a modified version thereof
   as a parser skeleton.  Alternatively, if you modify or redistribute
   the parser skeleton itself, you may (at your option) remove this
   special exception, which will cause the skeleton and the resulting
   Bison output files to be licensed under the GNU General Public
   License without this special exception.

   This special exception was added by the Free Software Foundation in
   version 2.2 of Bison.  */

/* C LALR(1) parser skeleton written by Richard Stallman, by
   simplifying the original so-called "semantic" parser.  */

/* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual,
   especially those whose name start with YY_ or yy_.  They are
   private implementation details that can be changed or removed.  */

/* All symbols defined below should begin with yy or YY, to avoid
   infringing on user name space.  This should be done even for local
   variables, as they might otherwise be expanded by user macros.
   There are some unavoidable exceptions within include files to
   define necessary library symbols; they are noted "INFRINGES ON
   USER NAME SPACE" below.  */

/* Identify Bison output, and Bison version.  */
#define YYBISON 30802

/* Bison version string.  */
#define YYBISON_VERSION "3.8.2"

/* Skeleton name.  */
#define YYSKELETON_NAME "yacc.c"

/* Pure parsers.  */
#define YYPURE 1

/* Push parsers.  */
#define YYPUSH 0

/* Pull parsers.  */
#define YYPULL 1


/* Substitute the variable and function names.  */
#define yyparse         libsieve_sieveparse
#define yylex           libsieve_sievelex
#define yyerror         libsieve_sieveerror
#define yydebug         libsieve_sievedebug
#define yynerrs         libsieve_sievenerrs

/* First part of user prologue.  */
#line 1 "src/sv_parser/sieve.y"

/* sieve.y -- sieve parser
 * Larry Greenfield
 * $Id$
 */
/***********************************************************
        Copyright 1999 by Carnegie Mellon University

                      All Rights Reserved

Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the name of Carnegie Mellon
University not be used in advertising or publicity pertaining to
distribution of the software without specific, written prior
permission.

CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE FOR
ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
******************************************************************/

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <stdlib.h>
#include <string.h>
#include <ctype.h>

#include <regex.h>

/* sv_parser */
#include "comparator.h"
#include "addrinc.h"
#include "sieveinc.h"

/* sv_interface */
#include "src/sv_interface/callbacks2.h"

/* sv_util */
#include "src/sv_util/util.h"
#include "sieve.h"
#include "sieve-lex.h"
#define THIS_MODULE "sv_parser"

struct vtags {
    int days;
    stringlist_t *addresses;
    char *subject;
    int mime;
    char *from;
    char *handle;
};

struct hftags {
    char *comparator;
    int comptag;
};

struct htags {
    char *comparator;
    int comptag;
};

struct aetags {
    int addrtag;
    char *comparator;
    int comptag;
};

struct ntags {
    char *method;
    char *id;
    stringlist_t *options;
    char *priority;
    char *message;
};

static test_t *static_build_address(struct sieve2_context *context, int t,
                     struct aetags *ae, stringlist_t *sl, patternlist_t *pl);
static test_t *static_build_header(struct sieve2_context *context, int t,
                     struct htags *h, stringlist_t *sl, patternlist_t *pl);
static commandlist_t *static_build_vacation(struct sieve2_context *context, int t, struct vtags *h, char *s);
static commandlist_t *static_build_notify(struct sieve2_context *context,
					  int t, struct ntags *n);
static commandlist_t *static_build_validnotif(struct sieve2_context *context,
					      int t, stringlist_t *sl);
static struct aetags *static_new_aetags(void);
static struct aetags *static_canon_aetags(struct aetags *ae);
static void static_free_aetags(struct aetags *ae);
static struct hftags *static_new_hftags(void);
static struct htags *static_new_htags(void);
static struct htags *static_canon_htags(struct htags *h);
static void static_free_htags(struct htags *h);
static struct vtags *static_new_vtags(void);
static struct vtags *static_canon_vtags(struct vtags *v);
static void static_free_vtags(struct vtags *v);
static struct ntags *static_new_ntags(void);
static struct ntags *static_canon_ntags(struct ntags *n);
static void static_free_ntags(struct ntags *n);

static int static_verify_stringlist(struct sieve2_context *context, stringlist_t *sl, int (*verify)(struct sieve2_context *context, const char *));
static int static_verify_mailbox(const char *s);
static int static_verify_address(struct sieve2_context *context, const char *s);
static int static_verify_header(struct sieve2_context *context, const char *s);
static int static_verify_flag(struct sieve2_context *context, const char *s);
static regex_t *static_verify_regex(struct sieve2_context *context, const char *s, int cflags);
static patternlist_t *static_verify_regexs(struct sieve2_context *context, stringlist_t *sl, char *comp);
static int static_ok_header(char *s);

static int static_check_reqs(struct sieve2_context *context, char *req);

extern YY_DECL;

#define YYERROR_VERBOSE /* i want better error messages! */

#line 200 "src/sv_parser/sieve.c"

# ifndef YY_CAST
#  ifdef __cplusplus
#   define YY_CAST(Type, Val) static_cast<Type> (Val)
#   define YY_REINTERPRET_CAST(Type, Val) reinterpret_cast<Type> (Val)
#  else
#   define YY_CAST(Type, Val) ((Type) (Val))
#   define YY_REINTERPRET_CAST(Type, Val) ((Type) (Val))
#  endif
# endif
# ifndef YY_NULLPTR
#  if defined __cplusplus
#   if 201103L <= __cplusplus
#    define YY_NULLPTR nullptr
#   else
#    define YY_NULLPTR 0
#   endif
#  else
#   define YY_NULLPTR ((void*)0)
#  endif
# endif

/* Use api.header.include to #include this header
   instead of duplicating it here.  */
#ifndef YY_LIBSIEVE_SIEVE_SRC_SV_PARSER_SIEVE_H_INCLUDED
# define YY_LIBSIEVE_SIEVE_SRC_SV_PARSER_SIEVE_H_INCLUDED
/* Debug traces.  */
#ifndef YYDEBUG
# define YYDEBUG 0
#endif
#if YYDEBUG
extern int libsieve_sievedebug;
#endif

/* Token kinds.  */
#ifndef YYTOKENTYPE
# define YYTOKENTYPE
  enum yytokentype
  {
    YYEMPTY = -2,
    YYEOF = 0,                     /* "end of file"  */
    YYerror = 256,                 /* error  */
    YYUNDEF = 257,                 /* "invalid token"  */
    NUMBER = 258,                  /* NUMBER  */
    STRING = 259,                  /* STRING  */
    IF = 260,                      /* IF  */
    ELSIF = 261,                   /* ELSIF  */
    ELSE = 262,                    /* ELSE  */
    REJCT = 263,                   /* REJCT  */
    FILEINTO = 264,                /* FILEINTO  */
    REDIRECT = 265,                /* REDIRECT  */
    KEEP = 266,                    /* KEEP  */
    STOP = 267,                    /* STOP  */
    DISCARD = 268,                 /* DISCARD  */
    VACATION = 269,                /* VACATION  */
    REQUIRE = 270,                 /* REQUIRE  */
    SETFLAG = 271,                 /* SETFLAG  */
    ADDFLAG = 272,                 /* ADDFLAG  */
    REMOVEFLAG = 273,              /* REMOVEFLAG  */
    MARK = 274,                    /* MARK  */
    UNMARK = 275,                  /* UNMARK  */
    FLAGS = 276,                   /* FLAGS  */
    HASFLAG = 277,                 /* HASFLAG  */
    NOTIFY = 278,                  /* NOTIFY  */
    VALIDNOTIF = 279,              /* VALIDNOTIF  */
    ANYOF = 280,                   /* ANYOF  */
    ALLOF = 281,                   /* ALLOF  */
    EXISTS = 282,                  /* EXISTS  */
    SFALSE = 283,                  /* SFALSE  */
    STRUE = 284,                   /* STRUE  */
    HEADER = 285,                  /* HEADER  */
    NOT = 286,                     /* NOT  */
    SIZE = 287,                    /* SIZE  */
    ADDRESS = 288,                 /* ADDRESS  */
    ENVELOPE = 289,                /* ENVELOPE  */
    COMPARATOR = 290,              /* COMPARATOR  */
    IS = 291,                      /* IS  */
    CONTAINS = 292,                /* CONTAINS  */
    MATCHES = 293,                 /* MATCHES  */
    REGEX = 294,                   /* REGEX  */
    OVER = 295,                    /* OVER  */
    UNDER = 296,                   /* UNDER  */
    COUNT = 297,                   /* COUNT  */
    VALUE = 298,                   /* VALUE  */
    ALL = 299,                     /* ALL  */
    LOCALPART = 300,               /* LOCALPART  */
    DOMAIN = 301,                  /* DOMAIN  */
    USER = 302,                    /* USER  */
    DETAIL = 303,                  /* DETAIL  */
    DAYS = 304,                    /* DAYS  */
    ADDRESSES = 305,               /* ADDRESSES  */
    SUBJECT = 306,                 /* SUBJECT  */
    MIME = 307,                    /* MIME  */
    FROM = 308,                    /* FROM  */
    HANDLE = 309,                  /* HANDLE  */
    METHOD = 310,                  /* METHOD  */
    ID = 311,                      /* ID  */
    OPTIONS = 312,                 /* OPTIONS  */
    LOW = 313,                     /* LOW  */
    NORMAL = 314,                  /* NORMAL  */
    HIGH = 315,                    /* HIGH  */
    MESSAGE = 316                  /* MESSAGE  */
  };
  typedef enum yytokentype yytoken_kind_t;
#endif
/* Token kinds.  */
#define YYEMPTY -2
#define YYEOF 0
#define YYerror 256
#define YYUNDEF 257
#define NUMBER 258
#define STRING 259
#define IF 260
#define ELSIF 261
#define ELSE 262
#define REJCT 263
#define FILEINTO 264
#define REDIRECT 265
#define KEEP 266
#define STOP 267
#define DISCARD 268
#define VACATION 269
#define REQUIRE 270
#define SETFLAG 271
#define ADDFLAG 272
#define REMOVEFLAG 273
#define MARK 274
#define UNMARK 275
#define FLAGS 276
#define HASFLAG 277
#define NOTIFY 278
#define VALIDNOTIF 279
#define ANYOF 280
#define ALLOF 281
#define EXISTS 282
#define SFALSE 283
#define STRUE 284
#define HEADER 285
#define NOT 286
#define SIZE 287
#define ADDRESS 288
#define ENVELOPE 289
#define COMPARATOR 290
#define IS 291
#define CONTAINS 292
#define MATCHES 293
#define REGEX 294
#define OVER 295
#define UNDER 296
#define COUNT 297
#define VALUE 298
#define ALL 299
#define LOCALPART 300
#define DOMAIN 301
#define USER 302
#define DETAIL 303
#define DAYS 304
#define ADDRESSES 305
#define SUBJECT 306
#define MIME 307
#define FROM 308
#define HANDLE 309
#define METHOD 310
#define ID 311
#define OPTIONS 312
#define LOW 313
#define NORMAL 314
#define HIGH 315
#define MESSAGE 316

/* Value type.  */
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
union YYSTYPE
{
#line 133 "src/sv_parser/sieve.y"

    int nval;
    char *sval;
    stringlist_t *sl;
    test_t *test;
    testlist_t *testl;
    commandlist_t *cl;
    struct vtags *vtag;
    struct aetags *aetag;
    struct htags *htag;
    struct hftags *hftag;
    struct ntags *ntag;

#line 389 "src/sv_parser/sieve.c"

};
typedef union YYSTYPE YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1
# define YYSTYPE_IS_DECLARED 1
#endif




int libsieve_sieveparse (struct sieve2_context *context, void *yyscanner);


#endif /* !YY_LIBSIEVE_SIEVE_SRC_SV_PARSER_SIEVE_H_INCLUDED  */
/* Symbol kind.  */
enum yysymbol_kind_t
{
  YYSYMBOL_YYEMPTY = -2,
  YYSYMBOL_YYEOF = 0,                      /* "end of file"  */
  YYSYMBOL_YYerror = 1,                    /* error  */
  YYSYMBOL_YYUNDEF = 2,                    /* "invalid token"  */
  YYSYMBOL_NUMBER = 3,                     /* NUMBER  */
  YYSYMBOL_STRING = 4,                     /* STRING  */
  YYSYMBOL_IF = 5,                         /* IF  */
  YYSYMBOL_ELSIF = 6,                      /* ELSIF  */
  YYSYMBOL_ELSE = 7,                       /* ELSE  */
  YYSYMBOL_REJCT = 8,                      /* REJCT  */
  YYSYMBOL_FILEINTO = 9,                   /* FILEINTO  */
  YYSYMBOL_REDIRECT = 10,                  /* REDIRECT  */
  YYSYMBOL_KEEP = 11,                      /* KEEP  */
  YYSYMBOL_STOP = 12,                      /* STOP  */
  YYSYMBOL_DISCARD = 13,                   /* DISCARD  */
  YYSYMBOL_VACATION = 14,                  /* VACATION  */
  YYSYMBOL_REQUIRE = 15,                   /* REQUIRE  */
  YYSYMBOL_SETFLAG = 16,                   /* SETFLAG  */
  YYSYMBOL_ADDFLAG = 17,                   /* ADDFLAG  */
  YYSYMBOL_REMOVEFLAG = 18,                /* REMOVEFLAG  */
  YYSYMBOL_MARK = 19,                      /* MARK  */
  YYSYMBOL_UNMARK = 20,                    /* UNMARK  */
  YYSYMBOL_FLAGS = 21,                     /* FLAGS  */
  YYSYMBOL_HASFLAG = 22,                   /* HASFLAG  */
  YYSYMBOL_NOTIFY = 23,                    /* NOTIFY  */
  YYSYMBOL_VALIDNOTIF = 24,                /* VALIDNOTIF  */
  YYSYMBOL_ANYOF = 25,                     /* ANYOF  */
  YYSYMBOL_ALLOF = 26,                     /* ALLOF  */
  YYSYMBOL_EXISTS = 27,                    /* EXISTS  */
  YYSYMBOL_SFALSE = 28,                    /* SFALSE  */
  YYSYMBOL_STRUE = 29,                     /* STRUE  */
  YYSYMBOL_HEADER = 30,                    /* HEADER  */
  YYSYMBOL_NOT = 31,                       /* NOT  */
  YYSYMBOL_SIZE = 32,                      /* SIZE  */
  YYSYMBOL_ADDRESS = 33,                   /* ADDRESS  */
  YYSYMBOL_ENVELOPE = 34,                  /* ENVELOPE  */
  YYSYMBOL_COMPARATOR = 35,                /* COMPARATOR  */
  YYSYMBOL_IS = 36,                        /* IS  */
  YYSYMBOL_CONTAINS = 37,                  /* CONTAINS  */
  YYSYMBOL_MATCHES = 38,                   /* MATCHES  */
  YYSYMBOL_REGEX = 39,                     /* REGEX  */
  YYSYMBOL_OVER = 40,                      /* OVER  */
  YYSYMBOL_UNDER = 41,                     /* UNDER  */
  YYSYMBOL_COUNT = 42,                     /* COUNT  */
  YYSYMBOL_VALUE = 43,                     /* VALUE  */
  YYSYMBOL_ALL = 44,                       /* ALL  */
  YYSYMBOL_LOCALPART = 45,                 /* LOCALPART  */
  YYSYMBOL_DOMAIN = 46,                    /* DOMAIN  */
  YYSYMBOL_USER = 47,                      /* USER  */
  YYSYMBOL_DETAIL = 48,                    /* DETAIL  */
  YYSYMBOL_DAYS = 49,                      /* DAYS  */
  YYSYMBOL_ADDRESSES = 50,                 /* ADDRESSES  */
  YYSYMBOL_SUBJECT = 51,                   /* SUBJECT  */
  YYSYMBOL_MIME = 52,                      /* MIME  */
  YYSYMBOL_FROM = 53,                      /* FROM  */
  YYSYMBOL_HANDLE = 54,                    /* HANDLE  */
  YYSYMBOL_METHOD = 55,                    /* METHOD  */
  YYSYMBOL_ID = 56,                        /* ID  */
  YYSYMBOL_OPTIONS = 57,                   /* OPTIONS  */
  YYSYMBOL_LOW = 58,                       /* LOW  */
  YYSYMBOL_NORMAL = 59,                    /* NORMAL  */
  YYSYMBOL_HIGH = 60,                      /* HIGH  */
  YYSYMBOL_MESSAGE = 61,                   /* MESSAGE  */
  YYSYMBOL_62_ = 62,                       /* ';'  */
  YYSYMBOL_63_ = 63,                       /* '['  */
  YYSYMBOL_64_ = 64,                       /* ']'  */
  YYSYMBOL_65_ = 65,                       /* ','  */
  YYSYMBOL_66_ = 66,                       /* '{'  */
  YYSYMBOL_67_ = 67,                       /* '}'  */
  YYSYMBOL_68_ = 68,                       /* '('  */
  YYSYMBOL_69_ = 69,                       /* ')'  */
  YYSYMBOL_YYACCEPT = 70,                  /* $accept  */
  YYSYMBOL_start = 71,                     /* start  */
  YYSYMBOL_reqs = 72,                      /* reqs  */
  YYSYMBOL_require = 73,                   /* require  */
  YYSYMBOL_commands = 74,                  /* commands  */
  YYSYMBOL_command = 75,                   /* command  */
  YYSYMBOL_elsif = 76,                     /* elsif  */
  YYSYMBOL_action = 77,                    /* action  */
  YYSYMBOL_ntags = 78,                     /* ntags  */
  YYSYMBOL_hftags = 79,                    /* hftags  */
  YYSYMBOL_priority = 80,                  /* priority  */
  YYSYMBOL_vtags = 81,                     /* vtags  */
  YYSYMBOL_stringlist = 82,                /* stringlist  */
  YYSYMBOL_strings = 83,                   /* strings  */
  YYSYMBOL_block = 84,                     /* block  */
  YYSYMBOL_test = 85,                      /* test  */
  YYSYMBOL_addrorenv = 86,                 /* addrorenv  */
  YYSYMBOL_aetags = 87,                    /* aetags  */
  YYSYMBOL_htags = 88,                     /* htags  */
  YYSYMBOL_addrparttag = 89,               /* addrparttag  */
  YYSYMBOL_comptag = 90,                   /* comptag  */
  YYSYMBOL_sizetag = 91,                   /* sizetag  */
  YYSYMBOL_testlist = 92,                  /* testlist  */
  YYSYMBOL_tests = 93                      /* tests  */
};
typedef enum yysymbol_kind_t yysymbol_kind_t;




#ifdef short
# undef short
#endif

/* On compilers that do not define __PTRDIFF_MAX__ etc., make sure
   <limits.h> and (if available) <stdint.h> are included
   so that the code can choose integer types of a good width.  */

#ifndef __PTRDIFF_MAX__
# include <limits.h> /* INFRINGES ON USER NAME SPACE */
# if defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__
#  include <stdint.h> /* INFRINGES ON USER NAME SPACE */
#  define YY_STDINT_H
# endif
#endif

/* Narrow types that promote to a signed type and that can represent a
   signed or unsigned integer of at least N bits.  In tables they can
   save space and decrease cache pressure.  Promoting to a signed type
   helps avoid bugs in integer arithmetic.  */

#ifdef __INT_LEAST8_MAX__
typedef __INT_LEAST8_TYPE__ yytype_int8;
#elif defined YY_STDINT_H
typedef int_least8_t yytype_int8;
#else
typedef signed char yytype_int8;
#endif

#ifdef __INT_LEAST16_MAX__
typedef __INT_LEAST16_TYPE__ yytype_int16;
#elif defined YY_STDINT_H
typedef int_least16_t yytype_int16;
#else
typedef short yytype_int16;
#endif

/* Work around bug in HP-UX 11.23, which defines these macros
   incorrectly for preprocessor constants.  This workaround can likely
   be removed in 2023, as HPE has promised support for HP-UX 11.23
   (aka HP-UX 11i v2) only through the end of 2022; see Table 2 of
   <https://h20195.www2.hpe.com/V2/getpdf.aspx/4AA4-7673ENW.pdf>.  */
#ifdef __hpux
# undef UINT_LEAST8_MAX
# undef UINT_LEAST16_MAX
# define UINT_LEAST8_MAX 255
# define UINT_LEAST16_MAX 65535
#endif

#if defined __UINT_LEAST8_MAX__ && __UINT_LEAST8_MAX__ <= __INT_MAX__
typedef __UINT_LEAST8_TYPE__ yytype_uint8;
#elif (!defined __UINT_LEAST8_MAX__ && defined YY_STDINT_H \
       && UINT_LEAST8_MAX <= INT_MAX)
typedef uint_least8_t yytype_uint8;
#elif !defined __UINT_LEAST8_MAX__ && UCHAR_MAX <= INT_MAX
typedef unsigned char yytype_uint8;
#else
typedef short yytype_uint8;
#endif

#if defined __UINT_LEAST16_MAX__ && __UINT_LEAST16_MAX__ <= __INT_MAX__
typedef __UINT_LEAST16_TYPE__ yytype_uint16;
#elif (!defined __UINT_LEAST16_MAX__ && defined YY_STDINT_H \
       && UINT_LEAST16_MAX <= INT_MAX)
typedef uint_least16_t yytype_uint16;
#elif !defined __UINT_LEAST16_MAX__ && USHRT_MAX <= INT_MAX
typedef unsigned short yytype_uint16;
#else
typedef int yytype_uint16;
#endif

#ifndef YYPTRDIFF_T
# if defined __PTRDIFF_TYPE__ && defined __PTRDIFF_MAX__
#  define YYPTRDIFF_T __PTRDIFF_TYPE__
#  define YYPTRDIFF_MAXIMUM __PTRDIFF_MAX__
# elif defined PTRDIFF_MAX
#  ifndef ptrdiff_t
#   include <stddef.h> /* INFRINGES ON USER NAME SPACE */
#  endif
#  define YYPTRDIFF_T ptrdiff_t
#  define YYPTRDIFF_MAXIMUM PTRDIFF_MAX
# else
#  define YYPTRDIFF_T long
#  define YYPTRDIFF_MAXIMUM LONG_MAX
# endif
#endif

#ifndef YYSIZE_T
# ifdef __SIZE_TYPE__
#  define YYSIZE_T __SIZE_TYPE__
# elif defined size_t
#  define YYSIZE_T size_t
# elif defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__
#  include <stddef.h> /* INFRINGES ON USER NAME SPACE */
#  define YYSIZE_T size_t
# else
#  define YYSIZE_T unsigned
# endif
#endif

#define YYSIZE_MAXIMUM                                  \
  YY_CAST (YYPTRDIFF_T,                                 \
           (YYPTRDIFF_MAXIMUM < YY_CAST (YYSIZE_T, -1)  \
            ? YYPTRDIFF_MAXIMUM                         \
            : YY_CAST (YYSIZE_T, -1)))

#define YYSIZEOF(X) YY_CAST (YYPTRDIFF_T, sizeof (X))


/* Stored state numbers (used for stacks). */
typedef yytype_uint8 yy_state_t;

/* State numbers in computations.  */
typedef int yy_state_fast_t;

#ifndef YY_
# if defined YYENABLE_NLS && YYENABLE_NLS
#  if ENABLE_NLS
#   include <libintl.h> /* INFRINGES ON USER NAME SPACE */
#   define YY_(Msgid) dgettext ("bison-runtime", Msgid)
#  endif
# endif
# ifndef YY_
#  define YY_(Msgid) Msgid
# endif
#endif


#ifndef YY_ATTRIBUTE_PURE
# if defined __GNUC__ && 2 < __GNUC__ + (96 <= __GNUC_MINOR__)
#  define YY_ATTRIBUTE_PURE __attribute__ ((__pure__))
# else
#  define YY_ATTRIBUTE_PURE
# endif
#endif

#ifndef YY_ATTRIBUTE_UNUSED
# if defined __GNUC__ && 2 < __GNUC__ + (7 <= __GNUC_MINOR__)
#  define YY_ATTRIBUTE_UNUSED __attribute__ ((__unused__))
# else
#  define YY_ATTRIBUTE_UNUSED
# endif
#endif

/* Suppress unused-variable warnings by "using" E.  */
#if ! defined lint || defined __GNUC__
# define YY_USE(E) ((void) (E))
#else
# define YY_USE(E) /* empty */
#endif

/* Suppress an incorrect diagnostic about yylval being uninitialized.  */
#if defined __GNUC__ && ! defined __ICC && 406 <= __GNUC__ * 100 + __GNUC_MINOR__
# if __GNUC__ * 100 + __GNUC_MINOR__ < 407
#  define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN                           \
    _Pragma ("GCC diagnostic push")                                     \
    _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")
# else
#  define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN                           \
    _Pragma ("GCC diagnostic push")                                     \
    _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")              \
    _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
# endif
# define YY_IGNORE_MAYBE_UNINITIALIZED_END      \
    _Pragma ("GCC diagnostic pop")
#else
# define YY_INITIAL_VALUE(Value) Value
#endif
#ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
# define YY_IGNORE_MAYBE_UNINITIALIZED_END
#endif
#ifndef YY_INITIAL_VALUE
# define YY_INITIAL_VALUE(Value) /* Nothing. */
#endif

#if defined __cplusplus && defined __GNUC__ && ! defined __ICC && 6 <= __GNUC__
# define YY_IGNORE_USELESS_CAST_BEGIN                          \
    _Pragma ("GCC diagnostic push")                            \
    _Pragma ("GCC diagnostic ignored \"-Wuseless-cast\"")
# define YY_IGNORE_USELESS_CAST_END            \
    _Pragma ("GCC diagnostic pop")
#endif
#ifndef YY_IGNORE_USELESS_CAST_BEGIN
# define YY_IGNORE_USELESS_CAST_BEGIN
# define YY_IGNORE_USELESS_CAST_END
#endif


#define YY_ASSERT(E) ((void) (0 && (E)))

#if !defined yyoverflow

/* The parser invokes alloca or malloc; define the necessary symbols.  */

# ifdef YYSTACK_USE_ALLOCA
#  if YYSTACK_USE_ALLOCA
#   ifdef __GNUC__
#    define YYSTACK_ALLOC __builtin_alloca
#   elif defined __BUILTIN_VA_ARG_INCR
#    include <alloca.h> /* INFRINGES ON USER NAME SPACE */
#   elif defined _AIX
#    define YYSTACK_ALLOC __alloca
#   elif defined _MSC_VER
#    include <malloc.h> /* INFRINGES ON USER NAME SPACE */
#    define alloca _alloca
#   else
#    define YYSTACK_ALLOC alloca
#    if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS
#     include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
      /* Use EXIT_SUCCESS as a witness for stdlib.h.  */
#     ifndef EXIT_SUCCESS
#      define EXIT_SUCCESS 0
#     endif
#    endif
#   endif
#  endif
# endif

# ifdef YYSTACK_ALLOC
   /* Pacify GCC's 'empty if-body' warning.  */
#  define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
#  ifndef YYSTACK_ALLOC_MAXIMUM
    /* The OS might guarantee only one guard page at the bottom of the stack,
       and a page size can be as small as 4096 bytes.  So we cannot safely
       invoke alloca (N) if N exceeds 4096.  Use a slightly smaller number
       to allow for a few compiler-allocated temporary stack slots.  */
#   define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
#  endif
# else
#  define YYSTACK_ALLOC YYMALLOC
#  define YYSTACK_FREE YYFREE
#  ifndef YYSTACK_ALLOC_MAXIMUM
#   define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
#  endif
#  if (defined __cplusplus && ! defined EXIT_SUCCESS \
       && ! ((defined YYMALLOC || defined malloc) \
             && (defined YYFREE || defined free)))
#   include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
#   ifndef EXIT_SUCCESS
#    define EXIT_SUCCESS 0
#   endif
#  endif
#  ifndef YYMALLOC
#   define YYMALLOC malloc
#   if ! defined malloc && ! defined EXIT_SUCCESS
void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
#   endif
#  endif
#  ifndef YYFREE
#   define YYFREE free
#   if ! defined free && ! defined EXIT_SUCCESS
void free (void *); /* INFRINGES ON USER NAME SPACE */
#   endif
#  endif
# endif
#endif /* !defined yyoverflow */

#if (! defined yyoverflow \
     && (! defined __cplusplus \
         || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))

/* A type that is properly aligned for any stack member.  */
union yyalloc
{
  yy_state_t yyss_alloc;
  YYSTYPE yyvs_alloc;
};

/* The size of the maximum gap between one aligned stack and the next.  */
# define YYSTACK_GAP_MAXIMUM (YYSIZEOF (union yyalloc) - 1)

/* The size of an array large to enough to hold all stacks, each with
   N elements.  */
# define YYSTACK_BYTES(N) \
     ((N) * (YYSIZEOF (yy_state_t) + YYSIZEOF (YYSTYPE)) \
      + YYSTACK_GAP_MAXIMUM)

# define YYCOPY_NEEDED 1

/* Relocate STACK from its old location to the new one.  The
   local variables YYSIZE and YYSTACKSIZE give the old and new number of
   elements in the stack, and YYPTR gives the new location of the
   stack.  Advance YYPTR to a properly aligned location for the next
   stack.  */
# define YYSTACK_RELOCATE(Stack_alloc, Stack)                           \
    do                                                                  \
      {                                                                 \
        YYPTRDIFF_T yynewbytes;                                         \
        YYCOPY (&yyptr->Stack_alloc, Stack, yysize);                    \
        Stack = &yyptr->Stack_alloc;                                    \
        yynewbytes = yystacksize * YYSIZEOF (*Stack) + YYSTACK_GAP_MAXIMUM; \
        yyptr += yynewbytes / YYSIZEOF (*yyptr);                        \
      }                                                                 \
    while (0)

#endif

#if defined YYCOPY_NEEDED && YYCOPY_NEEDED
/* Copy COUNT objects from SRC to DST.  The source and destination do
   not overlap.  */
# ifndef YYCOPY
#  if defined __GNUC__ && 1 < __GNUC__
#   define YYCOPY(Dst, Src, Count) \
      __builtin_memcpy (Dst, Src, YY_CAST (YYSIZE_T, (Count)) * sizeof (*(Src)))
#  else
#   define YYCOPY(Dst, Src, Count)              \
      do                                        \
        {                                       \
          YYPTRDIFF_T yyi;                      \
          for (yyi = 0; yyi < (Count); yyi++)   \
            (Dst)[yyi] = (Src)[yyi];            \
        }                                       \
      while (0)
#  endif
# endif
#endif /* !YYCOPY_NEEDED */

/* YYFINAL -- State number of the termination state.  */
#define YYFINAL  8
/* YYLAST -- Last index in YYTABLE.  */
#define YYLAST   189

/* YYNTOKENS -- Number of terminals.  */
#define YYNTOKENS  70
/* YYNNTS -- Number of nonterminals.  */
#define YYNNTS  24
/* YYNRULES -- Number of rules.  */
#define YYNRULES  89
/* YYNSTATES -- Number of states.  */
#define YYNSTATES  145

/* YYMAXUTOK -- Last valid token kind.  */
#define YYMAXUTOK   316


/* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM
   as returned by yylex, with out-of-bounds checking.  */
#define YYTRANSLATE(YYX)                                \
  (0 <= (YYX) && (YYX) <= YYMAXUTOK                     \
   ? YY_CAST (yysymbol_kind_t, yytranslate[YYX])        \
   : YYSYMBOL_YYUNDEF)

/* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM
   as returned by yylex.  */
static const yytype_int8 yytranslate[] =
{
       0,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
      68,    69,     2,     2,    65,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,    62,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,    63,     2,    64,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,    66,     2,    67,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     1,     2,     3,     4,
       5,     6,     7,     8,     9,    10,    11,    12,    13,    14,
      15,    16,    17,    18,    19,    20,    21,    22,    23,    24,
      25,    26,    27,    28,    29,    30,    31,    32,    33,    34,
      35,    36,    37,    38,    39,    40,    41,    42,    43,    44,
      45,    46,    47,    48,    49,    50,    51,    52,    53,    54,
      55,    56,    57,    58,    59,    60,    61
};

#if YYDEBUG
/* YYRLINE[YYN] -- Source line where rule number YYN was defined.  */
static const yytype_int16 yyrline[] =
{
       0,   173,   173,   174,   177,   178,   181,   218,   219,   222,
     223,   224,   227,   228,   229,   232,   237,   244,   247,   265,
     275,   280,   281,   282,   290,   299,   308,   317,   325,   334,
     335,   338,   341,   344,   347,   352,   353,   354,   359,   360,
     361,   364,   365,   369,   377,   383,   389,   395,   401,   402,
     405,   406,   409,   410,   413,   414,   415,   416,   417,   418,
     434,   450,   466,   467,   469,   472,   473,   476,   477,   482,
     486,   492,   493,   497,   504,   505,   506,   507,   512,   519,
     520,   521,   522,   523,   524,   531,   532,   535,   538,   539
};
#endif

/** Accessing symbol of state STATE.  */
#define YY_ACCESSING_SYMBOL(State) YY_CAST (yysymbol_kind_t, yystos[State])

#if YYDEBUG || 0
/* The user-facing name of the symbol whose (internal) number is
   YYSYMBOL.  No bounds checking.  */
static const char *yysymbol_name (yysymbol_kind_t yysymbol) YY_ATTRIBUTE_UNUSED;

/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
   First, the terminals, then, starting at YYNTOKENS, nonterminals.  */
static const char *const yytname[] =
{
  "\"end of file\"", "error", "\"invalid token\"", "NUMBER", "STRING",
  "IF", "ELSIF", "ELSE", "REJCT", "FILEINTO", "REDIRECT", "KEEP", "STOP",
  "DISCARD", "VACATION", "REQUIRE", "SETFLAG", "ADDFLAG", "REMOVEFLAG",
  "MARK", "UNMARK", "FLAGS", "HASFLAG", "NOTIFY", "VALIDNOTIF", "ANYOF",
  "ALLOF", "EXISTS", "SFALSE", "STRUE", "HEADER", "NOT", "SIZE", "ADDRESS",
  "ENVELOPE", "COMPARATOR", "IS", "CONTAINS", "MATCHES", "REGEX", "OVER",
  "UNDER", "COUNT", "VALUE", "ALL", "LOCALPART", "DOMAIN", "USER",
  "DETAIL", "DAYS", "ADDRESSES", "SUBJECT", "MIME", "FROM", "HANDLE",
  "METHOD", "ID", "OPTIONS", "LOW", "NORMAL", "HIGH", "MESSAGE", "';'",
  "'['", "']'", "','", "'{'", "'}'", "'('", "')'", "$accept", "start",
  "reqs", "require", "commands", "command", "elsif", "action", "ntags",
  "hftags", "priority", "vtags", "stringlist", "strings", "block", "test",
  "addrorenv", "aetags", "htags", "addrparttag", "comptag", "sizetag",
  "testlist", "tests", YY_NULLPTR
};

static const char *
yysymbol_name (yysymbol_kind_t yysymbol)
{
  return yytname[yysymbol];
}
#endif

#define YYPACT_NINF (-98)

#define yypact_value_is_default(Yyn) \
  ((Yyn) == YYPACT_NINF)

#define YYTABLE_NINF (-8)

#define yytable_value_is_error(Yyn) \
  0

/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
   STATE-NUM.  */
static const yytype_int16 yypact[] =
{
      30,     2,    35,   158,    31,   -98,    46,   -11,   -98,   -10,
     124,    51,     4,    52,    36,   -98,   -98,   -98,     2,     2,
       2,   -98,     2,   -98,    10,    -4,   -98,    -5,    -3,   -98,
     -98,   -98,   -98,    -6,    -6,     2,   -98,   -98,   -98,   124,
     -27,   -98,   -98,     3,   -98,   -98,   -98,     2,   -98,     2,
      91,   -98,   -98,   -98,   128,   -98,   -98,   -98,    46,   -98,
       1,   124,   -98,   -98,   -98,    85,   -98,   -98,   -98,    60,
      70,    42,    68,    63,   -98,   -98,    65,     2,    66,   -98,
      69,    72,    86,    87,     2,   -98,   -98,   -98,    88,   -98,
     -98,    92,   -98,   -98,   -98,   -98,    93,    94,   -98,   -98,
       9,    33,    96,     2,   -98,   -98,   -98,    41,   124,     3,
     -98,   105,   -98,   -98,   -98,   -98,   -98,     2,   -98,   -98,
     -98,   -98,   -98,   -98,   -98,   -98,   -98,   -98,   -98,   -98,
     -98,   -98,   -98,   124,   -98,   -98,   -98,   -98,     3,   -98,
     -98,   -98,   -98,    42,   -98
};

/* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
   Performed when YYTABLE does not specify something else to do.  Zero
   means the default is an error.  */
static const yytype_int8 yydefact[] =
{
       4,     0,     0,     0,     4,    49,     0,     0,     1,     0,
       0,     0,     0,     0,    17,    21,    22,    41,     0,     0,
       0,    29,     0,     3,     0,     0,     5,    50,     0,     6,
      11,    64,    35,     0,     0,     0,    57,    58,    71,     0,
       0,    65,    66,     0,    67,    15,    19,     0,    20,     0,
       0,    24,    25,    26,    27,    28,     8,     9,     0,    48,
       0,     0,    54,    55,    56,     0,    62,    85,    86,     0,
       0,    12,     0,     0,    16,    23,     0,     0,     0,    47,
       0,     0,     0,     0,     0,    38,    39,    40,     0,    33,
      51,     0,    79,    82,    83,    84,     0,     0,    59,    36,
      88,     0,     0,     0,    72,    63,    53,     0,     0,     0,
      10,     0,    74,    75,    76,    77,    78,     0,    68,    69,
      18,    42,    43,    44,    46,    45,    31,    30,    32,    34,
      37,    81,    80,     0,    87,    73,    60,    52,     0,    14,
      70,    61,    89,    12,    13
};

/* YYPGOTO[NTERM-NUM].  */
static const yytype_int8 yypgoto[] =
{
     -98,   -98,   113,   -98,   -17,   -98,   -25,   -98,   -98,   -98,
     -98,   -98,   -18,    61,   -97,    -7,   -98,   -98,   -98,   -98,
     -56,   -98,    95,    -1
};

/* YYDEFGOTO[NTERM-NUM].  */
static const yytype_int8 yydefgoto[] =
{
       0,     2,     3,     4,    23,    24,   110,    25,    54,    60,
      89,    50,     7,    28,    71,   100,    44,    72,    65,   118,
      99,    69,    62,   101
};

/* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM.  If
   positive, shift that token.  If negative, reduce the rule whose
   number is the opposite.  If YYTABLE_NINF, syntax error.  */
static const yytype_int16 yytable[] =
{
      51,    52,    53,    43,    55,     5,     5,    56,    46,   104,
      -7,     9,   139,    67,    68,    10,   119,    64,    11,    12,
      13,    14,    15,    16,    17,    47,    18,    19,    20,    73,
      -2,    74,    66,    21,    22,     8,    91,    92,    93,    94,
      95,   143,    98,    96,    97,     1,     1,   103,   108,   109,
      27,    29,    30,   107,   117,    45,    48,    49,    57,   122,
      58,    59,    61,   105,     6,     6,   128,   120,   121,    70,
     123,     9,     5,   124,   133,    10,   125,    -7,    11,    12,
      13,    14,    15,    16,    17,   136,    18,    19,    20,     5,
     126,   127,   129,    21,    22,    75,   130,   131,   132,   141,
     135,   138,   134,   111,    92,    93,    94,    95,   137,   140,
      96,    97,   112,   113,   114,   115,   116,    26,   144,    90,
     102,    92,    93,    94,    95,    31,     0,    96,    97,    63,
       0,     6,   142,     0,     0,     0,     0,   106,     0,     0,
      76,    77,    78,    79,    80,    81,    32,     0,     6,    33,
      34,    35,    36,    37,    38,    39,    40,    41,    42,     9,
       0,     0,     0,    10,     0,     0,    11,    12,    13,    14,
      15,    16,    17,     0,    18,    19,    20,     0,     0,     0,
       0,    21,    22,    82,    83,    84,    85,    86,    87,    88
};

static const yytype_int16 yycheck[] =
{
      18,    19,    20,    10,    22,     4,     4,    24,     4,    65,
       0,     1,   109,    40,    41,     5,    72,    35,     8,     9,
      10,    11,    12,    13,    14,    21,    16,    17,    18,    47,
       0,    49,    39,    23,    24,     0,    35,    36,    37,    38,
      39,   138,    60,    42,    43,    15,    15,    65,     6,     7,
       4,    62,    62,    70,    72,     4,     4,    21,    62,    77,
      65,    64,    68,     3,    63,    63,    84,     4,     3,    66,
       4,     1,     4,     4,    65,     5,     4,    67,     8,     9,
      10,    11,    12,    13,    14,   103,    16,    17,    18,     4,
       4,     4,     4,    23,    24,     4,     4,     4,     4,   117,
       4,   108,    69,    35,    36,    37,    38,    39,    67,     4,
      42,    43,    44,    45,    46,    47,    48,     4,   143,    58,
      35,    36,    37,    38,    39,     1,    -1,    42,    43,    34,
      -1,    63,   133,    -1,    -1,    -1,    -1,    67,    -1,    -1,
      49,    50,    51,    52,    53,    54,    22,    -1,    63,    25,
      26,    27,    28,    29,    30,    31,    32,    33,    34,     1,
      -1,    -1,    -1,     5,    -1,    -1,     8,     9,    10,    11,
      12,    13,    14,    -1,    16,    17,    18,    -1,    -1,    -1,
      -1,    23,    24,    55,    56,    57,    58,    59,    60,    61
};

/* YYSTOS[STATE-NUM] -- The symbol kind of the accessing symbol of
   state STATE-NUM.  */
static const yytype_int8 yystos[] =
{
       0,    15,    71,    72,    73,     4,    63,    82,     0,     1,
       5,     8,     9,    10,    11,    12,    13,    14,    16,    17,
      18,    23,    24,    74,    75,    77,    72,     4,    83,    62,
      62,     1,    22,    25,    26,    27,    28,    29,    30,    31,
      32,    33,    34,    85,    86,     4,     4,    21,     4,    21,
      81,    82,    82,    82,    78,    82,    74,    62,    65,    64,
      79,    68,    92,    92,    82,    88,    85,    40,    41,    91,
      66,    84,    87,    82,    82,     4,    49,    50,    51,    52,
      53,    54,    55,    56,    57,    58,    59,    60,    61,    80,
      83,    35,    36,    37,    38,    39,    42,    43,    82,    90,
      85,    93,    35,    82,    90,     3,    67,    74,     6,     7,
      76,    35,    44,    45,    46,    47,    48,    82,    89,    90,
       4,     3,    82,     4,     4,     4,     4,     4,    82,     4,
       4,     4,     4,    65,    69,     4,    82,    67,    85,    84,
       4,    82,    93,    84,    76
};

/* YYR1[RULE-NUM] -- Symbol kind of the left-hand side of rule RULE-NUM.  */
static const yytype_int8 yyr1[] =
{
       0,    70,    71,    71,    72,    72,    73,    74,    74,    75,
      75,    75,    76,    76,    76,    77,    77,    77,    77,    77,
      77,    77,    77,    77,    77,    77,    77,    77,    77,    78,
      78,    78,    78,    78,    78,    79,    79,    79,    80,    80,
      80,    81,    81,    81,    81,    81,    81,    81,    82,    82,
      83,    83,    84,    84,    85,    85,    85,    85,    85,    85,
      85,    85,    85,    85,    85,    86,    86,    87,    87,    87,
      87,    88,    88,    88,    89,    89,    89,    89,    89,    90,
      90,    90,    90,    90,    90,    91,    91,    92,    93,    93
};

/* YYR2[RULE-NUM] -- Number of symbols on the right-hand side of rule RULE-NUM.  */
static const yytype_int8 yyr2[] =
{
       0,     2,     0,     2,     0,     2,     3,     1,     2,     2,
       4,     2,     0,     4,     2,     2,     3,     1,     4,     2,
       2,     1,     1,     3,     2,     2,     2,     2,     2,     0,
       3,     3,     3,     2,     3,     0,     2,     3,     1,     1,
       1,     0,     3,     3,     3,     3,     3,     2,     3,     1,
       1,     3,     3,     2,     2,     2,     2,     1,     1,     3,
       4,     4,     2,     3,     1,     1,     1,     0,     2,     2,
       3,     0,     2,     3,     1,     1,     1,     1,     1,     1,
       2,     2,     1,     1,     1,     1,     1,     3,     1,     3
};


enum { YYENOMEM = -2 };

#define yyerrok         (yyerrstatus = 0)
#define yyclearin       (yychar = YYEMPTY)

#define YYACCEPT        goto yyacceptlab
#define YYABORT         goto yyabortlab
#define YYERROR         goto yyerrorlab
#define YYNOMEM         goto yyexhaustedlab


#define YYRECOVERING()  (!!yyerrstatus)

#define YYBACKUP(Token, Value)                                    \
  do                                                              \
    if (yychar == YYEMPTY)                                        \
      {                                                           \
        yychar = (Token);                                         \
        yylval = (Value);                                         \
        YYPOPSTACK (yylen);                                       \
        yystate = *yyssp;                                         \
        goto yybackup;                                            \
      }                                                           \
    else                                                          \
      {                                                           \
        yyerror (context, yyscanner, YY_("syntax error: cannot back up")); \
        YYERROR;                                                  \
      }                                                           \
  while (0)

/* Backward compatibility with an undocumented macro.
   Use YYerror or YYUNDEF. */
#define YYERRCODE YYUNDEF


/* Enable debugging if requested.  */
#if YYDEBUG

# ifndef YYFPRINTF
#  include <stdio.h> /* INFRINGES ON USER NAME SPACE */
#  define YYFPRINTF fprintf
# endif

# define YYDPRINTF(Args)                        \
do {                                            \
  if (yydebug)                                  \
    YYFPRINTF Args;                             \
} while (0)




# define YY_SYMBOL_PRINT(Title, Kind, Value, Location)                    \
do {                                                                      \
  if (yydebug)                                                            \
    {                                                                     \
      YYFPRINTF (stderr, "%s ", Title);                                   \
      yy_symbol_print (stderr,                                            \
                  Kind, Value, context, yyscanner); \
      YYFPRINTF (stderr, "\n");                                           \
    }                                                                     \
} while (0)


/*-----------------------------------.
| Print this symbol's value on YYO.  |
`-----------------------------------*/

static void
yy_symbol_value_print (FILE *yyo,
                       yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep, struct sieve2_context *context, void *yyscanner)
{
  FILE *yyoutput = yyo;
  YY_USE (yyoutput);
  YY_USE (context);
  YY_USE (yyscanner);
  if (!yyvaluep)
    return;
  YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
  YY_USE (yykind);
  YY_IGNORE_MAYBE_UNINITIALIZED_END
}


/*---------------------------.
| Print this symbol on YYO.  |
`---------------------------*/

static void
yy_symbol_print (FILE *yyo,
                 yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep, struct sieve2_context *context, void *yyscanner)
{
  YYFPRINTF (yyo, "%s %s (",
             yykind < YYNTOKENS ? "token" : "nterm", yysymbol_name (yykind));

  yy_symbol_value_print (yyo, yykind, yyvaluep, context, yyscanner);
  YYFPRINTF (yyo, ")");
}

/*------------------------------------------------------------------.
| yy_stack_print -- Print the state stack from its BOTTOM up to its |
| TOP (included).                                                   |
`------------------------------------------------------------------*/

static void
yy_stack_print (yy_state_t *yybottom, yy_state_t *yytop)
{
  YYFPRINTF (stderr, "Stack now");
  for (; yybottom <= yytop; yybottom++)
    {
      int yybot = *yybottom;
      YYFPRINTF (stderr, " %d", yybot);
    }
  YYFPRINTF (stderr, "\n");
}

# define YY_STACK_PRINT(Bottom, Top)                            \
do {                                                            \
  if (yydebug)                                                  \
    yy_stack_print ((Bottom), (Top));                           \
} while (0)


/*------------------------------------------------.
| Report that the YYRULE is going to be reduced.  |
`------------------------------------------------*/

static void
yy_reduce_print (yy_state_t *yyssp, YYSTYPE *yyvsp,
                 int yyrule, struct sieve2_context *context, void *yyscanner)
{
  int yylno = yyrline[yyrule];
  int yynrhs = yyr2[yyrule];
  int yyi;
  YYFPRINTF (stderr, "Reducing stack by rule %d (line %d):\n",
             yyrule - 1, yylno);
  /* The symbols being reduced.  */
  for (yyi = 0; yyi < yynrhs; yyi++)
    {
      YYFPRINTF (stderr, "   $%d = ", yyi + 1);
      yy_symbol_print (stderr,
                       YY_ACCESSING_SYMBOL (+yyssp[yyi + 1 - yynrhs]),
                       &yyvsp[(yyi + 1) - (yynrhs)], context, yyscanner);
      YYFPRINTF (stderr, "\n");
    }
}

# define YY_REDUCE_PRINT(Rule)          \
do {                                    \
  if (yydebug)                          \
    yy_reduce_print (yyssp, yyvsp, Rule, context, yyscanner); \
} while (0)

/* Nonzero means print parse trace.  It is left uninitialized so that
   multiple parsers can coexist.  */
int yydebug;
#else /* !YYDEBUG */
# define YYDPRINTF(Args) ((void) 0)
# define YY_SYMBOL_PRINT(Title, Kind, Value, Location)
# define YY_STACK_PRINT(Bottom, Top)
# define YY_REDUCE_PRINT(Rule)
#endif /* !YYDEBUG */


/* YYINITDEPTH -- initial size of the parser's stacks.  */
#ifndef YYINITDEPTH
# define YYINITDEPTH 200
#endif

/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
   if the built-in stack extension method is used).

   Do not make this value too large; the results are undefined if
   YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
   evaluated with infinite-precision integer arithmetic.  */

#ifndef YYMAXDEPTH
# define YYMAXDEPTH 10000
#endif






/*-----------------------------------------------.
| Release the memory associated to this symbol.  |
`-----------------------------------------------*/

static void
yydestruct (const char *yymsg,
            yysymbol_kind_t yykind, YYSTYPE *yyvaluep, struct sieve2_context *context, void *yyscanner)
{
  YY_USE (yyvaluep);
  YY_USE (context);
  YY_USE (yyscanner);
  if (!yymsg)
    yymsg = "Deleting";
  YY_SYMBOL_PRINT (yymsg, yykind, yyvaluep, yylocationp);

  YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
  YY_USE (yykind);
  YY_IGNORE_MAYBE_UNINITIALIZED_END
}






/*----------.
| yyparse.  |
`----------*/

int
yyparse (struct sieve2_context *context, void *yyscanner)
{
/* Lookahead token kind.  */
int yychar;


/* The semantic value of the lookahead symbol.  */
/* Default value used for initialization, for pacifying older GCCs
   or non-GCC compilers.  */
YY_INITIAL_VALUE (static YYSTYPE yyval_default;)
YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default);

    /* Number of syntax errors so far.  */
    int yynerrs = 0;

    yy_state_fast_t yystate = 0;
    /* Number of tokens to shift before error messages enabled.  */
    int yyerrstatus = 0;

    /* Refer to the stacks through separate pointers, to allow yyoverflow
       to reallocate them elsewhere.  */

    /* Their size.  */
    YYPTRDIFF_T yystacksize = YYINITDEPTH;

    /* The state stack: array, bottom, top.  */
    yy_state_t yyssa[YYINITDEPTH];
    yy_state_t *yyss = yyssa;
    yy_state_t *yyssp = yyss;

    /* The semantic value stack: array, bottom, top.  */
    YYSTYPE yyvsa[YYINITDEPTH];
    YYSTYPE *yyvs = yyvsa;
    YYSTYPE *yyvsp = yyvs;

  int yyn;
  /* The return value of yyparse.  */
  int yyresult;
  /* Lookahead symbol kind.  */
  yysymbol_kind_t yytoken = YYSYMBOL_YYEMPTY;
  /* The variables used to return semantic value and location from the
     action routines.  */
  YYSTYPE yyval;



#define YYPOPSTACK(N)   (yyvsp -= (N), yyssp -= (N))

  /* The number of symbols on the RHS of the reduced rule.
     Keep to zero when no symbol should be popped.  */
  int yylen = 0;

  YYDPRINTF ((stderr, "Starting parse\n"));

  yychar = YYEMPTY; /* Cause a token to be read.  */

  goto yysetstate;


/*------------------------------------------------------------.
| yynewstate -- push a new state, which is found in yystate.  |
`------------------------------------------------------------*/
yynewstate:
  /* In all cases, when you get here, the value and location stacks
     have just been pushed.  So pushing a state here evens the stacks.  */
  yyssp++;


/*--------------------------------------------------------------------.
| yysetstate -- set current state (the top of the stack) to yystate.  |
`--------------------------------------------------------------------*/
yysetstate:
  YYDPRINTF ((stderr, "Entering state %d\n", yystate));
  YY_ASSERT (0 <= yystate && yystate < YYNSTATES);
  YY_IGNORE_USELESS_CAST_BEGIN
  *yyssp = YY_CAST (yy_state_t, yystate);
  YY_IGNORE_USELESS_CAST_END
  YY_STACK_PRINT (yyss, yyssp);

  if (yyss + yystacksize - 1 <= yyssp)
#if !defined yyoverflow && !defined YYSTACK_RELOCATE
    YYNOMEM;
#else
    {
      /* Get the current used size of the three stacks, in elements.  */
      YYPTRDIFF_T yysize = yyssp - yyss + 1;

# if defined yyoverflow
      {
        /* Give user a chance to reallocate the stack.  Use copies of
           these so that the &'s don't force the real ones into
           memory.  */
        yy_state_t *yyss1 = yyss;
        YYSTYPE *yyvs1 = yyvs;

        /* Each stack pointer address is followed by the size of the
           data in use in that stack, in bytes.  This used to be a
           conditional around just the two extra args, but that might
           be undefined if yyoverflow is a macro.  */
        yyoverflow (YY_("memory exhausted"),
                    &yyss1, yysize * YYSIZEOF (*yyssp),
                    &yyvs1, yysize * YYSIZEOF (*yyvsp),
                    &yystacksize);
        yyss = yyss1;
        yyvs = yyvs1;
      }
# else /* defined YYSTACK_RELOCATE */
      /* Extend the stack our own way.  */
      if (YYMAXDEPTH <= yystacksize)
        YYNOMEM;
      yystacksize *= 2;
      if (YYMAXDEPTH < yystacksize)
        yystacksize = YYMAXDEPTH;

      {
        yy_state_t *yyss1 = yyss;
        union yyalloc *yyptr =
          YY_CAST (union yyalloc *,
                   YYSTACK_ALLOC (YY_CAST (YYSIZE_T, YYSTACK_BYTES (yystacksize))));
        if (! yyptr)
          YYNOMEM;
        YYSTACK_RELOCATE (yyss_alloc, yyss);
        YYSTACK_RELOCATE (yyvs_alloc, yyvs);
#  undef YYSTACK_RELOCATE
        if (yyss1 != yyssa)
          YYSTACK_FREE (yyss1);
      }
# endif

      yyssp = yyss + yysize - 1;
      yyvsp = yyvs + yysize - 1;

      YY_IGNORE_USELESS_CAST_BEGIN
      YYDPRINTF ((stderr, "Stack size increased to %ld\n",
                  YY_CAST (long, yystacksize)));
      YY_IGNORE_USELESS_CAST_END

      if (yyss + yystacksize - 1 <= yyssp)
        YYABORT;
    }
#endif /* !defined yyoverflow && !defined YYSTACK_RELOCATE */


  if (yystate == YYFINAL)
    YYACCEPT;

  goto yybackup;


/*-----------.
| yybackup.  |
`-----------*/
yybackup:
  /* Do appropriate processing given the current state.  Read a
     lookahead token if we need one and don't already have one.  */

  /* First try to decide what to do without reference to lookahead token.  */
  yyn = yypact[yystate];
  if (yypact_value_is_default (yyn))
    goto yydefault;

  /* Not known => get a lookahead token if don't already have one.  */

  /* YYCHAR is either empty, or end-of-input, or a valid lookahead.  */
  if (yychar == YYEMPTY)
    {
      YYDPRINTF ((stderr, "Reading a token\n"));
      yychar = yylex (&yylval, context, yyscanner);
    }

  if (yychar <= YYEOF)
    {
      yychar = YYEOF;
      yytoken = YYSYMBOL_YYEOF;
      YYDPRINTF ((stderr, "Now at end of input.\n"));
    }
  else if (yychar == YYerror)
    {
      /* The scanner already issued an error message, process directly
         to error recovery.  But do not keep the error token as
         lookahead, it is too special and may lead us to an endless
         loop in error recovery. */
      yychar = YYUNDEF;
      yytoken = YYSYMBOL_YYerror;
      goto yyerrlab1;
    }
  else
    {
      yytoken = YYTRANSLATE (yychar);
      YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
    }

  /* If the proper action on seeing token YYTOKEN is to reduce or to
     detect an error, take that action.  */
  yyn += yytoken;
  if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
    goto yydefault;
  yyn = yytable[yyn];
  if (yyn <= 0)
    {
      if (yytable_value_is_error (yyn))
        goto yyerrlab;
      yyn = -yyn;
      goto yyreduce;
    }

  /* Count tokens shifted since error; after three, turn off error
     status.  */
  if (yyerrstatus)
    yyerrstatus--;

  /* Shift the lookahead token.  */
  YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
  yystate = yyn;
  YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
  *++yyvsp = yylval;
  YY_IGNORE_MAYBE_UNINITIALIZED_END

  /* Discard the shifted token.  */
  yychar = YYEMPTY;
  goto yynewstate;


/*-----------------------------------------------------------.
| yydefault -- do the default action for the current state.  |
`-----------------------------------------------------------*/
yydefault:
  yyn = yydefact[yystate];
  if (yyn == 0)
    goto yyerrlab;
  goto yyreduce;


/*-----------------------------.
| yyreduce -- do a reduction.  |
`-----------------------------*/
yyreduce:
  /* yyn is the number of a rule to reduce with.  */
  yylen = yyr2[yyn];

  /* If YYLEN is nonzero, implement the default value of the action:
     '$$ = $1'.

     Otherwise, the following line sets YYVAL to garbage.
     This behavior is undocumented and Bison
     users should not rely upon it.  Assigning to YYVAL
     unconditionally makes the parser a bit smaller, and it avoids a
     GCC warning that YYVAL may be used uninitialized.  */
  yyval = yyvsp[1-yylen];


  YY_REDUCE_PRINT (yyn);
  switch (yyn)
    {
  case 2: /* start: %empty  */
#line 173 "src/sv_parser/sieve.y"
                                { context->sieve_ret = NULL; }
#line 1580 "src/sv_parser/sieve.c"
    break;

  case 3: /* start: reqs commands  */
#line 174 "src/sv_parser/sieve.y"
                                { context->sieve_ret = (yyvsp[0].cl); }
#line 1586 "src/sv_parser/sieve.c"
    break;

  case 6: /* require: REQUIRE stringlist ';'  */
#line 181 "src/sv_parser/sieve.y"
                                {
                                    int unsupp = 0;
                                    char *msg;
                                    char *freemsg;
                                    stringlist_t *s;
                                    stringlist_t *sl = (yyvsp[-1].sl);

                                    msg = libsieve_strconcat("unsupported feature:", NULL);

                                    while (sl != NULL) {
                                        s = sl;
                                        sl = sl->next;

					/* Returns 1 if supported, 0 if not. */
                                        if (!static_check_reqs(context, s->s)) {
					    unsupp = 1;
                                            freemsg = msg;
                                            msg = libsieve_strconcat(freemsg, " ", s->s, NULL);
                                            libsieve_free(freemsg);
                                        }

                                        libsieve_free(s->s);
                                        libsieve_free(s);
                                    }

				    /* If something wasn't supported, bomb out with msg. */
                                    if (unsupp) {
                                        libsieve_sieveerror(context, yyscanner, msg);
                                        libsieve_free(msg);
                                        YYERROR; 
                                    }

                                    /* This needs to be free'd regardless of error */
                                    libsieve_free(msg);
                                }
#line 1626 "src/sv_parser/sieve.c"
    break;

  case 7: /* commands: command  */
#line 218 "src/sv_parser/sieve.y"
                                { (yyval.cl) = (yyvsp[0].cl); }
#line 1632 "src/sv_parser/sieve.c"
    break;

  case 8: /* commands: command commands  */
#line 219 "src/sv_parser/sieve.y"
                                { (yyvsp[-1].cl)->next = (yyvsp[0].cl); (yyval.cl) = (yyvsp[-1].cl); }
#line 1638 "src/sv_parser/sieve.c"
    break;

  case 9: /* command: action ';'  */
#line 222 "src/sv_parser/sieve.y"
                                { (yyval.cl) = (yyvsp[-1].cl); }
#line 1644 "src/sv_parser/sieve.c"
    break;

  case 10: /* command: IF test block elsif  */
#line 223 "src/sv_parser/sieve.y"
                                { (yyval.cl) = libsieve_new_if((yyvsp[-2].test), (yyvsp[-1].cl), (yyvsp[0].cl)); }
#line 1650 "src/sv_parser/sieve.c"
    break;

  case 11: /* command: error ';'  */
#line 224 "src/sv_parser/sieve.y"
                                { (yyval.cl) = libsieve_new_command(STOP); }
#line 1656 "src/sv_parser/sieve.c"
    break;

  case 12: /* elsif: %empty  */
#line 227 "src/sv_parser/sieve.y"
                                 { (yyval.cl) = NULL; }
#line 1662 "src/sv_parser/sieve.c"
    break;

  case 13: /* elsif: ELSIF test block elsif  */
#line 228 "src/sv_parser/sieve.y"
                                 { (yyval.cl) = libsieve_new_if((yyvsp[-2].test), (yyvsp[-1].cl), (yyvsp[0].cl)); }
#line 1668 "src/sv_parser/sieve.c"
    break;

  case 14: /* elsif: ELSE block  */
#line 229 "src/sv_parser/sieve.y"
                                 { (yyval.cl) = (yyvsp[0].cl); }
#line 1674 "src/sv_parser/sieve.c"
    break;

  case 15: /* action: REJCT STRING  */
#line 232 "src/sv_parser/sieve.y"
                                 { if (!context->require.reject) {
	                             libsieve_sieveerror(context, yyscanner, "reject not required");
				     YYERROR;
				   }
				   (yyval.cl) = libsieve_new_command(REJCT); (yyval.cl)->u.str = (yyvsp[0].sval); }
#line 1684 "src/sv_parser/sieve.c"
    break;

  case 16: /* action: KEEP FLAGS stringlist  */
#line 237 "src/sv_parser/sieve.y"
                                 { if (!context->require.imap4flags) {
	                             libsieve_sieveerror(context, yyscanner, "imap4flags not required");
	                             YYERROR;
                                   }
	                           (yyval.cl) = libsieve_new_command(KEEP);
                                   (yyval.cl)->u.f.mailbox = NULL; 
				   (yyval.cl)->u.f.slflags = (yyvsp[0].sl); }
#line 1696 "src/sv_parser/sieve.c"
    break;

  case 17: /* action: KEEP  */
#line 244 "src/sv_parser/sieve.y"
                                 { (yyval.cl) = libsieve_new_command(KEEP);
	                           (yyval.cl)->u.f.mailbox = NULL;
				   (yyval.cl)->u.f.slflags = NULL; }
#line 1704 "src/sv_parser/sieve.c"
    break;

  case 18: /* action: FILEINTO FLAGS stringlist STRING  */
#line 247 "src/sv_parser/sieve.y"
                                                 { if (!context->require.fileinto) {
	                             libsieve_sieveerror(context, yyscanner, "fileinto not required");
	                             YYERROR;
                                   } if (!context->require.imap4flags) {
	                             libsieve_sieveerror(context, yyscanner, "imap4flags not required");
	                             YYERROR;
                                   }

                                   if (!static_verify_stringlist(context, (yyvsp[-1].sl), static_verify_flag)) {
                                     YYERROR; /* vh should call sieveerror() */
                                   }

				   if (!static_verify_mailbox((yyvsp[0].sval))) {
				     YYERROR; /* vm should call sieveerror() */
				   }
	                           (yyval.cl) = libsieve_new_command(FILEINTO);
				   (yyval.cl)->u.f.slflags = (yyvsp[-1].sl);
				   (yyval.cl)->u.f.mailbox = (yyvsp[0].sval); }
#line 1727 "src/sv_parser/sieve.c"
    break;

  case 19: /* action: FILEINTO STRING  */
#line 265 "src/sv_parser/sieve.y"
                                 { if (!context->require.fileinto) {
	                             libsieve_sieveerror(context, yyscanner, "fileinto not required");
	                             YYERROR;
                                   }
				   if (!static_verify_mailbox((yyvsp[0].sval))) {
				     YYERROR; /* vm should call sieveerror() */
				   }
	                           (yyval.cl) = libsieve_new_command(FILEINTO);
				   (yyval.cl)->u.f.slflags = NULL;
				   (yyval.cl)->u.f.mailbox = (yyvsp[0].sval); }
#line 1742 "src/sv_parser/sieve.c"
    break;

  case 20: /* action: REDIRECT STRING  */
#line 275 "src/sv_parser/sieve.y"
                                  { (yyval.cl) = libsieve_new_command(REDIRECT);
                                  if (!static_verify_address(context, (yyvsp[0].sval))) {
				     YYERROR; /* va should call sieveerror() */
				   }
				   (yyval.cl)->u.str = (yyvsp[0].sval); }
#line 1752 "src/sv_parser/sieve.c"
    break;

  case 21: /* action: STOP  */
#line 280 "src/sv_parser/sieve.y"
                                 { (yyval.cl) = libsieve_new_command(STOP); }
#line 1758 "src/sv_parser/sieve.c"
    break;

  case 22: /* action: DISCARD  */
#line 281 "src/sv_parser/sieve.y"
                                 { (yyval.cl) = libsieve_new_command(DISCARD); }
#line 1764 "src/sv_parser/sieve.c"
    break;

  case 23: /* action: VACATION vtags STRING  */
#line 282 "src/sv_parser/sieve.y"
                                 { if (!context->require.vacation) {
	                             libsieve_sieveerror(context, yyscanner, "vacation not required");
				     (yyval.cl) = libsieve_new_command(VACATION);
				     YYERROR;
				   } else {
	                             (yyval.cl) = static_build_vacation(context,
                                       VACATION, static_canon_vtags((yyvsp[-1].vtag)), (yyvsp[0].sval));
				   } }
#line 1777 "src/sv_parser/sieve.c"
    break;

  case 24: /* action: SETFLAG stringlist  */
#line 290 "src/sv_parser/sieve.y"
                                 { if (!context->require.imap4flags) {
                                    libsieve_sieveerror(context, yyscanner, "imap4flags not required");
                                    YYERROR;
                                    }
                                  if (!static_verify_stringlist(context, (yyvsp[0].sl), static_verify_flag)) {
                                    YYERROR; /* vf should call sieveerror() */
				    }
                                 (yyval.cl) = libsieve_new_command(SETFLAG);
                                 (yyval.cl)->u.sl = (yyvsp[0].sl); }
#line 1791 "src/sv_parser/sieve.c"
    break;

  case 25: /* action: ADDFLAG stringlist  */
#line 299 "src/sv_parser/sieve.y"
                                 { if (!context->require.imap4flags) {
                                    libsieve_sieveerror(context, yyscanner, "imap4flags not required");
                                    YYERROR;
                                    }
                                 if (!static_verify_stringlist(context, (yyvsp[0].sl), static_verify_flag)) {
                                    YYERROR; /* vf should call sieveerror() */
                                    }
                                 (yyval.cl) = libsieve_new_command(ADDFLAG);
                                 (yyval.cl)->u.sl = (yyvsp[0].sl); }
#line 1805 "src/sv_parser/sieve.c"
    break;

  case 26: /* action: REMOVEFLAG stringlist  */
#line 308 "src/sv_parser/sieve.y"
                                 { if (!context->require.imap4flags) {
                                     libsieve_sieveerror(context, yyscanner, "imap4flags not required");
                                     YYERROR;
                                     }
                                 if (!static_verify_stringlist(context, (yyvsp[0].sl), static_verify_flag)) {
                                     YYERROR; /* vf should call sieveerror() */
                                     }
                                 (yyval.cl) = libsieve_new_command(REMOVEFLAG);
                                 (yyval.cl)->u.sl = (yyvsp[0].sl); }
#line 1819 "src/sv_parser/sieve.c"
    break;

  case 27: /* action: NOTIFY ntags  */
#line 317 "src/sv_parser/sieve.y"
                                 { if (!context->require.notify) {
	                             libsieve_sieveerror(context, yyscanner, "notify not required");
	       		             (yyval.cl) = libsieve_new_command(NOTIFY); 
	       		             YYERROR;
				 } else {
	                             (yyval.cl) = static_build_notify(context, NOTIFY,
	       		             static_canon_ntags((yyvsp[0].ntag)));
	       		         } }
#line 1832 "src/sv_parser/sieve.c"
    break;

  case 28: /* action: VALIDNOTIF stringlist  */
#line 325 "src/sv_parser/sieve.y"
                                 { if (!context->require.notify) {
                                     libsieve_sieveerror(context, yyscanner, "notify not required");
				     (yyval.cl) = libsieve_new_command(VALIDNOTIF);
				     YYERROR;
				 } else {
	                             (yyval.cl) = static_build_validnotif(context, VALIDNOTIF, (yyvsp[0].sl));
				 } }
#line 1844 "src/sv_parser/sieve.c"
    break;

  case 29: /* ntags: %empty  */
#line 334 "src/sv_parser/sieve.y"
                                 { (yyval.ntag) = static_new_ntags(); }
#line 1850 "src/sv_parser/sieve.c"
    break;

  case 30: /* ntags: ntags ID STRING  */
#line 335 "src/sv_parser/sieve.y"
                                 { if ((yyval.ntag)->id != NULL) { 
	                                libsieve_sieveerror(context, yyscanner, "duplicate :method"); YYERROR; }
				   else { (yyval.ntag)->id = (yyvsp[0].sval); } }
#line 1858 "src/sv_parser/sieve.c"
    break;

  case 31: /* ntags: ntags METHOD STRING  */
#line 338 "src/sv_parser/sieve.y"
                                 { if ((yyval.ntag)->method != NULL) { 
	                                libsieve_sieveerror(context, yyscanner, "duplicate :method"); YYERROR; }
				   else { (yyval.ntag)->method = (yyvsp[0].sval); } }
#line 1866 "src/sv_parser/sieve.c"
    break;

  case 32: /* ntags: ntags OPTIONS stringlist  */
#line 341 "src/sv_parser/sieve.y"
                                   { if ((yyval.ntag)->options != NULL) { 
	                                libsieve_sieveerror(context, yyscanner, "duplicate :options"); YYERROR; }
				     else { (yyval.ntag)->options = (yyvsp[0].sl); } }
#line 1874 "src/sv_parser/sieve.c"
    break;

  case 33: /* ntags: ntags priority  */
#line 344 "src/sv_parser/sieve.y"
                                 { if ((yyval.ntag)->priority != NULL) { 
	                                libsieve_sieveerror(context, yyscanner,"duplicate :priority"); YYERROR; }
				   else { (yyval.ntag)->priority = (yyvsp[0].sval); } }
#line 1882 "src/sv_parser/sieve.c"
    break;

  case 34: /* ntags: ntags MESSAGE STRING  */
#line 347 "src/sv_parser/sieve.y"
                                 { if ((yyval.ntag)->message != NULL) { 
					libsieve_sieveerror(context, yyscanner, "duplicate :message"); YYERROR; }
				   else { (yyval.ntag)->message = (yyvsp[0].sval); } }
#line 1890 "src/sv_parser/sieve.c"
    break;

  case 35: /* hftags: %empty  */
#line 352 "src/sv_parser/sieve.y"
                                 { (yyval.hftag) = static_new_hftags(); }
#line 1896 "src/sv_parser/sieve.c"
    break;

  case 36: /* hftags: hftags comptag  */
#line 353 "src/sv_parser/sieve.y"
                                 { (yyval.hftag)->comptag = (yyvsp[0].nval); }
#line 1902 "src/sv_parser/sieve.c"
    break;

  case 37: /* hftags: hftags COMPARATOR STRING  */
#line 354 "src/sv_parser/sieve.y"
                                   { if ((yyval.hftag)->comparator != NULL) { 
				   libsieve_sieveerror(context, yyscanner, "duplicate comparator tag"); YYERROR; }
				   else { (yyval.hftag)->comparator = (yyvsp[0].sval); } }
#line 1910 "src/sv_parser/sieve.c"
    break;

  case 38: /* priority: LOW  */
#line 359 "src/sv_parser/sieve.y"
                 { (yyval.sval) = "low"; }
#line 1916 "src/sv_parser/sieve.c"
    break;

  case 39: /* priority: NORMAL  */
#line 360 "src/sv_parser/sieve.y"
                 { (yyval.sval) = "normal"; }
#line 1922 "src/sv_parser/sieve.c"
    break;

  case 40: /* priority: HIGH  */
#line 361 "src/sv_parser/sieve.y"
                 { (yyval.sval) = "high"; }
#line 1928 "src/sv_parser/sieve.c"
    break;

  case 41: /* vtags: %empty  */
#line 364 "src/sv_parser/sieve.y"
                                 { (yyval.vtag) = static_new_vtags(); }
#line 1934 "src/sv_parser/sieve.c"
    break;

  case 42: /* vtags: vtags DAYS NUMBER  */
#line 365 "src/sv_parser/sieve.y"
                                 { if ((yyval.vtag)->days != -1) { 
					libsieve_sieveerror(context, yyscanner, "duplicate :days");
					YYERROR; }
				   else { (yyval.vtag)->days = (yyvsp[0].nval); } }
#line 1943 "src/sv_parser/sieve.c"
    break;

  case 43: /* vtags: vtags ADDRESSES stringlist  */
#line 369 "src/sv_parser/sieve.y"
                                     { if ((yyval.vtag)->addresses != NULL) { 
					libsieve_sieveerror(context, yyscanner, "duplicate :addresses");
					YYERROR;
				       } else if (!static_verify_stringlist(context, (yyvsp[0].sl),
							static_verify_address)) {
					  YYERROR;
				       } else {
					 (yyval.vtag)->addresses = (yyvsp[0].sl); } }
#line 1956 "src/sv_parser/sieve.c"
    break;

  case 44: /* vtags: vtags SUBJECT STRING  */
#line 377 "src/sv_parser/sieve.y"
                                 { if ((yyval.vtag)->subject != NULL) { 
					libsieve_sieveerror(context, yyscanner, "duplicate :subject");
					YYERROR;
				   } else if (!static_ok_header((yyvsp[0].sval))) {
					YYERROR;
				   } else { (yyval.vtag)->subject = (yyvsp[0].sval); } }
#line 1967 "src/sv_parser/sieve.c"
    break;

  case 45: /* vtags: vtags HANDLE STRING  */
#line 383 "src/sv_parser/sieve.y"
                                 { if ((yyval.vtag)->handle != NULL) { 
					libsieve_sieveerror(context, yyscanner, "duplicate :handle");
					YYERROR;
				   } else if (!static_ok_header((yyvsp[0].sval))) {
					YYERROR;
				   } else { (yyval.vtag)->handle = (yyvsp[0].sval); } }
#line 1978 "src/sv_parser/sieve.c"
    break;

  case 46: /* vtags: vtags FROM STRING  */
#line 389 "src/sv_parser/sieve.y"
                                 { if ((yyval.vtag)->from != NULL) { 
					libsieve_sieveerror(context, yyscanner, "duplicate :from");
					YYERROR;
				   } else if (!static_ok_header((yyvsp[0].sval))) {
					YYERROR;
				   } else { (yyval.vtag)->from = (yyvsp[0].sval); } }
#line 1989 "src/sv_parser/sieve.c"
    break;

  case 47: /* vtags: vtags MIME  */
#line 395 "src/sv_parser/sieve.y"
                                 { if ((yyval.vtag)->mime != -1) { 
					libsieve_sieveerror(context, yyscanner, "duplicate :mime");
					YYERROR; }
				   else { (yyval.vtag)->mime = MIME; } }
#line 1998 "src/sv_parser/sieve.c"
    break;

  case 48: /* stringlist: '[' strings ']'  */
#line 401 "src/sv_parser/sieve.y"
                                 { (yyval.sl) = (yyvsp[-1].sl); }
#line 2004 "src/sv_parser/sieve.c"
    break;

  case 49: /* stringlist: STRING  */
#line 402 "src/sv_parser/sieve.y"
                                 { (yyval.sl) = libsieve_new_sl((yyvsp[0].sval), NULL); }
#line 2010 "src/sv_parser/sieve.c"
    break;

  case 50: /* strings: STRING  */
#line 405 "src/sv_parser/sieve.y"
                                 { (yyval.sl) = libsieve_new_sl((yyvsp[0].sval), NULL); }
#line 2016 "src/sv_parser/sieve.c"
    break;

  case 51: /* strings: STRING ',' strings  */
#line 406 "src/sv_parser/sieve.y"
                                 { (yyval.sl) = libsieve_new_sl((yyvsp[-2].sval), (yyvsp[0].sl)); }
#line 2022 "src/sv_parser/sieve.c"
    break;

  case 52: /* block: '{' commands '}'  */
#line 409 "src/sv_parser/sieve.y"
                                 { (yyval.cl) = (yyvsp[-1].cl); }
#line 2028 "src/sv_parser/sieve.c"
    break;

  case 53: /* block: '{' '}'  */
#line 410 "src/sv_parser/sieve.y"
                                 { (yyval.cl) = NULL; }
#line 2034 "src/sv_parser/sieve.c"
    break;

  case 54: /* test: ANYOF testlist  */
#line 413 "src/sv_parser/sieve.y"
                                 { (yyval.test) = libsieve_new_test(ANYOF); (yyval.test)->u.tl = (yyvsp[0].testl); }
#line 2040 "src/sv_parser/sieve.c"
    break;

  case 55: /* test: ALLOF testlist  */
#line 414 "src/sv_parser/sieve.y"
                                 { (yyval.test) = libsieve_new_test(ALLOF); (yyval.test)->u.tl = (yyvsp[0].testl); }
#line 2046 "src/sv_parser/sieve.c"
    break;

  case 56: /* test: EXISTS stringlist  */
#line 415 "src/sv_parser/sieve.y"
                                 { (yyval.test) = libsieve_new_test(EXISTS); (yyval.test)->u.sl = (yyvsp[0].sl); }
#line 2052 "src/sv_parser/sieve.c"
    break;

  case 57: /* test: SFALSE  */
#line 416 "src/sv_parser/sieve.y"
                                 { (yyval.test) = libsieve_new_test(SFALSE); }
#line 2058 "src/sv_parser/sieve.c"
    break;

  case 58: /* test: STRUE  */
#line 417 "src/sv_parser/sieve.y"
                                 { (yyval.test) = libsieve_new_test(STRUE); }
#line 2064 "src/sv_parser/sieve.c"
    break;

  case 59: /* test: HASFLAG hftags stringlist  */
#line 418 "src/sv_parser/sieve.y"
                                    { if (!context->require.imap4flags) {
                                       libsieve_sieveerror(context, yyscanner, "imap4flags not required");
                                       YYERROR;
                                    }
                                    if (!static_verify_stringlist(context, (yyvsp[0].sl), static_verify_flag)) {
                                       YYERROR; /* vf should call sieveerror() */
				    }
                                    (yyval.test) = libsieve_new_test(HASFLAG);
				    if ((yyvsp[-1].hftag)->comptag != -1) { 
				       (yyval.test)->u.hf.comp = libsieve_comparator_lookup(context, (yyvsp[-1].hftag)->comparator, (yyvsp[-1].hftag)->comptag);
				       (yyval.test)->u.hf.comptag = (yyvsp[-1].hftag)->comptag;
				    }
				    if ((yyvsp[-1].hftag)) {
				       libsieve_free((yyvsp[-1].hftag));
				    }
                                    (yyval.test)->u.hf.sl = (yyvsp[0].sl); }
#line 2085 "src/sv_parser/sieve.c"
    break;

  case 60: /* test: HEADER htags stringlist stringlist  */
#line 435 "src/sv_parser/sieve.y"
                                 { patternlist_t *pl;
                                   if (!static_verify_stringlist(context, (yyvsp[-1].sl), static_verify_header)) {
                                     YYERROR; /* vh should call sieveerror() */
                                   }

				   (yyvsp[-2].htag) = static_canon_htags((yyvsp[-2].htag));
				   if ((yyvsp[-2].htag)->comptag == REGEX) {
				     pl = static_verify_regexs(context, (yyvsp[0].sl), (yyvsp[-2].htag)->comparator);
				     if (!pl) { YYERROR; }
				   }
				   else
				     pl = (patternlist_t *) (yyvsp[0].sl);
				       
				   (yyval.test) = static_build_header(context, HEADER, (yyvsp[-2].htag), (yyvsp[-1].sl), pl);
				   if ((yyval.test) == NULL) { YYERROR; } }
#line 2105 "src/sv_parser/sieve.c"
    break;

  case 61: /* test: addrorenv aetags stringlist stringlist  */
#line 451 "src/sv_parser/sieve.y"
                                 { patternlist_t *pl;
                                   if (!static_verify_stringlist(context, (yyvsp[-1].sl), static_verify_header)) {
                                     YYERROR; /* vh should call sieveerror() */
                                   }

				   (yyvsp[-2].aetag) = static_canon_aetags((yyvsp[-2].aetag));
				   if ((yyvsp[-2].aetag)->comptag == REGEX) {
				     pl = static_verify_regexs(context, (yyvsp[0].sl), (yyvsp[-2].aetag)->comparator);
				     if (!pl) { YYERROR; }
				   }
				   else
				     pl = (patternlist_t *) (yyvsp[0].sl);
				       
				   (yyval.test) = static_build_address(context, (yyvsp[-3].nval), (yyvsp[-2].aetag), (yyvsp[-1].sl), pl);
				   if ((yyval.test) == NULL) { YYERROR; } }
#line 2125 "src/sv_parser/sieve.c"
    break;

  case 62: /* test: NOT test  */
#line 466 "src/sv_parser/sieve.y"
                                 { (yyval.test) = libsieve_new_test(NOT); (yyval.test)->u.t = (yyvsp[0].test); }
#line 2131 "src/sv_parser/sieve.c"
    break;

  case 63: /* test: SIZE sizetag NUMBER  */
#line 467 "src/sv_parser/sieve.y"
                                 { (yyval.test) = libsieve_new_test(SIZE); (yyval.test)->u.sz.t = (yyvsp[-1].nval);
		                   (yyval.test)->u.sz.n = (yyvsp[0].nval); }
#line 2138 "src/sv_parser/sieve.c"
    break;

  case 64: /* test: error  */
#line 469 "src/sv_parser/sieve.y"
                                 { (yyval.test) = NULL; }
#line 2144 "src/sv_parser/sieve.c"
    break;

  case 65: /* addrorenv: ADDRESS  */
#line 472 "src/sv_parser/sieve.y"
                                 { (yyval.nval) = ADDRESS; }
#line 2150 "src/sv_parser/sieve.c"
    break;

  case 66: /* addrorenv: ENVELOPE  */
#line 473 "src/sv_parser/sieve.y"
                                 { (yyval.nval) = ENVELOPE; }
#line 2156 "src/sv_parser/sieve.c"
    break;

  case 67: /* aetags: %empty  */
#line 476 "src/sv_parser/sieve.y"
                                 { (yyval.aetag) = static_new_aetags(); }
#line 2162 "src/sv_parser/sieve.c"
    break;

  case 68: /* aetags: aetags addrparttag  */
#line 477 "src/sv_parser/sieve.y"
                                 { (yyval.aetag) = (yyvsp[-1].aetag);
				   if ((yyval.aetag)->addrtag != -1) { 
		        libsieve_sieveerror(context, yyscanner, "duplicate or conflicting address part tag");
			YYERROR; }
				   else { (yyval.aetag)->addrtag = (yyvsp[0].nval); } }
#line 2172 "src/sv_parser/sieve.c"
    break;

  case 69: /* aetags: aetags comptag  */
#line 482 "src/sv_parser/sieve.y"
                                 { (yyval.aetag) = (yyvsp[-1].aetag);
				   if ((yyval.aetag)->comptag != -1) { 
		        libsieve_sieveerror(context, yyscanner, "duplicate comparator type tag"); YYERROR; }
				   else { (yyval.aetag)->comptag = (yyvsp[0].nval); } }
#line 2181 "src/sv_parser/sieve.c"
    break;

  case 70: /* aetags: aetags COMPARATOR STRING  */
#line 486 "src/sv_parser/sieve.y"
                                   { (yyval.aetag) = (yyvsp[-2].aetag);
				   if ((yyval.aetag)->comparator != NULL) { 
		        libsieve_sieveerror(context, yyscanner, "duplicate comparator tag"); YYERROR; }
				   else { (yyval.aetag)->comparator = (yyvsp[0].sval); } }
#line 2190 "src/sv_parser/sieve.c"
    break;

  case 71: /* htags: %empty  */
#line 492 "src/sv_parser/sieve.y"
                                 { (yyval.htag) = static_new_htags(); }
#line 2196 "src/sv_parser/sieve.c"
    break;

  case 72: /* htags: htags comptag  */
#line 493 "src/sv_parser/sieve.y"
                                 { (yyval.htag) = (yyvsp[-1].htag);
				   if ((yyval.htag)->comptag != -1) { 
		        libsieve_sieveerror(context, yyscanner, "duplicate comparator type tag"); YYERROR; }
				   else { (yyval.htag)->comptag = (yyvsp[0].nval); } }
#line 2205 "src/sv_parser/sieve.c"
    break;

  case 73: /* htags: htags COMPARATOR STRING  */
#line 497 "src/sv_parser/sieve.y"
                                  { (yyval.htag) = (yyvsp[-2].htag);
				   if ((yyval.htag)->comparator != NULL) { 
 		        libsieve_sieveerror(context, yyscanner, "duplicate comparator tag");
					YYERROR; }
				   else { (yyval.htag)->comparator = (yyvsp[0].sval); } }
#line 2215 "src/sv_parser/sieve.c"
    break;

  case 74: /* addrparttag: ALL  */
#line 504 "src/sv_parser/sieve.y"
                                 { (yyval.nval) = ALL; }
#line 2221 "src/sv_parser/sieve.c"
    break;

  case 75: /* addrparttag: LOCALPART  */
#line 505 "src/sv_parser/sieve.y"
                                 { (yyval.nval) = LOCALPART; }
#line 2227 "src/sv_parser/sieve.c"
    break;

  case 76: /* addrparttag: DOMAIN  */
#line 506 "src/sv_parser/sieve.y"
                                 { (yyval.nval) = DOMAIN; }
#line 2233 "src/sv_parser/sieve.c"
    break;

  case 77: /* addrparttag: USER  */
#line 507 "src/sv_parser/sieve.y"
                                 { if (!context->require.subaddress) {
				     libsieve_sieveerror(context, yyscanner, "subaddress not required");
				     YYERROR;
				   }
				   (yyval.nval) = USER; }
#line 2243 "src/sv_parser/sieve.c"
    break;

  case 78: /* addrparttag: DETAIL  */
#line 512 "src/sv_parser/sieve.y"
                                { if (!context->require.subaddress) {
				     libsieve_sieveerror(context, yyscanner, "subaddress not required");
				     YYERROR;
				   }
				   (yyval.nval) = DETAIL; }
#line 2253 "src/sv_parser/sieve.c"
    break;

  case 79: /* comptag: IS  */
#line 519 "src/sv_parser/sieve.y"
                                 { (yyval.nval) = IS; }
#line 2259 "src/sv_parser/sieve.c"
    break;

  case 80: /* comptag: VALUE STRING  */
#line 520 "src/sv_parser/sieve.y"
                                 { (yyval.nval) = VALUE | libsieve_relational_lookup((yyvsp[0].sval)); libsieve_free((yyvsp[0].sval)); /* HACK: bits above 10 carry the relational. And we don't need this string anymore, either. */ }
#line 2265 "src/sv_parser/sieve.c"
    break;

  case 81: /* comptag: COUNT STRING  */
#line 521 "src/sv_parser/sieve.y"
                                 { (yyval.nval) = COUNT | libsieve_relational_lookup((yyvsp[0].sval)); libsieve_free((yyvsp[0].sval)); /* HACK: bits above 10 carry the relational. And we don't need this string anymore, either. */ }
#line 2271 "src/sv_parser/sieve.c"
    break;

  case 82: /* comptag: CONTAINS  */
#line 522 "src/sv_parser/sieve.y"
                                 { (yyval.nval) = CONTAINS; }
#line 2277 "src/sv_parser/sieve.c"
    break;

  case 83: /* comptag: MATCHES  */
#line 523 "src/sv_parser/sieve.y"
                                 { (yyval.nval) = MATCHES; }
#line 2283 "src/sv_parser/sieve.c"
    break;

  case 84: /* comptag: REGEX  */
#line 524 "src/sv_parser/sieve.y"
                                 { if (!context->require.regex) {
	                             libsieve_sieveerror(context, yyscanner, "regex not required");
				     YYERROR;
				     }
				   (yyval.nval) = REGEX; }
#line 2293 "src/sv_parser/sieve.c"
    break;

  case 85: /* sizetag: OVER  */
#line 531 "src/sv_parser/sieve.y"
                                 { (yyval.nval) = OVER; }
#line 2299 "src/sv_parser/sieve.c"
    break;

  case 86: /* sizetag: UNDER  */
#line 532 "src/sv_parser/sieve.y"
                                 { (yyval.nval) = UNDER; }
#line 2305 "src/sv_parser/sieve.c"
    break;

  case 87: /* testlist: '(' tests ')'  */
#line 535 "src/sv_parser/sieve.y"
                                 { (yyval.testl) = (yyvsp[-1].testl); }
#line 2311 "src/sv_parser/sieve.c"
    break;

  case 88: /* tests: test  */
#line 538 "src/sv_parser/sieve.y"
                                 { (yyval.testl) = libsieve_new_testlist((yyvsp[0].test), NULL); }
#line 2317 "src/sv_parser/sieve.c"
    break;

  case 89: /* tests: test ',' tests  */
#line 539 "src/sv_parser/sieve.y"
                                 { (yyval.testl) = libsieve_new_testlist((yyvsp[-2].test), (yyvsp[0].testl)); }
#line 2323 "src/sv_parser/sieve.c"
    break;


#line 2327 "src/sv_parser/sieve.c"

      default: break;
    }
  /* User semantic actions sometimes alter yychar, and that requires
     that yytoken be updated with the new translation.  We take the
     approach of translating immediately before every use of yytoken.
     One alternative is translating here after every semantic action,
     but that translation would be missed if the semantic action invokes
     YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
     if it invokes YYBACKUP.  In the case of YYABORT or YYACCEPT, an
     incorrect destructor might then be invoked immediately.  In the
     case of YYERROR or YYBACKUP, subsequent parser actions might lead
     to an incorrect destructor call or verbose syntax error message
     before the lookahead is translated.  */
  YY_SYMBOL_PRINT ("-> $$ =", YY_CAST (yysymbol_kind_t, yyr1[yyn]), &yyval, &yyloc);

  YYPOPSTACK (yylen);
  yylen = 0;

  *++yyvsp = yyval;

  /* Now 'shift' the result of the reduction.  Determine what state
     that goes to, based on the state we popped back to and the rule
     number reduced by.  */
  {
    const int yylhs = yyr1[yyn] - YYNTOKENS;
    const int yyi = yypgoto[yylhs] + *yyssp;
    yystate = (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyssp
               ? yytable[yyi]
               : yydefgoto[yylhs]);
  }

  goto yynewstate;


/*--------------------------------------.
| yyerrlab -- here on detecting error.  |
`--------------------------------------*/
yyerrlab:
  /* Make sure we have latest lookahead translation.  See comments at
     user semantic actions for why this is necessary.  */
  yytoken = yychar == YYEMPTY ? YYSYMBOL_YYEMPTY : YYTRANSLATE (yychar);
  /* If not already recovering from an error, report this error.  */
  if (!yyerrstatus)
    {
      ++yynerrs;
      yyerror (context, yyscanner, YY_("syntax error"));
    }

  if (yyerrstatus == 3)
    {
      /* If just tried and failed to reuse lookahead token after an
         error, discard it.  */

      if (yychar <= YYEOF)
        {
          /* Return failure if at end of input.  */
          if (yychar == YYEOF)
            YYABORT;
        }
      else
        {
          yydestruct ("Error: discarding",
                      yytoken, &yylval, context, yyscanner);
          yychar = YYEMPTY;
        }
    }

  /* Else will try to reuse lookahead token after shifting the error
     token.  */
  goto yyerrlab1;


/*---------------------------------------------------.
| yyerrorlab -- error raised explicitly by YYERROR.  |
`---------------------------------------------------*/
yyerrorlab:
  /* Pacify compilers when the user code never invokes YYERROR and the
     label yyerrorlab therefore never appears in user code.  */
  if (0)
    YYERROR;
  ++yynerrs;

  /* Do not reclaim the symbols of the rule whose action triggered
     this YYERROR.  */
  YYPOPSTACK (yylen);
  yylen = 0;
  YY_STACK_PRINT (yyss, yyssp);
  yystate = *yyssp;
  goto yyerrlab1;


/*-------------------------------------------------------------.
| yyerrlab1 -- common code for both syntax error and YYERROR.  |
`-------------------------------------------------------------*/
yyerrlab1:
  yyerrstatus = 3;      /* Each real token shifted decrements this.  */

  /* Pop stack until we find a state that shifts the error token.  */
  for (;;)
    {
      yyn = yypact[yystate];
      if (!yypact_value_is_default (yyn))
        {
          yyn += YYSYMBOL_YYerror;
          if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYSYMBOL_YYerror)
            {
              yyn = yytable[yyn];
              if (0 < yyn)
                break;
            }
        }

      /* Pop the current state because it cannot handle the error token.  */
      if (yyssp == yyss)
        YYABORT;


      yydestruct ("Error: popping",
                  YY_ACCESSING_SYMBOL (yystate), yyvsp, context, yyscanner);
      YYPOPSTACK (1);
      yystate = *yyssp;
      YY_STACK_PRINT (yyss, yyssp);
    }

  YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
  *++yyvsp = yylval;
  YY_IGNORE_MAYBE_UNINITIALIZED_END


  /* Shift the error token.  */
  YY_SYMBOL_PRINT ("Shifting", YY_ACCESSING_SYMBOL (yyn), yyvsp, yylsp);

  yystate = yyn;
  goto yynewstate;


/*-------------------------------------.
| yyacceptlab -- YYACCEPT comes here.  |
`-------------------------------------*/
yyacceptlab:
  yyresult = 0;
  goto yyreturnlab;


/*-----------------------------------.
| yyabortlab -- YYABORT comes here.  |
`-----------------------------------*/
yyabortlab:
  yyresult = 1;
  goto yyreturnlab;


/*-----------------------------------------------------------.
| yyexhaustedlab -- YYNOMEM (memory exhaustion) comes here.  |
`-----------------------------------------------------------*/
yyexhaustedlab:
  yyerror (context, yyscanner, YY_("memory exhausted"));
  yyresult = 2;
  goto yyreturnlab;


/*----------------------------------------------------------.
| yyreturnlab -- parsing is finished, clean up and return.  |
`----------------------------------------------------------*/
yyreturnlab:
  if (yychar != YYEMPTY)
    {
      /* Make sure we have latest lookahead translation.  See comments at
         user semantic actions for why this is necessary.  */
      yytoken = YYTRANSLATE (yychar);
      yydestruct ("Cleanup: discarding lookahead",
                  yytoken, &yylval, context, yyscanner);
    }
  /* Do not reclaim the symbols of the rule whose action triggered
     this YYABORT or YYACCEPT.  */
  YYPOPSTACK (yylen);
  YY_STACK_PRINT (yyss, yyssp);
  while (yyssp != yyss)
    {
      yydestruct ("Cleanup: popping",
                  YY_ACCESSING_SYMBOL (+*yyssp), yyvsp, context, yyscanner);
      YYPOPSTACK (1);
    }
#ifndef yyoverflow
  if (yyss != yyssa)
    YYSTACK_FREE (yyss);
#endif

  return yyresult;
}

#line 542 "src/sv_parser/sieve.y"


commandlist_t *libsieve_sieve_parse_buffer(struct sieve2_context *context)
{
    commandlist_t *t;
    void *sieve_scan = context->sieve_scan;
    YY_BUFFER_STATE buf = libsieve_sieve_scan_string(context->script.script, sieve_scan);
    if (libsieve_sieveparse(context, sieve_scan)) {
	return NULL;
    } else {
	libsieve_sieve_delete_buffer(buf, sieve_scan);
	t = context->sieve_ret;
	context->sieve_ret = NULL;
	return t;
    }
}

int libsieve_sieveerror(struct sieve2_context *context, void* yyscanner, const char *msg)
{
    context->parse_errors++;

    libsieve_do_error_parse(context, libsieve_sieveget_lineno(context->sieve_scan), msg);

    return 0;
}

static test_t *static_build_address(struct sieve2_context *context, int t,
			struct aetags *ae, stringlist_t *sl, patternlist_t *pl)
{
    test_t *ret = libsieve_new_test(t);	/* can be either ADDRESS or ENVELOPE */

    libsieve_assert((t == ADDRESS) || (t == ENVELOPE));

    if (ret) {
	ret->u.ae.comptag = ae->comptag;
	ret->u.ae.comp = libsieve_comparator_lookup(context, ae->comparator, ae->comptag);
	ret->u.ae.sl = sl;
	ret->u.ae.pl = pl;
	ret->u.ae.addrpart = ae->addrtag;
	static_free_aetags(ae);
	if (ret->u.ae.comp == NULL) {
	    libsieve_free_test(ret);
	    ret = NULL;
	}
    }
    return ret;
}

static test_t *static_build_header(struct sieve2_context *context, int t, struct htags *h, stringlist_t *sl, patternlist_t *pl)
{
    test_t *ret = libsieve_new_test(t);	/* can be HEADER */

    libsieve_assert(t == HEADER);

    if (ret) {
	ret->u.h.comptag = h->comptag;
	ret->u.h.comp = libsieve_comparator_lookup(context, h->comparator, h->comptag);
	ret->u.h.sl = sl;
	ret->u.h.pl = pl;
	static_free_htags(h);
	if (ret->u.h.comp == NULL) {
	    libsieve_free_test(ret);
	    ret = NULL;
	}
    }
    return ret;
}

static commandlist_t *static_build_vacation(struct sieve2_context *context, int t, struct vtags *v, char *reason)
{
    commandlist_t *ret = libsieve_new_command(t);

    libsieve_assert(t == VACATION);

    if (ret) {
	ret->u.v.subject = v->subject; v->subject = NULL;
	ret->u.v.handle = v->handle; v->handle = NULL;
	ret->u.v.from = v->from; v->from = NULL;
	ret->u.v.days = v->days;
	ret->u.v.mime = v->mime;
	ret->u.v.addresses = v->addresses; v->addresses = NULL;
	static_free_vtags(v);
	ret->u.v.message = reason;
    }
    return ret;
}

static commandlist_t *static_build_notify(struct sieve2_context *context, int t, struct ntags *n)
{
    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.options = n->options; n->options = NULL;
	ret->u.n.priority = n->priority;
	ret->u.n.message = n->message; n->message = NULL;
	static_free_ntags(n);
    }
    return ret;
}

// FIXME: I think we just test and return true or false... check around.
static commandlist_t *static_build_validnotif(struct sieve2_context *context, int t, stringlist_t *sl)
{
    commandlist_t *ret = libsieve_new_command(t);

    libsieve_assert(t == VALIDNOTIF);

/*
    if (ret) {
	ret->u.d.comptag = d->comptag;
	ret->u.d.comp = libsieve_comparator_lookup(context, "i;ascii-casemap", d->comptag);
	ret->u.d.pattern = d->pattern; d->pattern = NULL;
	ret->u.d.priority = d->priority;
	static_free_dtags(d);
    }*/
    return ret;
}

static struct hftags *static_new_hftags(void)
{
    struct hftags *r = (struct hftags *) libsieve_malloc(sizeof(struct hftags));

    r->comptag = -1;
    r->comparator = NULL;

    return r;
}

static struct aetags *static_new_aetags(void)
{
    struct aetags *r = (struct aetags *) libsieve_malloc(sizeof(struct aetags));

    r->addrtag = r->comptag = -1;
    r->comparator = NULL;

    return r;
}

static struct aetags *static_canon_aetags(struct aetags *ae)
{
    char *map = "i;ascii-casemap";
    if (ae->addrtag == -1) { ae->addrtag = ALL; }
    if (ae->comparator == NULL) { ae->comparator = libsieve_strdup(map); }
    if (ae->comptag == -1) { ae->comptag = IS; }
    return ae;
}

static void static_free_aetags(struct aetags *ae)
{
    libsieve_free(ae->comparator);
    libsieve_free(ae);
}

static struct htags *static_new_htags(void)
{
    struct htags *r = (struct htags *) libsieve_malloc(sizeof(struct htags));

    r->comptag = -1;
    r->comparator = NULL;

    return r;
}

static struct htags *static_canon_htags(struct htags *h)
{
    char *map = "i;ascii-casemap";
    if (h->comparator == NULL) { h->comparator = libsieve_strdup(map); }
    if (h->comptag == -1) { h->comptag = IS; }
    return h;
}

static void static_free_htags(struct htags *h)
{
    libsieve_free(h->comparator);
    libsieve_free(h);
}

static struct vtags *static_new_vtags(void)
{
    struct vtags *r = (struct vtags *) libsieve_malloc(sizeof(struct vtags));

    r->days = -1;
    r->addresses = NULL;
    r->subject = NULL;
    r->handle = NULL;
    r->from = NULL;
    r->mime = -1;

    return r;
}

static struct vtags *static_canon_vtags(struct vtags *v)
{
/* TODO: Change this to an *in*sane default, and specify that the
 * client app has to check for boundaries.  That would be much
 * simpler than having a context registration for something that
 * the user cannot test/check for at all.
 */

    if (v->days == -1) { v->days = 7; }
    if (v->mime == -1) { v->mime = 0; }

    return v;
}

static void static_free_vtags(struct vtags *v)
{
    if (v->addresses) { libsieve_free_sl(v->addresses); }
    libsieve_free(v->subject);
    libsieve_free(v->handle);
    libsieve_free(v->from);
    libsieve_free(v);
}

static struct ntags *static_new_ntags(void)
{
    struct ntags *r = (struct ntags *) libsieve_malloc(sizeof(struct ntags));

    r->method = NULL;
    r->id = NULL;
    r->options = NULL;
    r->priority = NULL;
    r->message = NULL;

    return r;
}

static struct ntags *static_canon_ntags(struct ntags *n)
{
    char *from = "$from$: $subject$";
    if (n->priority == NULL) { n->priority = "normal"; }
    if (n->message == NULL) { n->message = libsieve_strdup(from); }

    return n;
}

static void static_free_ntags(struct ntags *n)
{
    libsieve_free(n->method);
    libsieve_free(n->id);
    if (n->options) libsieve_free_sl(n->options);
    libsieve_free(n->message);
    libsieve_free(n);
}

static int static_verify_stringlist(struct sieve2_context *context, stringlist_t *sl, int (*verify)(struct sieve2_context*, const char *))
{
    for (; sl != NULL && verify(context, sl->s); sl = sl->next) ;
    return (sl == NULL);
}

static int static_verify_flag(struct sieve2_context *context, const char *s)
{
    /* xxx if not a flag, call sieveerror */
    return 1;
}

static int static_verify_address(struct sieve2_context *context, const char *s)
{
    struct address *addr = NULL;

    addr = libsieve_addr_parse_buffer(context, &addr, &s);
    if (addr == NULL) {
        return 0;
    }
    libsieve_addrstructfree(context, addr, CHARSALSO);
    return 1;
}

static int static_verify_mailbox(const char *s UNUSED)
{
    /* xxx if not a mailbox, call sieveerror */
    return 1;
}

static int static_verify_header(struct sieve2_context *context, const char *hdr)
{
    const char *h = hdr;
    char *err;

    while (*h) {
	/* field-name      =       1*ftext
	   ftext           =       %d33-57 / %d59-126         
	   ; Any character except
	   ;  controls, SP, and
	   ;  ":". */
	if (!((*h >= 33 && *h <= 57) || (*h >= 59 && *h <= 126))) {
	    err = libsieve_strconcat("header '", hdr, "': not a valid header", NULL);
	    libsieve_sieveerror(context, context->sieve_scan, err);
	    libsieve_free(err);
	    return 0;
	}
	h++;
    }
    return 1;
}
 
/* Was this supposed to be modifying its argument?! */
/*
static int static_verify_flag(const char *flag)
{
    int ret;
    char *f, *err;

    // Make ourselves a local copy to change the case
    f = libsieve_strdup(flag);
 
    if (f[0] == '\\') {
	libsieve_strtolower(f,strlen(f));
	if (strcmp(f, "\\\\seen") && strcmp(f, "\\\\answered") &&
	    strcmp(f, "\\\\flagged") && strcmp(f, "\\\\draft") &&
	    strcmp(f, "\\\\deleted")) {
            err = libsieve_strconcat("flag '", f, "': not a system flag", NULL);
	    libsieve_sieveerror(err);
	    libsieve_free(err);
	    ret = 0;
	}
	ret = 1;
    }
    else if (!libsieve_strisatom(f,strlen(f))) {
	err = libsieve_strconcat("flag '", f, "': not a valid keyword", NULL);
	libsieve_sieveerror(err);
	libsieve_free(err);
	ret = 0;
    }
    ret = 1;

    libsieve_free(f);
    return ret;
}
*/

static regex_t *static_verify_regex(struct sieve2_context *context, const char *s, int cflags)
{
    int ret;
    char errbuf[100];
    regex_t *reg = (regex_t *) libsieve_malloc(sizeof(regex_t));

    if ((ret = regcomp(reg, s, cflags)) != 0) {
	(void) regerror(ret, reg, errbuf, sizeof(errbuf));
	libsieve_sieveerror(context, context->sieve_scan, errbuf);
	libsieve_free(reg);
	return NULL;
    }
    return reg;
}

static patternlist_t *static_verify_regexs(struct sieve2_context *context, stringlist_t *sl, char *comp)
{
    stringlist_t *sl2;
    patternlist_t *pl = NULL;
    int cflags = REG_EXTENDED | REG_NOSUB;
    regex_t *reg;

    if (!strcmp(comp, "i;ascii-casemap")) {
	cflags |= REG_ICASE;
    }

    for (sl2 = sl; sl2 != NULL; sl2 = sl2->next) {
        if ((reg = static_verify_regex(context, sl2->s, cflags)) == NULL) {
	    libsieve_free_pl(pl, REGEX);
	    break;
	}
	pl = libsieve_new_pl(reg, pl);
    }
    if (sl2 == NULL) {
	libsieve_free_sl(sl);
	return pl;
    }
    return NULL;
}

/* xxx is it ok to put this in an RFC822 header body? */
static int static_ok_header(char *s UNUSED)
{
    return 1;
}

/* Checks if interpreter supports specified action
 * */
static int static_check_reqs(struct sieve2_context *c, char *req)
{
    if (0 == strcmp("fileinto", req)) {
        return c->require.fileinto = c->support.fileinto;
    } else if (0 == strcmp("reject", req)) {
        return c->require.reject = c->support.reject;
    } else if (!strcmp("envelope", req)) {
        return c->require.envelope = c->support.envelope;
    } else if (!strcmp("vacation", req)) {
        return c->require.vacation = c->support.vacation;
    } else if (!strcmp("notify",req)) {
        return c->require.notify = c->support.notify;
    } else if (!strcmp("subaddress", req)) {
	return c->require.subaddress = c->support.subaddress;
    /* imap4flags is built into the parser. */
    } else if (!strcmp("imap4flags", req)) {
        return c->require.imap4flags = 1;
    /* regex is built into the parser. */
    } else if (!strcmp("regex", req)) {
	return c->require.regex = 1;
    /* relational is built into the parser. */
    } else if (!strcmp("relational", req)) {
	return c->require.relational = 1;
    /* These comparators are built into the parser. */
    } else if (!strcmp("comparator-i;octet", req)) {
	return 1;
    } else if (!strcmp("comparator-i;ascii-casemap", req)) {
	return 1;
    } else if (!strcmp("comparator-i;ascii-numeric", req)) {
	return 1;
    }
    /* If we don't recognize it, then we don't support it! */
    return 0;
}
