/* 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         sieveparse
#define yylex           sievelex
#define yyerror         sieveerror
#define yydebug         sievedebug
#define yynerrs         sievenerrs

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

/* sieve.y -- sieve parser
 * Larry Greenfield
 * Ken Murchison
 *
 * Copyright (c) 1994-2017 Carnegie Mellon University.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. The name "Carnegie Mellon University" must not be used to
 *    endorse or promote products derived from this software without
 *    prior written permission. For permission or any legal
 *    details, please contact
 *      Carnegie Mellon University
 *      Center for Technology Transfer and Enterprise Creation
 *      4615 Forbes Avenue
 *      Suite 302
 *      Pittsburgh, PA  15213
 *      (412) 268-7393, fax: (412) 268-7395
 *      innovation@andrew.cmu.edu
 *
 * 4. Redistributions of any form whatsoever must retain the following
 *    acknowledgment:
 *    "This product includes software developed by Computing Services
 *     at Carnegie Mellon University (http://www.cmu.edu/computing/)."
 *
 * 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.
 */

/*
 * Yacc definitions
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include "xmalloc.h"
#include "sieve/comparator.h"
#include "sieve/interp.h"
#include "sieve/script.h"
#include "sieve/tree.h"
#include "sieve/flags.h"
#include "sieve/grammar.h"
#include "sieve/sieve_err.h"

#include "lib/gmtoff.h"
#include "util.h"
#include "imparse.h"
#include "libconfig.h"
#include "times.h"
#include "tok.h"

#define ERR_BUF_SIZE 1024

int encoded_char = 0;  /* used to send encoded-character feedback to lexer */
int getdatepart = 0;   /* used to send start state feedback to lexer */
static comp_t *ctags;  /* used for accessing comp_t* in a test/command union */

extern int addrparse(sieve_script_t*);
typedef struct yy_buffer_state *YY_BUFFER_STATE;
extern YY_BUFFER_STATE addr_scan_string(const char*);
extern void addr_delete_buffer(YY_BUFFER_STATE);

extern int sievelineno;

void sieveerror_c(sieve_script_t*, int code, ...);

static int check_reqs(sieve_script_t*, strarray_t *sl);
static int chk_match_vars(sieve_script_t*, char *s);

/* construct/canonicalize action commands */
static commandlist_t *build_keep(sieve_script_t*, commandlist_t *c);
static commandlist_t *build_fileinto(sieve_script_t*,
                                     commandlist_t *c, char *folder);
static commandlist_t *build_redirect(sieve_script_t*,
                                     commandlist_t *c, char *addr);
static commandlist_t *build_rej_err(sieve_script_t*, int t, char *message);
static commandlist_t *build_vacation(sieve_script_t*, commandlist_t *t, char *s);
static commandlist_t *build_flag(sieve_script_t*,
                                 commandlist_t *c, strarray_t *flags);
static commandlist_t *build_notify(sieve_script_t*, int t,
                                   commandlist_t *c, char *method);
static commandlist_t *build_denotify(sieve_script_t*, commandlist_t *c);
static commandlist_t *build_include(sieve_script_t*, commandlist_t *c, char*);
static commandlist_t *build_set(sieve_script_t*, commandlist_t *c,
                                char *variable, char *value);
static commandlist_t *build_addheader(sieve_script_t*, commandlist_t *c,
                                      char *name, char *value);
static commandlist_t *build_deleteheader(sieve_script_t*, commandlist_t *c,
                                         char *name, strarray_t *values);
static commandlist_t *build_log(sieve_script_t*, char *text);
static commandlist_t *build_snooze(sieve_script_t *sscript,
                                   commandlist_t *c, arrayu64_t *times);

/* construct/canonicalize test commands */
static test_t *build_anyof(sieve_script_t*, testlist_t *tl);
static test_t *build_allof(sieve_script_t*, testlist_t *tl);
static test_t *build_not(sieve_script_t*, test_t *t);
static test_t *build_address(sieve_script_t*, test_t *t,
                             strarray_t *sl, strarray_t *pl);
static test_t *build_envelope(sieve_script_t*, test_t *t,
                              strarray_t *sl, strarray_t *pl);
static test_t *build_header(sieve_script_t*, test_t *t,
                            strarray_t *sl, strarray_t *pl);
static test_t *build_body(sieve_script_t*, test_t *t, strarray_t *pl);
static test_t *build_stringt(sieve_script_t*, test_t *t,
                             strarray_t *sl, strarray_t *pl);
static test_t *build_hasflag(sieve_script_t*, test_t *t,
                             strarray_t *sl, strarray_t *pl);
static test_t *build_date(sieve_script_t*, test_t *t,
                          char *hn, int part, strarray_t *kl);
static test_t *build_ihave(sieve_script_t*, strarray_t *sa);
static test_t *build_mbox_meta(sieve_script_t*, test_t *t, char *extname,
                               char *keyname, strarray_t *keylist);
static test_t *build_duplicate(sieve_script_t*, test_t *t);
static test_t *build_jmapquery(sieve_script_t*, test_t *t, const char *json);

static int verify_weekday(sieve_script_t *sscript, char *day);
static int verify_time(sieve_script_t *sscript, char *time);

void yyerror(sieve_script_t*, const char *msg);
extern int yylex(void*, sieve_script_t*);
extern void sieverestart(FILE *f);

#define supported(capa) (sscript->support & capa)

#define _verify_flaglist(flags) \
  (supported(SIEVE_CAPA_VARIABLES) || verify_flaglist(flags))

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

/* byacc default is 500, bison default is 10000 - go with the
   larger to support big sieve scripts (see Bug #3461) */
#define YYSTACKSIZE 10000

#line 232 "sieve/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_SIEVE_SIEVE_SIEVE_H_INCLUDED
# define YY_SIEVE_SIEVE_SIEVE_H_INCLUDED
/* Debug traces.  */
#ifndef YYDEBUG
# define YYDEBUG 0
#endif
#if YYDEBUG
extern int 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  */
    REQUIRE = 263,                 /* REQUIRE  */
    STOP = 264,                    /* STOP  */
    DISCARD = 265,                 /* DISCARD  */
    KEEP = 266,                    /* KEEP  */
    FILEINTO = 267,                /* FILEINTO  */
    REDIRECT = 268,                /* REDIRECT  */
    ANYOF = 269,                   /* ANYOF  */
    ALLOF = 270,                   /* ALLOF  */
    EXISTS = 271,                  /* EXISTS  */
    NOT = 272,                     /* NOT  */
    SFALSE = 273,                  /* SFALSE  */
    STRUE = 274,                   /* STRUE  */
    SIZE = 275,                    /* SIZE  */
    HEADERT = 276,                 /* HEADERT  */
    ADDRESS = 277,                 /* ADDRESS  */
    ENVELOPE = 278,                /* ENVELOPE  */
    COMPARATOR = 279,              /* COMPARATOR  */
    OVER = 280,                    /* OVER  */
    UNDER = 281,                   /* UNDER  */
    ALL = 282,                     /* ALL  */
    LOCALPART = 283,               /* LOCALPART  */
    DOMAIN = 284,                  /* DOMAIN  */
    IS = 285,                      /* IS  */
    CONTAINS = 286,                /* CONTAINS  */
    MATCHES = 287,                 /* MATCHES  */
    OCTET = 288,                   /* OCTET  */
    ASCIICASEMAP = 289,            /* ASCIICASEMAP  */
    ASCIINUMERIC = 290,            /* ASCIINUMERIC  */
    REGEX = 291,                   /* REGEX  */
    QUOTEREGEX = 292,              /* QUOTEREGEX  */
    COPY = 293,                    /* COPY  */
    BODY = 294,                    /* BODY  */
    RAW = 295,                     /* RAW  */
    TEXT = 296,                    /* TEXT  */
    CONTENT = 297,                 /* CONTENT  */
    ENVIRONMENT = 298,             /* ENVIRONMENT  */
    STRINGT = 299,                 /* STRINGT  */
    SET = 300,                     /* SET  */
    LOWER = 301,                   /* LOWER  */
    UPPER = 302,                   /* UPPER  */
    LOWERFIRST = 303,              /* LOWERFIRST  */
    UPPERFIRST = 304,              /* UPPERFIRST  */
    QUOTEWILDCARD = 305,           /* QUOTEWILDCARD  */
    LENGTH = 306,                  /* LENGTH  */
    VACATION = 307,                /* VACATION  */
    DAYS = 308,                    /* DAYS  */
    SUBJECT = 309,                 /* SUBJECT  */
    FROM = 310,                    /* FROM  */
    ADDRESSES = 311,               /* ADDRESSES  */
    MIME = 312,                    /* MIME  */
    HANDLE = 313,                  /* HANDLE  */
    SECONDS = 314,                 /* SECONDS  */
    COUNT = 315,                   /* COUNT  */
    VALUE = 316,                   /* VALUE  */
    GT = 317,                      /* GT  */
    GE = 318,                      /* GE  */
    LT = 319,                      /* LT  */
    LE = 320,                      /* LE  */
    EQ = 321,                      /* EQ  */
    NE = 322,                      /* NE  */
    FLAGS = 323,                   /* FLAGS  */
    HASFLAG = 324,                 /* HASFLAG  */
    SETFLAG = 325,                 /* SETFLAG  */
    ADDFLAG = 326,                 /* ADDFLAG  */
    REMOVEFLAG = 327,              /* REMOVEFLAG  */
    MARK = 328,                    /* MARK  */
    UNMARK = 329,                  /* UNMARK  */
    USER = 330,                    /* USER  */
    DETAIL = 331,                  /* DETAIL  */
    DATE = 332,                    /* DATE  */
    CURRENTDATE = 333,             /* CURRENTDATE  */
    ORIGINALZONE = 334,            /* ORIGINALZONE  */
    ZONE = 335,                    /* ZONE  */
    TIMEZONE = 336,                /* TIMEZONE  */
    YEARP = 337,                   /* YEARP  */
    MONTHP = 338,                  /* MONTHP  */
    DAYP = 339,                    /* DAYP  */
    DATEP = 340,                   /* DATEP  */
    JULIAN = 341,                  /* JULIAN  */
    HOURP = 342,                   /* HOURP  */
    MINUTEP = 343,                 /* MINUTEP  */
    SECONDP = 344,                 /* SECONDP  */
    TIMEP = 345,                   /* TIMEP  */
    ISO8601 = 346,                 /* ISO8601  */
    STD11 = 347,                   /* STD11  */
    ZONEP = 348,                   /* ZONEP  */
    WEEKDAYP = 349,                /* WEEKDAYP  */
    INDEX = 350,                   /* INDEX  */
    LAST = 351,                    /* LAST  */
    ADDHEADER = 352,               /* ADDHEADER  */
    DELETEHEADER = 353,            /* DELETEHEADER  */
    REJCT = 354,                   /* REJCT  */
    EREJECT = 355,                 /* EREJECT  */
    METHOD = 356,                  /* METHOD  */
    OPTIONS = 357,                 /* OPTIONS  */
    MESSAGE = 358,                 /* MESSAGE  */
    IMPORTANCE = 359,              /* IMPORTANCE  */
    VALIDNOTIFYMETHOD = 360,       /* VALIDNOTIFYMETHOD  */
    NOTIFYMETHODCAPABILITY = 361,  /* NOTIFYMETHODCAPABILITY  */
    NOTIFY = 362,                  /* NOTIFY  */
    ENOTIFY = 363,                 /* ENOTIFY  */
    ENCODEURL = 364,               /* ENCODEURL  */
    DENOTIFY = 365,                /* DENOTIFY  */
    ID = 366,                      /* ID  */
    ANY = 367,                     /* ANY  */
    LOW = 368,                     /* LOW  */
    NORMAL = 369,                  /* NORMAL  */
    HIGH = 370,                    /* HIGH  */
    IHAVE = 371,                   /* IHAVE  */
    ERROR = 372,                   /* ERROR  */
    MAILBOXEXISTS = 373,           /* MAILBOXEXISTS  */
    CREATE = 374,                  /* CREATE  */
    METADATA = 375,                /* METADATA  */
    METADATAEXISTS = 376,          /* METADATAEXISTS  */
    SERVERMETADATA = 377,          /* SERVERMETADATA  */
    SERVERMETADATAEXISTS = 378,    /* SERVERMETADATAEXISTS  */
    BYTIMEREL = 379,               /* BYTIMEREL  */
    BYTIMEABS = 380,               /* BYTIMEABS  */
    BYMODE = 381,                  /* BYMODE  */
    BYTRACE = 382,                 /* BYTRACE  */
    DSNNOTIFY = 383,               /* DSNNOTIFY  */
    DSNRET = 384,                  /* DSNRET  */
    VALIDEXTLIST = 385,            /* VALIDEXTLIST  */
    LIST = 386,                    /* LIST  */
    INCLUDE = 387,                 /* INCLUDE  */
    OPTIONAL = 388,                /* OPTIONAL  */
    ONCE = 389,                    /* ONCE  */
    RETURN = 390,                  /* RETURN  */
    PERSONAL = 391,                /* PERSONAL  */
    GLOBAL = 392,                  /* GLOBAL  */
    DUPLICATE = 393,               /* DUPLICATE  */
    HEADER = 394,                  /* HEADER  */
    UNIQUEID = 395,                /* UNIQUEID  */
    SPECIALUSEEXISTS = 396,        /* SPECIALUSEEXISTS  */
    SPECIALUSE = 397,              /* SPECIALUSE  */
    FCC = 398,                     /* FCC  */
    MAILBOXID = 399,               /* MAILBOXID  */
    MAILBOXIDEXISTS = 400,         /* MAILBOXIDEXISTS  */
    LOG = 401,                     /* LOG  */
    JMAPQUERY = 402,               /* JMAPQUERY  */
    SNOOZE = 403,                  /* SNOOZE  */
    MAILBOX = 404,                 /* MAILBOX  */
    ADDFLAGS = 405,                /* ADDFLAGS  */
    REMOVEFLAGS = 406,             /* REMOVEFLAGS  */
    WEEKDAYS = 407                 /* WEEKDAYS  */
  };
  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 REQUIRE 263
#define STOP 264
#define DISCARD 265
#define KEEP 266
#define FILEINTO 267
#define REDIRECT 268
#define ANYOF 269
#define ALLOF 270
#define EXISTS 271
#define NOT 272
#define SFALSE 273
#define STRUE 274
#define SIZE 275
#define HEADERT 276
#define ADDRESS 277
#define ENVELOPE 278
#define COMPARATOR 279
#define OVER 280
#define UNDER 281
#define ALL 282
#define LOCALPART 283
#define DOMAIN 284
#define IS 285
#define CONTAINS 286
#define MATCHES 287
#define OCTET 288
#define ASCIICASEMAP 289
#define ASCIINUMERIC 290
#define REGEX 291
#define QUOTEREGEX 292
#define COPY 293
#define BODY 294
#define RAW 295
#define TEXT 296
#define CONTENT 297
#define ENVIRONMENT 298
#define STRINGT 299
#define SET 300
#define LOWER 301
#define UPPER 302
#define LOWERFIRST 303
#define UPPERFIRST 304
#define QUOTEWILDCARD 305
#define LENGTH 306
#define VACATION 307
#define DAYS 308
#define SUBJECT 309
#define FROM 310
#define ADDRESSES 311
#define MIME 312
#define HANDLE 313
#define SECONDS 314
#define COUNT 315
#define VALUE 316
#define GT 317
#define GE 318
#define LT 319
#define LE 320
#define EQ 321
#define NE 322
#define FLAGS 323
#define HASFLAG 324
#define SETFLAG 325
#define ADDFLAG 326
#define REMOVEFLAG 327
#define MARK 328
#define UNMARK 329
#define USER 330
#define DETAIL 331
#define DATE 332
#define CURRENTDATE 333
#define ORIGINALZONE 334
#define ZONE 335
#define TIMEZONE 336
#define YEARP 337
#define MONTHP 338
#define DAYP 339
#define DATEP 340
#define JULIAN 341
#define HOURP 342
#define MINUTEP 343
#define SECONDP 344
#define TIMEP 345
#define ISO8601 346
#define STD11 347
#define ZONEP 348
#define WEEKDAYP 349
#define INDEX 350
#define LAST 351
#define ADDHEADER 352
#define DELETEHEADER 353
#define REJCT 354
#define EREJECT 355
#define METHOD 356
#define OPTIONS 357
#define MESSAGE 358
#define IMPORTANCE 359
#define VALIDNOTIFYMETHOD 360
#define NOTIFYMETHODCAPABILITY 361
#define NOTIFY 362
#define ENOTIFY 363
#define ENCODEURL 364
#define DENOTIFY 365
#define ID 366
#define ANY 367
#define LOW 368
#define NORMAL 369
#define HIGH 370
#define IHAVE 371
#define ERROR 372
#define MAILBOXEXISTS 373
#define CREATE 374
#define METADATA 375
#define METADATAEXISTS 376
#define SERVERMETADATA 377
#define SERVERMETADATAEXISTS 378
#define BYTIMEREL 379
#define BYTIMEABS 380
#define BYMODE 381
#define BYTRACE 382
#define DSNNOTIFY 383
#define DSNRET 384
#define VALIDEXTLIST 385
#define LIST 386
#define INCLUDE 387
#define OPTIONAL 388
#define ONCE 389
#define RETURN 390
#define PERSONAL 391
#define GLOBAL 392
#define DUPLICATE 393
#define HEADER 394
#define UNIQUEID 395
#define SPECIALUSEEXISTS 396
#define SPECIALUSE 397
#define FCC 398
#define MAILBOXID 399
#define MAILBOXIDEXISTS 400
#define LOG 401
#define JMAPQUERY 402
#define SNOOZE 403
#define MAILBOX 404
#define ADDFLAGS 405
#define REMOVEFLAGS 406
#define WEEKDAYS 407

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

    int nval;
    char *sval;
    arrayu64_t *nl;
    strarray_t *sl;
    comp_t *ctag;
    test_t *test;
    testlist_t *testl;
    commandlist_t *cl;

#line 600 "sieve/sieve.c"

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




int sieveparse (sieve_script_t *sscript);


