26 |
#include <sys/file.h> |
#include <sys/file.h> |
27 |
#include <sys/stat.h> |
#include <sys/stat.h> |
28 |
#include <errno.h> |
#include <errno.h> |
29 |
#include <string.h> |
#include <string.h> |
30 |
|
#include <mailutils/argcv.h> |
31 |
#include <sieve.h> |
#include <sieve.h> |
32 |
#include <sieve-gram.h> |
#include <sieve-gram.h> |
33 |
|
|
41 |
|
|
42 |
static int number __P ((void)); |
static int number __P ((void)); |
43 |
static int string __P ((void)); |
static int string __P ((void)); |
44 |
|
static void line_begin __P ((void)); |
45 |
|
static void line_add __P((char *text, size_t len)); |
46 |
|
static void line_finish __P ((void)); |
47 |
static void multiline_begin __P ((void)); |
static void multiline_begin __P ((void)); |
48 |
static void multiline_add __P ((char *)); |
static void multiline_add __P ((char *)); |
49 |
static void multiline_finish __P ((void)); |
static void multiline_finish __P ((void)); |
51 |
static void ident __P((const char *text)); |
static void ident __P((const char *text)); |
52 |
static void sieve_include __P((void)); |
static void sieve_include __P((void)); |
53 |
static void sieve_searchpath __P((void)); |
static void sieve_searchpath __P((void)); |
54 |
static char *str_escape __P((void)); |
static char *str_unescape __P((char *text, size_t len)); |
55 |
static int isemptystr __P((char *text)); |
static int isemptystr __P((char *text)); |
56 |
|
|
57 |
#ifdef FLEX_SCANNER |
#ifdef FLEX_SCANNER |
356 |
/* Quoted strings */ |
/* Quoted strings */ |
357 |
\"[^\\"\n]*\" { return string (); } |
\"[^\\"\n]*\" { return string (); } |
358 |
\"[^\\"\n]*\\. { BEGIN(STR); |
\"[^\\"\n]*\\. { BEGIN(STR); |
359 |
multiline_begin (); |
line_begin (); |
360 |
multiline_add (str_escape ()); } |
line_add (str_unescape (yytext + 1, yyleng - 1), 0); } |
361 |
<STR>[^\\"\n]*\\. { multiline_add (str_escape ()); } |
<STR>[^\\"\n]*\\. { line_add (str_unescape (yytext, yyleng), 0); } |
362 |
<STR>[^\\"\n]*\" { BEGIN(INITIAL); |
<STR>[^\\"\n]*\" { BEGIN(INITIAL); |
363 |
multiline_add (NULL); |
if (yyleng > 1) |
364 |
multiline_finish (); |
line_add (yytext, yyleng - 1); |
365 |
|
line_finish (); |
366 |
return STRING; } |
return STRING; } |
367 |
/* Multiline strings */ |
/* Multiline strings */ |
368 |
text:-?[ \t]*#.*\n { BEGIN(ML); multiline_begin (); sieve_line_num++; } |
text:-?[ \t]*#.*\n { BEGIN(ML); multiline_begin (); sieve_line_num++; } |
581 |
} |
} |
582 |
|
|
583 |
void |
void |
584 |
multiline_add (char *s) |
line_add (char *text, size_t len) |
585 |
{ |
{ |
586 |
|
char *s; |
587 |
|
|
588 |
|
if (len == 0) |
589 |
|
len = strlen (text); |
590 |
|
s = malloc (len + 1); |
591 |
if (!s) |
if (!s) |
592 |
{ |
{ |
593 |
s = strdup (multiline_strip_tabs (yytext)); |
yyerror (_("not enough memory")); |
594 |
if (!s) |
exit (1); |
|
{ |
|
|
yyerror (_("not enough memory")); |
|
|
exit (1); |
|
|
} |
|
595 |
} |
} |
596 |
|
memcpy (s, text, len); |
597 |
|
s[len] = 0; |
598 |
list_append (string_list, s); |
list_append (string_list, s); |
599 |
} |
} |
600 |
|
|
601 |
void |
void |
602 |
multiline_begin () |
multiline_add (char *s) |
603 |
|
{ |
604 |
|
if (!s) |
605 |
|
s = multiline_strip_tabs (yytext); |
606 |
|
line_add (s, 0); |
607 |
|
} |
608 |
|
|
609 |
|
void |
610 |
|
line_begin () |
611 |
{ |
{ |
612 |
int status; |
int status; |
613 |
|
|
614 |
|
if (string_list) |
615 |
|
sieve_slist_destroy (&string_list); |
616 |
|
status = list_create (&string_list); |
617 |
|
if (status) |
618 |
|
{ |
619 |
|
sieve_compile_error (sieve_filename, sieve_line_num, |
620 |
|
"list_create: %s", mu_strerror (status)); |
621 |
|
exit (1); |
622 |
|
} |
623 |
|
} |
624 |
|
|
625 |
|
void |
626 |
|
multiline_begin () |
627 |
|
{ |
628 |
char *p = yytext + 5; /* past the text: keyword */ |
char *p = yytext + 5; /* past the text: keyword */ |
629 |
|
|
630 |
if (*p == '-') |
if (*p == '-') |
658 |
exit (1); |
exit (1); |
659 |
} |
} |
660 |
} |
} |
|
|
|
|
if (string_list) |
|
|
sieve_slist_destroy (&string_list); |
|
|
status = list_create (&string_list); |
|
|
if (status) |
|
|
{ |
|
|
sieve_compile_error (sieve_filename, sieve_line_num, |
|
|
"list_create: %s", mu_strerror (status)); |
|
|
exit (1); |
|
|
} |
|
661 |
|
|
662 |
|
line_begin (); |
663 |
} |
} |
664 |
|
|
665 |
void |
void |
666 |
multiline_finish () |
line_finish () |
667 |
{ |
{ |
668 |
iterator_t itr; |
iterator_t itr; |
669 |
int length = 0; |
int length = 0; |
697 |
} |
} |
698 |
|
|
699 |
void |
void |
700 |
|
multiline_finish () |
701 |
|
{ |
702 |
|
line_finish (); |
703 |
|
} |
704 |
|
|
705 |
|
void |
706 |
ident (const char *text) |
ident (const char *text) |
707 |
{ |
{ |
708 |
yylval.string = strdup (text); |
yylval.string = strdup (text); |
715 |
|
|
716 |
/* Escapes the last character from yytext */ |
/* Escapes the last character from yytext */ |
717 |
char * |
char * |
718 |
str_escape () |
str_unescape (char *text, size_t len) |
719 |
{ |
{ |
720 |
char *str = sieve_alloc (yyleng - 1); |
char *str = sieve_alloc (len); |
721 |
memcpy (str, yytext, yyleng - 2); |
memcpy (str, text, len - 2); |
722 |
str[yyleng - 2] = yytext[yyleng - 1]; |
str[len - 2] = argcv_unescape_char (text[len - 1]); |
723 |
str[yyleng - 1] = 0; |
str[len - 1] = 0; |
724 |
return str; |
return str; |
725 |
} |
} |