diff options
Diffstat (limited to 'pigeonhole/src/lib-sieve/plugins/mime')
-rw-r--r-- | pigeonhole/src/lib-sieve/plugins/mime/Makefile.am | 30 | ||||
-rw-r--r-- | pigeonhole/src/lib-sieve/plugins/mime/Makefile.in | 727 | ||||
-rw-r--r-- | pigeonhole/src/lib-sieve/plugins/mime/cmd-break.c | 273 | ||||
-rw-r--r-- | pigeonhole/src/lib-sieve/plugins/mime/cmd-extracttext.c | 370 | ||||
-rw-r--r-- | pigeonhole/src/lib-sieve/plugins/mime/cmd-foreverypart.c | 377 | ||||
-rw-r--r-- | pigeonhole/src/lib-sieve/plugins/mime/ext-extracttext.c | 130 | ||||
-rw-r--r-- | pigeonhole/src/lib-sieve/plugins/mime/ext-foreverypart.c | 62 | ||||
-rw-r--r-- | pigeonhole/src/lib-sieve/plugins/mime/ext-mime-common.c | 27 | ||||
-rw-r--r-- | pigeonhole/src/lib-sieve/plugins/mime/ext-mime-common.h | 85 | ||||
-rw-r--r-- | pigeonhole/src/lib-sieve/plugins/mime/ext-mime.c | 77 | ||||
-rw-r--r-- | pigeonhole/src/lib-sieve/plugins/mime/tag-mime.c | 757 |
11 files changed, 2915 insertions, 0 deletions
diff --git a/pigeonhole/src/lib-sieve/plugins/mime/Makefile.am b/pigeonhole/src/lib-sieve/plugins/mime/Makefile.am new file mode 100644 index 0000000..8ded659 --- /dev/null +++ b/pigeonhole/src/lib-sieve/plugins/mime/Makefile.am @@ -0,0 +1,30 @@ +noinst_LTLIBRARIES = libsieve_ext_mime.la + +AM_CPPFLAGS = \ + -I$(srcdir)/../.. \ + -I$(srcdir)/../../util \ + -I$(srcdir)/../variables \ + $(LIBDOVECOT_INCLUDE) + +commands = \ + cmd-foreverypart.c \ + cmd-break.c \ + cmd-extracttext.c + +tags = \ + tag-mime.c + +extensions = \ + ext-mime.c \ + ext-foreverypart.c \ + ext-extracttext.c + +libsieve_ext_mime_la_SOURCES = \ + ext-mime-common.c \ + $(commands) \ + $(tags) \ + $(extensions) + +noinst_HEADERS = \ + ext-mime-common.h + diff --git a/pigeonhole/src/lib-sieve/plugins/mime/Makefile.in b/pigeonhole/src/lib-sieve/plugins/mime/Makefile.in new file mode 100644 index 0000000..cfe25ff --- /dev/null +++ b/pigeonhole/src/lib-sieve/plugins/mime/Makefile.in @@ -0,0 +1,727 @@ +# Makefile.in generated by automake 1.16.3 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994-2020 Free Software Foundation, Inc. + +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + + +VPATH = @srcdir@ +am__is_gnu_make = { \ + if test -z '$(MAKELEVEL)'; then \ + false; \ + elif test -n '$(MAKE_HOST)'; then \ + true; \ + elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ + true; \ + else \ + false; \ + fi; \ +} +am__make_running_with_option = \ + case $${target_option-} in \ + ?) ;; \ + *) echo "am__make_running_with_option: internal error: invalid" \ + "target option '$${target_option-}' specified" >&2; \ + exit 1;; \ + esac; \ + has_opt=no; \ + sane_makeflags=$$MAKEFLAGS; \ + if $(am__is_gnu_make); then \ + sane_makeflags=$$MFLAGS; \ + else \ + case $$MAKEFLAGS in \ + *\\[\ \ ]*) \ + bs=\\; \ + sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \ + | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \ + esac; \ + fi; \ + skip_next=no; \ + strip_trailopt () \ + { \ + flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \ + }; \ + for flg in $$sane_makeflags; do \ + test $$skip_next = yes && { skip_next=no; continue; }; \ + case $$flg in \ + *=*|--*) continue;; \ + -*I) strip_trailopt 'I'; skip_next=yes;; \ + -*I?*) strip_trailopt 'I';; \ + -*O) strip_trailopt 'O'; skip_next=yes;; \ + -*O?*) strip_trailopt 'O';; \ + -*l) strip_trailopt 'l'; skip_next=yes;; \ + -*l?*) strip_trailopt 'l';; \ + -[dEDm]) skip_next=yes;; \ + -[JT]) skip_next=yes;; \ + esac; \ + case $$flg in \ + *$$target_option*) has_opt=yes; break;; \ + esac; \ + done; \ + test $$has_opt = yes +am__make_dryrun = (target_option=n; $(am__make_running_with_option)) +am__make_keepgoing = (target_option=k; $(am__make_running_with_option)) +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +subdir = src/lib-sieve/plugins/mime +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/m4/dovecot.m4 \ + $(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltoptions.m4 \ + $(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \ + $(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +DIST_COMMON = $(srcdir)/Makefile.am $(noinst_HEADERS) \ + $(am__DIST_COMMON) +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = $(top_builddir)/dummy-config.h \ + $(top_builddir)/pigeonhole-config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +LTLIBRARIES = $(noinst_LTLIBRARIES) +libsieve_ext_mime_la_LIBADD = +am__objects_1 = cmd-foreverypart.lo cmd-break.lo cmd-extracttext.lo +am__objects_2 = tag-mime.lo +am__objects_3 = ext-mime.lo ext-foreverypart.lo ext-extracttext.lo +am_libsieve_ext_mime_la_OBJECTS = ext-mime-common.lo $(am__objects_1) \ + $(am__objects_2) $(am__objects_3) +libsieve_ext_mime_la_OBJECTS = $(am_libsieve_ext_mime_la_OBJECTS) +AM_V_lt = $(am__v_lt_@AM_V@) +am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) +am__v_lt_0 = --silent +am__v_lt_1 = +AM_V_P = $(am__v_P_@AM_V@) +am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) +am__v_P_0 = false +am__v_P_1 = : +AM_V_GEN = $(am__v_GEN_@AM_V@) +am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@) +am__v_GEN_0 = @echo " GEN " $@; +am__v_GEN_1 = +AM_V_at = $(am__v_at_@AM_V@) +am__v_at_ = $(am__v_at_@AM_DEFAULT_V@) +am__v_at_0 = @ +am__v_at_1 = +DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) +depcomp = $(SHELL) $(top_srcdir)/depcomp +am__maybe_remake_depfiles = depfiles +am__depfiles_remade = ./$(DEPDIR)/cmd-break.Plo \ + ./$(DEPDIR)/cmd-extracttext.Plo \ + ./$(DEPDIR)/cmd-foreverypart.Plo \ + ./$(DEPDIR)/ext-extracttext.Plo \ + ./$(DEPDIR)/ext-foreverypart.Plo \ + ./$(DEPDIR)/ext-mime-common.Plo ./$(DEPDIR)/ext-mime.Plo \ + ./$(DEPDIR)/tag-mime.Plo +am__mv = mv -f +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \ + $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ + $(AM_CFLAGS) $(CFLAGS) +AM_V_CC = $(am__v_CC_@AM_V@) +am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@) +am__v_CC_0 = @echo " CC " $@; +am__v_CC_1 = +CCLD = $(CC) +LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(AM_LDFLAGS) $(LDFLAGS) -o $@ +AM_V_CCLD = $(am__v_CCLD_@AM_V@) +am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@) +am__v_CCLD_0 = @echo " CCLD " $@; +am__v_CCLD_1 = +SOURCES = $(libsieve_ext_mime_la_SOURCES) +DIST_SOURCES = $(libsieve_ext_mime_la_SOURCES) +am__can_run_installinfo = \ + case $$AM_UPDATE_INFO_DIR in \ + n|no|NO) false;; \ + *) (install-info --version) >/dev/null 2>&1;; \ + esac +HEADERS = $(noinst_HEADERS) +am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) +# Read a list of newline-separated strings from the standard input, +# and print each of them once, without duplicates. Input order is +# *not* preserved. +am__uniquify_input = $(AWK) '\ + BEGIN { nonempty = 0; } \ + { items[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in items) print i; }; } \ +' +# Make sure the list of sources is unique. This is necessary because, +# e.g., the same source file might be shared among _SOURCES variables +# for different programs/libraries. +am__define_uniq_tagged_files = \ + list='$(am__tagged_files)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | $(am__uniquify_input)` +ETAGS = etags +CTAGS = ctags +am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/depcomp +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +AMTAR = @AMTAR@ +AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ +AR = @AR@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +BINARY_CFLAGS = @BINARY_CFLAGS@ +BINARY_LDFLAGS = @BINARY_LDFLAGS@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DISTCHECK_CONFIGURE_FLAGS = @DISTCHECK_CONFIGURE_FLAGS@ +DLLTOOL = @DLLTOOL@ +DOVECOT_BINARY_CFLAGS = @DOVECOT_BINARY_CFLAGS@ +DOVECOT_BINARY_LDFLAGS = @DOVECOT_BINARY_LDFLAGS@ +DOVECOT_CFLAGS = @DOVECOT_CFLAGS@ +DOVECOT_COMPRESS_LIBS = @DOVECOT_COMPRESS_LIBS@ +DOVECOT_INSTALLED = @DOVECOT_INSTALLED@ +DOVECOT_LIBS = @DOVECOT_LIBS@ +DOVECOT_LUA_CFLAGS = @DOVECOT_LUA_CFLAGS@ +DOVECOT_LUA_LIBS = @DOVECOT_LUA_LIBS@ +DOVECOT_SQL_LIBS = @DOVECOT_SQL_LIBS@ +DOVECOT_SSL_LIBS = @DOVECOT_SSL_LIBS@ +DSYMUTIL = @DSYMUTIL@ +DUMPBIN = @DUMPBIN@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +FGREP = @FGREP@ +GREP = @GREP@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +LD = @LD@ +LDAP_LIBS = @LDAP_LIBS@ +LDFLAGS = @LDFLAGS@ +LIBDOVECOT = @LIBDOVECOT@ +LIBDOVECOT_ACL_INCLUDE = @LIBDOVECOT_ACL_INCLUDE@ +LIBDOVECOT_AUTH_INCLUDE = @LIBDOVECOT_AUTH_INCLUDE@ +LIBDOVECOT_COMPRESS = @LIBDOVECOT_COMPRESS@ +LIBDOVECOT_COMPRESS_DEPS = @LIBDOVECOT_COMPRESS_DEPS@ +LIBDOVECOT_CONFIG_INCLUDE = @LIBDOVECOT_CONFIG_INCLUDE@ +LIBDOVECOT_DEPS = @LIBDOVECOT_DEPS@ +LIBDOVECOT_DOVEADM_INCLUDE = @LIBDOVECOT_DOVEADM_INCLUDE@ +LIBDOVECOT_DSYNC = @LIBDOVECOT_DSYNC@ +LIBDOVECOT_DSYNC_DEPS = @LIBDOVECOT_DSYNC_DEPS@ +LIBDOVECOT_DSYNC_INCLUDE = @LIBDOVECOT_DSYNC_INCLUDE@ +LIBDOVECOT_FTS_INCLUDE = @LIBDOVECOT_FTS_INCLUDE@ +LIBDOVECOT_IMAPC_INCLUDE = @LIBDOVECOT_IMAPC_INCLUDE@ +LIBDOVECOT_IMAP_INCLUDE = @LIBDOVECOT_IMAP_INCLUDE@ +LIBDOVECOT_IMAP_LOGIN_INCLUDE = @LIBDOVECOT_IMAP_LOGIN_INCLUDE@ +LIBDOVECOT_INCLUDE = @LIBDOVECOT_INCLUDE@ +LIBDOVECOT_LDA = @LIBDOVECOT_LDA@ +LIBDOVECOT_LDA_DEPS = @LIBDOVECOT_LDA_DEPS@ +LIBDOVECOT_LDA_INCLUDE = @LIBDOVECOT_LDA_INCLUDE@ +LIBDOVECOT_LIBFTS = @LIBDOVECOT_LIBFTS@ +LIBDOVECOT_LIBFTS_DEPS = @LIBDOVECOT_LIBFTS_DEPS@ +LIBDOVECOT_LIBFTS_INCLUDE = @LIBDOVECOT_LIBFTS_INCLUDE@ +LIBDOVECOT_LMTP_INCLUDE = @LIBDOVECOT_LMTP_INCLUDE@ +LIBDOVECOT_LOGIN = @LIBDOVECOT_LOGIN@ +LIBDOVECOT_LOGIN_DEPS = @LIBDOVECOT_LOGIN_DEPS@ +LIBDOVECOT_LOGIN_INCLUDE = @LIBDOVECOT_LOGIN_INCLUDE@ +LIBDOVECOT_LUA = @LIBDOVECOT_LUA@ +LIBDOVECOT_LUA_DEPS = @LIBDOVECOT_LUA_DEPS@ +LIBDOVECOT_LUA_INCLUDE = @LIBDOVECOT_LUA_INCLUDE@ +LIBDOVECOT_NOTIFY_INCLUDE = @LIBDOVECOT_NOTIFY_INCLUDE@ +LIBDOVECOT_POP3_INCLUDE = @LIBDOVECOT_POP3_INCLUDE@ +LIBDOVECOT_PUSH_NOTIFICATION_INCLUDE = @LIBDOVECOT_PUSH_NOTIFICATION_INCLUDE@ +LIBDOVECOT_SERVICE_INCLUDE = @LIBDOVECOT_SERVICE_INCLUDE@ +LIBDOVECOT_SQL = @LIBDOVECOT_SQL@ +LIBDOVECOT_SQL_DEPS = @LIBDOVECOT_SQL_DEPS@ +LIBDOVECOT_SQL_INCLUDE = @LIBDOVECOT_SQL_INCLUDE@ +LIBDOVECOT_SSL = @LIBDOVECOT_SSL@ +LIBDOVECOT_SSL_DEPS = @LIBDOVECOT_SSL_DEPS@ +LIBDOVECOT_STORAGE = @LIBDOVECOT_STORAGE@ +LIBDOVECOT_STORAGE_DEPS = @LIBDOVECOT_STORAGE_DEPS@ +LIBDOVECOT_STORAGE_INCLUDE = @LIBDOVECOT_STORAGE_INCLUDE@ +LIBDOVECOT_SUBMISSION_INCLUDE = @LIBDOVECOT_SUBMISSION_INCLUDE@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBTOOL = @LIBTOOL@ +LIPO = @LIPO@ +LN_S = @LN_S@ +LTLIBOBJS = @LTLIBOBJS@ +LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@ +MAINT = @MAINT@ +MAKEINFO = @MAKEINFO@ +MANIFEST_TOOL = @MANIFEST_TOOL@ +MKDIR_P = @MKDIR_P@ +NM = @NM@ +NMEDIT = @NMEDIT@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +OTOOL = @OTOOL@ +OTOOL64 = @OTOOL64@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PIE_CFLAGS = @PIE_CFLAGS@ +PIE_LDFLAGS = @PIE_LDFLAGS@ +RANLIB = @RANLIB@ +RELRO_LDFLAGS = @RELRO_LDFLAGS@ +RUN_TEST = @RUN_TEST@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +VALGRIND = @VALGRIND@ +VERSION = @VERSION@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_ct_AR = @ac_ct_AR@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +docdir = @docdir@ +dovecot_docdir = @dovecot_docdir@ +dovecot_installed_moduledir = @dovecot_installed_moduledir@ +dovecot_moduledir = @dovecot_moduledir@ +dovecot_pkgincludedir = @dovecot_pkgincludedir@ +dovecot_pkglibdir = @dovecot_pkglibdir@ +dovecot_pkglibexecdir = @dovecot_pkglibexecdir@ +dovecot_statedir = @dovecot_statedir@ +dovecotdir = @dovecotdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +moduledir = @moduledir@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +runstatedir = @runstatedir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +sieve_docdir = @sieve_docdir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target_alias = @target_alias@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +noinst_LTLIBRARIES = libsieve_ext_mime.la +AM_CPPFLAGS = \ + -I$(srcdir)/../.. \ + -I$(srcdir)/../../util \ + -I$(srcdir)/../variables \ + $(LIBDOVECOT_INCLUDE) + +commands = \ + cmd-foreverypart.c \ + cmd-break.c \ + cmd-extracttext.c + +tags = \ + tag-mime.c + +extensions = \ + ext-mime.c \ + ext-foreverypart.c \ + ext-extracttext.c + +libsieve_ext_mime_la_SOURCES = \ + ext-mime-common.c \ + $(commands) \ + $(tags) \ + $(extensions) + +noinst_HEADERS = \ + ext-mime-common.h + +all: all-am + +.SUFFIXES: +.SUFFIXES: .c .lo .o .obj +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign src/lib-sieve/plugins/mime/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --foreign src/lib-sieve/plugins/mime/Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): + +clean-noinstLTLIBRARIES: + -test -z "$(noinst_LTLIBRARIES)" || rm -f $(noinst_LTLIBRARIES) + @list='$(noinst_LTLIBRARIES)'; \ + locs=`for p in $$list; do echo $$p; done | \ + sed 's|^[^/]*$$|.|; s|/[^/]*$$||; s|$$|/so_locations|' | \ + sort -u`; \ + test -z "$$locs" || { \ + echo rm -f $${locs}; \ + rm -f $${locs}; \ + } + +libsieve_ext_mime.la: $(libsieve_ext_mime_la_OBJECTS) $(libsieve_ext_mime_la_DEPENDENCIES) $(EXTRA_libsieve_ext_mime_la_DEPENDENCIES) + $(AM_V_CCLD)$(LINK) $(libsieve_ext_mime_la_OBJECTS) $(libsieve_ext_mime_la_LIBADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cmd-break.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cmd-extracttext.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cmd-foreverypart.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ext-extracttext.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ext-foreverypart.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ext-mime-common.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ext-mime.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tag-mime.Plo@am__quote@ # am--include-marker + +$(am__depfiles_remade): + @$(MKDIR_P) $(@D) + @echo '# dummy' >$@-t && $(am__mv) $@-t $@ + +am--depfiles: $(am__depfiles_remade) + +.c.o: +@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ $< + +.c.obj: +@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'` + +.c.lo: +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +ID: $(am__tagged_files) + $(am__define_uniq_tagged_files); mkid -fID $$unique +tags: tags-am +TAGS: tags + +tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + set x; \ + here=`pwd`; \ + $(am__define_uniq_tagged_files); \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: ctags-am + +CTAGS: ctags +ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + $(am__define_uniq_tagged_files); \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" +cscopelist: cscopelist-am + +cscopelist-am: $(am__tagged_files) + list='$(am__tagged_files)'; \ + case "$(srcdir)" in \ + [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ + *) sdir=$(subdir)/$(srcdir) ;; \ + esac; \ + for i in $$list; do \ + if test -f "$$i"; then \ + echo "$(subdir)/$$i"; \ + else \ + echo "$$sdir/$$i"; \ + fi; \ + done >> $(top_builddir)/cscope.files + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags + +distdir: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) distdir-am + +distdir-am: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ + else \ + test -f "$(distdir)/$$file" \ + || cp -p $$d/$$file "$(distdir)/$$file" \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile $(LTLIBRARIES) $(HEADERS) +installdirs: +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + if test -z '$(STRIP)'; then \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + install; \ + else \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ + fi +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-libtool clean-noinstLTLIBRARIES \ + mostlyclean-am + +distclean: distclean-am + -rm -f ./$(DEPDIR)/cmd-break.Plo + -rm -f ./$(DEPDIR)/cmd-extracttext.Plo + -rm -f ./$(DEPDIR)/cmd-foreverypart.Plo + -rm -f ./$(DEPDIR)/ext-extracttext.Plo + -rm -f ./$(DEPDIR)/ext-foreverypart.Plo + -rm -f ./$(DEPDIR)/ext-mime-common.Plo + -rm -f ./$(DEPDIR)/ext-mime.Plo + -rm -f ./$(DEPDIR)/tag-mime.Plo + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -f ./$(DEPDIR)/cmd-break.Plo + -rm -f ./$(DEPDIR)/cmd-extracttext.Plo + -rm -f ./$(DEPDIR)/cmd-foreverypart.Plo + -rm -f ./$(DEPDIR)/ext-extracttext.Plo + -rm -f ./$(DEPDIR)/ext-foreverypart.Plo + -rm -f ./$(DEPDIR)/ext-mime-common.Plo + -rm -f ./$(DEPDIR)/ext-mime.Plo + -rm -f ./$(DEPDIR)/tag-mime.Plo + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: + +.MAKE: install-am install-strip + +.PHONY: CTAGS GTAGS TAGS all all-am am--depfiles check check-am clean \ + clean-generic clean-libtool clean-noinstLTLIBRARIES \ + cscopelist-am ctags ctags-am distclean distclean-compile \ + distclean-generic distclean-libtool distclean-tags distdir dvi \ + dvi-am html html-am info info-am install install-am \ + install-data install-data-am install-dvi install-dvi-am \ + install-exec install-exec-am install-html install-html-am \ + install-info install-info-am install-man install-pdf \ + install-pdf-am install-ps install-ps-am install-strip \ + installcheck installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-compile \ + mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ + tags tags-am uninstall uninstall-am + +.PRECIOUS: Makefile + + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/pigeonhole/src/lib-sieve/plugins/mime/cmd-break.c b/pigeonhole/src/lib-sieve/plugins/mime/cmd-break.c new file mode 100644 index 0000000..e6ade4c --- /dev/null +++ b/pigeonhole/src/lib-sieve/plugins/mime/cmd-break.c @@ -0,0 +1,273 @@ +/* Copyright (c) 2002-2018 Pigeonhole authors, see the included COPYING file + */ + +#include "sieve-common.h" +#include "sieve-code.h" +#include "sieve-extensions.h" +#include "sieve-commands.h" +#include "sieve-validator.h" +#include "sieve-generator.h" +#include "sieve-interpreter.h" +#include "sieve-binary.h" +#include "sieve-dump.h" + +#include "ext-mime-common.h" + +#include <ctype.h> + +/* break + * + * Syntax: + * break [":name" <name: string>] + * + */ + +static bool cmd_break_registered + (struct sieve_validator *valdtr, const struct sieve_extension *ext, + struct sieve_command_registration *cmd_reg); +static bool cmd_break_pre_validate + (struct sieve_validator *valdtr, struct sieve_command *cmd); +static bool cmd_break_validate + (struct sieve_validator *valdtr, struct sieve_command *cmd); +static bool cmd_break_generate + (const struct sieve_codegen_env *cgenv, + struct sieve_command *ctx); + +const struct sieve_command_def cmd_break = { + .identifier = "break", + .type = SCT_COMMAND, + .positional_args = 0, + .subtests = 0, + .block_allowed = FALSE, + .block_required = FALSE, + .registered = cmd_break_registered, + .pre_validate = cmd_break_pre_validate, + .validate = cmd_break_validate, + .generate = cmd_break_generate, +}; + +/* + * Tagged arguments + */ + +/* Forward declarations */ + +static bool cmd_break_validate_name_tag + (struct sieve_validator *valdtr, struct sieve_ast_argument **arg, + struct sieve_command *cmd); + +/* Argument objects */ + +static const struct sieve_argument_def break_name_tag = { + .identifier = "name", + .validate = cmd_break_validate_name_tag +}; + +/* + * Break operation + */ + +static bool cmd_break_operation_dump + (const struct sieve_dumptime_env *denv, sieve_size_t *address); +static int cmd_break_operation_execute + (const struct sieve_runtime_env *renv, sieve_size_t *address); + +const struct sieve_operation_def break_operation = { + .mnemonic = "BREAK", + .ext_def = &foreverypart_extension, + .code = EXT_FOREVERYPART_OPERATION_BREAK, + .dump = cmd_break_operation_dump, + .execute = cmd_break_operation_execute +}; + +/* + * Validation data + */ + +struct cmd_break_data { + struct sieve_ast_argument *name; + struct sieve_command *loop_cmd; +}; + +/* + * Tag validation + */ + +static bool cmd_break_validate_name_tag +(struct sieve_validator *valdtr, struct sieve_ast_argument **arg, + struct sieve_command *cmd) +{ + struct cmd_break_data *data = + (struct cmd_break_data *)cmd->data; + struct sieve_ast_argument *tag = *arg; + + /* Detach the tag itself */ + *arg = sieve_ast_arguments_detach(*arg, 1); + + /* Check syntax: + * :name <string> + */ + if ( !sieve_validate_tag_parameter + (valdtr, cmd, tag, *arg, NULL, 0, SAAT_STRING, TRUE) ) + return FALSE; + data->name = *arg; + + /* Skip parameter */ + *arg = sieve_ast_argument_next(*arg); + return TRUE; +} + +/* + * Command registration + */ + +static bool cmd_break_registered +(struct sieve_validator *valdtr, const struct sieve_extension *ext, + struct sieve_command_registration *cmd_reg) +{ + sieve_validator_register_tag + (valdtr, cmd_reg, ext, &break_name_tag, 0); + + return TRUE; +} + +/* + * Command validation + */ + +static bool cmd_break_pre_validate +(struct sieve_validator *valdtr ATTR_UNUSED, struct sieve_command *cmd) +{ + struct cmd_break_data *data; + pool_t pool = sieve_command_pool(cmd); + + data = p_new(pool, struct cmd_break_data, 1); + cmd->data = data; + return TRUE; +} + +static bool cmd_break_validate +(struct sieve_validator *valdtr, struct sieve_command *cmd) +{ + struct cmd_break_data *data = + (struct cmd_break_data *)cmd->data; + struct sieve_ast_node *node = cmd->ast_node; + const char *name = ( data->name == NULL ? + NULL : sieve_ast_argument_strc(data->name) ); + + i_assert(node != NULL); + while ( node != NULL && node->command != NULL ) { + if ( sieve_command_is(node->command, cmd_foreverypart) ) { + struct ext_foreverypart_loop *loop = + (struct ext_foreverypart_loop *)node->command->data; + if ( name == NULL || + (name != NULL && loop->name != NULL && + strcmp(name, loop->name) == 0) ) { + data->loop_cmd = node->command; + break; + } + } + node = sieve_ast_node_parent(node); + } + + if ( data->loop_cmd == NULL ) { + if ( name == NULL ) { + sieve_command_validate_error(valdtr, cmd, + "the break command is not placed inside " + "a foreverypart loop"); + } else { + sieve_command_validate_error(valdtr, cmd, + "the break command is not placed inside " + "a foreverypart loop named `%s'", + name); + } + return FALSE; + } + + sieve_command_exit_block_unconditionally(cmd); + return TRUE; +} + +/* + * Code generation + */ + +static bool cmd_break_generate +(const struct sieve_codegen_env *cgenv, struct sieve_command *cmd) +{ + struct cmd_break_data *data = + (struct cmd_break_data *)cmd->data; + struct ext_foreverypart_loop *loop; + + i_assert( data->loop_cmd != NULL ); + loop = (struct ext_foreverypart_loop *)data->loop_cmd->data; + + sieve_operation_emit(cgenv->sblock, cmd->ext, &break_operation); + sieve_jumplist_add(loop->exit_jumps, + sieve_binary_emit_offset(cgenv->sblock, 0)); + return TRUE; +} + +/* + * Code dump + */ + +static bool cmd_break_operation_dump +(const struct sieve_dumptime_env *denv, sieve_size_t *address) +{ + unsigned int pc = *address; + sieve_offset_t offset; + + sieve_code_dumpf(denv, "BREAK"); + sieve_code_descend(denv); + + if ( !sieve_binary_read_offset(denv->sblock, address, &offset) ) + return FALSE; + + sieve_code_dumpf(denv, "END: %d [%08x]", offset, pc + offset); + return TRUE; +} + +/* + * Code execution + */ + +static int cmd_break_operation_execute +(const struct sieve_runtime_env *renv, sieve_size_t *address) +{ + struct sieve_interpreter_loop *loop; + unsigned int pc = *address; + sieve_offset_t offset; + sieve_size_t loop_end; + + /* + * Read operands + */ + + if ( !sieve_binary_read_offset(renv->sblock, address, &offset) ) + { + sieve_runtime_trace_error(renv, "invalid loop end offset"); + return SIEVE_EXEC_BIN_CORRUPT; + } + + loop_end = pc + offset; + + /* + * Perform operation + */ + + sieve_runtime_trace(renv, SIEVE_TRLVL_ACTIONS, "break command"); + sieve_runtime_trace_descend(renv); + + loop = sieve_interpreter_loop_get + (renv->interp, loop_end, &foreverypart_extension); + if ( loop == NULL ) { + sieve_runtime_trace_error(renv, "no matching loop found"); + return SIEVE_EXEC_BIN_CORRUPT; + } + + sieve_interpreter_loop_break(renv->interp, loop); + return SIEVE_EXEC_OK; +} + + diff --git a/pigeonhole/src/lib-sieve/plugins/mime/cmd-extracttext.c b/pigeonhole/src/lib-sieve/plugins/mime/cmd-extracttext.c new file mode 100644 index 0000000..d9b31a2 --- /dev/null +++ b/pigeonhole/src/lib-sieve/plugins/mime/cmd-extracttext.c @@ -0,0 +1,370 @@ +/* Copyright (c) 2002-2018 Pigeonhole authors, see the included COPYING file + */ + +#include "lib.h" +#include "str.h" +#include "array.h" + +#include "sieve-common.h" +#include "sieve-extensions.h" +#include "sieve-code.h" +#include "sieve-ast.h" +#include "sieve-commands.h" +#include "sieve-binary.h" +#include "sieve-message.h" +#include "sieve-validator.h" +#include "sieve-generator.h" +#include "sieve-interpreter.h" +#include "sieve-dump.h" + +#include "sieve-ext-variables.h" + +#include "ext-mime-common.h" + +/* + * Extracttext command + * + * Syntax: + * extracttext [MODIFIER] [":first" number] <varname: string> + */ + +static bool cmd_extracttext_registered + (struct sieve_validator *valdtr, const struct sieve_extension *ext, + struct sieve_command_registration *cmd_reg); +static bool cmd_extracttext_validate + (struct sieve_validator *valdtr, struct sieve_command *cmd); +static bool cmd_extracttext_generate + (const struct sieve_codegen_env *cgenv, struct sieve_command *ctx); + +const struct sieve_command_def cmd_extracttext = { + .identifier = "extracttext", + .type = SCT_COMMAND, + .positional_args = 1, + .subtests = 0, + .block_allowed = FALSE, + .block_required = FALSE, + .registered = cmd_extracttext_registered, + .validate = cmd_extracttext_validate, + .generate = cmd_extracttext_generate +}; + +/* + * Extracttext command tags + */ + +enum cmd_extracttext_optional { + CMD_EXTRACTTEXT_OPT_END, + CMD_EXTRACTTEXT_OPT_FIRST +}; + +static bool cmd_extracttext_validate_first_tag + (struct sieve_validator *valdtr, struct sieve_ast_argument **arg, + struct sieve_command *cmd); + +static const struct sieve_argument_def extracttext_from_tag = { + .identifier = "first", + .validate = cmd_extracttext_validate_first_tag +}; + +/* + * Extracttext operation + */ + +static bool cmd_extracttext_operation_dump + (const struct sieve_dumptime_env *denv, sieve_size_t *address); +static int cmd_extracttext_operation_execute + (const struct sieve_runtime_env *renv, sieve_size_t *address); + +const struct sieve_operation_def extracttext_operation = { + .mnemonic = "EXTRACTTEXT", + .ext_def = &extracttext_extension, + .dump = cmd_extracttext_operation_dump, + .execute = cmd_extracttext_operation_execute +}; + +/* + * Compiler context + */ + +struct cmd_extracttext_context { + ARRAY_TYPE(sieve_variables_modifier) modifiers; +}; + +/* + * Tag validation + */ + +static bool cmd_extracttext_validate_first_tag +(struct sieve_validator *valdtr, struct sieve_ast_argument **arg, + struct sieve_command *cmd) +{ + struct sieve_ast_argument *tag = *arg; + + /* Detach the tag itself */ + *arg = sieve_ast_arguments_detach(*arg,1); + + /* Check syntax: + * :first <number> + */ + if ( !sieve_validate_tag_parameter + (valdtr, cmd, tag, *arg, NULL, 0, SAAT_NUMBER, FALSE) ) + return FALSE; + + /* Skip parameter */ + *arg = sieve_ast_argument_next(*arg); + + return TRUE; +} + +/* Command registration */ + +static bool cmd_extracttext_registered +(struct sieve_validator *valdtr, const struct sieve_extension *ext, + struct sieve_command_registration *cmd_reg) +{ + struct ext_extracttext_context *ectx = + (struct ext_extracttext_context *)ext->context; + + sieve_validator_register_tag(valdtr, cmd_reg, ext, + &extracttext_from_tag, CMD_EXTRACTTEXT_OPT_FIRST); + sieve_variables_modifiers_link_tag + (valdtr, ectx->var_ext, cmd_reg); + return TRUE; +} + +/* + * Command validation + */ + +static bool cmd_extracttext_validate(struct sieve_validator *valdtr, + struct sieve_command *cmd) +{ + const struct sieve_extension *this_ext = cmd->ext; + struct ext_extracttext_context *ectx = + (struct ext_extracttext_context *)this_ext->context; + struct sieve_ast_node *node = cmd->ast_node; + struct sieve_ast_argument *arg = cmd->first_positional; + pool_t pool = sieve_command_pool(cmd); + struct cmd_extracttext_context *sctx; + + /* Create command context */ + sctx = p_new(pool, struct cmd_extracttext_context, 1); + p_array_init(&sctx->modifiers, pool, 4); + cmd->data = (void *) sctx; + + /* Validate modifiers */ + if ( !sieve_variables_modifiers_validate + (valdtr, cmd, &sctx->modifiers) ) + return FALSE; + + /* Validate varname argument */ + if ( !sieve_validate_positional_argument + (valdtr, cmd, arg, "varname", 1, SAAT_STRING) ) { + return FALSE; + } + if ( !sieve_variable_argument_activate + (ectx->var_ext, ectx->var_ext, valdtr, cmd, arg, TRUE) ) + return FALSE; + + /* Check foreverypart context */ + i_assert(node != NULL); + while ( node != NULL ) { + if ( node->command != NULL && + sieve_command_is(node->command, cmd_foreverypart) ) + break; + node = sieve_ast_node_parent(node); + } + + if ( node == NULL ) { + sieve_command_validate_error(valdtr, cmd, + "the extracttext command is not placed inside " + "a foreverypart loop"); + return FALSE; + } + return TRUE; +} + +/* + * Code generation + */ + +static bool cmd_extracttext_generate + (const struct sieve_codegen_env *cgenv, struct sieve_command *cmd) +{ + const struct sieve_extension *this_ext = cmd->ext; + struct sieve_binary_block *sblock = cgenv->sblock; + struct cmd_extracttext_context *sctx = + (struct cmd_extracttext_context *) cmd->data; + + sieve_operation_emit(sblock, this_ext, &extracttext_operation); + + /* Generate arguments */ + if ( !sieve_generate_arguments(cgenv, cmd, NULL) ) + return FALSE; + + /* Generate modifiers */ + if ( !sieve_variables_modifiers_generate + (cgenv, &sctx->modifiers) ) + return FALSE; + + return TRUE; +} + +/* + * Code dump + */ + +static bool cmd_extracttext_operation_dump +(const struct sieve_dumptime_env *denv, sieve_size_t *address) +{ + int opt_code = 0; + + sieve_code_dumpf(denv, "EXTRACTTEXT"); + sieve_code_descend(denv); + + /* Dump optional operands */ + + for (;;) { + int opt; + bool opok = TRUE; + + if ( (opt=sieve_opr_optional_dump(denv, address, &opt_code)) < 0 ) + return FALSE; + if ( opt == 0 ) break; + + switch ( opt_code ) { + case CMD_EXTRACTTEXT_OPT_FIRST: + opok = sieve_opr_number_dump(denv, address, "first"); + break; + default: + return FALSE; + } + if ( !opok ) return FALSE; + } + + /* Print both variable name and string value */ + if ( !sieve_opr_string_dump(denv, address, "varname") ) + return FALSE; + + return sieve_variables_modifiers_code_dump(denv, address); +} + +/* + * Code execution + */ + +static int cmd_extracttext_operation_execute +(const struct sieve_runtime_env *renv, sieve_size_t *address) +{ + const struct sieve_extension *this_ext = renv->oprtn->ext; + struct ext_extracttext_context *ectx = + (struct ext_extracttext_context *)this_ext->context; + struct sieve_variable_storage *storage; + ARRAY_TYPE(sieve_variables_modifier) modifiers; + struct ext_foreverypart_runtime_loop *sfploop; + struct sieve_message_part *mpart; + struct sieve_message_part_data mpart_data; + int opt_code = 0; + sieve_number_t first = 0; + string_t *value; + unsigned int var_index; + bool have_first = FALSE; + int ret = SIEVE_EXEC_OK; + + /* + * Read the normal operands + */ + + /* Optional operands */ + + for (;;) { + int opt; + + if ( (opt=sieve_opr_optional_read + (renv, address, &opt_code)) < 0 ) + return SIEVE_EXEC_BIN_CORRUPT; + if ( opt == 0 ) break; + + switch ( opt_code ) { + case CMD_EXTRACTTEXT_OPT_FIRST: + ret = sieve_opr_number_read + (renv, address, "first", &first); + have_first = TRUE; + break; + default: + sieve_runtime_trace_error(renv, "unknown optional operand"); + return SIEVE_EXEC_BIN_CORRUPT; + } + if ( ret <= 0 ) return ret; + } + + /* Varname operand */ + + if ( (ret=sieve_variable_operand_read + (renv, address, "varname", &storage, &var_index)) <= 0 ) + return ret; + + /* Modifiers */ + + if ( (ret=sieve_variables_modifiers_code_read + (renv, ectx->var_ext, address, &modifiers)) <= 0 ) + return ret; + + /* + * Determine and assign the value + */ + + sieve_runtime_trace(renv, SIEVE_TRLVL_COMMANDS, "extracttext command"); + sieve_runtime_trace_descend(renv); + + sfploop = ext_foreverypart_runtime_loop_get_current(renv); + if ( sfploop == NULL ) { + sieve_runtime_trace_error(renv, + "outside foreverypart context"); + return SIEVE_EXEC_BIN_CORRUPT; + } + + /* Get current message part */ + mpart = sieve_message_part_iter_current(&sfploop->part_iter); + i_assert( mpart != NULL ); + + /* Get message part content */ + sieve_message_part_get_data(mpart, &mpart_data, TRUE); + + /* Apply ":first" limit, if any */ + if ( !have_first || (size_t)first > mpart_data.size ) { + value = t_str_new_const(mpart_data.content, mpart_data.size); + } else { + value = t_str_new((size_t)first); + str_append_data(value, mpart_data.content, (size_t)first); + } + + /* Apply modifiers */ + if ( (ret=sieve_variables_modifiers_apply + (renv, ectx->var_ext, &modifiers, &value)) <= 0 ) + return ret; + + /* Actually assign the value if all is well */ + i_assert ( value != NULL ); + if ( !sieve_variable_assign(storage, var_index, value) ) + return SIEVE_EXEC_BIN_CORRUPT; + + /* Trace */ + if ( sieve_runtime_trace_active(renv, SIEVE_TRLVL_COMMANDS) ) { + const char *var_name, *var_id; + + (void)sieve_variable_get_identifier(storage, var_index, &var_name); + var_id = sieve_variable_get_varid(storage, var_index); + + sieve_runtime_trace_here(renv, 0, "assign `%s' [%s] = \"%s\"", + var_name, var_id, str_c(value)); + } + + return SIEVE_EXEC_OK; +} + + + + + + diff --git a/pigeonhole/src/lib-sieve/plugins/mime/cmd-foreverypart.c b/pigeonhole/src/lib-sieve/plugins/mime/cmd-foreverypart.c new file mode 100644 index 0000000..435cb5c --- /dev/null +++ b/pigeonhole/src/lib-sieve/plugins/mime/cmd-foreverypart.c @@ -0,0 +1,377 @@ +/* Copyright (c) 2002-2018 Pigeonhole authors, see the included COPYING file + */ + +#include "sieve-common.h" +#include "sieve-limits.h" +#include "sieve-code.h" +#include "sieve-extensions.h" +#include "sieve-commands.h" +#include "sieve-validator.h" +#include "sieve-generator.h" +#include "sieve-interpreter.h" +#include "sieve-binary.h" +#include "sieve-dump.h" +#include "sieve-message.h" + +#include "ext-mime-common.h" + +#include <ctype.h> + +/* Foreverypart + * + * Syntax: + * foreverypart [":name" <name: string>] <block> + * + */ + +static bool cmd_foreverypart_registered + (struct sieve_validator *valdtr, const struct sieve_extension *ext, + struct sieve_command_registration *cmd_reg); +static bool cmd_foreverypart_pre_validate + (struct sieve_validator *valdtr, struct sieve_command *cmd); +static bool cmd_foreverypart_validate + (struct sieve_validator *valdtr, struct sieve_command *cmd); +static bool cmd_foreverypart_generate + (const struct sieve_codegen_env *cgenv, + struct sieve_command *ctx); + +const struct sieve_command_def cmd_foreverypart = { + .identifier = "foreverypart", + .type = SCT_COMMAND, + .positional_args = 0, + .subtests = 0, + .block_allowed = TRUE, + .block_required = TRUE, + .registered = cmd_foreverypart_registered, + .pre_validate = cmd_foreverypart_pre_validate, + .validate = cmd_foreverypart_validate, + .generate = cmd_foreverypart_generate +}; + +/* + * Tagged arguments + */ + +/* Forward declarations */ + +static bool cmd_foreverypart_validate_name_tag + (struct sieve_validator *valdtr, struct sieve_ast_argument **arg, + struct sieve_command *cmd); + +/* Argument objects */ + +static const struct sieve_argument_def foreverypart_name_tag = { + .identifier = "name", + .validate = cmd_foreverypart_validate_name_tag, +}; + +/* + * foreverypart operation + */ + +static bool cmd_foreverypart_begin_operation_dump + (const struct sieve_dumptime_env *denv, sieve_size_t *address); +static int cmd_foreverypart_begin_operation_execute + (const struct sieve_runtime_env *renv, sieve_size_t *address); + +const struct sieve_operation_def foreverypart_begin_operation = { + .mnemonic = "FOREVERYPART_BEGIN", + .ext_def = &foreverypart_extension, + .code = EXT_FOREVERYPART_OPERATION_FOREVERYPART_BEGIN, + .dump = cmd_foreverypart_begin_operation_dump, + .execute = cmd_foreverypart_begin_operation_execute +}; + +static bool cmd_foreverypart_end_operation_dump + (const struct sieve_dumptime_env *denv, sieve_size_t *address); +static int cmd_foreverypart_end_operation_execute + (const struct sieve_runtime_env *renv, sieve_size_t *address); + +const struct sieve_operation_def foreverypart_end_operation = { + .mnemonic = "FOREVERYPART_END", + .ext_def = &foreverypart_extension, + .code = EXT_FOREVERYPART_OPERATION_FOREVERYPART_END, + .dump = cmd_foreverypart_end_operation_dump, + .execute = cmd_foreverypart_end_operation_execute +}; + +/* + * Tag validation + */ + +static bool cmd_foreverypart_validate_name_tag +(struct sieve_validator *valdtr, struct sieve_ast_argument **arg, + struct sieve_command *cmd) +{ + struct ext_foreverypart_loop *loop = + (struct ext_foreverypart_loop *)cmd->data; + struct sieve_ast_argument *tag = *arg; + + /* Detach the tag itself */ + *arg = sieve_ast_arguments_detach(*arg, 1); + + /* Check syntax: + * :name <string> + */ + if ( !sieve_validate_tag_parameter + (valdtr, cmd, tag, *arg, NULL, 0, SAAT_STRING, TRUE) ) + return FALSE; + loop->name = sieve_ast_argument_strc(*arg); + + /* Detach parameter */ + *arg = sieve_ast_arguments_detach(*arg, 1); + return TRUE; +} + +/* + * Command registration + */ + +static bool cmd_foreverypart_registered +(struct sieve_validator *valdtr, const struct sieve_extension *ext, + struct sieve_command_registration *cmd_reg) +{ + sieve_validator_register_tag + (valdtr, cmd_reg, ext, &foreverypart_name_tag, 0); + return TRUE; +} + +/* + * Command validation + */ + +static bool cmd_foreverypart_pre_validate +(struct sieve_validator *valdtr ATTR_UNUSED, struct sieve_command *cmd) +{ + struct ext_foreverypart_loop *loop; + pool_t pool = sieve_command_pool(cmd); + + loop = p_new(pool, struct ext_foreverypart_loop, 1); + cmd->data = loop; + + return TRUE; +} + +static bool cmd_foreverypart_validate +(struct sieve_validator *valdtr, struct sieve_command *cmd) +{ + struct sieve_ast_node *node = cmd->ast_node; + unsigned int nesting = 0; + + /* Determine nesting depth of foreverypart commands at this point. */ + i_assert(node != NULL); + node = sieve_ast_node_parent(node); + while ( node != NULL && node->command != NULL ) { + if ( sieve_command_is(node->command, cmd_foreverypart) ) + nesting++; + node = sieve_ast_node_parent(node); + } + + /* Enforce nesting limit + NOTE: this only recognizes the foreverypart command as a loop; if + new loop commands are introduced in the future, these must be + recognized somehow. */ + if ( nesting + 1 > SIEVE_MAX_LOOP_DEPTH ) { + sieve_command_validate_error(valdtr, cmd, + "the nested foreverypart loop exceeds " + "the nesting limit (<= %u levels)", + SIEVE_MAX_LOOP_DEPTH); + return FALSE; + } + + return TRUE; +} + +/* + * Code generation + */ + +static bool cmd_foreverypart_generate +(const struct sieve_codegen_env *cgenv, struct sieve_command *cmd) +{ + struct ext_foreverypart_loop *loop = + (struct ext_foreverypart_loop *)cmd->data; + sieve_size_t block_begin, loop_jump; + + /* Emit FOREVERYPART_BEGIN operation */ + sieve_operation_emit(cgenv->sblock, + cmd->ext, &foreverypart_begin_operation); + + /* Emit exit address */ + loop->exit_jumps = sieve_jumplist_create + (sieve_command_pool(cmd), cgenv->sblock); + sieve_jumplist_add(loop->exit_jumps, + sieve_binary_emit_offset(cgenv->sblock, 0)); + block_begin = sieve_binary_block_get_size(cgenv->sblock); + + /* Generate loop block */ + if ( !sieve_generate_block(cgenv, cmd->ast_node) ) + return FALSE; + + /* Emit FOREVERYPART_END operation */ + sieve_operation_emit(cgenv->sblock, + cmd->ext, &foreverypart_end_operation); + loop_jump = sieve_binary_block_get_size(cgenv->sblock); + i_assert(loop_jump > block_begin); + (void)sieve_binary_emit_offset + (cgenv->sblock, (loop_jump - block_begin)); + + /* Resolve exit address */ + sieve_jumplist_resolve(loop->exit_jumps); + + return TRUE; +} + +/* + * Code dump + */ + +static bool cmd_foreverypart_begin_operation_dump +(const struct sieve_dumptime_env *denv, sieve_size_t *address) +{ + unsigned int pc = *address; + sieve_offset_t offset; + + sieve_code_dumpf(denv, "FOREVERYPART_BEGIN"); + sieve_code_descend(denv); + + if ( !sieve_binary_read_offset(denv->sblock, address, &offset) ) + return FALSE; + + sieve_code_dumpf(denv, "END: %d [%08x]", offset, pc + offset); + return TRUE; +} + +static bool cmd_foreverypart_end_operation_dump +(const struct sieve_dumptime_env *denv, + sieve_size_t *address ATTR_UNUSED) +{ + unsigned int pc = *address; + sieve_offset_t offset; + + sieve_code_dumpf(denv, "FOREVERYPART_END"); + sieve_code_descend(denv); + + if ( !sieve_binary_read_offset(denv->sblock, address, &offset) ) + return FALSE; + + sieve_code_dumpf(denv, "BEGIN: -%d [%08x]", offset, pc - offset); + return TRUE; +} + +/* + * Code execution + */ + +static int cmd_foreverypart_begin_operation_execute +(const struct sieve_runtime_env *renv, sieve_size_t *address) +{ + struct sieve_interpreter_loop *loop; + struct ext_foreverypart_runtime_loop *fploop, *sfploop; + unsigned int pc = *address; + sieve_offset_t offset; + sieve_size_t loop_end; + pool_t pool; + int ret; + + /* + * Read operands + */ + + if ( !sieve_binary_read_offset(renv->sblock, address, &offset) ) + { + sieve_runtime_trace_error(renv, "invalid loop end offset"); + return SIEVE_EXEC_BIN_CORRUPT; + } + + loop_end = pc + offset; + + /* + * Perform operation + */ + + sieve_runtime_trace(renv, SIEVE_TRLVL_COMMANDS, + "foreverypart loop begin"); + sieve_runtime_trace_descend(renv); + + sfploop = ext_foreverypart_runtime_loop_get_current(renv); + + if ( (ret=sieve_interpreter_loop_start(renv->interp, + loop_end, &foreverypart_extension, &loop)) <= 0 ) + return ret; + + pool = sieve_interpreter_loop_get_pool(loop); + fploop = p_new(pool, struct ext_foreverypart_runtime_loop, 1); + + if ( sfploop == NULL ) { + if ( (ret=sieve_message_part_iter_init + (&fploop->part_iter, renv)) <= 0 ) + return ret; + } else { + sieve_message_part_iter_children(&sfploop->part_iter, + &fploop->part_iter); + } + fploop->part = sieve_message_part_iter_current(&fploop->part_iter); + if (fploop->part != NULL) { + sieve_interpreter_loop_set_context(loop, (void*)fploop); + } else { + /* No children parts to iterate */ + sieve_runtime_trace(renv, SIEVE_TRLVL_COMMANDS, + "no children at this level"); + sieve_interpreter_loop_break(renv->interp, loop); + } + return SIEVE_EXEC_OK; +} + +static int cmd_foreverypart_end_operation_execute +(const struct sieve_runtime_env *renv, sieve_size_t *address) +{ + struct sieve_interpreter_loop *loop; + struct ext_foreverypart_runtime_loop *fploop; + unsigned int pc = *address; + sieve_offset_t offset; + sieve_size_t loop_begin; + + /* + * Read operands + */ + + if ( !sieve_binary_read_offset(renv->sblock, address, &offset) ) + { + sieve_runtime_trace_error(renv, "invalid loop begin offset"); + return SIEVE_EXEC_BIN_CORRUPT; + } + + loop_begin = pc - offset; + + /* + * Perform operation + */ + + sieve_runtime_trace(renv, + SIEVE_TRLVL_COMMANDS, "foreverypart loop end"); + sieve_runtime_trace_descend(renv); + + loop = sieve_interpreter_loop_get + (renv->interp, *address, &foreverypart_extension); + if ( loop == NULL ) { + sieve_runtime_trace_error(renv, "no matching loop found"); + return SIEVE_EXEC_BIN_CORRUPT; + } + + fploop = (struct ext_foreverypart_runtime_loop *) + sieve_interpreter_loop_get_context(loop); + i_assert(fploop->part != NULL); + fploop->part = sieve_message_part_iter_next(&fploop->part_iter); + if ( fploop->part == NULL ) { + sieve_runtime_trace(renv, + SIEVE_TRLVL_COMMANDS, "no more message parts"); + return sieve_interpreter_loop_break(renv->interp, loop); + } + + sieve_runtime_trace(renv, + SIEVE_TRLVL_COMMANDS, "switched to next message part"); + return sieve_interpreter_loop_next(renv->interp, loop, loop_begin); +} + + diff --git a/pigeonhole/src/lib-sieve/plugins/mime/ext-extracttext.c b/pigeonhole/src/lib-sieve/plugins/mime/ext-extracttext.c new file mode 100644 index 0000000..4eab76b --- /dev/null +++ b/pigeonhole/src/lib-sieve/plugins/mime/ext-extracttext.c @@ -0,0 +1,130 @@ +/* Copyright (c) 2002-2018 Pigeonhole authors, see the included COPYING file + */ + +/* Extension extracttext + * --------------------- + * + * Authors: Stephan Bosch + * Specification: RFC 5703, Section 7 + * Implementation: full + * Status: experimental + * + */ + +#include "sieve-common.h" + +#include "sieve-code.h" +#include "sieve-extensions.h" +#include "sieve-actions.h" +#include "sieve-commands.h" +#include "sieve-validator.h" +#include "sieve-generator.h" +#include "sieve-interpreter.h" +#include "sieve-result.h" + +#include "sieve-ext-variables.h" + +#include "ext-mime-common.h" + +/* + * Extension + */ + +static bool ext_extracttext_load + (const struct sieve_extension *ext, void **context); +static void ext_extracttext_unload + (const struct sieve_extension *ext); +static bool ext_extracttext_validator_load + (const struct sieve_extension *ext, struct sieve_validator *valdtr); + +const struct sieve_extension_def extracttext_extension = { + .name = "extracttext", + .load = ext_extracttext_load, + .unload = ext_extracttext_unload, + .validator_load = ext_extracttext_validator_load, + SIEVE_EXT_DEFINE_OPERATION(extracttext_operation) +}; + +static bool ext_extracttext_load +(const struct sieve_extension *ext, void **context) +{ + struct sieve_instance *svinst = ext->svinst; + struct ext_extracttext_context *ectx; + + if ( *context != NULL ) + ext_extracttext_unload(ext); + + ectx = i_new(struct ext_extracttext_context, 1); + ectx->var_ext = sieve_ext_variables_get_extension(ext->svinst); + ectx->fep_ext = sieve_extension_register + (svinst, &foreverypart_extension, FALSE); + *context = (void *)ectx; + return TRUE; +} + +static void ext_extracttext_unload +(const struct sieve_extension *ext) +{ + struct ext_extracttext_context *ctx = + (struct ext_extracttext_context *) ext->context; + + i_free(ctx); +} + +/* + * Extension validation + */ + +static bool ext_extracttext_validator_validate + (const struct sieve_extension *ext, + struct sieve_validator *valdtr, void *context, + struct sieve_ast_argument *require_arg, + bool required); + +const struct sieve_validator_extension +extracttext_validator_extension = { + .ext = &extracttext_extension, + .validate = ext_extracttext_validator_validate +}; + +static bool ext_extracttext_validator_load +(const struct sieve_extension *ext, struct sieve_validator *valdtr) +{ + /* Register validator extension to check for conflict with eextracttext */ + sieve_validator_extension_register + (valdtr, ext, &extracttext_validator_extension, NULL); + + /* Register new commands */ + sieve_validator_register_command(valdtr, ext, &cmd_extracttext); + + return TRUE; +} + +static bool ext_extracttext_validator_validate +(const struct sieve_extension *ext, + struct sieve_validator *valdtr, void *context ATTR_UNUSED, + struct sieve_ast_argument *require_arg, + bool required ATTR_UNUSED) +{ + struct ext_extracttext_context *ectx = + (struct ext_extracttext_context *)ext->context; + + if ( ectx->var_ext == NULL || + !sieve_ext_variables_is_active + (ectx->var_ext, valdtr) ) { + sieve_argument_validate_error(valdtr, require_arg, + "extracttext extension cannot be used " + "without variables extension"); + return FALSE; + } + if ( ectx->fep_ext == NULL || + !sieve_validator_extension_loaded + (valdtr, ectx->fep_ext) ) { + sieve_argument_validate_error(valdtr, require_arg, + "extracttext extension cannot be used " + "without foreverypart extension"); + return FALSE; + } + + return TRUE; +} diff --git a/pigeonhole/src/lib-sieve/plugins/mime/ext-foreverypart.c b/pigeonhole/src/lib-sieve/plugins/mime/ext-foreverypart.c new file mode 100644 index 0000000..6bca199 --- /dev/null +++ b/pigeonhole/src/lib-sieve/plugins/mime/ext-foreverypart.c @@ -0,0 +1,62 @@ +/* Copyright (c) 2002-2018 Pigeonhole authors, see the included COPYING file + */ + +/* Extension foreverypart + * ---------------------- + * + * Authors: Stephan Bosch + * Specification: RFC 5703, Section 3 + * Implementation: full + * Status: experimental + * + */ + +#include "sieve-common.h" + +#include "sieve-code.h" +#include "sieve-extensions.h" +#include "sieve-actions.h" +#include "sieve-commands.h" +#include "sieve-validator.h" +#include "sieve-generator.h" +#include "sieve-interpreter.h" +#include "sieve-result.h" + +#include "ext-mime-common.h" + +/* + * Operations + */ + +const struct sieve_operation_def *ext_foreverypart_operations[] = { + &foreverypart_begin_operation, + &foreverypart_end_operation, + &break_operation +}; + +/* + * Extension + */ + +static bool ext_foreverypart_validator_load + (const struct sieve_extension *ext, struct sieve_validator *valdtr); + +const struct sieve_extension_def foreverypart_extension = { + .name = "foreverypart", + .validator_load = ext_foreverypart_validator_load, + SIEVE_EXT_DEFINE_OPERATIONS(ext_foreverypart_operations) +}; + +/* + * Extension validation + */ + +static bool ext_foreverypart_validator_load +(const struct sieve_extension *ext, struct sieve_validator *valdtr) +{ + /* Register new commands */ + sieve_validator_register_command(valdtr, ext, &cmd_foreverypart); + sieve_validator_register_command(valdtr, ext, &cmd_break); + + return TRUE; +} diff --git a/pigeonhole/src/lib-sieve/plugins/mime/ext-mime-common.c b/pigeonhole/src/lib-sieve/plugins/mime/ext-mime-common.c new file mode 100644 index 0000000..5b38bcb --- /dev/null +++ b/pigeonhole/src/lib-sieve/plugins/mime/ext-mime-common.c @@ -0,0 +1,27 @@ +/* Copyright (c) 2002-2018 Pigeonhole authors, see the included COPYING file + */ + +#include "sieve-common.h" +#include "sieve-interpreter.h" + +#include "ext-mime-common.h" + +struct ext_foreverypart_runtime_loop * +ext_foreverypart_runtime_loop_get_current +(const struct sieve_runtime_env *renv) +{ + struct sieve_interpreter_loop *loop; + struct ext_foreverypart_runtime_loop *fploop; + + loop = sieve_interpreter_loop_get_global + (renv->interp, NULL, &foreverypart_extension); + if ( loop == NULL ) { + fploop = NULL; + } else { + fploop = (struct ext_foreverypart_runtime_loop *) + sieve_interpreter_loop_get_context(loop); + i_assert(fploop->part != NULL); + } + + return fploop; +} diff --git a/pigeonhole/src/lib-sieve/plugins/mime/ext-mime-common.h b/pigeonhole/src/lib-sieve/plugins/mime/ext-mime-common.h new file mode 100644 index 0000000..8b0054d --- /dev/null +++ b/pigeonhole/src/lib-sieve/plugins/mime/ext-mime-common.h @@ -0,0 +1,85 @@ +#ifndef EXT_FOREVERYPART_COMMON_H +#define EXT_FOREVERYPART_COMMON_H + +#include "sieve-message.h" + +/* + * Extension + */ + +struct ext_extracttext_context { + const struct sieve_extension *var_ext; + const struct sieve_extension *fep_ext; +}; + +extern const struct sieve_extension_def foreverypart_extension; +extern const struct sieve_extension_def mime_extension; +extern const struct sieve_extension_def extracttext_extension; + +/* + * Tagged arguments + */ + +extern const struct sieve_argument_def mime_tag; +extern const struct sieve_argument_def mime_anychild_tag; +extern const struct sieve_argument_def mime_type_tag; +extern const struct sieve_argument_def mime_subtype_tag; +extern const struct sieve_argument_def mime_contenttype_tag; +extern const struct sieve_argument_def mime_param_tag; + +/* + * Commands + */ + +struct ext_foreverypart_loop { + const char *name; + struct sieve_jumplist *exit_jumps; +}; + +extern const struct sieve_command_def cmd_foreverypart; +extern const struct sieve_command_def cmd_break; +extern const struct sieve_command_def cmd_extracttext; + +/* + * Operations + */ + +extern const struct sieve_operation_def foreverypart_begin_operation; +extern const struct sieve_operation_def foreverypart_end_operation; +extern const struct sieve_operation_def break_operation; +extern const struct sieve_operation_def extracttext_operation; + +enum ext_foreverypart_opcode { + EXT_FOREVERYPART_OPERATION_FOREVERYPART_BEGIN, + EXT_FOREVERYPART_OPERATION_FOREVERYPART_END, + EXT_FOREVERYPART_OPERATION_BREAK, +}; + +/* + * Operands + */ + +enum ext_mime_option { + EXT_MIME_OPTION_NONE = 0, + EXT_MIME_OPTION_TYPE, + EXT_MIME_OPTION_SUBTYPE, + EXT_MIME_OPTION_CONTENTTYPE, + EXT_MIME_OPTION_PARAM +}; + +extern const struct sieve_operand_def mime_operand; + +/* + * Foreverypart loop + */ + +struct ext_foreverypart_runtime_loop { + struct sieve_message_part_iter part_iter; + struct sieve_message_part *part; +}; + +struct ext_foreverypart_runtime_loop * +ext_foreverypart_runtime_loop_get_current +(const struct sieve_runtime_env *renv); + +#endif diff --git a/pigeonhole/src/lib-sieve/plugins/mime/ext-mime.c b/pigeonhole/src/lib-sieve/plugins/mime/ext-mime.c new file mode 100644 index 0000000..da9963f --- /dev/null +++ b/pigeonhole/src/lib-sieve/plugins/mime/ext-mime.c @@ -0,0 +1,77 @@ +/* Copyright (c) 2002-2018 Pigeonhole authors, see the included COPYING file + */ + +/* Extension mime + * -------------- + * + * Authors: Stephan Bosch + * Specification: RFC 5703, Section 4 + * Implementation: full + * Status: experimental + * + */ + +#include "sieve-common.h" + +#include "sieve-code.h" +#include "sieve-extensions.h" +#include "sieve-actions.h" +#include "sieve-commands.h" +#include "sieve-validator.h" +#include "sieve-generator.h" +#include "sieve-interpreter.h" +#include "sieve-message.h" +#include "sieve-result.h" + +#include "ext-mime-common.h" + +/* + * Extension + */ + +static bool ext_mime_validator_load + (const struct sieve_extension *ext, struct sieve_validator *valdtr); + +const struct sieve_extension_def mime_extension = { + .name = "mime", + .validator_load = ext_mime_validator_load, + SIEVE_EXT_DEFINE_OPERAND(mime_operand) +}; + +/* + * Extension validation + */ + +static bool ext_mime_validator_load +(const struct sieve_extension *ext, struct sieve_validator *valdtr) +{ + /* Register :mime tag and friends with header, address and exists test + * commands and we don't care whether these command are registered or + * even whether these will be registered at all. The validator handles + * either situation gracefully. + */ + sieve_validator_register_external_tag + (valdtr, "header", ext, &mime_tag, SIEVE_OPT_MESSAGE_OVERRIDE); + sieve_validator_register_external_tag + (valdtr, "header", ext, &mime_anychild_tag, 0); + sieve_validator_register_external_tag + (valdtr, "header", ext, &mime_type_tag, 0); + sieve_validator_register_external_tag + (valdtr, "header", ext, &mime_subtype_tag, 0); + sieve_validator_register_external_tag + (valdtr, "header", ext, &mime_contenttype_tag, 0); + sieve_validator_register_external_tag + (valdtr, "header", ext, &mime_param_tag, 0); + + sieve_validator_register_external_tag + (valdtr, "address", ext, &mime_tag, SIEVE_OPT_MESSAGE_OVERRIDE); + sieve_validator_register_external_tag + (valdtr, "address", ext, &mime_anychild_tag, 0); + + sieve_validator_register_external_tag + (valdtr, "exists", ext, &mime_tag, SIEVE_OPT_MESSAGE_OVERRIDE); + sieve_validator_register_external_tag + (valdtr, "exists", ext, &mime_anychild_tag, 0); + + return TRUE; +} diff --git a/pigeonhole/src/lib-sieve/plugins/mime/tag-mime.c b/pigeonhole/src/lib-sieve/plugins/mime/tag-mime.c new file mode 100644 index 0000000..379365e --- /dev/null +++ b/pigeonhole/src/lib-sieve/plugins/mime/tag-mime.c @@ -0,0 +1,757 @@ +/* Copyright (c) 2002-2018 Pigeonhole authors, see the included COPYING file + */ + +#include "lib.h" +#include "rfc822-parser.h" +#include "rfc2231-parser.h" +#include "mail-storage.h" + +#include "sieve-common.h" +#include "sieve-stringlist.h" +#include "sieve-extensions.h" +#include "sieve-commands.h" +#include "sieve-binary.h" +#include "sieve-code.h" +#include "sieve-message.h" +#include "sieve-result.h" +#include "sieve-validator.h" +#include "sieve-generator.h" + +#include "ext-mime-common.h" + +/* + * Tagged argument + */ + +static bool tag_mime_validate + (struct sieve_validator *valdtr, struct sieve_ast_argument **arg, + struct sieve_command *cmd); +static bool tag_mime_generate + (const struct sieve_codegen_env *cgenv, struct sieve_ast_argument *arg, + struct sieve_command *context); + +const struct sieve_argument_def mime_tag = { + .identifier = "mime", + .validate = tag_mime_validate, + .generate = tag_mime_generate +}; + +static bool tag_mime_option_validate + (struct sieve_validator *valdtr, struct sieve_ast_argument **arg, + struct sieve_command *cmd); + +const struct sieve_argument_def mime_anychild_tag = { + .identifier = "anychild", + .validate = tag_mime_option_validate +}; + +const struct sieve_argument_def mime_type_tag = { + .identifier = "type", + .validate = tag_mime_option_validate +}; + +const struct sieve_argument_def mime_subtype_tag = { + .identifier = "subtype", + .validate = tag_mime_option_validate +}; + +const struct sieve_argument_def mime_contenttype_tag = { + .identifier = "contenttype", + .validate = tag_mime_option_validate +}; + +const struct sieve_argument_def mime_param_tag = { + .identifier = "param", + .validate = tag_mime_option_validate +}; + +/* + * Header override + */ + +static bool svmo_mime_dump_context + (const struct sieve_message_override *svmo, + const struct sieve_dumptime_env *denv, sieve_size_t *address); +static int svmo_mime_read_context + (const struct sieve_message_override *svmo, + const struct sieve_runtime_env *renv, sieve_size_t *address, + void **ho_context); +static int svmo_mime_header_override + (const struct sieve_message_override *svmo, + const struct sieve_runtime_env *renv, + bool mime_decode, struct sieve_stringlist **headers); + +const struct sieve_message_override_def mime_header_override = { + SIEVE_OBJECT("mime", &mime_operand, 0), + .sequence = 0, /* Completely replace header source */ + .dump_context = svmo_mime_dump_context, + .read_context = svmo_mime_read_context, + .header_override = svmo_mime_header_override +}; + +/* + * Operand + */ + +static const struct sieve_extension_objects ext_header_overrides = + SIEVE_EXT_DEFINE_MESSAGE_OVERRIDE(mime_header_override); + +const struct sieve_operand_def mime_operand = { + .name = "mime operand", + .ext_def = &mime_extension, + .class = &sieve_message_override_operand_class, + .interface = &ext_header_overrides +}; + +/* + * Tag data + */ + +struct tag_mime_data { + enum ext_mime_option mimeopt; + struct sieve_ast_argument *param_arg; + bool anychild:1; +}; + +/* + * Tag validation + */ + +static struct tag_mime_data * +tag_mime_get_data(struct sieve_command *cmd, + struct sieve_ast_argument *tag) +{ + struct tag_mime_data *data; + + if (tag->argument->data == NULL) { + data = p_new(sieve_command_pool(cmd), struct tag_mime_data, 1); + tag->argument->data = (void *)data; + } else { + data = (struct tag_mime_data *)tag->argument->data; + } + + return data; +} + +static bool tag_mime_validate +(struct sieve_validator *valdtr ATTR_UNUSED, + struct sieve_ast_argument **arg, struct sieve_command *cmd) +{ + struct sieve_ast_argument *tag = *arg; + + /* Skip the tag itself */ + *arg = sieve_ast_argument_next(*arg); + + (void)tag_mime_get_data(cmd, tag); + return TRUE; +} + +static bool tag_mime_option_validate +(struct sieve_validator *valdtr ATTR_UNUSED, + struct sieve_ast_argument **arg, struct sieve_command *cmd) +{ + struct sieve_ast_argument *tag = *arg; + struct sieve_ast_argument *mime_arg; + struct tag_mime_data *data; + + i_assert(tag != NULL); + + /* Detach tag itself */ + *arg = sieve_ast_arguments_detach(*arg,1); + + /* Find required ":mime" tag */ + mime_arg = sieve_command_find_argument(cmd, &mime_tag); + if ( mime_arg == NULL ) { + sieve_argument_validate_error(valdtr, tag, + "the :%s tag for the %s %s cannot be specified " + "without the :mime tag", sieve_ast_argument_tag(tag), + sieve_command_identifier(cmd), sieve_command_type_name(cmd)); + return FALSE; + } + + /* Annotate ":mime" tag with the data provided by this option tag */ + data = tag_mime_get_data(cmd, mime_arg); + if ( sieve_argument_is(tag, mime_anychild_tag) ) + data->anychild = TRUE; + else { + if ( data->mimeopt != EXT_MIME_OPTION_NONE ) { + sieve_argument_validate_error(valdtr, *arg, + "the :type, :subtype, :contenttype, and :param " + "arguments for the %s test are mutually exclusive, " + "but more than one was specified", + sieve_command_identifier(cmd)); + return FALSE; + } + if ( sieve_argument_is(tag, mime_type_tag) ) + data->mimeopt = EXT_MIME_OPTION_TYPE; + else if ( sieve_argument_is(tag, mime_subtype_tag) ) + data->mimeopt = EXT_MIME_OPTION_SUBTYPE; + else if ( sieve_argument_is(tag, mime_contenttype_tag) ) + data->mimeopt = EXT_MIME_OPTION_CONTENTTYPE; + else if ( sieve_argument_is(tag, mime_param_tag) ) { + /* Check syntax: + * ":param" <param-list: string-list> + */ + if ( !sieve_validate_tag_parameter + (valdtr, cmd, tag, *arg, NULL, 0, SAAT_STRING_LIST, FALSE) ) { + return FALSE; + } + + data->mimeopt = EXT_MIME_OPTION_PARAM; + data->param_arg = *arg; + + /* Detach parameter */ + *arg = sieve_ast_arguments_detach(*arg,1); + } else + i_unreached(); + } + return TRUE; +} + +/* + * Code generation + */ + +static bool tag_mime_generate +(const struct sieve_codegen_env *cgenv, struct sieve_ast_argument *arg, + struct sieve_command *cmd) +{ + struct tag_mime_data *data = + (struct tag_mime_data *)arg->argument->data; + + if ( sieve_ast_argument_type(arg) != SAAT_TAG ) + return FALSE; + + sieve_opr_message_override_emit + (cgenv->sblock, arg->argument->ext, &mime_header_override); + + (void)sieve_binary_emit_byte + (cgenv->sblock, ( data->anychild ? 1 : 0 )); + (void)sieve_binary_emit_byte + (cgenv->sblock, data->mimeopt); + if ( data->mimeopt == EXT_MIME_OPTION_PARAM && + !sieve_generate_argument(cgenv, data->param_arg, cmd) ) + return FALSE; + return TRUE; +} + +/* + * Content-type stringlist + */ + +enum content_type_part { + CONTENT_TYPE_PART_NONE = 0, + CONTENT_TYPE_PART_TYPE, + CONTENT_TYPE_PART_SUBTYPE, + CONTENT_TYPE_PART_CONTENTTYPE, +}; + +/* Object */ + +static int content_header_stringlist_next_item + (struct sieve_stringlist *_strlist, string_t **str_r); +static void content_header_stringlist_reset + (struct sieve_stringlist *_strlist); +static int content_header_stringlist_get_length + (struct sieve_stringlist *_strlist); +static void content_header_stringlist_set_trace + (struct sieve_stringlist *strlist, bool trace); + +struct content_header_stringlist { + struct sieve_stringlist strlist; + + struct sieve_header_list *source; + + enum ext_mime_option option; + const char *const *params; + + const char *const *param_values; +}; + +static struct sieve_stringlist *content_header_stringlist_create +(const struct sieve_runtime_env *renv, + struct sieve_header_list *source, + enum ext_mime_option option, const char *const *params) +{ + struct content_header_stringlist *strlist; + + strlist = t_new(struct content_header_stringlist, 1); + strlist->strlist.runenv = renv; + strlist->strlist.exec_status = SIEVE_EXEC_OK; + strlist->strlist.next_item = content_header_stringlist_next_item; + strlist->strlist.reset = content_header_stringlist_reset; + strlist->strlist.set_trace = content_header_stringlist_set_trace; + strlist->source = source; + strlist->option = option; + strlist->params = params; + + if ( option != EXT_MIME_OPTION_PARAM ) { + /* One header can have multiple parameters, so we cannot rely + on the source length for the :param option. */ + strlist->strlist.get_length = content_header_stringlist_get_length; + } + + return &strlist->strlist; +} + +/* Implementation */ + +static inline int _decode_hex_digit(const unsigned char digit) +{ + switch ( digit ) { + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + return digit - '0'; + + case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': + return digit - 'a' + 0x0a; + + case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': + return digit - 'A' + 0x0A; + } + return -1; +} + +static string_t * +content_type_param_decode(const char *value) +{ + const unsigned char *p, *plast; + + string_t *str = t_str_new(64); + plast = p = (const unsigned char *)value; + while ( *p != '\0' ) { + unsigned char ch; + int digit; + + if ( *p == '%' ) { + if ( p - plast > 0 ) + str_append_data(str, plast, (p - plast)); + p++; + if ( *p == '\0' || (digit=_decode_hex_digit(*p)) < 0 ) + return NULL; + ch = (unsigned char)digit; + p++; + if ( *p == '\0' || (digit=_decode_hex_digit(*p)) < 0 ) + return NULL; + ch = (ch << 4) + (unsigned char)digit; + str_append_data(str, &ch, 1); + plast = p + 1; + } + p++; + } + if ( p - plast > 0 ) + str_append_data(str, plast, (p - plast)); + return str; +} + +static string_t * +content_type_param_next(struct content_header_stringlist *strlist) +{ + const struct sieve_runtime_env *renv = strlist->strlist.runenv; + const char *const *values = strlist->param_values; + bool trace = strlist->strlist.trace; + + i_assert( strlist->params != NULL ); + + /* Iterate over all parsed parameter values */ + for ( ; *values != NULL; values += 2 ) { + const char *const *params = strlist->params; + const char *name = values[0], *value = values[1]; + size_t nlen = strlen(name); + + /* Iterate over all interesting parameter names */ + for ( ; *params != NULL; params++ ) { + size_t plen = strlen(*params); + + if ( plen != nlen && + (nlen != plen + 1 || name[nlen-1] != '*') ) + continue; + + if ( plen == nlen ) { + if ( strcasecmp(name, *params) == 0 ) { + /* Return raw value */ + if ( trace ) { + sieve_runtime_trace(renv, 0, + "found mime parameter `%s' in mime header", + *params); + } + + strlist->param_values = values + 2; + return t_str_new_const(value, strlen(value)); + } + } else { + if ( trace ) { + sieve_runtime_trace(renv, 0, + "found encoded parameter `%s' in mime header", + *params); + } + + if ( strncasecmp(name, *params, plen) == 0 ) { + string_t *result = NULL; + + strlist->param_values = values + 2; + + /* Decode value first */ + // FIXME: transcode charset + value = strchr(value, '\''); + if (value != NULL) + value = strchr(value+1, '\''); + if (value != NULL) + result = content_type_param_decode(value + 1); + if (result == NULL) + strlist->param_values = NULL; + return result; + } + } + } + } + + strlist->param_values = NULL; + return NULL; +} + +// FIXME: not too happy with the use of string_t like this. +// Sieve should have a special runtime string type (TODO) +static string_t * +content_header_parse(struct content_header_stringlist *strlist, + const char *hdr_name, string_t *str) +{ + const struct sieve_runtime_env *renv = strlist->strlist.runenv; + bool trace = strlist->strlist.trace; + struct rfc822_parser_context parser; + const char *type, *p; + bool is_ctype = FALSE; + string_t *content; + + if ( strlist->option == EXT_MIME_OPTION_NONE ) + return str; + + if ( strcasecmp(hdr_name, "content-type") == 0 ) + is_ctype = TRUE; + else if ( strcasecmp(hdr_name, "content-disposition") != 0 ) { + if ( trace ) { + sieve_runtime_trace(renv, 0, + "non-mime header yields empty string"); + } + return t_str_new(0); + } + + /* Initialize parsing */ + rfc822_parser_init(&parser, str_data(str), str_len(str), NULL); + (void)rfc822_skip_lwsp(&parser); + + /* Parse content type/disposition */ + content = t_str_new(64); + if ( is_ctype ){ + if (rfc822_parse_content_type(&parser, content) < 0) { + str_truncate(content, 0); + return content; + } + } else { + if (rfc822_parse_mime_token(&parser, content) < 0) { + str_truncate(content, 0); + return content; + } + } + + /* Content-type value must end here, otherwise it is invalid after all */ + (void)rfc822_skip_lwsp(&parser); + if ( parser.data != parser.end && *parser.data != ';' ) { + str_truncate(content, 0); + return content; + } + + if ( strlist->option == EXT_MIME_OPTION_PARAM ) { + string_t *param_val; + + /* MIME parameter */ + i_assert( strlist->params != NULL ); + + // FIXME: not very nice when multiple parameters in the same header + // are queried in successive tests. + str_truncate(content, 0); + rfc2231_parse(&parser, &strlist->param_values); + + param_val = content_type_param_next(strlist); + if ( param_val != NULL ) + content = param_val; + } else { + /* Get :type/:subtype:/:contenttype value */ + type = str_c(content); + p = strchr(type, '/'); + switch ( strlist->option ) { + case EXT_MIME_OPTION_TYPE: + if ( trace ) { + sieve_runtime_trace(renv, 0, + "extracted MIME type"); + } + if ( p != NULL ) { + i_assert( is_ctype ); + str_truncate(content, (p - type)); + } + break; + case EXT_MIME_OPTION_SUBTYPE: + if ( p == NULL ) { + i_assert( !is_ctype ); + if ( trace ) { + sieve_runtime_trace(renv, 0, + "no MIME sub-type for content-disposition"); + } + str_truncate(content, 0); + break; + } + + i_assert( is_ctype ); + if ( trace ) { + sieve_runtime_trace(renv, 0, + "extracted MIME sub-type"); + } + str_delete(content, 0, (p - type) + 1); + break; + case EXT_MIME_OPTION_CONTENTTYPE: + sieve_runtime_trace(renv, 0, + "extracted full MIME contenttype"); + break; + default: + break; + } + } + + /* Success */ + return content; +} + +static int content_header_stringlist_next_item +(struct sieve_stringlist *_strlist, string_t **str_r) +{ + struct content_header_stringlist *strlist = + (struct content_header_stringlist *)_strlist; + const char *hdr_name; + int ret; + + if ( strlist->param_values != NULL ) { + string_t *param_val; + + i_assert( strlist->option == EXT_MIME_OPTION_PARAM ); + param_val = content_type_param_next(strlist); + if ( param_val != NULL ) { + *str_r = param_val; + return 1; + } + } + + if ( (ret=sieve_header_list_next_item + (strlist->source, &hdr_name, str_r)) <= 0 ) { + if (ret < 0) { + _strlist->exec_status = + strlist->source->strlist.exec_status; + } + return ret; + } + + *str_r = content_header_parse(strlist, hdr_name, *str_r); + return 1; +} + +static void content_header_stringlist_reset +(struct sieve_stringlist *_strlist) +{ + struct content_header_stringlist *strlist = + (struct content_header_stringlist *)_strlist; + sieve_header_list_reset(strlist->source); +} + +static int content_header_stringlist_get_length +(struct sieve_stringlist *_strlist) +{ + struct content_header_stringlist *strlist = + (struct content_header_stringlist *)_strlist; + return sieve_header_list_get_length(strlist->source); +} + +static void content_header_stringlist_set_trace +(struct sieve_stringlist *_strlist, bool trace) +{ + struct content_header_stringlist *strlist = + (struct content_header_stringlist *)_strlist; + sieve_header_list_set_trace(strlist->source, trace); +} + +/* + * Header override implementation + */ + +/* Context data */ + +struct svmo_mime_context { + enum ext_mime_option mimeopt; + const char *const *params; + bool anychild:1; +}; + +/* Context coding */ + +static bool svmo_mime_dump_context +(const struct sieve_message_override *svmo ATTR_UNUSED, + const struct sieve_dumptime_env *denv, sieve_size_t *address) +{ + unsigned int anychild, mimeopt; + + if ( !sieve_binary_read_byte(denv->sblock, address, &anychild) ) + return FALSE; + if ( anychild > 0 ) + sieve_code_dumpf(denv, "anychild"); + + if ( !sieve_binary_read_byte(denv->sblock, address, &mimeopt) ) + return FALSE; + + switch ( mimeopt ) { + case EXT_MIME_OPTION_NONE: + break; + case EXT_MIME_OPTION_TYPE: + sieve_code_dumpf(denv, "option: type"); + break; + case EXT_MIME_OPTION_SUBTYPE: + sieve_code_dumpf(denv, "option: subtype"); + break; + case EXT_MIME_OPTION_CONTENTTYPE: + sieve_code_dumpf(denv, "option: contenttype"); + break; + case EXT_MIME_OPTION_PARAM: + sieve_code_dumpf(denv, "option: param"); + sieve_code_descend(denv); + if ( !sieve_opr_stringlist_dump(denv, address, "param-list") ) + return FALSE; + sieve_code_ascend(denv); + break; + default: + return FALSE; + } + return TRUE; +} + +static int svmo_mime_read_context +(const struct sieve_message_override *svmo ATTR_UNUSED, + const struct sieve_runtime_env *renv, sieve_size_t *address, + void **ho_context) +{ + pool_t pool = sieve_result_pool(renv->result); // FIXME: investigate + struct svmo_mime_context *ctx; + unsigned int anychild = 0, mimeopt = EXT_MIME_OPTION_NONE; + struct sieve_stringlist *param_list = NULL; + int ret; + + if ( !sieve_binary_read_byte + (renv->sblock, address, &anychild) ) { + sieve_runtime_trace_error(renv, + "anychild: invalid byte"); + return SIEVE_EXEC_BIN_CORRUPT; + } + + if ( !sieve_binary_read_byte + (renv->sblock, address, &mimeopt) || + mimeopt > EXT_MIME_OPTION_PARAM ) { + sieve_runtime_trace_error(renv, + "option: invalid mime option code"); + return SIEVE_EXEC_BIN_CORRUPT; + } + + if ( mimeopt == EXT_MIME_OPTION_PARAM && + (ret=sieve_opr_stringlist_read + (renv, address, "param-list", ¶m_list)) <= 0 ) + return ret; + + ctx = p_new(pool, struct svmo_mime_context, 1); + ctx->anychild = (anychild == 0 ? FALSE : TRUE); + ctx->mimeopt = (enum ext_mime_option)mimeopt; + + if ( param_list != NULL && sieve_stringlist_read_all + (param_list, pool, &ctx->params) < 0 ) { + sieve_runtime_trace_error(renv, + "failed to read param-list operand"); + return param_list->exec_status; + } + + *ho_context = (void *) ctx; + return SIEVE_EXEC_OK; +} + +/* Override */ + +static int svmo_mime_header_override +(const struct sieve_message_override *svmo, + const struct sieve_runtime_env *renv, bool mime_decode, + struct sieve_stringlist **headers_r) +{ + struct svmo_mime_context *ctx = + (struct svmo_mime_context *)svmo->context; + struct ext_foreverypart_runtime_loop *sfploop; + struct sieve_header_list *headers; + struct sieve_stringlist *values; + int ret; + + sieve_runtime_trace(renv, SIEVE_TRLVL_MATCHING, + "header mime override:"); + sieve_runtime_trace_descend(renv); + + if ( ctx->anychild ) { + sieve_runtime_trace(renv, SIEVE_TRLVL_MATCHING, + "headers from current mime part and children"); + } else { + sieve_runtime_trace(renv, SIEVE_TRLVL_MATCHING, + "headers from current mime part"); + } + + sfploop = ext_foreverypart_runtime_loop_get_current(renv); + if ( sfploop != NULL ) { + headers = sieve_mime_header_list_create + (renv, *headers_r, &sfploop->part_iter, + mime_decode, ctx->anychild); + } else if ( ctx->anychild ) { + struct sieve_message_part_iter part_iter; + + if ( (ret=sieve_message_part_iter_init + (&part_iter, renv)) <= 0 ) + return ret; + + headers = sieve_mime_header_list_create + (renv, *headers_r, &part_iter, mime_decode, TRUE); + } else { + headers = sieve_message_header_list_create + (renv, *headers_r, mime_decode); + } + values = &headers->strlist; + + switch ( ctx->mimeopt ) { + case EXT_MIME_OPTION_NONE: + break; + case EXT_MIME_OPTION_TYPE: + sieve_runtime_trace(renv, SIEVE_TRLVL_MATCHING, + "extract mime type from header value"); + break; + case EXT_MIME_OPTION_SUBTYPE: + sieve_runtime_trace(renv, SIEVE_TRLVL_MATCHING, + "extract mime subtype from header value"); + break; + case EXT_MIME_OPTION_CONTENTTYPE: + sieve_runtime_trace(renv, SIEVE_TRLVL_MATCHING, + "extract mime contenttype from header value"); + break; + case EXT_MIME_OPTION_PARAM: + sieve_runtime_trace(renv, SIEVE_TRLVL_MATCHING, + "extract mime parameters from header value"); + break; + default: + i_unreached(); + } + + if ( ctx->mimeopt != EXT_MIME_OPTION_NONE ) { + values = content_header_stringlist_create + (renv, headers, ctx->mimeopt, ctx->params); + } + *headers_r = values; + + sieve_runtime_trace_ascend(renv); + return SIEVE_EXEC_OK; +} + |