#endif /* !YY_SIEVE_SIEVE_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_REQUIRE = 8,                    /* REQUIRE  */
  YYSYMBOL_STOP = 9,                       /* STOP  */
  YYSYMBOL_DISCARD = 10,                   /* DISCARD  */
  YYSYMBOL_KEEP = 11,                      /* KEEP  */
  YYSYMBOL_FILEINTO = 12,                  /* FILEINTO  */
  YYSYMBOL_REDIRECT = 13,                  /* REDIRECT  */
  YYSYMBOL_ANYOF = 14,                     /* ANYOF  */
  YYSYMBOL_ALLOF = 15,                     /* ALLOF  */
  YYSYMBOL_EXISTS = 16,                    /* EXISTS  */
  YYSYMBOL_NOT = 17,                       /* NOT  */
  YYSYMBOL_SFALSE = 18,                    /* SFALSE  */
  YYSYMBOL_STRUE = 19,                     /* STRUE  */
  YYSYMBOL_SIZE = 20,                      /* SIZE  */
  YYSYMBOL_HEADERT = 21,                   /* HEADERT  */
  YYSYMBOL_ADDRESS = 22,                   /* ADDRESS  */
  YYSYMBOL_ENVELOPE = 23,                  /* ENVELOPE  */
  YYSYMBOL_COMPARATOR = 24,                /* COMPARATOR  */
  YYSYMBOL_OVER = 25,                      /* OVER  */
  YYSYMBOL_UNDER = 26,                     /* UNDER  */
  YYSYMBOL_ALL = 27,                       /* ALL  */
  YYSYMBOL_LOCALPART = 28,                 /* LOCALPART  */
  YYSYMBOL_DOMAIN = 29,                    /* DOMAIN  */
  YYSYMBOL_IS = 30,                        /* IS  */
  YYSYMBOL_CONTAINS = 31,                  /* CONTAINS  */
  YYSYMBOL_MATCHES = 32,                   /* MATCHES  */
  YYSYMBOL_OCTET = 33,                     /* OCTET  */
  YYSYMBOL_ASCIICASEMAP = 34,              /* ASCIICASEMAP  */
  YYSYMBOL_ASCIINUMERIC = 35,              /* ASCIINUMERIC  */
  YYSYMBOL_REGEX = 36,                     /* REGEX  */
  YYSYMBOL_QUOTEREGEX = 37,                /* QUOTEREGEX  */
  YYSYMBOL_COPY = 38,                      /* COPY  */
  YYSYMBOL_BODY = 39,                      /* BODY  */
  YYSYMBOL_RAW = 40,                       /* RAW  */
  YYSYMBOL_TEXT = 41,                      /* TEXT  */
  YYSYMBOL_CONTENT = 42,                   /* CONTENT  */
  YYSYMBOL_ENVIRONMENT = 43,               /* ENVIRONMENT  */
  YYSYMBOL_STRINGT = 44,                   /* STRINGT  */
  YYSYMBOL_SET = 45,                       /* SET  */
  YYSYMBOL_LOWER = 46,                     /* LOWER  */
  YYSYMBOL_UPPER = 47,                     /* UPPER  */
  YYSYMBOL_LOWERFIRST = 48,                /* LOWERFIRST  */
  YYSYMBOL_UPPERFIRST = 49,                /* UPPERFIRST  */
  YYSYMBOL_QUOTEWILDCARD = 50,             /* QUOTEWILDCARD  */
  YYSYMBOL_LENGTH = 51,                    /* LENGTH  */
  YYSYMBOL_VACATION = 52,                  /* VACATION  */
  YYSYMBOL_DAYS = 53,                      /* DAYS  */
  YYSYMBOL_SUBJECT = 54,                   /* SUBJECT  */
  YYSYMBOL_FROM = 55,                      /* FROM  */
  YYSYMBOL_ADDRESSES = 56,                 /* ADDRESSES  */
  YYSYMBOL_MIME = 57,                      /* MIME  */
  YYSYMBOL_HANDLE = 58,                    /* HANDLE  */
  YYSYMBOL_SECONDS = 59,                   /* SECONDS  */
  YYSYMBOL_COUNT = 60,                     /* COUNT  */
  YYSYMBOL_VALUE = 61,                     /* VALUE  */
  YYSYMBOL_GT = 62,                        /* GT  */
  YYSYMBOL_GE = 63,                        /* GE  */
  YYSYMBOL_LT = 64,                        /* LT  */
  YYSYMBOL_LE = 65,                        /* LE  */
  YYSYMBOL_EQ = 66,                        /* EQ  */
  YYSYMBOL_NE = 67,                        /* NE  */
  YYSYMBOL_FLAGS = 68,                     /* FLAGS  */
  YYSYMBOL_HASFLAG = 69,                   /* HASFLAG  */
  YYSYMBOL_SETFLAG = 70,                   /* SETFLAG  */
  YYSYMBOL_ADDFLAG = 71,                   /* ADDFLAG  */
  YYSYMBOL_REMOVEFLAG = 72,                /* REMOVEFLAG  */
  YYSYMBOL_MARK = 73,                      /* MARK  */
  YYSYMBOL_UNMARK = 74,                    /* UNMARK  */
  YYSYMBOL_USER = 75,                      /* USER  */
  YYSYMBOL_DETAIL = 76,                    /* DETAIL  */
  YYSYMBOL_DATE = 77,                      /* DATE  */
  YYSYMBOL_CURRENTDATE = 78,               /* CURRENTDATE  */
  YYSYMBOL_ORIGINALZONE = 79,              /* ORIGINALZONE  */
  YYSYMBOL_ZONE = 80,                      /* ZONE  */
  YYSYMBOL_TIMEZONE = 81,                  /* TIMEZONE  */
  YYSYMBOL_YEARP = 82,                     /* YEARP  */
  YYSYMBOL_MONTHP = 83,                    /* MONTHP  */
  YYSYMBOL_DAYP = 84,                      /* DAYP  */
  YYSYMBOL_DATEP = 85,                     /* DATEP  */
  YYSYMBOL_JULIAN = 86,                    /* JULIAN  */
  YYSYMBOL_HOURP = 87,                     /* HOURP  */
  YYSYMBOL_MINUTEP = 88,                   /* MINUTEP  */
  YYSYMBOL_SECONDP = 89,                   /* SECONDP  */
  YYSYMBOL_TIMEP = 90,                     /* TIMEP  */
  YYSYMBOL_ISO8601 = 91,                   /* ISO8601  */
  YYSYMBOL_STD11 = 92,                     /* STD11  */
  YYSYMBOL_ZONEP = 93,                     /* ZONEP  */
  YYSYMBOL_WEEKDAYP = 94,                  /* WEEKDAYP  */
  YYSYMBOL_INDEX = 95,                     /* INDEX  */
  YYSYMBOL_LAST = 96,                      /* LAST  */
  YYSYMBOL_ADDHEADER = 97,                 /* ADDHEADER  */
  YYSYMBOL_DELETEHEADER = 98,              /* DELETEHEADER  */
  YYSYMBOL_REJCT = 99,                     /* REJCT  */
  YYSYMBOL_EREJECT = 100,                  /* EREJECT  */
  YYSYMBOL_METHOD = 101,                   /* METHOD  */
  YYSYMBOL_OPTIONS = 102,                  /* OPTIONS  */
  YYSYMBOL_MESSAGE = 103,                  /* MESSAGE  */
  YYSYMBOL_IMPORTANCE = 104,               /* IMPORTANCE  */
  YYSYMBOL_VALIDNOTIFYMETHOD = 105,        /* VALIDNOTIFYMETHOD  */
  YYSYMBOL_NOTIFYMETHODCAPABILITY = 106,   /* NOTIFYMETHODCAPABILITY  */
  YYSYMBOL_NOTIFY = 107,                   /* NOTIFY  */
  YYSYMBOL_ENOTIFY = 108,                  /* ENOTIFY  */
  YYSYMBOL_ENCODEURL = 109,                /* ENCODEURL  */
  YYSYMBOL_DENOTIFY = 110,                 /* DENOTIFY  */
  YYSYMBOL_ID = 111,                       /* ID  */
  YYSYMBOL_ANY = 112,                      /* ANY  */
  YYSYMBOL_LOW = 113,                      /* LOW  */
  YYSYMBOL_NORMAL = 114,                   /* NORMAL  */
  YYSYMBOL_HIGH = 115,                     /* HIGH  */
  YYSYMBOL_IHAVE = 116,                    /* IHAVE  */
  YYSYMBOL_ERROR = 117,                    /* ERROR  */
  YYSYMBOL_MAILBOXEXISTS = 118,            /* MAILBOXEXISTS  */
  YYSYMBOL_CREATE = 119,                   /* CREATE  */
  YYSYMBOL_METADATA = 120,                 /* METADATA  */
  YYSYMBOL_METADATAEXISTS = 121,           /* METADATAEXISTS  */
  YYSYMBOL_SERVERMETADATA = 122,           /* SERVERMETADATA  */
  YYSYMBOL_SERVERMETADATAEXISTS = 123,     /* SERVERMETADATAEXISTS  */
  YYSYMBOL_BYTIMEREL = 124,                /* BYTIMEREL  */
  YYSYMBOL_BYTIMEABS = 125,                /* BYTIMEABS  */
  YYSYMBOL_BYMODE = 126,                   /* BYMODE  */
  YYSYMBOL_BYTRACE = 127,                  /* BYTRACE  */
  YYSYMBOL_DSNNOTIFY = 128,                /* DSNNOTIFY  */
  YYSYMBOL_DSNRET = 129,                   /* DSNRET  */
  YYSYMBOL_VALIDEXTLIST = 130,             /* VALIDEXTLIST  */
  YYSYMBOL_LIST = 131,                     /* LIST  */
  YYSYMBOL_INCLUDE = 132,                  /* INCLUDE  */
  YYSYMBOL_OPTIONAL = 133,                 /* OPTIONAL  */
  YYSYMBOL_ONCE = 134,                     /* ONCE  */
  YYSYMBOL_RETURN = 135,                   /* RETURN  */
  YYSYMBOL_PERSONAL = 136,                 /* PERSONAL  */
  YYSYMBOL_GLOBAL = 137,                   /* GLOBAL  */
  YYSYMBOL_DUPLICATE = 138,                /* DUPLICATE  */
  YYSYMBOL_HEADER = 139,                   /* HEADER  */
  YYSYMBOL_UNIQUEID = 140,                 /* UNIQUEID  */
  YYSYMBOL_SPECIALUSEEXISTS = 141,         /* SPECIALUSEEXISTS  */
  YYSYMBOL_SPECIALUSE = 142,               /* SPECIALUSE  */
  YYSYMBOL_FCC = 143,                      /* FCC  */
  YYSYMBOL_MAILBOXID = 144,                /* MAILBOXID  */
  YYSYMBOL_MAILBOXIDEXISTS = 145,          /* MAILBOXIDEXISTS  */
  YYSYMBOL_LOG = 146,                      /* LOG  */
  YYSYMBOL_JMAPQUERY = 147,                /* JMAPQUERY  */
  YYSYMBOL_SNOOZE = 148,                   /* SNOOZE  */
  YYSYMBOL_MAILBOX = 149,                  /* MAILBOX  */
  YYSYMBOL_ADDFLAGS = 150,                 /* ADDFLAGS  */
  YYSYMBOL_REMOVEFLAGS = 151,              /* REMOVEFLAGS  */
  YYSYMBOL_WEEKDAYS = 152,                 /* WEEKDAYS  */
  YYSYMBOL_153_ = 153,                     /* ';'  */
  YYSYMBOL_154_ = 154,                     /* '['  */
  YYSYMBOL_155_ = 155,                     /* ']'  */
  YYSYMBOL_156_ = 156,                     /* ','  */
  YYSYMBOL_157_ = 157,                     /* '{'  */
  YYSYMBOL_158_ = 158,                     /* '}'  */
  YYSYMBOL_159_ = 159,                     /* '('  */
  YYSYMBOL_160_ = 160,                     /* ')'  */
  YYSYMBOL_YYACCEPT = 161,                 /* $accept  */
  YYSYMBOL_start = 162,                    /* start  */
  YYSYMBOL_reqs = 163,                     /* reqs  */
  YYSYMBOL_commands = 164,                 /* commands  */
  YYSYMBOL_command = 165,                  /* command  */
  YYSYMBOL_optstringlist = 166,            /* optstringlist  */
  YYSYMBOL_stringlist = 167,               /* stringlist  */
  YYSYMBOL_strings = 168,                  /* strings  */
  YYSYMBOL_string1 = 169,                  /* string1  */
  YYSYMBOL_string = 170,                   /* string  */
  YYSYMBOL_require = 171,                  /* require  */
  YYSYMBOL_control = 172,                  /* control  */
  YYSYMBOL_thenelse = 173,                 /* thenelse  */
  YYSYMBOL_elsif = 174,                    /* elsif  */
  YYSYMBOL_block = 175,                    /* block  */
  YYSYMBOL_action = 176,                   /* action  */
  YYSYMBOL_ktags = 177,                    /* ktags  */
  YYSYMBOL_flags = 178,                    /* flags  */
  YYSYMBOL_ftags = 179,                    /* ftags  */
  YYSYMBOL_copy = 180,                     /* copy  */
  YYSYMBOL_create = 181,                   /* create  */
  YYSYMBOL_specialuse = 182,               /* specialuse  */
  YYSYMBOL_mailboxid = 183,                /* mailboxid  */
  YYSYMBOL_rtags = 184,                    /* rtags  */
  YYSYMBOL_delbytags = 185,                /* delbytags  */
  YYSYMBOL_dsntags = 186,                  /* dsntags  */
  YYSYMBOL_stags = 187,                    /* stags  */
  YYSYMBOL_mod40 = 188,                    /* mod40  */
  YYSYMBOL_mod30 = 189,                    /* mod30  */
  YYSYMBOL_mod20 = 190,                    /* mod20  */
  YYSYMBOL_mod15 = 191,                    /* mod15  */
  YYSYMBOL_mod10 = 192,                    /* mod10  */
  YYSYMBOL_vtags = 193,                    /* vtags  */
  YYSYMBOL_fcctags = 194,                  /* fcctags  */
  YYSYMBOL_flagaction = 195,               /* flagaction  */
  YYSYMBOL_flagtags = 196,                 /* flagtags  */
  YYSYMBOL_flagmark = 197,                 /* flagmark  */
  YYSYMBOL_ahtags = 198,                   /* ahtags  */
  YYSYMBOL_dhtags = 199,                   /* dhtags  */
  YYSYMBOL_200_1 = 200,                    /* $@1  */
  YYSYMBOL_201_2 = 201,                    /* $@2  */
  YYSYMBOL_202_3 = 202,                    /* $@3  */
  YYSYMBOL_203_4 = 203,                    /* $@4  */
  YYSYMBOL_reject = 204,                   /* reject  */
  YYSYMBOL_ntags = 205,                    /* ntags  */
  YYSYMBOL_priority = 206,                 /* priority  */
  YYSYMBOL_dtags = 207,                    /* dtags  */
  YYSYMBOL_208_5 = 208,                    /* $@5  */
  YYSYMBOL_itags = 209,                    /* itags  */
  YYSYMBOL_location = 210,                 /* location  */
  YYSYMBOL_sntags = 211,                   /* sntags  */
  YYSYMBOL_weekdaylist = 212,              /* weekdaylist  */
  YYSYMBOL_weekdays = 213,                 /* weekdays  */
  YYSYMBOL_weekday = 214,                  /* weekday  */
  YYSYMBOL_timelist = 215,                 /* timelist  */
  YYSYMBOL_times = 216,                    /* times  */
  YYSYMBOL_time1 = 217,                    /* time1  */
  YYSYMBOL_time = 218,                     /* time  */
  YYSYMBOL_testlist = 219,                 /* testlist  */
  YYSYMBOL_tests = 220,                    /* tests  */
  YYSYMBOL_test = 221,                     /* test  */
  YYSYMBOL_222_6 = 222,                    /* $@6  */
  YYSYMBOL_sizetag = 223,                  /* sizetag  */
  YYSYMBOL_htags = 224,                    /* htags  */
  YYSYMBOL_225_7 = 225,                    /* $@7  */
  YYSYMBOL_226_8 = 226,                    /* $@8  */
  YYSYMBOL_227_9 = 227,                    /* $@9  */
  YYSYMBOL_228_10 = 228,                   /* $@10  */
  YYSYMBOL_matchtype = 229,                /* matchtype  */
  YYSYMBOL_matchtag = 230,                 /* matchtag  */
  YYSYMBOL_relmatch = 231,                 /* relmatch  */
  YYSYMBOL_relation = 232,                 /* relation  */
  YYSYMBOL_listmatch = 233,                /* listmatch  */
  YYSYMBOL_comparator = 234,               /* comparator  */
  YYSYMBOL_collation = 235,                /* collation  */
  YYSYMBOL_idxtags = 236,                  /* idxtags  */
  YYSYMBOL_atags = 237,                    /* atags  */
  YYSYMBOL_238_11 = 238,                   /* $@11  */
  YYSYMBOL_239_12 = 239,                   /* $@12  */
  YYSYMBOL_240_13 = 240,                   /* $@13  */
  YYSYMBOL_241_14 = 241,                   /* $@14  */
  YYSYMBOL_addrpart = 242,                 /* addrpart  */
  YYSYMBOL_addrparttag = 243,              /* addrparttag  */
  YYSYMBOL_subaddress = 244,               /* subaddress  */
  YYSYMBOL_etags = 245,                    /* etags  */
  YYSYMBOL_246_15 = 246,                   /* $@15  */
  YYSYMBOL_247_16 = 247,                   /* $@16  */
  YYSYMBOL_248_17 = 248,                   /* $@17  */
  YYSYMBOL_envtags = 249,                  /* envtags  */
  YYSYMBOL_250_18 = 250,                   /* $@18  */
  YYSYMBOL_251_19 = 251,                   /* $@19  */
  YYSYMBOL_btags = 252,                    /* btags  */
  YYSYMBOL_253_20 = 253,                   /* $@20  */
  YYSYMBOL_254_21 = 254,                   /* $@21  */
  YYSYMBOL_transform = 255,                /* transform  */
  YYSYMBOL_strtags = 256,                  /* strtags  */
  YYSYMBOL_257_22 = 257,                   /* $@22  */
  YYSYMBOL_258_23 = 258,                   /* $@23  */
  YYSYMBOL_259_24 = 259,                   /* $@24  */
  YYSYMBOL_hftags = 260,                   /* hftags  */
  YYSYMBOL_261_25 = 261,                   /* $@25  */
  YYSYMBOL_262_26 = 262,                   /* $@26  */
  YYSYMBOL_dttags = 263,                   /* dttags  */
  YYSYMBOL_264_27 = 264,                   /* $@27  */
  YYSYMBOL_265_28 = 265,                   /* $@28  */
  YYSYMBOL_266_29 = 266,                   /* $@29  */
  YYSYMBOL_zone = 267,                     /* zone  */
  YYSYMBOL_cdtags = 268,                   /* cdtags  */
  YYSYMBOL_269_30 = 269,                   /* $@30  */
  YYSYMBOL_270_31 = 270,                   /* $@31  */
  YYSYMBOL_datepart = 271,                 /* datepart  */
  YYSYMBOL_methtags = 272,                 /* methtags  */
  YYSYMBOL_273_32 = 273,                   /* $@32  */
  YYSYMBOL_274_33 = 274,                   /* $@33  */
  YYSYMBOL_mtags = 275,                    /* mtags  */
  YYSYMBOL_276_34 = 276,                   /* $@34  */
  YYSYMBOL_277_35 = 277,                   /* $@35  */
  YYSYMBOL_duptags = 278,                  /* duptags  */
  YYSYMBOL_idtype = 279                    /* idtype  */
};
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_int16 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  10
/* YYLAST -- Last index in YYTABLE.  */
#define YYLAST   722

/* YYNTOKENS -- Number of terminals.  */
#define YYNTOKENS  161
/* YYNNTS -- Number of nonterminals.  */
#define YYNNTS  119
/* YYNRULES -- Number of rules.  */
#define YYNRULES  321
/* YYNSTATES -- Number of states.  */
#define YYNSTATES  438

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


/* 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_uint8 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,
     159,   160,     2,     2,   156,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,   153,
       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,   154,     2,   155,     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,   157,     2,   158,     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,    62,    63,    64,
      65,    66,    67,    68,    69,    70,    71,    72,    73,    74,
      75,    76,    77,    78,    79,    80,    81,    82,    83,    84,
      85,    86,    87,    88,    89,    90,    91,    92,    93,    94,
      95,    96,    97,    98,    99,   100,   101,   102,   103,   104,
     105,   106,   107,   108,   109,   110,   111,   112,   113,   114,
     115,   116,   117,   118,   119,   120,   121,   122,   123,   124,
     125,   126,   127,   128,   129,   130,   131,   132,   133,   134,
     135,   136,   137,   138,   139,   140,   141,   142,   143,   144,
     145,   146,   147,   148,   149,   150,   151,   152
};

#if YYDEBUG
/* YYRLINE[YYN] -- Source line where rule number YYN was defined.  */
static const yytype_int16 yyrline[] =
{
       0,   358,   358,   359,   363,   364,   369,   370,   374,   375,
     376,   388,   389,   393,   394,   398,   399,   403,   410,   417,
     421,   422,   423,   427,   438,   439,   440,   444,   445,   452,
     453,   454,   455,   456,   458,   461,   465,   467,   470,   474,
     475,   478,   481,   482,   483,   484,   486,   491,   492,   497,
     531,   532,   533,   534,   535,   536,   541,   562,   591,   624,
     662,   663,   664,   676,   683,   693,   707,   720,   732,   748,
     760,   776,   777,   786,   795,   804,   813,   826,   827,   830,
     831,   834,   835,   845,   854,   859,   860,   869,   883,   893,
     904,   915,   924,   934,   938,   964,   965,   966,   971,   972,
     973,   978,   979,   998,   999,  1004,  1005,  1018,  1019,  1019,
    1020,  1020,  1021,  1021,  1022,  1022,  1027,  1028,  1039,  1042,
    1053,  1063,  1066,  1076,  1086,  1097,  1108,  1123,  1124,  1125,
    1130,  1131,  1141,  1141,  1150,  1151,  1160,  1169,  1182,  1183,
    1188,  1189,  1199,  1201,  1212,  1223,  1236,  1237,  1241,  1242,
    1246,  1250,  1251,  1255,  1256,  1260,  1267,  1274,  1278,  1279,
    1283,  1284,  1285,  1286,  1287,  1288,  1292,  1298,  1301,  1303,
    1306,  1308,  1312,  1319,  1321,  1325,  1325,  1328,  1330,  1335,
    1339,  1341,  1348,  1352,  1359,  1363,  1371,  1376,  1378,  1385,
    1392,  1399,  1404,  1409,  1410,  1415,  1416,  1416,  1417,  1417,
    1418,  1418,  1419,  1419,  1424,  1433,  1455,  1456,  1457,  1458,
    1469,  1470,  1475,  1476,  1477,  1478,  1479,  1480,  1485,  1504,
    1518,  1519,  1520,  1532,  1552,  1576,  1577,  1578,  1578,  1579,
    1579,  1580,  1580,  1581,  1581,  1586,  1601,  1602,  1603,  1604,
    1615,  1616,  1621,  1622,  1623,  1623,  1624,  1624,  1625,  1625,
    1630,  1631,  1631,  1632,  1632,  1637,  1638,  1648,  1661,  1661,
    1662,  1662,  1667,  1668,  1673,  1674,  1674,  1675,  1675,  1676,
    1676,  1681,  1682,  1682,  1683,  1683,  1688,  1689,  1690,  1699,
    1699,  1700,  1700,  1701,  1701,  1706,  1723,  1724,  1725,  1725,
    1726,  1726,  1731,  1732,  1733,  1734,  1735,  1736,  1737,  1738,
    1739,  1740,  1741,  1742,  1743,  1748,  1749,  1749,  1750,  1750,
    1755,  1756,  1756,  1757,  1757,  1762,  1763,  1775,  1785,  1794,
    1807,  1808
};
#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", "REQUIRE", "STOP", "DISCARD", "KEEP", "FILEINTO",
  "REDIRECT", "ANYOF", "ALLOF", "EXISTS", "NOT", "SFALSE", "STRUE", "SIZE",
  "HEADERT", "ADDRESS", "ENVELOPE", "COMPARATOR", "OVER", "UNDER", "ALL",
  "LOCALPART", "DOMAIN", "IS", "CONTAINS", "MATCHES", "OCTET",
  "ASCIICASEMAP", "ASCIINUMERIC", "REGEX", "QUOTEREGEX", "COPY", "BODY",
  "RAW", "TEXT", "CONTENT", "ENVIRONMENT", "STRINGT", "SET", "LOWER",
  "UPPER", "LOWERFIRST", "UPPERFIRST", "QUOTEWILDCARD", "LENGTH",
  "VACATION", "DAYS", "SUBJECT", "FROM", "ADDRESSES", "MIME", "HANDLE",
  "SECONDS", "COUNT", "VALUE", "GT", "GE", "LT", "LE", "EQ", "NE", "FLAGS",
  "HASFLAG", "SETFLAG", "ADDFLAG", "REMOVEFLAG", "MARK", "UNMARK", "USER",
  "DETAIL", "DATE", "CURRENTDATE", "ORIGINALZONE", "ZONE", "TIMEZONE",
  "YEARP", "MONTHP", "DAYP", "DATEP", "JULIAN", "HOURP", "MINUTEP",
  "SECONDP", "TIMEP", "ISO8601", "STD11", "ZONEP", "WEEKDAYP", "INDEX",
  "LAST", "ADDHEADER", "DELETEHEADER", "REJCT", "EREJECT", "METHOD",
  "OPTIONS", "MESSAGE", "IMPORTANCE", "VALIDNOTIFYMETHOD",
  "NOTIFYMETHODCAPABILITY", "NOTIFY", "ENOTIFY", "ENCODEURL", "DENOTIFY",
  "ID", "ANY", "LOW", "NORMAL", "HIGH", "IHAVE", "ERROR", "MAILBOXEXISTS",
  "CREATE", "METADATA", "METADATAEXISTS", "SERVERMETADATA",
  "SERVERMETADATAEXISTS", "BYTIMEREL", "BYTIMEABS", "BYMODE", "BYTRACE",
  "DSNNOTIFY", "DSNRET", "VALIDEXTLIST", "LIST", "INCLUDE", "OPTIONAL",
  "ONCE", "RETURN", "PERSONAL", "GLOBAL", "DUPLICATE", "HEADER",
  "UNIQUEID", "SPECIALUSEEXISTS", "SPECIALUSE", "FCC", "MAILBOXID",
  "MAILBOXIDEXISTS", "LOG", "JMAPQUERY", "SNOOZE", "MAILBOX", "ADDFLAGS",
  "REMOVEFLAGS", "WEEKDAYS", "';'", "'['", "']'", "','", "'{'", "'}'",
  "'('", "')'", "$accept", "start", "reqs", "commands", "command",
  "optstringlist", "stringlist", "strings", "string1", "string", "require",
  "control", "thenelse", "elsif", "block", "action", "ktags", "flags",
  "ftags", "copy", "create", "specialuse", "mailboxid", "rtags",
  "delbytags", "dsntags", "stags", "mod40", "mod30", "mod20", "mod15",
  "mod10", "vtags", "fcctags", "flagaction", "flagtags", "flagmark",
  "ahtags", "dhtags", "$@1", "$@2", "$@3", "$@4", "reject", "ntags",
  "priority", "dtags", "$@5", "itags", "location", "sntags", "weekdaylist",
  "weekdays", "weekday", "timelist", "times", "time1", "time", "testlist",
  "tests", "test", "$@6", "sizetag", "htags", "$@7", "$@8", "$@9", "$@10",
  "matchtype", "matchtag", "relmatch", "relation", "listmatch",
  "comparator", "collation", "idxtags", "atags", "$@11", "$@12", "$@13",
  "$@14", "addrpart", "addrparttag", "subaddress", "etags", "$@15", "$@16",
  "$@17", "envtags", "$@18", "$@19", "btags", "$@20", "$@21", "transform",
  "strtags", "$@22", "$@23", "$@24", "hftags", "$@25", "$@26", "dttags",
  "$@27", "$@28", "$@29", "zone", "cdtags", "$@30", "$@31", "datepart",
  "methtags", "$@32", "$@33", "mtags", "$@34", "$@35", "duptags", "idtype", YY_NULLPTR
};

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

#define YYPACT_NINF (-346)

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

#define YYTABLE_NINF (-314)

#define yytable_value_is_error(Yyn) \
  0

/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
   STATE-NUM.  */
static const yytype_int16 yypact[] =
{
      29,     1,    13,   430,    29,  -346,    38,  -109,  -346,  -346,
    -346,  -102,   495,   -80,  -346,  -346,  -346,  -346,  -346,  -346,
    -346,  -346,  -346,  -346,  -346,  -346,  -346,  -346,  -346,  -346,
    -346,    38,  -346,  -346,    38,  -346,  -346,   270,  -346,   -77,
    -346,  -346,    38,  -346,   -87,  -346,  -346,  -346,  -346,   -81,
     -81,     1,   495,  -346,  -346,    76,  -346,  -346,  -346,  -346,
    -346,  -346,  -346,  -346,  -346,     1,  -346,     1,     1,  -346,
      38,  -346,     1,     1,  -346,     1,     1,    38,  -346,   -76,
    -346,    17,    45,   105,   360,   253,     0,     2,   148,   -22,
     -49,    62,  -346,    23,  -346,  -346,     1,  -346,  -346,    38,
     495,  -346,  -346,  -346,  -346,  -346,  -346,   104,    -1,     4,
      11,     6,    37,     5,    30,    32,   561,  -346,    48,  -346,
    -346,    66,     1,    66,  -346,  -346,   160,  -346,     1,  -346,
    -346,   349,   119,     1,  -346,  -346,  -346,    38,    38,  -346,
    -346,  -346,  -346,  -346,  -346,   111,    38,    38,  -346,    38,
      38,  -346,  -346,  -346,  -346,  -346,  -346,  -346,  -346,  -346,
    -346,  -346,  -346,  -346,    38,  -346,  -346,  -346,  -346,  -346,
     120,    38,    38,     1,  -346,    38,   134,    38,  -346,  -346,
    -346,  -346,  -346,  -346,    38,     1,   108,    35,   137,    51,
      38,    38,     1,    38,   -95,    38,  -346,  -346,  -346,  -346,
    -346,  -346,  -346,   108,  -346,  -346,  -346,  -346,  -346,  -346,
    -346,  -346,    38,     1,     1,     3,   174,  -346,  -346,  -346,
    -346,  -346,    28,  -346,    25,    44,  -346,     1,   108,    35,
     137,    51,  -346,  -346,  -346,  -346,  -346,     1,   108,    35,
     137,    51,  -346,  -346,  -346,     1,  -346,   108,    35,   137,
    -346,  -346,     1,  -346,   108,   137,  -346,     1,   108,   137,
       1,   108,    35,   137,     1,   108,   137,  -346,   107,  -346,
     108,   137,    51,  -346,  -346,  -346,  -346,  -346,  -346,  -346,
    -346,  -346,  -346,  -346,  -346,  -346,  -346,  -346,   108,   137,
       1,    38,   108,   137,    38,   108,   137,  -346,     1,    38,
     190,  -346,  -346,  -346,    38,  -346,  -346,    49,   495,   -76,
    -346,  -346,  -346,  -346,  -346,  -346,  -346,  -346,  -346,  -346,
    -346,  -346,  -346,  -346,  -346,  -346,  -346,  -346,  -346,  -346,
    -346,  -346,  -346,  -346,  -346,  -346,  -346,  -346,   222,  -346,
    -346,   157,  -346,   199,  -346,  -346,  -346,  -346,  -346,  -346,
    -346,  -346,    38,  -346,  -346,  -346,  -346,   216,  -346,  -346,
      -6,  -346,  -346,   495,  -346,  -346,  -346,  -346,  -346,  -346,
    -346,  -346,  -346,  -346,  -346,  -346,  -346,  -346,  -346,  -346,
    -346,  -346,  -346,  -346,  -346,  -346,  -346,  -346,  -346,  -346,
    -346,  -346,   616,  -346,  -346,  -346,  -346,  -346,  -346,     1,
    -346,  -346,     1,  -346,  -346,  -346,  -346,  -346,  -346,  -346,
    -346,  -346,  -346,  -346,  -346,  -346,  -346,  -346,  -346,  -346,
    -346,  -346,  -346,  -346,  -346,    56,  -346,  -346,   174,  -346,
       1,  -346,  -346,  -346,   216,  -346,  -346,  -346
};

/* 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_int16 yydefact[] =
{
       4,     0,     0,     0,     4,    18,     0,     0,    13,    17,
       1,     0,     0,     0,    32,    47,    50,    60,    71,    85,
      98,    99,   100,   103,   104,   105,   107,   116,   117,   118,
     130,     0,   134,    46,     0,   140,     3,     0,     8,     0,
     101,    36,     0,     5,     0,    15,    19,    10,   192,     0,
       0,     0,     0,   163,   164,     0,   195,   225,   242,   255,
     250,   264,   271,   276,   286,     0,   305,     0,     0,   310,
       0,   310,     0,     0,   315,     0,     0,     0,    20,     0,
      21,    29,     0,     0,     0,     0,     0,   108,    41,   132,
       0,     0,    44,     0,     7,     9,     0,    39,    14,     0,
       0,   160,   161,   165,   162,   193,   194,     0,   196,   227,
     244,   258,   251,   265,   272,   279,   288,   178,   306,   180,
     181,   311,     0,   311,   185,   186,   187,   188,    17,   190,
     191,     0,    24,     0,    48,    56,    57,     0,     0,    30,
      52,    51,    53,    54,    55,     0,     0,     0,    68,     0,
       0,    62,    31,    61,    63,    64,    82,    77,    78,    79,
      80,    81,    84,    83,     0,    72,    73,    74,    75,    76,
       0,     0,     0,     0,    91,     0,     0,     0,    34,    96,
      95,    97,    93,   106,     0,    11,     0,     0,     0,     0,
       0,     0,     0,     0,     0,     0,   127,   128,   129,    40,
     121,   124,   131,     0,    22,   137,   136,   138,   139,    43,
     135,   156,     0,     0,     0,     0,     0,   142,    45,   151,
     155,    35,   102,    16,     0,   158,   166,     0,     0,     0,
       0,     0,   236,   237,   238,   240,   241,     0,     0,     0,
       0,     0,   226,   235,   239,     0,   243,     0,     0,     0,
     262,   263,     0,   170,     0,     0,   256,     0,     0,     0,
       0,     0,     0,     0,   174,     0,     0,   278,     0,   175,
       0,     0,     0,   277,   292,   293,   294,   295,   296,   297,
     298,   299,   300,   301,   302,   303,   304,   287,     0,     0,
       0,     0,     0,     0,     0,     0,     0,   183,     0,     0,
       0,   319,   320,   321,     0,   189,    28,     0,     0,     0,
      23,    49,    58,    59,    65,    66,    67,    69,    70,    33,
      86,    88,    89,    90,    92,    87,    94,    37,    38,    12,
     206,   207,   208,   209,   210,   211,   109,   204,     0,   218,
     111,     0,   113,     0,   224,   115,   119,   123,   126,   125,
     120,   122,     0,   141,   143,   144,   150,     0,   145,   146,
       0,   153,   157,     0,   167,   197,   199,   201,   203,   168,
     228,   230,   232,   234,   169,   245,   247,   249,   257,   259,
     261,   171,   252,   254,   172,   266,   268,   270,   173,   273,
     275,   285,     0,   280,   282,   284,   289,   291,   177,     0,
     307,   309,     0,   312,   314,   184,   317,   318,   316,    27,
      25,    26,   214,   215,   216,   217,   212,   213,   205,   220,
     221,   222,   219,   223,   133,     0,   148,   152,     0,   159,
       0,   179,   182,   147,     0,   154,   176,   149
};

/* YYPGOTO[NTERM-NUM].  */
static const yytype_int16 yypgoto[] =
{
    -346,  -346,   217,   -26,  -346,  -346,   -51,  -346,   219,    33,
    -346,  -346,   -86,  -346,   -82,  -346,  -346,   133,  -346,   152,
     155,   156,   147,  -346,  -346,  -346,  -346,  -346,  -346,  -346,
    -346,  -346,  -346,   153,  -346,  -346,  -346,  -346,  -346,  -346,
    -346,  -346,  -346,  -346,  -346,   -88,  -346,  -346,  -346,  -346,
    -346,  -346,  -346,  -345,  -346,  -346,    26,  -185,   194,  -117,
     -50,  -346,  -346,  -346,  -346,  -346,  -346,  -346,   332,  -346,
    -346,  -346,  -174,   426,  -346,  -188,  -346,  -346,  -346,  -346,
    -346,   138,  -346,  -346,  -346,  -346,  -346,  -346,  -346,  -346,
    -346,  -346,  -346,  -346,  -346,  -346,  -346,  -346,  -346,  -346,
    -346,  -346,  -346,  -346,  -346,  -346,   139,  -346,  -346,  -346,
    -139,  -346,  -346,  -346,   183,  -346,  -346,  -346,  -346
};

/* YYDEFGOTO[NTERM-NUM].  */
static const yytype_int16 yydefgoto[] =
{
       0,     2,     3,    36,    37,   328,     7,    44,     8,     9,
       4,    38,    78,   310,   132,    39,    81,   179,    82,   141,
     180,   181,   144,    83,   154,   155,    84,   165,   166,   167,
     168,   169,    85,   182,    40,    96,    41,    86,    87,   186,
     187,   188,   189,    42,    88,   201,    89,   203,    91,   210,
      93,   358,   425,   359,   218,   360,   219,   220,   101,   224,
      79,   392,   107,   108,   228,   229,   230,   231,   336,   337,
     338,   418,   340,   342,   422,   345,   109,   238,   239,   240,
     241,   242,   243,   244,   110,   247,   248,   249,   112,   258,
     259,   111,   254,   255,   256,   113,   261,   262,   263,   114,
     265,   266,   115,   270,   271,   272,   273,   116,   288,   289,
     290,   118,   292,   293,   121,   295,   296,   126,   304
};

/* 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[] =
{
     103,   202,   104,     5,     5,     5,     5,   356,     5,     5,
       5,    94,   426,    10,   117,     5,   119,   120,   196,   197,
     198,   124,   125,  -200,   127,   129,  -112,   211,  -231,  -269,
    -260,   232,   233,   234,     5,  -248,     5,     1,   232,   233,
     234,     5,     5,   368,    46,   221,   250,   251,   252,     5,
     225,    47,     5,   373,  -274,   366,  -281,   227,   237,   245,
     253,  -253,   260,   264,    90,   371,     5,    92,    98,    99,
       5,   297,  -308,    80,   376,    97,    95,   305,   100,   235,
     236,   131,   311,   135,   395,   133,   235,   236,   386,   437,
    -313,   196,   197,   198,  -202,  -202,   183,  -114,  -114,  -233,
    -233,   105,   106,   122,   204,   307,   350,   226,   128,     5,
     130,   267,   268,   133,   314,   139,   152,   164,   178,   184,
     185,   199,   323,   320,   209,   308,   309,  -283,  -283,   222,
    -198,   -42,   223,  -110,   329,  -229,  -267,   325,   330,   331,
     332,   348,  -246,   135,   333,   257,   343,   344,   269,   427,
     428,   291,     5,     6,   294,     6,   298,   357,     6,     6,
       6,   341,   354,   355,   136,     6,   339,   138,   334,   335,
     312,   313,   212,   213,   214,   215,   364,   216,   211,   315,
     316,   -17,   317,   318,     6,   362,   369,   137,   391,   138,
     419,   420,   421,   407,   374,   205,   206,   319,   207,   208,
     363,   378,   423,   190,   321,   322,   381,   409,   324,   384,
     326,   433,   434,   388,   134,   140,   133,   327,   299,   300,
     356,    43,   410,   346,   347,    45,   349,   411,   351,   145,
     146,   147,   148,   149,   150,   153,   151,   142,   143,   398,
     217,   200,   361,   435,   102,   353,   429,   405,   246,   191,
     192,   193,   194,   430,   123,   287,   301,     5,     0,   195,
       0,   196,   197,   198,     0,     0,     0,   136,     0,     0,
      -6,    11,     0,     0,     0,    12,     0,     0,     0,    13,
      14,    15,    16,    17,   412,   413,   414,   415,   416,   417,
     137,   177,     0,     0,     0,     0,     0,     0,     0,   302,
     303,     0,     0,     0,     0,     0,   170,   171,   172,   173,
     174,   175,   176,   225,     0,    18,     0,     0,     0,     0,
       0,   133,    19,     0,   399,     0,     0,   402,     0,     0,
       0,     0,   406,     0,     0,     0,     0,   408,     0,     0,
      20,    21,    22,    23,    24,     0,     0,     0,   431,     0,
      11,   432,     0,     0,    12,     0,     0,     0,    13,    14,
      15,    16,    17,     0,     5,     0,     0,    25,    26,    27,
      28,     0,   136,     0,     0,     0,     0,    29,     0,   436,
      30,     0,     0,     0,     0,   424,     0,    31,     0,     0,
       0,     0,     0,     0,    18,   137,   177,   156,     0,     0,
       0,    19,    32,     0,     0,    33,   157,   158,   159,   160,
     161,   162,     0,     0,     0,     0,    34,     0,    35,    20,
      21,    22,    23,    24,     0,     0,     0,     0,    -6,     0,
      -2,    11,     0,     0,     0,    12,     0,     0,     0,    13,
      14,    15,    16,    17,     0,     0,    25,    26,    27,    28,
       0,     0,     0,     0,     0,     0,    29,     0,     0,    30,
       0,     0,     0,     0,     0,     0,    31,     0,     0,   163,
       0,     0,     0,     0,     0,    18,     0,     0,     0,     0,
       0,    32,    19,     0,    33,     0,     0,     0,     0,     0,
       0,     0,     0,     0,     0,    34,    48,    35,     0,     0,
      20,    21,    22,    23,    24,     0,     0,   306,     0,    49,
      50,    51,    52,    53,    54,    55,    56,    57,    58,     0,
       0,     0,     0,     0,     0,     0,     0,    25,    26,    27,
      28,     0,     0,     0,    59,   352,     0,    29,    60,    61,
      30,     0,     0,     0,     0,     0,     0,    31,     0,     0,
       0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
     365,     0,    32,     0,    62,    33,     0,     0,     0,     0,
     370,     0,    63,    64,     0,     0,    34,     0,    35,   375,
       0,     0,     0,     0,     0,  -290,   379,     0,     0,     0,
     382,     0,     0,   385,     0,     0,     0,   389,     0,     0,
      65,    66,   393,     0,     0,     0,     0,     0,     0,     0,
       0,    67,     0,    68,     0,    69,    70,    71,    72,     0,
     396,     0,     0,     0,   400,    73,     0,   403,     0,     0,
       0,     0,     0,    74,     0,     0,    75,     0,     0,     0,
      76,   268,    77,   274,   275,   276,   277,   278,   279,   280,
     281,   282,   283,   284,   285,   286,   367,     0,     0,     0,
       0,     0,     0,     0,     0,     0,   372,     0,     0,     0,
       0,     0,     0,     0,     0,   377,     0,     0,     0,     0,
       0,   380,     0,     0,     0,   383,     0,     0,     0,   387,
       0,     0,   390,     0,     0,     0,     0,   394,   274,   275,
     276,   277,   278,   279,   280,   281,   282,   283,   284,   285,
     286,     0,     0,     0,     0,   397,     0,     0,     0,   401,
       0,     0,   404
};

static const yytype_int16 yycheck[] =
{
      51,    89,    52,     4,     4,     4,     4,     4,     4,     4,
       4,    37,   357,     0,    65,     4,    67,    68,   113,   114,
     115,    72,    73,    24,    75,    76,    24,     4,    24,    24,
      24,    27,    28,    29,     4,    24,     4,     8,    27,    28,
      29,     4,     4,   231,   153,    96,    40,    41,    42,     4,
     100,   153,     4,   241,    24,   229,    24,   108,   109,   110,
     111,    24,   113,   114,    31,   239,     4,    34,   155,   156,
       4,   122,    24,   153,   248,    42,   153,   128,   159,    75,
      76,   157,   133,    38,   272,    68,    75,    76,   262,   434,
      24,   113,   114,   115,    95,    96,    96,    95,    96,    95,
      96,    25,    26,    70,   153,   131,   194,     3,    75,     4,
      77,    79,    80,    68,     3,    82,    83,    84,    85,    86,
      87,    88,   173,     3,    91,     6,     7,    95,    96,    96,
     131,   153,    99,   131,   185,   131,   131,     3,    30,    31,
      32,   192,   131,    38,    36,   112,    95,    96,   115,   155,
     156,   118,     4,   154,   121,   154,   123,   154,   154,   154,
     154,    24,   213,   214,   119,   154,   131,   144,    60,    61,
     137,   138,   149,   150,   151,   152,   227,   154,     4,   146,
     147,   153,   149,   150,   154,   160,   237,   142,    81,   144,
      33,    34,    35,     3,   245,   133,   134,   164,   136,   137,
     156,   252,     3,    55,   171,   172,   257,   158,   175,   260,
     177,   155,   156,   264,    81,    82,    68,   184,    58,    59,
       4,     4,   308,   190,   191,     6,   193,   309,   195,   124,
     125,   126,   127,   128,   129,    83,   131,    82,    82,   290,
      93,    88,   216,   428,    50,   212,   363,   298,   110,   101,
     102,   103,   104,   392,    71,   116,    96,     4,    -1,   111,
      -1,   113,   114,   115,    -1,    -1,    -1,   119,    -1,    -1,
       0,     1,    -1,    -1,    -1,     5,    -1,    -1,    -1,     9,
      10,    11,    12,    13,    62,    63,    64,    65,    66,    67,
     142,   143,    -1,    -1,    -1,    -1,    -1,    -1,    -1,   139,
     140,    -1,    -1,    -1,    -1,    -1,    53,    54,    55,    56,
      57,    58,    59,   363,    -1,    45,    -1,    -1,    -1,    -1,
      -1,    68,    52,    -1,   291,    -1,    -1,   294,    -1,    -1,
      -1,    -1,   299,    -1,    -1,    -1,    -1,   304,    -1,    -1,
      70,    71,    72,    73,    74,    -1,    -1,    -1,   399,    -1,
       1,   402,    -1,    -1,     5,    -1,    -1,    -1,     9,    10,
      11,    12,    13,    -1,     4,    -1,    -1,    97,    98,    99,
     100,    -1,   119,    -1,    -1,    -1,    -1,   107,    -1,   430,
     110,    -1,    -1,    -1,    -1,   352,    -1,   117,    -1,    -1,
      -1,    -1,    -1,    -1,    45,   142,   143,    37,    -1,    -1,
      -1,    52,   132,    -1,    -1,   135,    46,    47,    48,    49,
      50,    51,    -1,    -1,    -1,    -1,   146,    -1,   148,    70,
      71,    72,    73,    74,    -1,    -1,    -1,    -1,   158,    -1,
       0,     1,    -1,    -1,    -1,     5,    -1,    -1,    -1,     9,
      10,    11,    12,    13,    -1,    -1,    97,    98,    99,   100,
      -1,    -1,    -1,    -1,    -1,    -1,   107,    -1,    -1,   110,
      -1,    -1,    -1,    -1,    -1,    -1,   117,    -1,    -1,   109,
      -1,    -1,    -1,    -1,    -1,    45,    -1,    -1,    -1,    -1,
      -1,   132,    52,    -1,   135,    -1,    -1,    -1,    -1,    -1,
      -1,    -1,    -1,    -1,    -1,   146,     1,   148,    -1,    -1,
      70,    71,    72,    73,    74,    -1,    -1,   158,    -1,    14,
      15,    16,    17,    18,    19,    20,    21,    22,    23,    -1,
      -1,    -1,    -1,    -1,    -1,    -1,    -1,    97,    98,    99,
     100,    -1,    -1,    -1,    39,   203,    -1,   107,    43,    44,
     110,    -1,    -1,    -1,    -1,    -1,    -1,   117,    -1,    -1,
      -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
     228,    -1,   132,    -1,    69,   135,    -1,    -1,    -1,    -1,
     238,    -1,    77,    78,    -1,    -1,   146,    -1,   148,   247,
      -1,    -1,    -1,    -1,    -1,    24,   254,    -1,    -1,    -1,
     258,    -1,    -1,   261,    -1,    -1,    -1,   265,    -1,    -1,
     105,   106,   270,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
      -1,   116,    -1,   118,    -1,   120,   121,   122,   123,    -1,
     288,    -1,    -1,    -1,   292,   130,    -1,   295,    -1,    -1,
      -1,    -1,    -1,   138,    -1,    -1,   141,    -1,    -1,    -1,
     145,    80,   147,    82,    83,    84,    85,    86,    87,    88,
      89,    90,    91,    92,    93,    94,   230,    -1,    -1,    -1,
      -1,    -1,    -1,    -1,    -1,    -1,   240,    -1,    -1,    -1,
      -1,    -1,    -1,    -1,    -1,   249,    -1,    -1,    -1,    -1,
      -1,   255,    -1,    -1,    -1,   259,    -1,    -1,    -1,   263,
      -1,    -1,   266,    -1,    -1,    -1,    -1,   271,    82,    83,
      84,    85,    86,    87,    88,    89,    90,    91,    92,    93,
      94,    -1,    -1,    -1,    -1,   289,    -1,    -1,    -1,   293,
      -1,    -1,   296
};

/* YYSTOS[STATE-NUM] -- The symbol kind of the accessing symbol of
   state STATE-NUM.  */
static const yytype_int16 yystos[] =
{
       0,     8,   162,   163,   171,     4,   154,   167,   169,   170,
       0,     1,     5,     9,    10,    11,    12,    13,    45,    52,
      70,    71,    72,    73,    74,    97,    98,    99,   100,   107,
     110,   117,   132,   135,   146,   148,   164,   165,   172,   176,
     195,   197,   204,   163,   168,   169,   153,   153,     1,    14,
      15,    16,    17,    18,    19,    20,    21,    22,    23,    39,
      43,    44,    69,    77,    78,   105,   106,   116,   118,   120,
     121,   122,   123,   130,   138,   141,   145,   147,   173,   221,
     153,   177,   179,   184,   187,   193,   198,   199,   205,   207,
     170,   209,   170,   211,   164,   153,   196,   170,   155,   156,
     159,   219,   219,   167,   221,    25,    26,   223,   224,   237,
     245,   252,   249,   256,   260,   263,   268,   167,   272,   167,
     167,   275,   170,   275,   167,   167,   278,   167,   170,   167,
     170,   157,   175,    68,   178,    38,   119,   142,   144,   170,
     178,   180,   181,   182,   183,   124,   125,   126,   127,   128,
     129,   131,   170,   180,   185,   186,    37,    46,    47,    48,
      49,    50,    51,   109,   170,   188,   189,   190,   191,   192,
      53,    54,    55,    56,    57,    58,    59,   143,   170,   178,
     181,   182,   194,    96,   170,   170,   200,   201,   202,   203,
      55,   101,   102,   103,   104,   111,   113,   114,   115,   170,
     194,   206,   206,   208,   153,   133,   134,   136,   137,   170,
     210,     4,   149,   150,   151,   152,   154,   183,   215,   217,
     218,   167,   170,   170,   220,   221,     3,   167,   225,   226,
     227,   228,    27,    28,    29,    75,    76,   167,   238,   239,
     240,   241,   242,   243,   244,   167,   242,   246,   247,   248,
      40,    41,    42,   167,   253,   254,   255,   170,   250,   251,
     167,   257,   258,   259,   167,   261,   262,    79,    80,   170,
     264,   265,   266,   267,    82,    83,    84,    85,    86,    87,
      88,    89,    90,    91,    92,    93,    94,   267,   269,   270,
     271,   170,   273,   274,   170,   276,   277,   167,   170,    58,
      59,    96,   139,   140,   279,   167,   158,   164,     6,     7,
     174,   167,   170,   170,     3,   170,   170,   170,   170,   170,
       3,   170,   170,   167,   170,     3,   170,   170,   166,   167,
      30,    31,    32,    36,    60,    61,   229,   230,   231,   131,
     233,    24,   234,    95,    96,   236,   170,   170,   167,   170,
     206,   170,   229,   170,   167,   167,     4,   154,   212,   214,
     216,   217,   160,   156,   167,   229,   233,   234,   236,   167,
     229,   233,   234,   236,   167,   229,   233,   234,   167,   229,
     234,   167,   229,   234,   167,   229,   233,   234,   167,   229,
     234,    81,   222,   229,   234,   236,   229,   234,   167,   170,
     229,   234,   170,   229,   234,   167,   170,     3,   170,   158,
     173,   175,    62,    63,    64,    65,    66,    67,   232,    33,
      34,    35,   235,     3,   170,   213,   214,   155,   156,   220,
     271,   167,   167,   155,   156,   218,   167,   214
};

/* YYR1[RULE-NUM] -- Symbol kind of the left-hand side of rule RULE-NUM.  */
static const yytype_int16 yyr1[] =
{
       0,   161,   162,   162,   163,   163,   164,   164,   165,   165,
     165,   166,   166,   167,   167,   168,   168,   169,   170,   171,
     172,   172,   172,   173,   174,   174,   174,   175,   175,   176,
     176,   176,   176,   176,   176,   176,   176,   176,   176,   176,
     176,   176,   176,   176,   176,   176,   176,   177,   177,   178,
     179,   179,   179,   179,   179,   179,   180,   181,   182,   183,
     184,   184,   184,   184,   184,   185,   185,   185,   185,   186,
     186,   187,   187,   187,   187,   187,   187,   188,   188,   189,
     189,   190,   190,   191,   192,   193,   193,   193,   193,   193,
     193,   193,   193,   193,   194,   194,   194,   194,   195,   195,
     195,   196,   196,   197,   197,   198,   198,   199,   200,   199,
     201,   199,   202,   199,   203,   199,   204,   204,   205,   205,
     205,   205,   205,   205,   205,   205,   205,   206,   206,   206,
     207,   207,   208,   207,   209,   209,   209,   209,   210,   210,
     211,   211,   211,   211,   211,   211,   212,   212,   213,   213,
     214,   215,   215,   216,   216,   217,   218,   219,   220,   220,
     221,   221,   221,   221,   221,   221,   221,   221,   221,   221,
     221,   221,   221,   221,   221,   222,   221,   221,   221,   221,
     221,   221,   221,   221,   221,   221,   221,   221,   221,   221,
     221,   221,   221,   223,   223,   224,   225,   224,   226,   224,
     227,   224,   228,   224,   229,   229,   230,   230,   230,   230,
     231,   231,   232,   232,   232,   232,   232,   232,   233,   234,
     235,   235,   235,   236,   236,   237,   237,   238,   237,   239,
     237,   240,   237,   241,   237,   242,   243,   243,   243,   243,
     244,   244,   245,   245,   246,   245,   247,   245,   248,   245,
     249,   250,   249,   251,   249,   252,   252,   252,   253,   252,
     254,   252,   255,   255,   256,   257,   256,   258,   256,   259,
     256,   260,   261,   260,   262,   260,   263,   263,   263,   264,
     263,   265,   263,   266,   263,   267,   268,   268,   269,   268,
     270,   268,   271,   271,   271,   271,   271,   271,   271,   271,
     271,   271,   271,   271,   271,   272,   273,   272,   274,   272,
     275,   276,   275,   277,   275,   278,   278,   278,   278,   278,
     279,   279
};

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


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 (sscript, 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, sscript); \
      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, sieve_script_t *sscript)
{
  FILE *yyoutput = yyo;
  YY_USE (yyoutput);
  YY_USE (sscript);
  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, sieve_script_t *sscript)
{
  YYFPRINTF (yyo, "%s %s (",
             yykind < YYNTOKENS ? "token" : "nterm", yysymbol_name (yykind));

  yy_symbol_value_print (yyo, yykind, yyvaluep, sscript);
  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, sieve_script_t *sscript)
{
  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)], sscript);
      YYFPRINTF (stderr, "\n");
    }
}

# define YY_REDUCE_PRINT(Rule)          \
do {                                    \
  if (yydebug)                          \
    yy_reduce_print (yyssp, yyvsp, Rule, sscript); \
} 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, sieve_script_t *sscript)
{
  YY_USE (yyvaluep);
  YY_USE (sscript);
  if (!yymsg)
    yymsg = "Deleting";
  YY_SYMBOL_PRINT (yymsg, yykind, yyvaluep, yylocationp);

  YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
  switch (yykind)
    {
    case YYSYMBOL_STRING: /* STRING  */
#line 164 "sieve/sieve.y"
             { free(((*yyvaluep).sval));          }
#line 2031 "sieve/sieve.c"
        break;

    case YYSYMBOL_commands: /* commands  */
#line 160 "sieve/sieve.y"
             { free_tree(((*yyvaluep).cl));     }
#line 2037 "sieve/sieve.c"
        break;

    case YYSYMBOL_command: /* command  */
#line 160 "sieve/sieve.y"
             { free_tree(((*yyvaluep).cl));     }
#line 2043 "sieve/sieve.c"
        break;

    case YYSYMBOL_optstringlist: /* optstringlist  */
#line 163 "sieve/sieve.y"
             { strarray_free(((*yyvaluep).sl)); }
#line 2049 "sieve/sieve.c"
        break;

    case YYSYMBOL_stringlist: /* stringlist  */
#line 163 "sieve/sieve.y"
             { strarray_free(((*yyvaluep).sl)); }
#line 2055 "sieve/sieve.c"
        break;

    case YYSYMBOL_strings: /* strings  */
#line 163 "sieve/sieve.y"
             { strarray_free(((*yyvaluep).sl)); }
#line 2061 "sieve/sieve.c"
        break;

    case YYSYMBOL_string1: /* string1  */
#line 163 "sieve/sieve.y"
             { strarray_free(((*yyvaluep).sl)); }
#line 2067 "sieve/sieve.c"
        break;

    case YYSYMBOL_string: /* string  */
#line 164 "sieve/sieve.y"
             { free(((*yyvaluep).sval));          }
#line 2073 "sieve/sieve.c"
        break;

    case YYSYMBOL_control: /* control  */
#line 160 "sieve/sieve.y"
             { free_tree(((*yyvaluep).cl));     }
#line 2079 "sieve/sieve.c"
        break;

    case YYSYMBOL_thenelse: /* thenelse  */
#line 160 "sieve/sieve.y"
             { free_tree(((*yyvaluep).cl));     }
#line 2085 "sieve/sieve.c"
        break;

    case YYSYMBOL_elsif: /* elsif  */
#line 160 "sieve/sieve.y"
             { free_tree(((*yyvaluep).cl));     }
#line 2091 "sieve/sieve.c"
        break;

    case YYSYMBOL_block: /* block  */
#line 160 "sieve/sieve.y"
             { free_tree(((*yyvaluep).cl));     }
#line 2097 "sieve/sieve.c"
        break;

    case YYSYMBOL_action: /* action  */
#line 160 "sieve/sieve.y"
             { free_tree(((*yyvaluep).cl));     }
#line 2103 "sieve/sieve.c"
        break;

    case YYSYMBOL_timelist: /* timelist  */
#line 165 "sieve/sieve.y"
             { arrayu64_free(((*yyvaluep).nl)); }
#line 2109 "sieve/sieve.c"
        break;

    case YYSYMBOL_times: /* times  */
#line 165 "sieve/sieve.y"
             { arrayu64_free(((*yyvaluep).nl)); }
#line 2115 "sieve/sieve.c"
        break;

    case YYSYMBOL_time1: /* time1  */
#line 165 "sieve/sieve.y"
             { arrayu64_free(((*yyvaluep).nl)); }
#line 2121 "sieve/sieve.c"
        break;

    case YYSYMBOL_testlist: /* testlist  */
#line 161 "sieve/sieve.y"
             { free_testlist(((*yyvaluep).testl)); }
#line 2127 "sieve/sieve.c"
        break;

    case YYSYMBOL_tests: /* tests  */
#line 161 "sieve/sieve.y"
             { free_testlist(((*yyvaluep).testl)); }
#line 2133 "sieve/sieve.c"
        break;

    case YYSYMBOL_test: /* test  */
#line 162 "sieve/sieve.y"
             { free_test(((*yyvaluep).test));     }
#line 2139 "sieve/sieve.c"
        break;

      default:
        break;
    }
  YY_IGNORE_MAYBE_UNINITIALIZED_END
}






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

int
yyparse (sieve_script_t *sscript)
{
/* 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, sscript);
    }

  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: reqs  */
#line 358 "sieve/sieve.y"
                                 { sscript->cmds = NULL; }
#line 2415 "sieve/sieve.c"
    break;

  case 3: /* start: reqs commands  */
#line 359 "sieve/sieve.y"
                                 { sscript->cmds = (yyvsp[0].cl); }
#line 2421 "sieve/sieve.c"
    break;

  case 7: /* commands: command commands  */
#line 370 "sieve/sieve.y"
                                 { (yyval.cl) = (yyvsp[-1].cl); (yyval.cl)->next = (yyvsp[0].cl); }
#line 2427 "sieve/sieve.c"
    break;

  case 10: /* command: error ';'  */
#line 376 "sieve/sieve.y"
                                 {
                                     struct buf buf = BUF_INITIALIZER;
                                     buf_printf(&buf, "%s: line %d",
                                                error_message(SIEVE_UNSUPP_EXT),
                                                sievelineno);
                                     sscript->support |= SIEVE_CAPA_IHAVE;
                                     (yyval.cl) = build_rej_err(sscript, ERROR,
                                                        buf_release(&buf));
                                 }
#line 2441 "sieve/sieve.c"
    break;

  case 11: /* optstringlist: %empty  */
#line 388 "sieve/sieve.y"
                                 { (yyval.sl) = strarray_new(); }
#line 2447 "sieve/sieve.c"
    break;

  case 14: /* stringlist: '[' strings ']'  */
#line 394 "sieve/sieve.y"
                                 { (yyval.sl) = (yyvsp[-1].sl); }
#line 2453 "sieve/sieve.c"
    break;

  case 16: /* strings: strings ',' string  */
#line 399 "sieve/sieve.y"
                                 { (yyval.sl) = (yyvsp[-2].sl); strarray_appendm((yyval.sl), (yyvsp[0].sval)); }
#line 2459 "sieve/sieve.c"
    break;

  case 17: /* string1: string  */
#line 403 "sieve/sieve.y"
                                 {
                                     (yyval.sl) = strarray_new();
                                     strarray_appendm((yyval.sl), (yyvsp[0].sval));
                                 }
#line 2468 "sieve/sieve.c"
    break;

  case 18: /* string: STRING  */
#line 410 "sieve/sieve.y"
                                 { (yyval.sval) = (yyvsp[0].sval); chk_match_vars(sscript, (yyval.sval)); }
#line 2474 "sieve/sieve.c"
    break;

  case 19: /* require: REQUIRE stringlist ';'  */
#line 417 "sieve/sieve.y"
                                 { check_reqs(sscript, (yyvsp[-1].sl)); }
#line 2480 "sieve/sieve.c"
    break;

  case 20: /* control: IF thenelse  */
#line 421 "sieve/sieve.y"
                                 { (yyval.cl) = (yyvsp[0].cl); }
#line 2486 "sieve/sieve.c"
    break;

  case 21: /* control: STOP ';'  */
#line 422 "sieve/sieve.y"
                                 { (yyval.cl) = new_command(STOP, sscript); }
#line 2492 "sieve/sieve.c"
    break;

  case 22: /* control: ERROR string ';'  */
#line 423 "sieve/sieve.y"
                                 { (yyval.cl) = build_rej_err(sscript, ERROR, (yyvsp[-1].sval)); }
#line 2498 "sieve/sieve.c"
    break;

  case 23: /* thenelse: test block elsif  */
#line 427 "sieve/sieve.y"
                                 { 
                                     if ((yyvsp[-2].test)->ignore_err) {
                                         /* end of block - decrement counter */
                                         sscript->ignore_err--;
                                     }

                                     (yyval.cl) = new_if((yyvsp[-2].test), (yyvsp[-1].cl), (yyvsp[0].cl));
                                 }
#line 2511 "sieve/sieve.c"
    break;

  case 24: /* elsif: %empty  */
#line 438 "sieve/sieve.y"
                                 { (yyval.cl) = NULL; }
#line 2517 "sieve/sieve.c"
    break;

  case 25: /* elsif: ELSIF thenelse  */
#line 439 "sieve/sieve.y"
                                 { (yyval.cl) = (yyvsp[0].cl); }
#line 2523 "sieve/sieve.c"
    break;

  case 26: /* elsif: ELSE block  */
#line 440 "sieve/sieve.y"
                                 { (yyval.cl) = (yyvsp[0].cl); }
#line 2529 "sieve/sieve.c"
    break;

  case 27: /* block: '{' commands '}'  */
#line 444 "sieve/sieve.y"
                                 { (yyval.cl) = (yyvsp[-1].cl); }
#line 2535 "sieve/sieve.c"
    break;

  case 28: /* block: '{' '}'  */
#line 445 "sieve/sieve.y"
                                 { (yyval.cl) = NULL; }
#line 2541 "sieve/sieve.c"
    break;

  case 29: /* action: KEEP ktags  */
#line 452 "sieve/sieve.y"
                                 { (yyval.cl) = build_keep(sscript, (yyvsp[0].cl)); }
#line 2547 "sieve/sieve.c"
    break;

  case 30: /* action: FILEINTO ftags string  */
#line 453 "sieve/sieve.y"
                                 { (yyval.cl) = build_fileinto(sscript, (yyvsp[-1].cl), (yyvsp[0].sval)); }
#line 2553 "sieve/sieve.c"
    break;

  case 31: /* action: REDIRECT rtags string  */
#line 454 "sieve/sieve.y"
                                 { (yyval.cl) = build_redirect(sscript, (yyvsp[-1].cl), (yyvsp[0].sval)); }
#line 2559 "sieve/sieve.c"
    break;

  case 32: /* action: DISCARD  */
#line 455 "sieve/sieve.y"
                                 { (yyval.cl) = new_command(DISCARD, sscript); }
#line 2565 "sieve/sieve.c"
    break;

  case 33: /* action: SET stags string string  */
#line 457 "sieve/sieve.y"
                                 { (yyval.cl) = build_set(sscript, (yyvsp[-2].cl), (yyvsp[-1].sval), (yyvsp[0].sval)); }
#line 2571 "sieve/sieve.c"
    break;

  case 34: /* action: VACATION vtags string  */
#line 458 "sieve/sieve.y"
                                 { (yyval.cl) = build_vacation(sscript, (yyvsp[-1].cl), (yyvsp[0].sval)); }
#line 2577 "sieve/sieve.c"
    break;

  case 35: /* action: flagaction flagtags stringlist  */
#line 462 "sieve/sieve.y"
                                 { (yyval.cl) = build_flag(sscript, (yyvsp[-1].cl), (yyvsp[0].sl)); }
#line 2583 "sieve/sieve.c"
    break;

  case 36: /* action: flagmark  */
#line 465 "sieve/sieve.y"
                                 { (yyval.cl) = new_command((yyvsp[0].nval), sscript); }
#line 2589 "sieve/sieve.c"
    break;

  case 37: /* action: ADDHEADER ahtags string string  */
#line 468 "sieve/sieve.y"
                                 { (yyval.cl) = build_addheader(sscript,
                                                        (yyvsp[-2].cl), (yyvsp[-1].sval), (yyvsp[0].sval)); }
#line 2596 "sieve/sieve.c"
    break;

  case 38: /* action: DELETEHEADER dhtags string optstringlist  */
#line 471 "sieve/sieve.y"
                                 { (yyval.cl) = build_deleteheader(sscript,
                                                           (yyvsp[-2].cl), (yyvsp[-1].sval), (yyvsp[0].sl)); }
#line 2603 "sieve/sieve.c"
    break;

  case 39: /* action: reject string  */
#line 474 "sieve/sieve.y"
                                 { (yyval.cl) = build_rej_err(sscript, (yyvsp[-1].nval), (yyvsp[0].sval)); }
#line 2609 "sieve/sieve.c"
    break;

  case 40: /* action: NOTIFY ntags string  */
#line 475 "sieve/sieve.y"
                                 { (yyval.cl) = build_notify(sscript,
                                                     ENOTIFY, (yyvsp[-1].cl), (yyvsp[0].sval)); }
#line 2616 "sieve/sieve.c"
    break;

  case 41: /* action: NOTIFY ntags  */
#line 478 "sieve/sieve.y"
                                 { (yyval.cl) = build_notify(sscript,
                                                     NOTIFY, (yyvsp[0].cl), NULL); }
#line 2623 "sieve/sieve.c"
    break;

  case 42: /* action: DENOTIFY dtags  */
#line 481 "sieve/sieve.y"
                                 { (yyval.cl) = build_denotify(sscript, (yyvsp[0].cl)); }
#line 2629 "sieve/sieve.c"
    break;

  case 43: /* action: INCLUDE itags string  */
#line 482 "sieve/sieve.y"
                                 { (yyval.cl) = build_include(sscript, (yyvsp[-1].cl), (yyvsp[0].sval)); }
#line 2635 "sieve/sieve.c"
    break;

  case 44: /* action: LOG string  */
#line 483 "sieve/sieve.y"
                                 { (yyval.cl) = build_log(sscript, (yyvsp[0].sval)); }
#line 2641 "sieve/sieve.c"
    break;

  case 45: /* action: SNOOZE sntags timelist  */
#line 485 "sieve/sieve.y"
                                 { (yyval.cl) = build_snooze(sscript, (yyvsp[-1].cl), (yyvsp[0].nl)); }
#line 2647 "sieve/sieve.c"
    break;

  case 46: /* action: RETURN  */
#line 486 "sieve/sieve.y"
                                 { (yyval.cl) = new_command(RETURN, sscript); }
#line 2653 "sieve/sieve.c"
    break;

  case 47: /* ktags: %empty  */
#line 491 "sieve/sieve.y"
                                 { (yyval.cl) = new_command(KEEP, sscript); }
#line 2659 "sieve/sieve.c"
    break;

  case 49: /* flags: FLAGS stringlist  */
#line 497 "sieve/sieve.y"
                                 {
                                     /* $0 refers to ktags, ftags, or vtags */
                                     commandlist_t *c = (yyvsp[-2].cl);
                                     strarray_t **flags = NULL;

                                     switch (c->type) {
                                     case KEEP:
                                         flags = &c->u.k.flags; break;
                                     case FILEINTO:
                                         flags = &c->u.f.flags; break;
                                     case VACATION:
                                         flags = &c->u.v.fcc.flags; break;
                                     case ENOTIFY:
                                         flags = &c->u.n.fcc.flags; break;
                                     }

                                     if (*flags != NULL) {
                                         sieveerror_c(sscript,
                                                      SIEVE_DUPLICATE_TAG,
                                                      ":flags");
                                         strarray_free(*flags);
                                     }
                                     else if (!supported(SIEVE_CAPA_IMAP4FLAGS)) {
                                         sieveerror_c(sscript,
                                                      SIEVE_MISSING_REQUIRE,
                                                      "imap4flags");
                                     }

                                     *flags = (yyvsp[0].sl);
                                 }
#line 2694 "sieve/sieve.c"
    break;

  case 50: /* ftags: %empty  */
#line 531 "sieve/sieve.y"
                                 { (yyval.cl) = new_command(FILEINTO, sscript); }
#line 2700 "sieve/sieve.c"
    break;

  case 56: /* copy: COPY  */
#line 541 "sieve/sieve.y"
                                 {
                                     /* $0 refers to ftags or rtags */
                                     commandlist_t *c = (yyvsp[-1].cl);
                                     int *copy = (c->type == FILEINTO) ?
                                         &c->u.f.copy : &c->u.r.copy;

                                     if ((*copy)++) {
                                         sieveerror_c(sscript,
                                                      SIEVE_DUPLICATE_TAG,
                                                      ":copy");
                                     }
                                     else if (!supported(SIEVE_CAPA_COPY)) {
                                         sieveerror_c(sscript,
                                                      SIEVE_MISSING_REQUIRE,
                                                      "copy");
                                     }
                                 }
#line 2722 "sieve/sieve.c"
    break;

  case 57: /* create: CREATE  */
#line 562 "sieve/sieve.y"
                                {
                                     /* $0 refers to ftags or vtags */
                                     commandlist_t *c = (yyvsp[-1].cl);
                                     int *create = NULL;

                                     switch (c->type) {
                                     case FILEINTO:
                                         create = &c->u.f.create; break;
                                     case VACATION:
                                         create = &c->u.v.fcc.create; break;
                                     case ENOTIFY:
                                         create = &c->u.n.fcc.create; break;
                                     }

                                     if ((*create)++) {
                                         sieveerror_c(sscript,
                                                      SIEVE_DUPLICATE_TAG,
                                                      ":create");
                                     }
                                     else if (!supported(SIEVE_CAPA_MAILBOX)) {
                                         sieveerror_c(sscript,
                                                      SIEVE_MISSING_REQUIRE,
                                                      "mailbox");
                                     }
                                 }
#line 2752 "sieve/sieve.c"
    break;

  case 58: /* specialuse: SPECIALUSE string  */
#line 591 "sieve/sieve.y"
                                 {
                                     /* $0 refers to ftags or vtags */
                                     commandlist_t *c = (yyvsp[-2].cl);
                                     char **specialuse = NULL;

                                     switch (c->type) {
                                     case FILEINTO:
                                         specialuse = &c->u.f.specialuse;
                                         break;
                                     case VACATION:
                                         specialuse = &c->u.v.fcc.specialuse;
                                         break;
                                     case ENOTIFY:
                                         specialuse = &c->u.n.fcc.specialuse;
                                         break;
                                     }

                                     if (*specialuse != NULL) {
                                         sieveerror_c(sscript,
                                                      SIEVE_DUPLICATE_TAG,
                                                      ":specialuse");
                                         free(*specialuse);
                                     }
                                     else if (!supported(SIEVE_CAPA_SPECIAL_USE)) {
                                         sieveerror_c(sscript,
                                                      SIEVE_MISSING_REQUIRE,
                                                      "special-use");
                                     }

                                     *specialuse = (yyvsp[0].sval);
                                 }
#line 2788 "sieve/sieve.c"
    break;

  case 59: /* mailboxid: MAILBOXID string  */
#line 624 "sieve/sieve.y"
                                 {
                                     /* $0 refers to ftags, sntags or vtags */
                                     commandlist_t *c = (yyvsp[-2].cl);
                                     char **mailboxid = NULL;

                                     switch (c->type) {
                                     case FILEINTO:
                                         mailboxid = &c->u.f.mailboxid;
                                         break;
                                     case SNOOZE:
                                         mailboxid = &c->u.sn.mailbox;
                                         break;
                                     case VACATION:
                                         mailboxid = &c->u.v.fcc.mailboxid;
                                         break;
                                     case ENOTIFY:
                                         mailboxid = &c->u.n.fcc.mailboxid;
                                         break;
                                     }

                                     if (*mailboxid != NULL) {
                                         sieveerror_c(sscript,
                                                      SIEVE_DUPLICATE_TAG,
                                                      ":mailboxid");
                                         free(*mailboxid);
                                     }
                                     else if (!supported(SIEVE_CAPA_MAILBOXID)) {
                                         sieveerror_c(sscript,
                                                      SIEVE_MISSING_REQUIRE,
                                                      "mailboxid");
                                     }

                                     *mailboxid = (yyvsp[0].sval);
                                 }
#line 2827 "sieve/sieve.c"
    break;

  case 60: /* rtags: %empty  */
#line 662 "sieve/sieve.y"
                                 { (yyval.cl) = new_command(REDIRECT, sscript); }
#line 2833 "sieve/sieve.c"
    break;

  case 62: /* rtags: rtags LIST  */
#line 664 "sieve/sieve.y"
                                 {
                                     if ((yyval.cl)->u.r.list++) {
                                         sieveerror_c(sscript,
                                                      SIEVE_DUPLICATE_TAG,
                                                      ":list");
                                     }
                                     else if (!supported(SIEVE_CAPA_EXTLISTS)) {
                                         sieveerror_c(sscript,
                                                      SIEVE_MISSING_REQUIRE,
                                                      "extlists");
                                     }
                                 }
#line 2850 "sieve/sieve.c"
    break;

  case 63: /* rtags: rtags delbytags  */
#line 676 "sieve/sieve.y"
                                 {
                                     if (!supported(SIEVE_CAPA_REDIR_DELBY)) {
                                         sieveerror_c(sscript,
                                                      SIEVE_MISSING_REQUIRE,
                                                      "redirect-deliverby");
                                     }
                                 }
#line 2862 "sieve/sieve.c"
    break;

  case 64: /* rtags: rtags dsntags  */
#line 683 "sieve/sieve.y"
                                 {
                                     if (!supported(SIEVE_CAPA_REDIR_DSN)) {
                                         sieveerror_c(sscript,
                                                      SIEVE_MISSING_REQUIRE,
                                                      "redirect-dsn");
                                     }
                                 }
#line 2874 "sieve/sieve.c"
    break;

  case 65: /* delbytags: BYTIMEREL NUMBER  */
#line 693 "sieve/sieve.y"
                                 {
                                     /* $0 refers to rtags */
                                     commandlist_t *c = (yyvsp[-2].cl);

                                     if (c->u.r.bytime != NULL) {
                                         sieveerror_c(sscript,
                                                      SIEVE_DUPLICATE_TAG,
                                                      ":bytime*");
                                     }                                         

                                     struct buf buf = BUF_INITIALIZER;
                                     buf_printf(&buf, "+%d", (yyvsp[0].nval));
                                     c->u.r.bytime = buf_release(&buf);
                                 }
#line 2893 "sieve/sieve.c"
    break;

  case 66: /* delbytags: BYTIMEABS string  */
#line 707 "sieve/sieve.y"
                                 {
                                     /* $0 refers to rtags */
                                     commandlist_t *c = (yyvsp[-2].cl);

                                     if (c->u.r.bytime != NULL) {
                                         sieveerror_c(sscript,
                                                      SIEVE_DUPLICATE_TAG,
                                                      ":bytimerelative"
                                                      " OR :bytimeabsolute");
                                     }

                                     c->u.r.bytime = (yyvsp[0].sval);
                                 }
#line 2911 "sieve/sieve.c"
    break;

  case 67: /* delbytags: BYMODE string  */
#line 720 "sieve/sieve.y"
                                 {
                                     /* $0 refers to rtags */
                                     commandlist_t *c = (yyvsp[-2].cl);

                                     if (c->u.r.bymode != NULL) {
                                         sieveerror_c(sscript,
                                                      SIEVE_DUPLICATE_TAG,
                                                      ":bymode");
                                     }

                                     c->u.r.bymode = (yyvsp[0].sval);
                                 }
#line 2928 "sieve/sieve.c"
    break;

  case 68: /* delbytags: BYTRACE  */
#line 732 "sieve/sieve.y"
                                 {
                                     /* $0 refers to rtags */
                                     commandlist_t *c = (yyvsp[-1].cl);

                                     if (c->u.r.bytrace != 0) {
                                         sieveerror_c(sscript,
                                                      SIEVE_DUPLICATE_TAG,
                                                      ":bytrace");
                                     }

                                     c->u.r.bytrace = 1;
                                 }
#line 2945 "sieve/sieve.c"
    break;

  case 69: /* dsntags: DSNNOTIFY string  */
#line 748 "sieve/sieve.y"
                                 {
                                     /* $0 refers to rtags */
                                     commandlist_t *c = (yyvsp[-2].cl);

                                     if (c->u.r.dsn_notify != NULL) {
                                         sieveerror_c(sscript,
                                                      SIEVE_DUPLICATE_TAG,
                                                      ":notify");
                                     }                                         

                                     c->u.r.dsn_notify = (yyvsp[0].sval);
                                 }
#line 2962 "sieve/sieve.c"
    break;

  case 70: /* dsntags: DSNRET string  */
#line 760 "sieve/sieve.y"
                                 {
                                     /* $0 refers to rtags */
                                     commandlist_t *c = (yyvsp[-2].cl);

                                     if (c->u.r.dsn_ret != NULL) {
                                         sieveerror_c(sscript,
                                                      SIEVE_DUPLICATE_TAG,
                                                      ":ret");
                                     }

                                     c->u.r.dsn_ret = (yyvsp[0].sval);
                                 }
#line 2979 "sieve/sieve.c"
    break;

  case 71: /* stags: %empty  */
#line 776 "sieve/sieve.y"
                                 { (yyval.cl) = new_command(SET, sscript); }
#line 2985 "sieve/sieve.c"
    break;

  case 72: /* stags: stags mod40  */
#line 777 "sieve/sieve.y"
                                 {
                                     if ((yyval.cl)->u.s.mod40) {
                                         sieveerror_c(sscript,
                                                      SIEVE_DUPLICATE_TAG,
                                                      "precedence 40 modifier");
                                     }

                                     (yyval.cl)->u.s.mod40 = (yyvsp[0].nval);
                                 }
#line 2999 "sieve/sieve.c"
    break;

  case 73: /* stags: stags mod30  */
#line 786 "sieve/sieve.y"
                                 {
                                     if ((yyval.cl)->u.s.mod30) {
                                         sieveerror_c(sscript,
                                                      SIEVE_DUPLICATE_TAG,
                                                      "precedence 30 modifier");
                                     }

                                     (yyval.cl)->u.s.mod30 = (yyvsp[0].nval);
                                 }
#line 3013 "sieve/sieve.c"
    break;

  case 74: /* stags: stags mod20  */
#line 795 "sieve/sieve.y"
                                 {
                                     if ((yyval.cl)->u.s.mod20) {
                                         sieveerror_c(sscript,
                                                      SIEVE_DUPLICATE_TAG,
                                                      "precedence 20 modifier");
                                     }

                                     (yyval.cl)->u.s.mod20 = (yyvsp[0].nval);
                                 }
#line 3027 "sieve/sieve.c"
    break;

  case 75: /* stags: stags mod15  */
#line 804 "sieve/sieve.y"
                                 {
                                     if ((yyval.cl)->u.s.mod15) {
                                         sieveerror_c(sscript,
                                                      SIEVE_DUPLICATE_TAG,
                                                      "precedence 15 modifier");
                                     }

                                     (yyval.cl)->u.s.mod15 = (yyvsp[0].nval);
                                 }
#line 3041 "sieve/sieve.c"
    break;

  case 76: /* stags: stags mod10  */
#line 813 "sieve/sieve.y"
                                 {
                                     if ((yyval.cl)->u.s.mod10) {
                                         sieveerror_c(sscript,
                                                      SIEVE_DUPLICATE_TAG,
                                                      "precedence 10 modifier");
                                     }

                                     (yyval.cl)->u.s.mod10 = (yyvsp[0].nval);
                                 }
#line 3055 "sieve/sieve.c"
    break;

  case 82: /* mod20: QUOTEREGEX  */
#line 835 "sieve/sieve.y"
                                { 
                                     if (!supported(SIEVE_CAPA_REGEX)) {
                                         sieveerror_c(sscript,
                                                      SIEVE_MISSING_REQUIRE,
                                                      "regex");
                                     }
                                 }
#line 3067 "sieve/sieve.c"
    break;

  case 83: /* mod15: ENCODEURL  */
#line 845 "sieve/sieve.y"
                                 { 
                                     if (!supported(SIEVE_CAPA_ENOTIFY)) {
                                         sieveerror_c(sscript,
                                                      SIEVE_MISSING_REQUIRE,
                                                      "enotify");
                                     }
                                 }
#line 3079 "sieve/sieve.c"
    break;

  case 85: /* vtags: %empty  */
#line 859 "sieve/sieve.y"
                                 { (yyval.cl) = new_command(VACATION, sscript); }
#line 3085 "sieve/sieve.c"
    break;

  case 86: /* vtags: vtags DAYS NUMBER  */
#line 860 "sieve/sieve.y"
                                 {
                                     if ((yyval.cl)->u.v.seconds != -1) {
                                         sieveerror_c(sscript,
                                                      SIEVE_DUPLICATE_TAG,
                                                      ":days");
                                     }

                                     (yyval.cl)->u.v.seconds = (yyvsp[0].nval) * DAY2SEC;
                                 }
#line 3099 "sieve/sieve.c"
    break;

  case 87: /* vtags: vtags SECONDS NUMBER  */
#line 869 "sieve/sieve.y"
                                 {
                                     if (!supported(SIEVE_CAPA_VACATION_SEC)) {
                                         sieveerror_c(sscript,
                                                      SIEVE_MISSING_REQUIRE,
                                                      "vacation-seconds");
                                     }
                                     if ((yyval.cl)->u.v.seconds != -1) {
                                         sieveerror_c(sscript,
                                                      SIEVE_DUPLICATE_TAG,
                                                      ":seconds");
                                     }

                                     (yyval.cl)->u.v.seconds = (yyvsp[0].nval);
                                 }
#line 3118 "sieve/sieve.c"
    break;

  case 88: /* vtags: vtags SUBJECT string  */
#line 883 "sieve/sieve.y"
                                 {
                                     if ((yyval.cl)->u.v.subject != NULL) {
                                         sieveerror_c(sscript,
                                                      SIEVE_DUPLICATE_TAG,
                                                      ":subject");
                                         free((yyval.cl)->u.v.subject);
                                     }

                                     (yyval.cl)->u.v.subject = (yyvsp[0].sval);
                                 }
#line 3133 "sieve/sieve.c"
    break;

  case 89: /* vtags: vtags FROM string  */
#line 893 "sieve/sieve.y"
                                 {
                                     if ((yyval.cl)->u.v.from != NULL) {
                                         sieveerror_c(sscript,
                                                      SIEVE_DUPLICATE_TAG,
                                                      ":from");
                                         free((yyval.cl)->u.v.from);
                                     }

                                     (yyval.cl)->u.v.from = (yyvsp[0].sval);
                                 }
#line 3148 "sieve/sieve.c"
    break;

  case 90: /* vtags: vtags ADDRESSES stringlist  */
#line 905 "sieve/sieve.y"
                                 {
                                     if ((yyval.cl)->u.v.addresses != NULL) {
                                         sieveerror_c(sscript,
                                                      SIEVE_DUPLICATE_TAG,
                                                      ":addresses");
                                         strarray_free((yyval.cl)->u.v.addresses);
                                     }

                                     (yyval.cl)->u.v.addresses = (yyvsp[0].sl);
                                 }
#line 3163 "sieve/sieve.c"
    break;

  case 91: /* vtags: vtags MIME  */
#line 915 "sieve/sieve.y"
                                 {
                                     if ((yyval.cl)->u.v.mime != -1) {
                                         sieveerror_c(sscript,
                                                      SIEVE_DUPLICATE_TAG,
                                                      ":mime");
                                     }

                                     (yyval.cl)->u.v.mime = 1;
                                 }
#line 3177 "sieve/sieve.c"
    break;

  case 92: /* vtags: vtags HANDLE string  */
#line 924 "sieve/sieve.y"
                                 {
                                     if ((yyval.cl)->u.v.handle != NULL) {
                                         sieveerror_c(sscript,
                                                      SIEVE_DUPLICATE_TAG,
                                                      ":handle");
                                         free((yyval.cl)->u.v.handle);
                                     }

                                     (yyval.cl)->u.v.handle = (yyvsp[0].sval);
                                 }
#line 3192 "sieve/sieve.c"
    break;

  case 94: /* fcctags: FCC string  */
#line 938 "sieve/sieve.y"
                                 {
                                     /* $0 refers to vtags or ntags */
                                     commandlist_t *c = (yyvsp[-2].cl);
                                     char **folder = NULL;

                                     switch (c->type) {
                                     case VACATION:
                                         folder = &c->u.v.fcc.folder; break;
                                     case ENOTIFY:
                                         folder = &c->u.n.fcc.folder; break;
                                     }

                                     if (*folder != NULL) {
                                         sieveerror_c(sscript,
                                                      SIEVE_DUPLICATE_TAG,
                                                      ":fcc");
                                         free(*folder);
                                     }
                                     else if (!supported(SIEVE_CAPA_FCC)) {
                                         sieveerror_c(sscript,
                                                      SIEVE_MISSING_REQUIRE,
                                                      "fcc");
                                     }

                                     *folder = (yyvsp[0].sval);
                                 }
#line 3223 "sieve/sieve.c"
    break;

  case 101: /* flagtags: %empty  */
#line 978 "sieve/sieve.y"
                                 { (yyval.cl) = new_command((yyvsp[0].nval), sscript); }
#line 3229 "sieve/sieve.c"
    break;

  case 102: /* flagtags: flagtags string  */
#line 979 "sieve/sieve.y"
                                 {
                                     if ((yyval.cl)->u.fl.variable != NULL) {
                                         sieveerror_c(sscript,
                                                      SIEVE_DUPLICATE_ARG,
                                                      "variablename");
                                         free((yyval.cl)->u.fl.variable);
                                     }
                                     else if (!supported(SIEVE_CAPA_IMAP4FLAGS)) {
                                         sieveerror_c(sscript,
                                                      SIEVE_MISSING_REQUIRE,
                                                      "imap4flags");
                                     }

                                     (yyval.cl)->u.fl.variable = (yyvsp[0].sval);
                                 }
#line 3249 "sieve/sieve.c"
    break;

  case 105: /* ahtags: %empty  */
#line 1004 "sieve/sieve.y"
                                 { (yyval.cl) = new_command(ADDHEADER, sscript); }
#line 3255 "sieve/sieve.c"
    break;

  case 106: /* ahtags: ahtags LAST  */
#line 1005 "sieve/sieve.y"
                                 {
                                     if ((yyval.cl)->u.ah.index < 0) {
                                         sieveerror_c(sscript,
                                                      SIEVE_DUPLICATE_TAG,
                                                      ":last");
                                     }

                                     (yyval.cl)->u.ah.index = -1;
                                 }
#line 3269 "sieve/sieve.c"
    break;

  case 107: /* dhtags: %empty  */
#line 1018 "sieve/sieve.y"
                                 { (yyval.cl) = new_command(DELETEHEADER, sscript);}
#line 3275 "sieve/sieve.c"
    break;

  case 108: /* $@1: %empty  */
#line 1019 "sieve/sieve.y"
                 { ctags = &((yyvsp[0].cl)->u.dh.comp); }
#line 3281 "sieve/sieve.c"
    break;

  case 110: /* $@2: %empty  */
#line 1020 "sieve/sieve.y"
                 { ctags = &((yyvsp[0].cl)->u.dh.comp); }
#line 3287 "sieve/sieve.c"
    break;

  case 112: /* $@3: %empty  */
#line 1021 "sieve/sieve.y"
                 { ctags = &((yyvsp[0].cl)->u.dh.comp); }
#line 3293 "sieve/sieve.c"
    break;

  case 114: /* $@4: %empty  */
#line 1022 "sieve/sieve.y"
                 { ctags = &((yyvsp[0].cl)->u.dh.comp); }
#line 3299 "sieve/sieve.c"
    break;

  case 118: /* ntags: %empty  */
#line 1039 "sieve/sieve.y"
                                 { (yyval.cl) = new_command(ENOTIFY, sscript); }
#line 3305 "sieve/sieve.c"
    break;

  case 119: /* ntags: ntags FROM string  */
#line 1042 "sieve/sieve.y"
                                 {
                                     if ((yyval.cl)->u.n.from != NULL) {
                                         sieveerror_c(sscript,
                                                      SIEVE_DUPLICATE_TAG,
                                                      ":from");
                                         free((yyval.cl)->u.n.from);
                                     }

                                     (yyval.cl)->u.n.from = (yyvsp[0].sval);
                                 }
#line 3320 "sieve/sieve.c"
    break;

  case 120: /* ntags: ntags IMPORTANCE priority  */
#line 1054 "sieve/sieve.y"
                                 {
                                     if ((yyval.cl)->u.n.priority != -1) {
                                         sieveerror_c(sscript,
                                                      SIEVE_DUPLICATE_TAG,
                                                      ":importance");
                                     }

                                     (yyval.cl)->u.n.priority = (yyvsp[0].nval);
                                 }
#line 3334 "sieve/sieve.c"
    break;

  case 122: /* ntags: ntags ID string  */
#line 1066 "sieve/sieve.y"
                                 {
                                     if ((yyval.cl)->u.n.id != NULL) {
                                         sieveerror_c(sscript,
                                                      SIEVE_DUPLICATE_TAG,
                                                      ":id");
                                         free((yyval.cl)->u.n.id);
                                     }

                                     (yyval.cl)->u.n.id = (yyvsp[0].sval);
                                 }
#line 3349 "sieve/sieve.c"
    break;

  case 123: /* ntags: ntags METHOD string  */
#line 1076 "sieve/sieve.y"
                                 {
                                     if ((yyval.cl)->u.n.method != NULL) {
                                         sieveerror_c(sscript,
                                                      SIEVE_DUPLICATE_TAG,
                                                      ":method");
                                         free((yyval.cl)->u.n.method);
                                     }

                                     (yyval.cl)->u.n.method = (yyvsp[0].sval);
                                 }
#line 3364 "sieve/sieve.c"
    break;

  case 124: /* ntags: ntags priority  */
#line 1086 "sieve/sieve.y"
                                 {
                                     if ((yyval.cl)->u.n.priority != -1) {
                                         sieveerror_c(sscript,
                                                      SIEVE_DUPLICATE_TAG,
                                                      "priority");
                                     }

                                     (yyval.cl)->u.n.priority = (yyvsp[0].nval);
                                 }
#line 3378 "sieve/sieve.c"
    break;

  case 125: /* ntags: ntags MESSAGE string  */
#line 1097 "sieve/sieve.y"
                                 {
                                     if ((yyval.cl)->u.n.message != NULL) {
                                         sieveerror_c(sscript,
                                                      SIEVE_DUPLICATE_TAG,
                                                      ":message");
                                         free((yyval.cl)->u.n.message);
                                     }

                                     (yyval.cl)->u.n.message = (yyvsp[0].sval);
                                 }
#line 3393 "sieve/sieve.c"
    break;

  case 126: /* ntags: ntags OPTIONS stringlist  */
#line 1109 "sieve/sieve.y"
                                 {
                                     if ((yyval.cl)->u.n.options != NULL) {
                                         sieveerror_c(sscript,
                                                      SIEVE_DUPLICATE_TAG,
                                                      ":options");
                                         strarray_free((yyval.cl)->u.n.options);
                                     }

                                     (yyval.cl)->u.n.options = (yyvsp[0].sl);
                                 }
#line 3408 "sieve/sieve.c"
    break;

  case 130: /* dtags: %empty  */
#line 1130 "sieve/sieve.y"
                                 { (yyval.cl) = new_command(DENOTIFY, sscript); }
#line 3414 "sieve/sieve.c"
    break;

  case 131: /* dtags: dtags priority  */
#line 1131 "sieve/sieve.y"
                                 {
                                     if ((yyval.cl)->u.d.priority != -1) {
                                         sieveerror_c(sscript,
                                                      SIEVE_DUPLICATE_TAG,
                                                      "priority");
                                     }

                                     (yyval.cl)->u.d.priority = (yyvsp[0].nval);
                                 }
#line 3428 "sieve/sieve.c"
    break;

  case 132: /* $@5: %empty  */
#line 1141 "sieve/sieve.y"
                { ctags = &((yyvsp[0].cl)->u.d.comp); }
#line 3434 "sieve/sieve.c"
    break;

  case 133: /* dtags: dtags $@5 matchtype string  */
#line 1142 "sieve/sieve.y"
                                 {
                                     if ((yyval.cl)->u.d.pattern) free((yyval.cl)->u.d.pattern);
                                     (yyval.cl)->u.d.pattern = (yyvsp[0].sval);
                                 }
#line 3443 "sieve/sieve.c"
    break;

  case 134: /* itags: %empty  */
#line 1150 "sieve/sieve.y"
                                 { (yyval.cl) = new_command(INCLUDE, sscript); }
#line 3449 "sieve/sieve.c"
    break;

  case 135: /* itags: itags location  */
#line 1151 "sieve/sieve.y"
                                 {
                                     if ((yyval.cl)->u.inc.location != -1) {
                                         sieveerror_c(sscript,
                                                      SIEVE_DUPLICATE_TAG,
                                                      "location");
                                     }

                                     (yyval.cl)->u.inc.location = (yyvsp[0].nval);
                                 }
#line 3463 "sieve/sieve.c"
    break;

  case 136: /* itags: itags ONCE  */
#line 1160 "sieve/sieve.y"
                                 {
                                     if ((yyval.cl)->u.inc.once != -1) {
                                         sieveerror_c(sscript,
                                                      SIEVE_DUPLICATE_TAG,
                                                      ":once");
                                     }

                                     (yyval.cl)->u.inc.once = 1;
                                 }
#line 3477 "sieve/sieve.c"
    break;

  case 137: /* itags: itags OPTIONAL  */
#line 1169 "sieve/sieve.y"
                                 {
                                     if ((yyval.cl)->u.inc.optional != -1) {
                                         sieveerror_c(sscript,
                                                      SIEVE_DUPLICATE_TAG,
                                                      ":optional");
                                     }

                                     (yyval.cl)->u.inc.optional = 1;
                                 }
#line 3491 "sieve/sieve.c"
    break;

  case 140: /* sntags: %empty  */
#line 1188 "sieve/sieve.y"
                                 { (yyval.cl) = new_command(SNOOZE, sscript); }
#line 3497 "sieve/sieve.c"
    break;

  case 141: /* sntags: sntags MAILBOX string  */
#line 1189 "sieve/sieve.y"
                                 {
                                     if ((yyval.cl)->u.sn.mailbox != NULL) {
                                         sieveerror_c(sscript,
                                                      SIEVE_DUPLICATE_TAG,
                                                      ":mailbox");
                                         free((yyval.cl)->u.sn.mailbox);
                                     }

                                     (yyval.cl)->u.sn.mailbox = (yyvsp[0].sval);
                                 }
#line 3512 "sieve/sieve.c"
    break;

  case 142: /* sntags: sntags mailboxid  */
#line 1199 "sieve/sieve.y"
                                 { (yyval.cl)->u.sn.is_mboxid = 1; }
#line 3518 "sieve/sieve.c"
    break;

  case 143: /* sntags: sntags ADDFLAGS stringlist  */
#line 1202 "sieve/sieve.y"
                                 {
                                     if ((yyval.cl)->u.sn.addflags != NULL) {
                                         sieveerror_c(sscript,
                                                      SIEVE_DUPLICATE_TAG,
                                                      ":addflags");
                                         free((yyval.cl)->u.sn.addflags);
                                     }

                                     (yyval.cl)->u.sn.addflags = (yyvsp[0].sl);
                                 }
#line 3533 "sieve/sieve.c"
    break;

  case 144: /* sntags: sntags REMOVEFLAGS stringlist  */
#line 1213 "sieve/sieve.y"
                                 {
                                     if ((yyval.cl)->u.sn.removeflags != NULL) {
                                         sieveerror_c(sscript,
                                                      SIEVE_DUPLICATE_TAG,
                                                      ":removeflags");
                                         free((yyval.cl)->u.sn.removeflags);
                                     }

                                     (yyval.cl)->u.sn.removeflags = (yyvsp[0].sl);
                                 }
#line 3548 "sieve/sieve.c"
    break;

  case 145: /* sntags: sntags WEEKDAYS weekdaylist  */
#line 1224 "sieve/sieve.y"
                                 {
                                     if ((yyval.cl)->u.sn.days != 0) {
                                         sieveerror_c(sscript,
                                                      SIEVE_DUPLICATE_TAG,
                                                      ":weekdays");
                                     }

                                     (yyval.cl)->u.sn.days = (yyvsp[0].nval);
                                 }
#line 3562 "sieve/sieve.c"
    break;

  case 147: /* weekdaylist: '[' weekdays ']'  */
#line 1237 "sieve/sieve.y"
                                 { (yyval.nval) = (yyvsp[-1].nval); }
#line 3568 "sieve/sieve.c"
    break;

  case 149: /* weekdays: weekdays ',' weekday  */
#line 1242 "sieve/sieve.y"
                                 { (yyval.nval) = (yyvsp[-2].nval) | (yyvsp[0].nval); }
#line 3574 "sieve/sieve.c"
    break;

  case 150: /* weekday: STRING  */
#line 1246 "sieve/sieve.y"
                                 { (yyval.nval) = verify_weekday(sscript, (yyvsp[0].sval)); }
#line 3580 "sieve/sieve.c"
    break;

  case 152: /* timelist: '[' times ']'  */
#line 1251 "sieve/sieve.y"
                                 { (yyval.nl) = (yyvsp[-1].nl); }
#line 3586 "sieve/sieve.c"
    break;

  case 154: /* times: times ',' time  */
#line 1256 "sieve/sieve.y"
                                 { (yyval.nl) = (yyvsp[-2].nl); arrayu64_add((yyval.nl), (yyvsp[0].nval)); }
#line 3592 "sieve/sieve.c"
    break;

  case 155: /* time1: time  */
#line 1260 "sieve/sieve.y"
                                 {
                                     (yyval.nl) = arrayu64_new();
                                     arrayu64_add((yyval.nl), (yyvsp[0].nval));
                                 }
#line 3601 "sieve/sieve.c"
    break;

  case 156: /* time: STRING  */
#line 1267 "sieve/sieve.y"
                                 { (yyval.nval) = verify_time(sscript, (yyvsp[0].sval)); }
#line 3607 "sieve/sieve.c"
    break;

  case 157: /* testlist: '(' tests ')'  */
#line 1274 "sieve/sieve.y"
                                 { (yyval.testl) = (yyvsp[-1].testl); }
#line 3613 "sieve/sieve.c"
    break;

  case 158: /* tests: test  */
#line 1278 "sieve/sieve.y"
                                 { (yyval.testl) = new_testlist((yyvsp[0].test), NULL); }
#line 3619 "sieve/sieve.c"
    break;

  case 159: /* tests: test ',' tests  */
#line 1279 "sieve/sieve.y"
                                 { (yyval.testl) = new_testlist((yyvsp[-2].test), (yyvsp[0].testl)); }
#line 3625 "sieve/sieve.c"
    break;

  case 160: /* test: ANYOF testlist  */
#line 1283 "sieve/sieve.y"
                                 { (yyval.test) = build_anyof(sscript, (yyvsp[0].testl)); }
#line 3631 "sieve/sieve.c"
    break;

  case 161: /* test: ALLOF testlist  */
#line 1284 "sieve/sieve.y"
                                 { (yyval.test) = build_allof(sscript, (yyvsp[0].testl)); }
#line 3637 "sieve/sieve.c"
    break;

  case 162: /* test: NOT test  */
#line 1285 "sieve/sieve.y"
                                 { (yyval.test) = build_not(sscript, (yyvsp[0].test));   }
#line 3643 "sieve/sieve.c"
    break;

  case 163: /* test: SFALSE  */
#line 1286 "sieve/sieve.y"
                                 { (yyval.test) = new_test(SFALSE, sscript); }
#line 3649 "sieve/sieve.c"
    break;

  case 164: /* test: STRUE  */
#line 1287 "sieve/sieve.y"
                                 { (yyval.test) = new_test(STRUE, sscript);  }
#line 3655 "sieve/sieve.c"
    break;

  case 165: /* test: EXISTS stringlist  */
#line 1288 "sieve/sieve.y"
                                 {
                                     (yyval.test) = new_test(EXISTS, sscript);
                                     (yyval.test)->u.sl = (yyvsp[0].sl);
                                 }
#line 3664 "sieve/sieve.c"
    break;

  case 166: /* test: SIZE sizetag NUMBER  */
#line 1292 "sieve/sieve.y"
                                 {
                                     (yyval.test) = new_test(SIZE, sscript);
                                     (yyval.test)->u.sz.t = (yyvsp[-1].nval);
                                     (yyval.test)->u.sz.n = (yyvsp[0].nval);
                                 }
#line 3674 "sieve/sieve.c"
    break;

  case 167: /* test: HEADERT htags stringlist stringlist  */
#line 1299 "sieve/sieve.y"
                                 { (yyval.test) = build_header(sscript, (yyvsp[-2].test), (yyvsp[-1].sl), (yyvsp[0].sl)); }
#line 3680 "sieve/sieve.c"
    break;

  case 168: /* test: ADDRESS atags stringlist stringlist  */
#line 1302 "sieve/sieve.y"
                                 { (yyval.test) = build_address(sscript, (yyvsp[-2].test), (yyvsp[-1].sl), (yyvsp[0].sl)); }
#line 3686 "sieve/sieve.c"
    break;

  case 169: /* test: ENVELOPE etags stringlist stringlist  */
#line 1304 "sieve/sieve.y"
                                 { (yyval.test) = build_envelope(sscript, (yyvsp[-2].test), (yyvsp[-1].sl), (yyvsp[0].sl)); }
#line 3692 "sieve/sieve.c"
    break;

  case 170: /* test: BODY btags stringlist  */
#line 1306 "sieve/sieve.y"
                                 { (yyval.test) = build_body(sscript, (yyvsp[-1].test), (yyvsp[0].sl)); }
#line 3698 "sieve/sieve.c"
    break;

  case 171: /* test: ENVIRONMENT envtags string stringlist  */
#line 1309 "sieve/sieve.y"
                                 { (yyval.test) = build_mbox_meta(sscript,
                                                        (yyvsp[-2].test), NULL, (yyvsp[-1].sval), (yyvsp[0].sl)); }
#line 3705 "sieve/sieve.c"
    break;

  case 172: /* test: STRINGT strtags stringlist stringlist  */
#line 1313 "sieve/sieve.y"
                                 { (yyval.test) = build_stringt(sscript, (yyvsp[-2].test), (yyvsp[-1].sl), (yyvsp[0].sl)); }
#line 3711 "sieve/sieve.c"
    break;

  case 173: /* test: HASFLAG hftags stringlist stringlist  */
#line 1320 "sieve/sieve.y"
                                 { (yyval.test) = build_hasflag(sscript, (yyvsp[-2].test), (yyvsp[-1].sl), (yyvsp[0].sl)); }
#line 3717 "sieve/sieve.c"
    break;

  case 174: /* test: HASFLAG hftags stringlist  */
#line 1322 "sieve/sieve.y"
                                 { (yyval.test) = build_hasflag(sscript, (yyvsp[-1].test), NULL, (yyvsp[0].sl)); }
#line 3723 "sieve/sieve.c"
    break;

  case 175: /* $@6: %empty  */
#line 1325 "sieve/sieve.y"
                             { getdatepart = 1; }
#line 3729 "sieve/sieve.c"
    break;

  case 176: /* test: DATE dttags string $@6 datepart stringlist  */
#line 1326 "sieve/sieve.y"
                                 { (yyval.test) = build_date(sscript, (yyvsp[-4].test), (yyvsp[-3].sval), (yyvsp[-1].nval), (yyvsp[0].sl)); }
#line 3735 "sieve/sieve.c"
    break;

  case 177: /* test: CURRENTDATE cdtags datepart stringlist  */
#line 1329 "sieve/sieve.y"
                                 { (yyval.test) = build_date(sscript, (yyvsp[-2].test), NULL, (yyvsp[-1].nval), (yyvsp[0].sl)); }
#line 3741 "sieve/sieve.c"
    break;

  case 178: /* test: VALIDNOTIFYMETHOD stringlist  */
#line 1331 "sieve/sieve.y"
                                 {
                                     (yyval.test) = new_test(VALIDNOTIFYMETHOD, sscript);
                                     (yyval.test)->u.sl = (yyvsp[0].sl);
                                 }
#line 3750 "sieve/sieve.c"
    break;

  case 179: /* test: NOTIFYMETHODCAPABILITY methtags string string stringlist  */
#line 1336 "sieve/sieve.y"
                                 { (yyval.test) = build_mbox_meta(sscript,
                                                        (yyvsp[-3].test), (yyvsp[-2].sval), (yyvsp[-1].sval), (yyvsp[0].sl)); }
#line 3757 "sieve/sieve.c"
    break;

  case 180: /* test: IHAVE stringlist  */
#line 1339 "sieve/sieve.y"
                                 { (yyval.test) = build_ihave(sscript, (yyvsp[0].sl)); }
#line 3763 "sieve/sieve.c"
    break;

  case 181: /* test: MAILBOXEXISTS stringlist  */
#line 1342 "sieve/sieve.y"
                                 {
                                     (yyval.test) = new_test(MAILBOXEXISTS, sscript);
                                     (yyval.test) = build_mbox_meta(sscript,
                                                          (yyval.test), NULL, NULL, (yyvsp[0].sl));
                                 }
#line 3773 "sieve/sieve.c"
    break;

  case 182: /* test: METADATA mtags string string stringlist  */
#line 1349 "sieve/sieve.y"
                                 { (yyval.test) = build_mbox_meta(sscript,
                                                        (yyvsp[-3].test), (yyvsp[-2].sval), (yyvsp[-1].sval), (yyvsp[0].sl)); }
#line 3780 "sieve/sieve.c"
    break;

  case 183: /* test: METADATAEXISTS string stringlist  */
#line 1353 "sieve/sieve.y"
                                 {
                                     (yyval.test) = new_test(METADATAEXISTS, sscript);
                                     (yyval.test) = build_mbox_meta(sscript,
                                                          (yyval.test), (yyvsp[-1].sval), NULL, (yyvsp[0].sl));
                                 }
#line 3790 "sieve/sieve.c"
    break;

  case 184: /* test: SERVERMETADATA mtags string stringlist  */
#line 1360 "sieve/sieve.y"
                                 { (yyval.test) = build_mbox_meta(sscript,
                                                        (yyvsp[-2].test), NULL, (yyvsp[-1].sval), (yyvsp[0].sl)); }
#line 3797 "sieve/sieve.c"
    break;

  case 185: /* test: SERVERMETADATAEXISTS stringlist  */
#line 1364 "sieve/sieve.y"
                                 {
                                     (yyval.test) = new_test(SERVERMETADATAEXISTS,
                                                   sscript);
                                     (yyval.test) = build_mbox_meta(sscript,
                                                          (yyval.test), NULL, NULL, (yyvsp[0].sl));
                                 }
#line 3808 "sieve/sieve.c"
    break;

  case 186: /* test: VALIDEXTLIST stringlist  */
#line 1372 "sieve/sieve.y"
                                 {
                                     (yyval.test) = new_test(VALIDEXTLIST, sscript);
                                     (yyval.test)->u.sl = (yyvsp[0].sl);
                                 }
#line 3817 "sieve/sieve.c"
    break;

  case 187: /* test: DUPLICATE duptags  */
#line 1376 "sieve/sieve.y"
                                 { (yyval.test) = build_duplicate(sscript, (yyvsp[0].test)); }
#line 3823 "sieve/sieve.c"
    break;

  case 188: /* test: SPECIALUSEEXISTS stringlist  */
#line 1379 "sieve/sieve.y"
                                 { 
                                     (yyval.test) = new_test(SPECIALUSEEXISTS, sscript);
                                     (yyval.test) = build_mbox_meta(sscript,
                                                          (yyval.test), NULL, NULL, (yyvsp[0].sl));
                                 }
#line 3833 "sieve/sieve.c"
    break;

  case 189: /* test: SPECIALUSEEXISTS string stringlist  */
#line 1386 "sieve/sieve.y"
                                 {
                                     (yyval.test) = new_test(SPECIALUSEEXISTS, sscript);
                                     (yyval.test) = build_mbox_meta(sscript,
                                                          (yyval.test), (yyvsp[-1].sval), NULL, (yyvsp[0].sl));
                                 }
#line 3843 "sieve/sieve.c"
    break;

  case 190: /* test: MAILBOXIDEXISTS stringlist  */
#line 1393 "sieve/sieve.y"
                                 {
                                     (yyval.test) = new_test(MAILBOXIDEXISTS, sscript);
                                     (yyval.test) = build_mbox_meta(sscript,
                                                          (yyval.test), NULL, NULL, (yyvsp[0].sl));
                                 }
#line 3853 "sieve/sieve.c"
    break;

  case 191: /* test: JMAPQUERY string  */
#line 1399 "sieve/sieve.y"
                                 {
                                     (yyval.test) = new_test(JMAPQUERY, sscript);
                                     (yyval.test) = build_jmapquery(sscript, (yyval.test), (yyvsp[0].sval));
                                 }
#line 3862 "sieve/sieve.c"
    break;

  case 192: /* test: error  */
#line 1404 "sieve/sieve.y"
                                 { (yyval.test) = new_test(SFALSE, sscript); }
#line 3868 "sieve/sieve.c"
    break;

  case 195: /* htags: %empty  */
#line 1415 "sieve/sieve.y"
                                 { (yyval.test) = new_test(HEADERT, sscript); }
#line 3874 "sieve/sieve.c"
    break;

  case 196: /* $@7: %empty  */
#line 1416 "sieve/sieve.y"
                { ctags = &((yyvsp[0].test)->u.hhs.comp); }
#line 3880 "sieve/sieve.c"
    break;

  case 198: /* $@8: %empty  */
#line 1417 "sieve/sieve.y"
                { ctags = &((yyvsp[0].test)->u.hhs.comp); }
#line 3886 "sieve/sieve.c"
    break;

  case 200: /* $@9: %empty  */
#line 1418 "sieve/sieve.y"
                { ctags = &((yyvsp[0].test)->u.hhs.comp); }
#line 3892 "sieve/sieve.c"
    break;

  case 202: /* $@10: %empty  */
#line 1419 "sieve/sieve.y"
                { ctags = &((yyvsp[0].test)->u.hhs.comp); }
#line 3898 "sieve/sieve.c"
    break;

  case 204: /* matchtype: matchtag  */
#line 1424 "sieve/sieve.y"
                                 {
                                     if (ctags->match != -1) {
                                         sieveerror_c(sscript,
                                                      SIEVE_DUPLICATE_TAG,
                                                      "match-type");
                                     }

                                     ctags->match = (yyvsp[0].nval);
                                 }
#line 3912 "sieve/sieve.c"
    break;

  case 205: /* matchtype: relmatch relation  */
#line 1434 "sieve/sieve.y"
                                 {
                                     if (ctags->match != COUNT &&
                                         ctags->match != VALUE &&
                                         !supported(SIEVE_CAPA_RELATIONAL)) {
                                         sieveerror_c(sscript,
                                                      SIEVE_MISSING_REQUIRE,
                                                      "relational");
                                     }
                                     if (ctags->match != -1) {
                                         sieveerror_c(sscript,
                                                      SIEVE_DUPLICATE_TAG,
                                                      "match-type");
                                     }

                                     ctags->match = (yyvsp[-1].nval);
                                     ctags->relation = (yyvsp[0].nval);
                                 }
#line 3934 "sieve/sieve.c"
    break;

  case 209: /* matchtag: REGEX  */
#line 1458 "sieve/sieve.y"
                                 {
                                     if (!supported(SIEVE_CAPA_REGEX)) {
                                         sieveerror_c(sscript,
                                                      SIEVE_MISSING_REQUIRE,
                                                      "regex");
                                     }
                                 }
#line 3946 "sieve/sieve.c"
    break;

  case 218: /* listmatch: LIST  */
#line 1485 "sieve/sieve.y"
                                 {
                                     if (ctags->match != LIST &&
                                         !supported(SIEVE_CAPA_EXTLISTS)) {
                                         sieveerror_c(sscript,
                                                      SIEVE_MISSING_REQUIRE,
                                                      "extlists");
                                     }
                                     if (ctags->match != -1) {
                                         sieveerror_c(sscript,
                                                      SIEVE_DUPLICATE_TAG,
                                                      "match-type");
                                     }

                                     ctags->match = LIST;
                                 }
#line 3966 "sieve/sieve.c"
    break;

  case 219: /* comparator: COMPARATOR collation  */
#line 1505 "sieve/sieve.y"
                                 {
                                     if (ctags->collation != -1) {
                                         sieveerror_c(sscript,
                                                      SIEVE_DUPLICATE_TAG,
                                                      ":comparator");
                                     }

                                     ctags->collation = (yyvsp[0].nval);
                                 }
#line 3980 "sieve/sieve.c"
    break;

  case 222: /* collation: ASCIINUMERIC  */
#line 1520 "sieve/sieve.y"
                                 {
                                     if (!supported(SIEVE_CAPA_COMP_NUMERIC)) {
                                         sieveerror_c(sscript,
                                                      SIEVE_MISSING_REQUIRE,
                                                      "comparator-"
                                                      "i;ascii-numeric");
                                     }
                                 }
#line 3993 "sieve/sieve.c"
    break;

  case 223: /* idxtags: INDEX NUMBER  */
#line 1532 "sieve/sieve.y"
                                 {
                                     if (ctags->index == INT_MIN) {
                                         /* :last before :index */
                                         ctags->index = -(yyvsp[0].nval);
                                     }
                                     else if (ctags->index != 0) {
                                         sieveerror_c(sscript,
                                                      SIEVE_DUPLICATE_TAG,
                                                      ":index");
                                     }
                                     else {
                                       if (!supported(SIEVE_CAPA_INDEX)) {
                                             sieveerror_c(sscript,
                                                          SIEVE_MISSING_REQUIRE,
                                                          "index");
                                         }

                                         ctags->index = (yyvsp[0].nval);
                                     }
                                 }
#line 4018 "sieve/sieve.c"
    break;

  case 224: /* idxtags: LAST  */
#line 1552 "sieve/sieve.y"
                                 {
                                     if (ctags->index > 0) {
                                         ctags->index *= -1;
                                     }
                                     else if (ctags->index < 0) {
                                         sieveerror_c(sscript,
                                                      SIEVE_DUPLICATE_TAG,
                                                      ":last");
                                     }
                                     else if (ctags->index == 0) {
                                       if (!supported(SIEVE_CAPA_INDEX)) {
                                             sieveerror_c(sscript,
                                                          SIEVE_MISSING_REQUIRE,
                                                          "index");
                                         }

                                         /* :last before :index */
                                         ctags->index = INT_MIN;
                                     }
                                 }
#line 4043 "sieve/sieve.c"
    break;

  case 225: /* atags: %empty  */
#line 1576 "sieve/sieve.y"
                                 { (yyval.test) = new_test(ADDRESS, sscript); }
#line 4049 "sieve/sieve.c"
    break;

  case 227: /* $@11: %empty  */
#line 1578 "sieve/sieve.y"
                { ctags = &((yyvsp[0].test)->u.ae.comp); }
#line 4055 "sieve/sieve.c"
    break;

  case 229: /* $@12: %empty  */
#line 1579 "sieve/sieve.y"
                { ctags = &((yyvsp[0].test)->u.ae.comp); }
#line 4061 "sieve/sieve.c"
    break;

  case 231: /* $@13: %empty  */
#line 1580 "sieve/sieve.y"
                { ctags = &((yyvsp[0].test)->u.ae.comp); }
#line 4067 "sieve/sieve.c"
    break;

  case 233: /* $@14: %empty  */
#line 1581 "sieve/sieve.y"
                { ctags = &((yyvsp[0].test)->u.ae.comp); }
#line 4073 "sieve/sieve.c"
    break;

  case 235: /* addrpart: addrparttag  */
#line 1586 "sieve/sieve.y"
                                {
                                     /* $0 refers to a test_t* (ADDR/ENV)*/
                                     test_t *test = (yyvsp[-1].test);

                                     if (test->u.ae.addrpart != -1) {
                                         sieveerror_c(sscript,
                                                      SIEVE_DUPLICATE_TAG,
                                                      "address-part");
                                     }

                                     test->u.ae.addrpart = (yyvsp[0].nval);
                                 }
#line 4090 "sieve/sieve.c"
    break;

  case 239: /* addrparttag: subaddress  */
#line 1604 "sieve/sieve.y"
                                 {
                                     if (!supported(SIEVE_CAPA_SUBADDRESS)) {
                                         sieveerror_c(sscript,
                                                      SIEVE_MISSING_REQUIRE,
                                                      "subaddress");
                                     }
                                 }
#line 4102 "sieve/sieve.c"
    break;

  case 242: /* etags: %empty  */
#line 1621 "sieve/sieve.y"
                                 { (yyval.test) = new_test(ENVELOPE, sscript); }
#line 4108 "sieve/sieve.c"
    break;

  case 244: /* $@15: %empty  */
#line 1623 "sieve/sieve.y"
                { ctags = &((yyvsp[0].test)->u.ae.comp); }
#line 4114 "sieve/sieve.c"
    break;

  case 246: /* $@16: %empty  */
#line 1624 "sieve/sieve.y"
                { ctags = &((yyvsp[0].test)->u.ae.comp); }
#line 4120 "sieve/sieve.c"
    break;

  case 248: /* $@17: %empty  */
#line 1625 "sieve/sieve.y"
                { ctags = &((yyvsp[0].test)->u.ae.comp); }
#line 4126 "sieve/sieve.c"
    break;

  case 250: /* envtags: %empty  */
#line 1630 "sieve/sieve.y"
                                   { (yyval.test) = new_test(ENVIRONMENT, sscript); }
#line 4132 "sieve/sieve.c"
    break;

  case 251: /* $@18: %empty  */
#line 1631 "sieve/sieve.y"
                  { ctags = &((yyvsp[0].test)->u.mm.comp); }
#line 4138 "sieve/sieve.c"
    break;

  case 253: /* $@19: %empty  */
#line 1632 "sieve/sieve.y"
                  { ctags = &((yyvsp[0].test)->u.mm.comp); }
#line 4144 "sieve/sieve.c"
    break;

  case 255: /* btags: %empty  */
#line 1637 "sieve/sieve.y"
                                 { (yyval.test) = new_test(BODY, sscript); }
#line 4150 "sieve/sieve.c"
    break;

  case 256: /* btags: btags transform  */
#line 1638 "sieve/sieve.y"
                                 {
                                     if ((yyval.test)->u.b.transform != -1) {
                                         sieveerror_c(sscript,
                                                      SIEVE_DUPLICATE_TAG,
                                                      "transform");
                                     }

                                     (yyval.test)->u.b.transform = (yyvsp[0].nval);
                                 }
#line 4164 "sieve/sieve.c"
    break;

  case 257: /* btags: btags CONTENT stringlist  */
#line 1649 "sieve/sieve.y"
                                 {
                                     if ((yyval.test)->u.b.transform != -1) {
                                         sieveerror_c(sscript,
                                                      SIEVE_DUPLICATE_TAG,
                                                      "transform");
                                         strarray_free((yyval.test)->u.b.content_types);
                                     }

                                     (yyval.test)->u.b.transform = CONTENT;
                                     (yyval.test)->u.b.content_types = (yyvsp[0].sl);
                                 }
#line 4180 "sieve/sieve.c"
    break;

  case 258: /* $@20: %empty  */
#line 1661 "sieve/sieve.y"
                { ctags = &((yyvsp[0].test)->u.b.comp); }
#line 4186 "sieve/sieve.c"
    break;

  case 260: /* $@21: %empty  */
#line 1662 "sieve/sieve.y"
                { ctags = &((yyvsp[0].test)->u.b.comp); }
#line 4192 "sieve/sieve.c"
    break;

  case 264: /* strtags: %empty  */
#line 1673 "sieve/sieve.y"
                                 { (yyval.test) = new_test(STRINGT, sscript); }
#line 4198 "sieve/sieve.c"
    break;

  case 265: /* $@22: %empty  */
#line 1674 "sieve/sieve.y"
                  { ctags = &((yyvsp[0].test)->u.hhs.comp); }
#line 4204 "sieve/sieve.c"
    break;

  case 267: /* $@23: %empty  */
#line 1675 "sieve/sieve.y"
                  { ctags = &((yyvsp[0].test)->u.hhs.comp); }
#line 4210 "sieve/sieve.c"
    break;

  case 269: /* $@24: %empty  */
#line 1676 "sieve/sieve.y"
                  { ctags = &((yyvsp[0].test)->u.hhs.comp); }
#line 4216 "sieve/sieve.c"
    break;

  case 271: /* hftags: %empty  */
#line 1681 "sieve/sieve.y"
                                 { (yyval.test) = new_test(HASFLAG, sscript); }
#line 4222 "sieve/sieve.c"
    break;

  case 272: /* $@25: %empty  */
#line 1682 "sieve/sieve.y"
                 { ctags = &((yyvsp[0].test)->u.hhs.comp); }
#line 4228 "sieve/sieve.c"
    break;

  case 274: /* $@26: %empty  */
#line 1683 "sieve/sieve.y"
                 { ctags = &((yyvsp[0].test)->u.hhs.comp); }
#line 4234 "sieve/sieve.c"
    break;

  case 276: /* dttags: %empty  */
#line 1688 "sieve/sieve.y"
                                 { (yyval.test) = new_test(DATE, sscript); }
#line 4240 "sieve/sieve.c"
    break;

  case 278: /* dttags: dttags ORIGINALZONE  */
#line 1690 "sieve/sieve.y"
                                 {
                                     if ((yyval.test)->u.dt.zonetag != -1) {
                                         sieveerror_c(sscript,
                                                      SIEVE_DUPLICATE_TAG,
                                                      ":originalzone");
                                     }

                                     (yyval.test)->u.dt.zonetag = ORIGINALZONE;
                                 }
#line 4254 "sieve/sieve.c"
    break;

  case 279: /* $@27: %empty  */
#line 1699 "sieve/sieve.y"
                 { ctags = &((yyvsp[0].test)->u.dt.comp); }
#line 4260 "sieve/sieve.c"
    break;

  case 281: /* $@28: %empty  */
#line 1700 "sieve/sieve.y"
                 { ctags = &((yyvsp[0].test)->u.dt.comp); }
#line 4266 "sieve/sieve.c"
    break;

  case 283: /* $@29: %empty  */
#line 1701 "sieve/sieve.y"
                 { ctags = &((yyvsp[0].test)->u.dt.comp); }
#line 4272 "sieve/sieve.c"
    break;

  case 285: /* zone: ZONE TIMEZONE  */
#line 1706 "sieve/sieve.y"
                                 {
                                     /* $0 refers to a test_t* ([CURRENT]DATE)*/
                                     test_t *test = (yyvsp[-2].test);

                                     if (test->u.dt.zonetag != -1) {
                                         sieveerror_c(sscript,
                                                      SIEVE_DUPLICATE_TAG,
                                                      ":zone");
                                     }

                                     test->u.dt.zonetag = ZONE;
                                     test->u.dt.zone = (yyvsp[0].nval);
                                 }
#line 4290 "sieve/sieve.c"
    break;

  case 286: /* cdtags: %empty  */
#line 1723 "sieve/sieve.y"
                                 { (yyval.test) = new_test(CURRENTDATE, sscript); }
#line 4296 "sieve/sieve.c"
    break;

  case 288: /* $@30: %empty  */
#line 1725 "sieve/sieve.y"
                 { ctags = &((yyvsp[0].test)->u.dt.comp); }
#line 4302 "sieve/sieve.c"
    break;

  case 290: /* $@31: %empty  */
#line 1726 "sieve/sieve.y"
                 { ctags = &((yyvsp[0].test)->u.dt.comp); }
#line 4308 "sieve/sieve.c"
    break;

  case 305: /* methtags: %empty  */
#line 1748 "sieve/sieve.y"
                                 { (yyval.test) = new_test(NOTIFYMETHODCAPABILITY, sscript); }
#line 4314 "sieve/sieve.c"
    break;

  case 306: /* $@32: %empty  */
#line 1749 "sieve/sieve.y"
                   { ctags = &((yyvsp[0].test)->u.mm.comp); }
#line 4320 "sieve/sieve.c"
    break;

  case 308: /* $@33: %empty  */
#line 1750 "sieve/sieve.y"
                   { ctags = &((yyvsp[0].test)->u.mm.comp); }
#line 4326 "sieve/sieve.c"
    break;

  case 310: /* mtags: %empty  */
#line 1755 "sieve/sieve.y"
                                 { (yyval.test) = new_test((yyvsp[0].nval), sscript); }
#line 4332 "sieve/sieve.c"
    break;

  case 311: /* $@34: %empty  */
#line 1756 "sieve/sieve.y"
                { ctags = &((yyvsp[0].test)->u.mm.comp); }
#line 4338 "sieve/sieve.c"
    break;

  case 313: /* $@35: %empty  */
#line 1757 "sieve/sieve.y"
                { ctags = &((yyvsp[0].test)->u.mm.comp); }
#line 4344 "sieve/sieve.c"
    break;

  case 315: /* duptags: %empty  */
#line 1762 "sieve/sieve.y"
                                 { (yyval.test) = new_test(DUPLICATE, sscript); }
#line 4350 "sieve/sieve.c"
    break;

  case 316: /* duptags: duptags idtype string  */
#line 1763 "sieve/sieve.y"
                                 {
                                     if ((yyval.test)->u.dup.idtype != -1) {
                                         sieveerror_c(sscript,
                                                      SIEVE_DUPLICATE_TAG,
                                                      (yyvsp[-1].nval) == HEADER ?
                                                      ":header" : ":uniqueid");
                                         free((yyval.test)->u.dup.idval);
                                     }

                                     (yyval.test)->u.dup.idtype = (yyvsp[-1].nval);
                                     (yyval.test)->u.dup.idval = (yyvsp[0].sval);
                                 }
#line 4367 "sieve/sieve.c"
    break;

  case 317: /* duptags: duptags HANDLE string  */
#line 1775 "sieve/sieve.y"
                                 {
                                     if ((yyval.test)->u.dup.handle != NULL) {
                                         sieveerror_c(sscript,
                                                      SIEVE_DUPLICATE_TAG,
                                                      ":handle");
                                         free((yyval.test)->u.dup.handle);
                                     }

                                     (yyval.test)->u.dup.handle = (yyvsp[0].sval);
                                 }
#line 4382 "sieve/sieve.c"
    break;

  case 318: /* duptags: duptags SECONDS NUMBER  */
#line 1785 "sieve/sieve.y"
                                 {
                                     if ((yyval.test)->u.dup.seconds != -1) {
                                         sieveerror_c(sscript,
                                                      SIEVE_DUPLICATE_TAG,
                                                      ":seconds");
                                     }

                                     (yyval.test)->u.dup.seconds = (yyvsp[0].nval);
                                 }
#line 4396 "sieve/sieve.c"
    break;

  case 319: /* duptags: duptags LAST  */
#line 1794 "sieve/sieve.y"
                                 {
                                     if ((yyval.test)->u.dup.last != 0) {
                                         sieveerror_c(sscript,
                                                      SIEVE_DUPLICATE_TAG,
                                                      ":last");
                                     }

                                     (yyval.test)->u.dup.last = 1;
                                 }
#line 4410 "sieve/sieve.c"
    break;


#line 4414 "sieve/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 (sscript, 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, sscript);
          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, sscript);
      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 (sscript, 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, sscript);
    }
  /* 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, sscript);
      YYPOPSTACK (1);
    }
#ifndef yyoverflow
  if (yyss != yyssa)
    YYSTACK_FREE (yyss);
#endif

  return yyresult;
}

#line 1812 "sieve/sieve.y"



/*
 * Yacc actions
 */

void yyerror(sieve_script_t *sscript, const char *msg)
{
    if (sscript->ignore_err) return;

    sscript->err++;
    if (sscript->interp.err) {
        sscript->interp.err(sievelineno, msg, sscript->interp.interp_context,
                            sscript->script_context);
    }
}


static void
__attribute__((format(printf, 2, 0)))
vsieveerror_f(sieve_script_t *sscript,
              const char *fmt, va_list args)
{
    buf_reset(&sscript->sieveerr);
    buf_vprintf(&sscript->sieveerr, fmt, args);
    yyerror(sscript, buf_cstring(&sscript->sieveerr));
}

void
__attribute__((format(printf, 2, 3)))
sieveerror_f(sieve_script_t *sscript, const char *fmt, ...)
{
    va_list args;

    va_start(args, fmt);
    vsieveerror_f(sscript, fmt, args);
    va_end(args);
}

void sieveerror_c(sieve_script_t *sscript, int code, ...)
{
    va_list args;

    va_start(args, code);
    vsieveerror_f(sscript, error_message(code), args);
    va_end(args);
}

/*
 * variable-ref        =  "${" [namespace] variable-name "}"
 * namespace           =  identifier "." *sub-namespace
 * sub-namespace       =  variable-name "."
 * variable-name       =  num-variable / identifier
 * num-variable        =  1*DIGIT
 * identifier          =  (ALPHA / "_") *(ALPHA / DIGIT / "_")
 */
static int find_variables(sieve_script_t *sscript, char *s, int find_one)
{
    char *p = s;

    if (!supported(SIEVE_CAPA_VARIABLES)) return !find_one;

    while ((p = strstr(p, "${"))) {
        long num = 0, is_id = 0;

        p += 2;  /* skip over beginning of variable-ref */

        do {
            if (isdigit(*p)) {
                /* possible num-variable - get value and skip over digits */
                num = strtol(p, &p, 10);
            }
            else if (!find_one) {
                /* validating match variables - ignoroe identifiers */
                break;
            }
            else if (isalpha(*p) || *p == '_') {
                /* possible identifier - skip over identifier chars */
                for (++p; isalnum(*p) || *p == '_'; p++);
                is_id = 1;
            }
            else {
                /* not a valid variable-name */
                break;
            }

            if (*p == '}') {
                /* end of variable-ref */
                if (find_one) return 1;

                /* validating match variables */
                if (!is_id && num > MAX_MATCH_VARS) {
                    sieveerror_f(sscript, "string '%s':"
                                 " match variable index > %u unsupported",
                                 s, MAX_MATCH_VARS);
                    return 0;
                }
            }

        } while (is_id && *p == '.' && *(++p));  /* (sub-)namespace */
    }

    return !find_one;
}

static int chk_match_vars(sieve_script_t *sscript, char *s)
{
    return find_variables(sscript, s, 0 /* find_one */);
}

static int contains_variable(sieve_script_t *sscript, char *s)
{
    return find_variables(sscript, s, 1 /* find_one */);
}

/*
 * Valid UTF-8 check (from RFC 2640 Annex B.1)
 *
 * The following routine checks if a byte sequence is valid UTF-8. This
 * is done by checking for the proper tagging of the first and following
 * bytes to make sure they conform to the UTF-8 format. It then checks
 * to assure that the data part of the UTF-8 sequence conforms to the
 * proper range allowed by the encoding. Note: This routine will not
 * detect characters that have not been assigned and therefore do not
 * exist.
 */
static int verify_utf8(sieve_script_t *sscript, char *s)
{
    const char *buf = s;
    const char *endbuf = s + strlen(s);
    unsigned char byte2mask = 0x00, c;
    int trailing = 0;  /* trailing (continuation) bytes to follow */

    while (buf != endbuf) {
        c = *buf++;
        if (trailing) {
            if ((c & 0xC0) == 0x80) {           /* Does trailing byte
                                                   follow UTF-8 format? */
                if (byte2mask) {                /* Need to check 2nd byte
                                                   for proper range? */
                    if (c & byte2mask)          /* Are appropriate bits set? */
                        byte2mask = 0x00;
                    else
                        break;
                }
                trailing--;
            }
            else
                break;
        }
        else {
            if ((c & 0x80) == 0x00)             /* valid 1 byte UTF-8 */
                continue;
            else if ((c & 0xE0) == 0xC0)        /* valid 2 byte UTF-8 */
                if (c & 0x1E) {                 /* Is UTF-8 byte
                                                   in proper range? */
                    trailing = 1;
                }
                else
                    break;
            else if ((c & 0xF0) == 0xE0) {      /* valid 3 byte UTF-8 */
                if (!(c & 0x0F)) {              /* Is UTF-8 byte
                                                   in proper range? */
                    byte2mask = 0x20;           /* If not, set mask
                                                   to check next byte */
                }
                trailing = 2;
            }
            else if ((c & 0xF8) == 0xF0) {      /* valid 4 byte UTF-8 */
                if (!(c & 0x07)) {              /* Is UTF-8 byte
                                                   in proper range? */
                    byte2mask = 0x30;           /* If not, set mask
                                                   to check next byte */
                }
                trailing = 3;
            }
            else if ((c & 0xFC) == 0xF8) {      /* valid 5 byte UTF-8 */
                if (!(c & 0x03)) {              /* Is UTF-8 byte
                                                   in proper range? */
                    byte2mask = 0x38;           /* If not, set mask
                                                   to check next byte */
                }
                trailing = 4;
            }
            else if ((c & 0xFE) == 0xFC) {      /* valid 6 byte UTF-8 */
                if (!(c & 0x01)) {              /* Is UTF-8 byte
                                                   in proper range? */
                    byte2mask = 0x3C;           /* If not, set mask
                                                   to check next byte */
                }
                trailing = 5;
            }
            else
                break;
        }
    }

    if ((buf != endbuf) || trailing) {
        sieveerror_f(sscript, "string '%s': not valid utf8", s);
        return 0;
    }

    return 1;
}

static int verify_stringlist(sieve_script_t *sscript, strarray_t *sa,
                             int (*verify)(sieve_script_t*, char *))
{
    int i;

    for (i = 0 ; i < strarray_size(sa) ; i++) {
        if (!verify(sscript, (char *) strarray_nth(sa, i))) return 0;
    }
    return 1;
}

#ifdef ENABLE_REGEX
static int verify_regexlist(sieve_script_t *sscript,
                            const strarray_t *sa, int collation)
{
    int i, ret = 0;
    int cflags = REG_EXTENDED | REG_NOSUB;

    /* support UTF8 comparisons */
#if defined HAVE_PCREPOSIX_H
    cflags |= REG_UTF8;
#elif defined HAVE_PCRE2POSIX_H
    cflags |= REG_UTF;
#endif

    if (collation == ASCIICASEMAP) {
        cflags |= REG_ICASE;
    }

    for (i = 0 ; !ret && i < strarray_size(sa) ; i++) {
        const char *s = strarray_nth(sa, i);
        regex_t reg = {0};

        /* Don't try to validate a regex that includes variables */
        if (supported(SIEVE_CAPA_VARIABLES) && strstr(s, "${")) continue;

        /* Check if the regex will compile */
        if ((ret = regcomp(&reg, s, cflags)) != 0) {
            size_t errbuf_size = regerror(ret, &reg, NULL, 0);

            buf_reset(&sscript->sieveerr);
            buf_ensure(&sscript->sieveerr, errbuf_size);
            (void) regerror(ret, &reg,
                            (char *) buf_base(&sscript->sieveerr),
                            errbuf_size);
            buf_truncate(&sscript->sieveerr, errbuf_size);
            yyerror(sscript, buf_cstring(&sscript->sieveerr));
        }

        regfree(&reg);
    }

    return (ret == 0);
}
#else

static int verify_regexlist(sieve_script_t *sscript __attribute__((unused)),
                            const strarray_t *sa __attribute__((unused)),
                            char *comp __attribute__((unused)))
{
    return 0;
}
#endif /* ENABLE_REGEX */

static int verify_patternlist(sieve_script_t *sscript,
                              strarray_t *sa, comp_t *c,
                              int (*verify)(sieve_script_t*, char *))
{
    if (verify && !verify_stringlist(sscript, sa, verify)) return 0;

    canon_comptags(c, sscript);

    return (c->match == REGEX) ?
        verify_regexlist(sscript, sa, c->collation) : 1;
}

static int verify_address(sieve_script_t *sscript, char *s)
{
    if (contains_variable(sscript, s)) return 1;

    YY_BUFFER_STATE buffer = addr_scan_string(s);
    int r = 1;

    sscript->addrerr[0] = '\0';    /* paranoia */
    if (addrparse(sscript)) {
        sieveerror_f(sscript, "address '%s': %s", s, sscript->addrerr);
        r = 0;
    }
    addr_delete_buffer(buffer);

    return r;
}

static int verify_mailbox(sieve_script_t *sscript, char *s)
{
    if (!verify_utf8(sscript, s)) {
        sieveerror_f(sscript, "mailbox '%s': not a valid mailbox", s);
        return 0;
    }

    return 1;
}

static int verify_headername(sieve_script_t *sscript, char *hdr)
{
    char *h = hdr;

    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))) {
            sieveerror_f(sscript, "header field name '%s':"
                         " not a valid header field name"
                         " per RFC 5322, Section 3.6.8", hdr);
            return 0;
        }
        h++;
    }
    return 1;
}

static int verify_headerbody(sieve_script_t *sscript, char *val)
{
    char *v = val + strlen(val);

    /* trim any trailing CR/LF */
    while (--v >= val && (*v == '\r' || *v == '\n')) {
        *v = '\0';
    }

    /* make sure any other CRLF is folding whitespace */
    for (v = val; *v; v++) {
        if (*v == '\r' && *++v != '\n') break;
        if (*v == '\n' && *++v != ' ' && *v != '\t') break;
    }
    if (*v != '\0') {
        sieveerror_f(sscript, "header field body '%s':"
                     " not a valid header field body"
                     " per RFC 5322, Section 3.2.5", val);
        return 0;
    }

    return verify_utf8(sscript, val);
}

static int verify_addrheader(sieve_script_t *sscript, char *hdr)
{
    const char **h, *hdrs[] = {
        "from", "sender", "reply-to",   /* RFC5322 originator fields */
        "to", "cc", "bcc",              /* RFC5322 destination fields */
        "message-id", "in-reply-to",    /* RFC5322 identification fields */
        "references",
        "resent-from", "resent-sender", /* RFC5322 resent fields */
        "resent-to", "resent-cc", "resent-bcc",
        "return-path",                  /* RFC5322 trace fields */
        "disposition-notification-to",  /* RFC8098 MDN request fields */
        "approved",                     /* RFC5536 moderator/control fields */
        "delivered-to",                 /* non-standard (loop detection) */
        NULL
    };

    if (contains_variable(sscript, hdr)) return 1;

    if (!config_getswitch(IMAPOPT_RFC3028_STRICT))
        return verify_headername(sscript, hdr);

    for (lcase(hdr), h = hdrs; *h; h++) {
        if (!strcmp(*h, hdr)) return 1;
    }

    sieveerror_f(sscript,
                 "header '%s': not a valid header for an address test", hdr);
    return 0;
}

static int verify_envelope(sieve_script_t *sscript, char *env)
{
    if (contains_variable(sscript, env)) return 1;

    lcase(env);
    if (!config_getswitch(IMAPOPT_RFC3028_STRICT) ||
        !strcmp(env, "from") || !strcmp(env, "to") || !strcmp(env, "auth")) {
        return 1;
    }

    sieveerror_f(sscript,
                 "env-part '%s': not a valid part for an envelope test", env);
    return 0;
}

static int verify_list(sieve_script_t *sscript, char *s)
{
    if (sscript->interp.isvalidlist &&
        sscript->interp.isvalidlist(sscript->interp.interp_context, s)
        != SIEVE_OK) {
        sieveerror_f(sscript, "list '%s': is not valid/supported", s);
        return 0;
    }

    return 1;
}

static int check_reqs(sieve_script_t *sscript, strarray_t *sa)
{
    char *s;
    struct buf *errs = &sscript->sieveerr;
    int ret = 1, sep = ':';

    buf_setcstr(errs, "Unsupported feature(s) in \"require\"");
    while ((s = strarray_shift(sa))) {
        if (!script_require(sscript, s)) {
            buf_printf(errs, "%c \"%s\"", sep, s);
            ret = 0;
            sep = ',';
        }
        free(s);
    }
    strarray_free(sa);

    if (ret == 0) yyerror(sscript, buf_cstring(&sscript->sieveerr));
    else if (supported(SIEVE_CAPA_IHAVE)) {
        /* mark all allowed extensions as supported */
        sscript->support |= (SIEVE_CAPA_ALL & ~SIEVE_CAPA_IHAVE_INCOMPAT);
    }

    encoded_char = supported(SIEVE_CAPA_ENCODED_CHAR);

    return ret;
}

static commandlist_t *build_keep(sieve_script_t *sscript, commandlist_t *c)
{
    assert(c && c->type == KEEP);

    if (c->u.k.flags && !_verify_flaglist(c->u.k.flags)) {
        strarray_add(c->u.k.flags, "");
    }

    return c;
}

static commandlist_t *build_fileinto(sieve_script_t *sscript,
                                     commandlist_t *c, char *folder)
{
    assert(c && c->type == FILEINTO);

    if (c->u.f.flags && !_verify_flaglist(c->u.f.flags)) {
        strarray_add(c->u.f.flags, "");
    }
    verify_mailbox(sscript, folder);
    c->u.f.folder = folder;

    return c;
}

static commandlist_t *build_redirect(sieve_script_t *sscript,
                                     commandlist_t *c, char *address)
{
    assert(c && c->type == REDIRECT);

    if (c->u.r.list) verify_list(sscript, address);
    else verify_address(sscript, address);

    /* Verify DELIVERBY values */
    if (c->u.r.bytime) {
        if (!supported(SIEVE_CAPA_VARIABLES)) {
            time_t t;

            if (c->u.r.bytime[0] != '+' &&
                time_from_iso8601(c->u.r.bytime, &t) == -1) {
                sieveerror_f(sscript,
                             "string '%s': not a valid DELIVERBY time value",
                             c->u.r.bytime);
            }
            if (c->u.r.bymode &&
                strcasecmp(c->u.r.bymode, "NOTIFY") &&
                strcasecmp(c->u.r.bymode, "RETURN")) {
                sieveerror_f(sscript,
                             "string '%s': not a valid DELIVERBY mode value",
                             c->u.r.bymode);
            }
        }
    }
    else if (c->u.r.bymode || c->u.r.bytrace) {
        sieveerror_c(sscript, SIEVE_MISSING_TAG,
                     ":bytimerelative OR :bytimeabsolute");
    }

    /* Verify DSN NOTIFY value(s) */
    if (c->u.r.dsn_notify && !supported(SIEVE_CAPA_VARIABLES)) {
        tok_t tok =
            TOK_INITIALIZER(c->u.r.dsn_notify, ",", TOK_TRIMLEFT|TOK_TRIMRIGHT);
        char *token;
        int never = 0;

        while ((token = tok_next(&tok))) {
            if (!strcasecmp(token, "NEVER")) never = 1;
            else if (never) {
                sieveerror_f(sscript,
                             "DSN NOTIFY value 'NEVER' MUST be used by itself");
                break;
            }
            else if (strcasecmp(token, "SUCCESS") &&
                     strcasecmp(token, "FAILURE") &&
                     strcasecmp(token, "DELAY")) {
                sieveerror_f(sscript,
                             "string '%s': not a valid DSN NOTIFY value",
                             token);
                break;
            }
        }
        tok_fini(&tok);
    }

    /* Verify DSN RET value */
    if (c->u.r.dsn_ret && !supported(SIEVE_CAPA_VARIABLES) &&
        strcasecmp(c->u.r.dsn_ret, "FULL") &&
        strcasecmp(c->u.r.dsn_ret, "HDRS")) {
        sieveerror_f(sscript, "string '%s': not a valid DSN RET value",
                     c->u.r.dsn_ret);
    }

    c->u.r.address = address;

    return c;
}

static int verify_identifier(sieve_script_t *sscript, char *s)
{
    /* identifier         = (ALPHA / "_") *(ALPHA / DIGIT / "_") */

    if (!is_identifier(s)) {
        sieveerror_f(sscript,
                     "string '%s': not a valid sieve identifier", s);
        return 0;
    }
    return 1;
}

static commandlist_t *build_set(sieve_script_t *sscript,
                                commandlist_t *c, char *variable, char *value)
{
    assert(c && c->type == SET);

    verify_identifier(sscript, variable);
    verify_utf8(sscript, value);

    c->u.s.variable = variable;
    c->u.s.value = value;

    return c;
}

static commandlist_t *build_vacation(sieve_script_t *sscript,
                                     commandlist_t *c, char *message)
{
    int min = sscript->interp.vacation->min_response;
    int max = sscript->interp.vacation->max_response;

    assert(c && c->type == VACATION);

    if (c->u.v.handle) verify_utf8(sscript, c->u.v.handle);
    if (c->u.v.subject) verify_headerbody(sscript, c->u.v.subject);
    if (c->u.v.from) verify_address(sscript, c->u.v.from);
    if (c->u.v.addresses)
        verify_stringlist(sscript, c->u.v.addresses, verify_address);
    if (c->u.v.mime == -1) {
        verify_utf8(sscript, message);
        c->u.v.mime = 0;
    }
    if (c->u.v.fcc.folder) {
        verify_mailbox(sscript, c->u.v.fcc.folder);
        if (c->u.v.fcc.flags && !_verify_flaglist(c->u.v.fcc.flags)) {
            strarray_add(c->u.v.fcc.flags, "");
        }
    }
    else if (c->u.v.fcc.create || c->u.v.fcc.flags || c->u.v.fcc.specialuse) {
        sieveerror_c(sscript, SIEVE_MISSING_TAG, ":fcc");
    }

    c->u.v.message = message;

    if (c->u.v.seconds == -1) c->u.v.seconds = 7 * DAY2SEC;
    if (c->u.v.seconds < min) c->u.v.seconds = min;
    if (c->u.v.seconds > max) c->u.v.seconds = max;

    return c;
}

static commandlist_t *build_flag(sieve_script_t *sscript,
                                 commandlist_t *c, strarray_t *flags)
{
    assert(c &&
           (c->type == SETFLAG || c->type == ADDFLAG || c->type == REMOVEFLAG));

    if (!_verify_flaglist(flags)) {
        strarray_add(flags, "");
    }
    c->u.fl.flags = flags;

    if (!c->u.fl.variable) c->u.fl.variable = xstrdup("");
    else if (!is_identifier(c->u.fl.variable)) {
        sieveerror_c(sscript, SIEVE_INVALID_VALUE, "variablename");
    }

    return c;
}

static commandlist_t *build_addheader(sieve_script_t *sscript,
                                      commandlist_t *c, char *name, char *value)
{
    assert(c && c->type == ADDHEADER);

    verify_headername(sscript, name);
    verify_headerbody(sscript, value);

    if (c->u.ah.index == 0) c->u.ah.index = 1;
    c->u.ah.name = name;
    c->u.ah.value = value;

    return c;
}

static commandlist_t *build_deleteheader(sieve_script_t *sscript,
                                         commandlist_t *c,
                                         char *name, strarray_t *values)
{
    assert(c && c->type == DELETEHEADER);

    if (!strcasecmp("Received", name) || !strcasecmp("Auto-Submitted", name)) {
        sieveerror_f(sscript,
                     "MUST NOT delete Received or Auto-Submitted headers");
    }

    verify_headername(sscript, name);
    verify_patternlist(sscript, values, &c->u.dh.comp, verify_utf8);

    c->u.dh.name = name;
    c->u.dh.values = values;

    return c;
}

static int verify_weekday(sieve_script_t *sscript, char *day)
{
    int n = day[0] - '0';

    if (n >= 0 && n <= 6 && day[1] == '\0') {
        return (1 << n);
    }

    sieveerror_f(sscript, "'%s': not a valid weekday for snooze", day);
    return 0;
}

static int verify_time(sieve_script_t *sscript, char *time)
{
    struct tm tm;
    char *r = strptime(time, "%T", &tm);

    if (r && *r == '\0') {
        return (3600 * tm.tm_hour + 60 * tm.tm_min + tm.tm_sec);
    }

    sieveerror_f(sscript, "'%s': not a valid time for snooze", time);
    return 0;
}

static commandlist_t *build_snooze(sieve_script_t *sscript,
                                   commandlist_t *c, arrayu64_t *times)
{
    assert(c && c->type == SNOOZE);

    if (c->u.sn.mailbox) verify_mailbox(sscript, c->u.sn.mailbox);
    if (c->u.sn.addflags && !_verify_flaglist(c->u.sn.addflags)) {
        strarray_add(c->u.sn.addflags, "");
    }
    if (c->u.sn.removeflags && !_verify_flaglist(c->u.sn.removeflags)) {
        strarray_add(c->u.sn.removeflags, "");
    }
    if (!c->u.sn.days) c->u.sn.days = 0x7f; /* all days */

    /* Sort times earliest -> latest */
    arrayu64_sort(times, NULL/*ascending*/);
    c->u.sn.times = times;

    return c;
}

static commandlist_t *build_rej_err(sieve_script_t *sscript,
                                    int t, char *message)
{
    commandlist_t *c;

    assert(t == REJCT || t == EREJECT || t == ERROR);

    verify_utf8(sscript, message);

    c = new_command(t, sscript);
    c->u.str = message;

    return c;
}

static commandlist_t *build_notify(sieve_script_t *sscript, int t,
                                   commandlist_t *c, char *method)
{
    assert(c && (t == NOTIFY || t == ENOTIFY));

    if (t == ENOTIFY) {
        if (!supported(SIEVE_CAPA_ENOTIFY)) {
            sieveerror_c(sscript, SIEVE_MISSING_REQUIRE, "enotify");
        }
        if (c->u.n.id != NULL) {
            sieveerror_c(sscript, SIEVE_UNEXPECTED_TAG, ":id");
        }
        if (c->u.n.method != NULL) {
            sieveerror_c(sscript, SIEVE_UNEXPECTED_TAG, ":method");
        }
        if (c->u.n.fcc.folder) {
            verify_mailbox(sscript, c->u.n.fcc.folder);
            if (c->u.n.fcc.flags && !_verify_flaglist(c->u.n.fcc.flags)) {
                strarray_add(c->u.n.fcc.flags, "");
            }
        }
        else if (c->u.n.fcc.create || c->u.n.fcc.flags || c->u.n.fcc.specialuse) {
            sieveerror_c(sscript, SIEVE_MISSING_TAG, ":fcc");
        }

        c->u.n.method = method;
    }
    else {
        if (!supported(SIEVE_CAPA_NOTIFY)) {
            sieveerror_c(sscript, SIEVE_MISSING_REQUIRE, "notify");
        }
        if (c->u.n.from != NULL) {
            sieveerror_c(sscript, SIEVE_UNEXPECTED_TAG, ":from");
        }
        if (c->u.n.fcc.folder != NULL) {
            sieveerror_c(sscript, SIEVE_UNEXPECTED_TAG, ":fcc");
        }
        if (c->u.n.fcc.create != 0) {
            sieveerror_c(sscript, SIEVE_UNEXPECTED_TAG, ":create");
        }
        if (c->u.n.fcc.flags != NULL) {
            sieveerror_c(sscript, SIEVE_UNEXPECTED_TAG, ":flags");
        }
        if (c->u.n.fcc.specialuse != NULL) {
            sieveerror_c(sscript, SIEVE_UNEXPECTED_TAG, ":specialuse");
        }

        if (!c->u.n.method) c->u.n.method = xstrdup("default");
    }

    c->type = t;
    if (c->u.n.priority == -1) c->u.n.priority = NORMAL;
    if (!c->u.n.message) c->u.n.message = xstrdup("$from$: $subject$");

    return c;
}

static commandlist_t *build_denotify(sieve_script_t *sscript,
                                     commandlist_t *t)
{
    assert(t && t->type == DENOTIFY);

    canon_comptags(&t->u.d.comp, sscript);
    if (t->u.d.priority == -1) t->u.d.priority = ANY;
    if (t->u.d.pattern) {
        strarray_t sa = STRARRAY_INITIALIZER;

        strarray_pushm(&sa, t->u.d.pattern);
        verify_patternlist(sscript, &sa, &t->u.d.comp, NULL);
        strarray_pop(&sa);
        strarray_fini(&sa);
    }

    return t;
}

static commandlist_t *build_include(sieve_script_t *sscript,
                                    commandlist_t *c, char *script)
{
    assert(c && c->type == INCLUDE);

    if (strchr(script, '/')) {
        sieveerror_c(sscript, SIEVE_INVALID_VALUE, "script-name");
    }

    c->u.inc.script = script;
    if (c->u.inc.once == -1) c->u.inc.once = 0;
    if (c->u.inc.location == -1) c->u.inc.location = PERSONAL;
    if (c->u.inc.optional == -1) c->u.inc.optional = 0;

    return c;
}

static commandlist_t *build_log(sieve_script_t *sscript, char *text)
{
    commandlist_t *c;

    if (!supported(SIEVE_CAPA_LOG)) {
          sieveerror_c(sscript, SIEVE_MISSING_REQUIRE, "x-cyrus-log");
    }

    verify_utf8(sscript, text);

    c = new_command(LOG, sscript);
    c->u.l.text = text;

    return c;
}

static test_t *build_anyof(sieve_script_t *sscript, testlist_t *tl)
{
    test_t *t;

    assert(tl);

    if (tl->next == NULL) {
        /* collapse single item list into a simple test */
        t = tl->t;
        free(tl);
    }
    else {
        test_t *fail = NULL, *maybe = NULL;

        /* create ANYOF test */
        t = new_test(ANYOF, sscript);
        t->u.tl = tl;

        /* find first test that did/didn't set ignore_err */
        for ( ; tl && !fail && !maybe; tl = tl->next) {
            if (tl->t->ignore_err) {
                if (!fail) fail = tl->t;
            }
            else if (!maybe) maybe = tl->t;
        }

        if (fail) {
            if (maybe) {
                /* test may succeed - backout ignore_err */
                sscript->ignore_err = --fail->ignore_err;
            }
            else {
                /* test will fail - revert ignore_err to first value */
                sscript->ignore_err = t->ignore_err = fail->ignore_err;
            }
        }
    }

    return t;
}

static test_t *build_allof(sieve_script_t *sscript, testlist_t *tl)
{
    test_t *t;

    assert(tl);

    if (tl->next == NULL) {
        /* collapse single item list into a simple test */
        t = tl->t;
        free(tl);
    }
    else {
        /* create ALLOF test */
        t = new_test(ALLOF, sscript);
        t->u.tl = tl;

        /* find first test that set ignore_err and revert to that value */
        for ( ; tl; tl = tl->next) {
            if (tl->t->ignore_err) {
                sscript->ignore_err = t->ignore_err = tl->t->ignore_err;
                break;
            }
        }
    }

    return t;
}

static test_t *build_not(sieve_script_t *sscript, test_t *t)
{
    test_t *n;

    assert(t);

    if (t->ignore_err) {
        /* test will succeed - backout ignore_err */
        sscript->ignore_err = --t->ignore_err;
    }

    n = new_test(NOT, sscript);
    n->u.t = t;

    return n;
}

static test_t *build_hhs(sieve_script_t *sscript, test_t *t,
                         strarray_t *sl, strarray_t *pl)
{
    assert(t);

    verify_patternlist(sscript, pl, &t->u.hhs.comp, verify_utf8);

    t->u.hhs.sl = sl;
    t->u.hhs.pl = pl;

    return t;
}

static test_t *build_header(sieve_script_t *sscript, test_t *t,
                            strarray_t *sl, strarray_t *pl)
{
    assert(t && t->type == HEADERT);

    verify_stringlist(sscript, sl, verify_headername);

    return build_hhs(sscript, t, sl, pl);
}

static test_t *build_stringt(sieve_script_t *sscript, test_t *t,
                             strarray_t *sl, strarray_t *pl)
{
    assert(t && t->type == STRINGT);

    verify_stringlist(sscript, sl, verify_utf8);

    return build_hhs(sscript, t, sl, pl);
}

static test_t *build_hasflag(sieve_script_t *sscript, test_t *t,
                             strarray_t *sl, strarray_t *pl)
{
    assert(t && t->type == HASFLAG);

    if (sl) {
        if (!supported(SIEVE_CAPA_VARIABLES)) {
            sieveerror_c(sscript, SIEVE_MISSING_REQUIRE, "variables");
        }

        verify_stringlist(sscript, sl, verify_identifier);
    }

    return build_hhs(sscript, t, sl, pl);
}

static test_t *build_ae(sieve_script_t *sscript, test_t *t,
                        strarray_t *sl, strarray_t *pl)
{
    assert(t);

    verify_patternlist(sscript, pl, &t->u.ae.comp, NULL);

    if (t->u.ae.addrpart == -1) t->u.ae.addrpart = ALL;
    t->u.ae.sl = sl;
    t->u.ae.pl = pl;

    return t;
}

static test_t *build_address(sieve_script_t *sscript, test_t *t,
                             strarray_t *sl, strarray_t *pl)
{
    assert(t && t->type == ADDRESS);

    verify_stringlist(sscript, sl, verify_addrheader);

    return build_ae(sscript, t, sl, pl);
}

static test_t *build_envelope(sieve_script_t *sscript, test_t *t,
                              strarray_t *sl, strarray_t *pl)
{
    assert(t && t->type == ENVELOPE);

    verify_stringlist(sscript, sl, verify_envelope);

    return build_ae(sscript, t, sl, pl);
}

static test_t *build_body(sieve_script_t *sscript,
                          test_t *t, strarray_t *pl)
{
    assert(t && (t->type == BODY));

    verify_patternlist(sscript, pl, &t->u.b.comp, verify_utf8);

    if (t->u.b.offset == -1) t->u.b.offset = 0;
    if (t->u.b.transform == -1) t->u.b.transform = TEXT;
    if (t->u.b.content_types == NULL) {
        t->u.b.content_types = strarray_new();
        strarray_append(t->u.b.content_types,
                        (t->u.b.transform == RAW) ? "" : "text");
    }
    t->u.b.pl = pl;

    return t;
}

static test_t *build_date(sieve_script_t *sscript,
                          test_t *t, char *hn, int part, strarray_t *kl)
{
    assert(t && (t->type == DATE || t->type == CURRENTDATE));

    if (hn) verify_headername(sscript, hn);
    verify_patternlist(sscript, kl, &t->u.dt.comp, NULL);

    if (t->u.dt.comp.index == 0) t->u.dt.comp.index = 1;
    if (t->u.dt.zonetag == -1) {
        struct tm tm;
        time_t now = time(NULL);

        localtime_r(&now, &tm);
        t->u.dt.zone = gmtoff_of(&tm, now) / 60;
        t->u.dt.zonetag = ZONE;
    }

    t->u.dt.date_part = part;
    t->u.dt.header_name = hn;
    t->u.dt.kl = kl;

    return t;
}

static test_t *build_ihave(sieve_script_t *sscript, strarray_t *sa)
{
    test_t *t;
    int i;

    t = new_test(IHAVE, sscript);
    t->u.sl = sa;

    /* check if we support all listed extensions */
    for (i = 0; i < strarray_size(sa); i++) {
        unsigned long long capa = lookup_capability(strarray_nth(sa, i));

        if (!capa) {
            /* need to start ignoring errors immediately in case this ihave
               is part of a testlist with an unknown test later in the list */
            if (!t->ignore_err) t->ignore_err = ++sscript->ignore_err;
        }
        else if (capa & SIEVE_CAPA_IHAVE_INCOMPAT) {
            /* incompatible extension used in ihave - parse error */
            sscript->ignore_err = 0;
            sieveerror_c(sscript, SIEVE_IHAVE_INCOMPAT, strarray_nth(sa, i));
            break;
        }
    }

    return t;
}

static test_t *build_mbox_meta(sieve_script_t *sscript,
                               test_t *t, char *extname,
                               char *keyname, strarray_t *keylist)
{
    assert(t && (t->type == MAILBOXEXISTS || t->type == MAILBOXIDEXISTS ||
                 t->type == METADATA || t->type == METADATAEXISTS ||
                 t->type == SERVERMETADATA || t->type == SERVERMETADATAEXISTS ||
                 t->type == ENVIRONMENT || t->type == SPECIALUSEEXISTS ||
                 t->type == NOTIFYMETHODCAPABILITY));

    canon_comptags(&t->u.mm.comp, sscript);
    t->u.mm.extname = extname;
    t->u.mm.keyname = keyname;
    t->u.mm.keylist = keylist;

    return t;
}

static test_t *build_duplicate(sieve_script_t *sscript, test_t *t)
{
    assert(t && t->type == DUPLICATE);

    switch (t->u.dup.idtype) {
    case HEADER:
        verify_headername(sscript, t->u.dup.idval);
        break;

    case UNIQUEID:
        verify_utf8(sscript, t->u.dup.idval);
        break;

    default:
        t->u.dup.idtype = HEADER;
        t->u.dup.idval = xstrdup("Message-ID");
        break;
    }

    if (!t->u.dup.handle) t->u.dup.handle = xstrdup("");
    else verify_utf8(sscript, t->u.dup.handle);

    if (t->u.dup.seconds == -1) t->u.dup.seconds = 7 * 86400; /* 7 days */

    return t;
}

#ifdef WITH_JMAP
#include "imap/json_support.h"

static int jmap_parse_condition(json_t *cond, strarray_t *path)
{
    json_t *val;
    const char *field;

    json_object_foreach(cond, field, val) {
        /* inMailbox* and *InThreadHaveKeywords properties are incompatible */
        if (!strcmp(field, "before") ||
            !strcmp(field, "after")) {
            if (!json_is_utcdate(val)) break;
        }
        else if (!strcmp(field, "minSize") ||
                 !strcmp(field, "maxSize")) {
            if (!json_is_integer(val)) break;
        }
        else if (!strcmp(field, "hasAttachment")) {
            if (!json_is_boolean(val)) break;
        }
        else if (!strcmp(field, "text") ||
                 !strcmp(field, "from") ||
                 !strcmp(field, "to") ||
                 !strcmp(field, "cc") ||
                 !strcmp(field, "bcc") ||
                 !strcmp(field, "subject") ||
                 !strcmp(field, "body")) {
            if (!json_is_string(val)) break;
        }
        else if (!strcmp(field, "header")) {
            size_t n = json_array_size(val);

            if (n == 0 || n > 2) break;

            do {
                const char *s = json_string_value(json_array_get(val, --n));

                if (!s || !strlen(s)) {
                    struct buf buf = BUF_INITIALIZER;

                    buf_printf(&buf, "header[%lu]", n);
                    strarray_pushm(path, buf_release(&buf));
                    return 0;
                }
            } while (n);
        }
        /* JMAP Search Extension: https://cyrusimap.org/ns/jmap/search */
        else if (!strcmp(field, "attachmentBody")) {
            if (!json_is_string(val)) break;
        }
        /* JMAP Mail Extension: https://cyrusimap.org/ns/jmap/mail */
        else if (!strcmp(field, "attachmentName") ||
                 !strcmp(field, "attachmentType")) {
            if (!json_is_string(val)) break;
        }
        /* JMAP Mail Extension: https://cyrusimap.org/ns/jmap/mail */
        else if (!strcmp(field, "fromContactGroupId") ||
                 !strcmp(field, "toContactGroupId") ||
                 !strcmp(field, "ccContactGroupId") ||
                 !strcmp(field, "bccContactGroupId")) {
            if (!json_is_string(val)) break;
        }
        /* JMAP Mail Extension: https://cyrusimap.org/ns/jmap/mail */
        else if (!strcmp(field, "fromAnyContact") ||
                 !strcmp(field, "toAnyContact") ||
                 !strcmp(field, "ccAnyContact") ||
                 !strcmp(field, "bccAnyContact")) {
            if (!json_is_boolean(val)) break;
        }
        else break;
    }

    if (field) {
        strarray_push(path, field);
        return 0;
    }

    return 1;
}

static int jmap_parse_filter(json_t *filter, strarray_t *path)
{
    json_t *arg, *val;
    const char *s;
    size_t i;

    if (!JNOTNULL(filter) || !json_is_object(filter)) return 0;

    arg = json_object_get(filter, "operator");
    if (!arg) return jmap_parse_condition(filter, path);

    strarray_push(path, "operator");
    if (!json_is_string(arg)) return 0;

    s = json_string_value(arg);
    if (strcmp("AND", s) && strcmp("OR", s) && strcmp("NOT", s)) return 0;
    free(strarray_pop(path));

    arg = json_object_get(filter, "conditions");
    if (!json_array_size(arg)) {
        strarray_push(path, "conditions");
        return 0;
    }

    json_array_foreach(arg, i, val) {
        struct buf buf = BUF_INITIALIZER;

        buf_printf(&buf, "conditions[%lu]", i);
        strarray_pushm(path, buf_release(&buf));
        if (!jmap_parse_filter(val, path)) return 0;
        free(strarray_pop(path));
    }

    return 1;
}

static test_t *build_jmapquery(sieve_script_t *sscript,
                               test_t *t, const char *json)
{
    strarray_t path = STRARRAY_INITIALIZER;
    json_t *jquery;
    json_error_t jerr;

    assert(t && t->type == JMAPQUERY);

    /* validate query */
    jquery = json_loads(json, 0, &jerr);
    if (!jmap_parse_filter(jquery, &path)) {
        char *s = strarray_join(&path, "/");

        if (s) sieveerror_f(sscript, "invalid jmapquery argument: '%s'", s);
        else sieveerror_f(sscript, "invalid jmapquery format");

        free(s);
    }
    strarray_fini(&path);

    t->u.jquery = json_dumps(jquery, JSON_COMPACT);
    json_decref(jquery);

    return t;
}
#else
static test_t *build_jmapquery(sieve_script_t *sscript, test_t *t,
                               const char *json __attribute__((unused)))
{
    sieveerror_c(sscript, SIEVE_UNSUPP_EXT, "x-cyrus-jmapquery");

    return t;
}
#endif /* WITH_JMAP */
