From f7548d6d28c313cf80e6f3ef89aed16a19815df1 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 11:51:24 +0200 Subject: Adding upstream version 1:2.3.19.1+dfsg1. Signed-off-by: Daniel Baumann --- .../src/lib-sieve/plugins/notify/Makefile.am | 20 + .../src/lib-sieve/plugins/notify/Makefile.in | 699 ++++++++++++++++ .../src/lib-sieve/plugins/notify/cmd-denotify.c | 389 +++++++++ .../src/lib-sieve/plugins/notify/cmd-notify.c | 900 +++++++++++++++++++++ .../lib-sieve/plugins/notify/ext-notify-common.c | 361 +++++++++ .../lib-sieve/plugins/notify/ext-notify-common.h | 66 ++ .../lib-sieve/plugins/notify/ext-notify-limits.h | 7 + .../src/lib-sieve/plugins/notify/ext-notify.c | 108 +++ 8 files changed, 2550 insertions(+) create mode 100644 pigeonhole/src/lib-sieve/plugins/notify/Makefile.am create mode 100644 pigeonhole/src/lib-sieve/plugins/notify/Makefile.in create mode 100644 pigeonhole/src/lib-sieve/plugins/notify/cmd-denotify.c create mode 100644 pigeonhole/src/lib-sieve/plugins/notify/cmd-notify.c create mode 100644 pigeonhole/src/lib-sieve/plugins/notify/ext-notify-common.c create mode 100644 pigeonhole/src/lib-sieve/plugins/notify/ext-notify-common.h create mode 100644 pigeonhole/src/lib-sieve/plugins/notify/ext-notify-limits.h create mode 100644 pigeonhole/src/lib-sieve/plugins/notify/ext-notify.c (limited to 'pigeonhole/src/lib-sieve/plugins/notify') diff --git a/pigeonhole/src/lib-sieve/plugins/notify/Makefile.am b/pigeonhole/src/lib-sieve/plugins/notify/Makefile.am new file mode 100644 index 0000000..aaa76b3 --- /dev/null +++ b/pigeonhole/src/lib-sieve/plugins/notify/Makefile.am @@ -0,0 +1,20 @@ +noinst_LTLIBRARIES = libsieve_ext_notify.la + +AM_CPPFLAGS = \ + -I$(srcdir)/../.. \ + -I$(srcdir)/../../util \ + $(LIBDOVECOT_INCLUDE) + +commands = \ + cmd-notify.c \ + cmd-denotify.c + +libsieve_ext_notify_la_SOURCES = \ + ext-notify.c \ + ext-notify-common.c \ + $(commands) + +noinst_HEADERS = \ + ext-notify-common.h \ + ext-notify-limits.h + diff --git a/pigeonhole/src/lib-sieve/plugins/notify/Makefile.in b/pigeonhole/src/lib-sieve/plugins/notify/Makefile.in new file mode 100644 index 0000000..2e831b5 --- /dev/null +++ b/pigeonhole/src/lib-sieve/plugins/notify/Makefile.in @@ -0,0 +1,699 @@ +# Makefile.in generated by automake 1.16.1 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994-2018 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/notify +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_notify_la_LIBADD = +am__objects_1 = cmd-notify.lo cmd-denotify.lo +am_libsieve_ext_notify_la_OBJECTS = ext-notify.lo ext-notify-common.lo \ + $(am__objects_1) +libsieve_ext_notify_la_OBJECTS = $(am_libsieve_ext_notify_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-denotify.Plo \ + ./$(DEPDIR)/cmd-notify.Plo ./$(DEPDIR)/ext-notify-common.Plo \ + ./$(DEPDIR)/ext-notify.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_notify_la_SOURCES) +DIST_SOURCES = $(libsieve_ext_notify_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_notify.la +AM_CPPFLAGS = \ + -I$(srcdir)/../.. \ + -I$(srcdir)/../../util \ + $(LIBDOVECOT_INCLUDE) + +commands = \ + cmd-notify.c \ + cmd-denotify.c + +libsieve_ext_notify_la_SOURCES = \ + ext-notify.c \ + ext-notify-common.c \ + $(commands) + +noinst_HEADERS = \ + ext-notify-common.h \ + ext-notify-limits.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/notify/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --foreign src/lib-sieve/plugins/notify/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_notify.la: $(libsieve_ext_notify_la_OBJECTS) $(libsieve_ext_notify_la_DEPENDENCIES) $(EXTRA_libsieve_ext_notify_la_DEPENDENCIES) + $(AM_V_CCLD)$(LINK) $(libsieve_ext_notify_la_OBJECTS) $(libsieve_ext_notify_la_LIBADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cmd-denotify.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cmd-notify.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ext-notify-common.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ext-notify.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-denotify.Plo + -rm -f ./$(DEPDIR)/cmd-notify.Plo + -rm -f ./$(DEPDIR)/ext-notify-common.Plo + -rm -f ./$(DEPDIR)/ext-notify.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-denotify.Plo + -rm -f ./$(DEPDIR)/cmd-notify.Plo + -rm -f ./$(DEPDIR)/ext-notify-common.Plo + -rm -f ./$(DEPDIR)/ext-notify.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/notify/cmd-denotify.c b/pigeonhole/src/lib-sieve/plugins/notify/cmd-denotify.c new file mode 100644 index 0000000..8769808 --- /dev/null +++ b/pigeonhole/src/lib-sieve/plugins/notify/cmd-denotify.c @@ -0,0 +1,389 @@ +/* Copyright (c) 2002-2018 Pigeonhole authors, see the included COPYING file + */ + +#include "lib.h" + +#include "sieve-common.h" +#include "sieve-stringlist.h" +#include "sieve-code.h" +#include "sieve-extensions.h" +#include "sieve-ast.h" +#include "sieve-commands.h" +#include "sieve-match-types.h" +#include "sieve-comparators.h" +#include "sieve-match.h" +#include "sieve-actions.h" +#include "sieve-validator.h" +#include "sieve-generator.h" +#include "sieve-interpreter.h" +#include "sieve-dump.h" +#include "sieve-result.h" + +#include "ext-notify-common.h" + +/* + * Denotify command + * + * Syntax: + * denotify [MATCH-TYPE string] [<":low" / ":normal" / ":high">] + */ + +static bool cmd_denotify_registered + (struct sieve_validator *valdtr, const struct sieve_extension *ext, + struct sieve_command_registration *cmd_reg); +static bool cmd_denotify_pre_validate + (struct sieve_validator *valdtr, struct sieve_command *cmd); +static bool cmd_denotify_validate + (struct sieve_validator *valdtr, struct sieve_command *cmd); +static bool cmd_denotify_generate + (const struct sieve_codegen_env *cgenv, struct sieve_command *cmd); + +const struct sieve_command_def cmd_denotify = { + .identifier = "denotify", + .type = SCT_COMMAND, + .positional_args = 0, + .subtests = 0, + .block_allowed = FALSE, + .block_required = FALSE, + .registered = cmd_denotify_registered, + .pre_validate = cmd_denotify_pre_validate, + .validate = cmd_denotify_validate, + .generate = cmd_denotify_generate +}; + +/* + * Tagged arguments + */ + +/* Forward declarations */ + +static bool tag_match_type_is_instance_of + (struct sieve_validator *validator, struct sieve_command *cmd, + const struct sieve_extension *ext, const char *identifier, void **data); +static bool tag_match_type_validate + (struct sieve_validator *validator, struct sieve_ast_argument **arg, + struct sieve_command *cmd); + +/* Argument object */ + +const struct sieve_argument_def denotify_match_tag = { + .identifier = "MATCH-TYPE-STRING", + .is_instance_of = tag_match_type_is_instance_of, + .validate = tag_match_type_validate +}; + +/* Codes for optional operands */ + +enum cmd_denotify_optional { + OPT_END, + OPT_IMPORTANCE, + OPT_MATCH_TYPE, + OPT_MATCH_KEY +}; + +/* + * Denotify operation + */ + +static bool cmd_denotify_operation_dump + (const struct sieve_dumptime_env *denv, sieve_size_t *address); +static int cmd_denotify_operation_execute + (const struct sieve_runtime_env *renv, sieve_size_t *address); + +const struct sieve_operation_def denotify_operation = { + .mnemonic = "DENOTIFY", + .ext_def = ¬ify_extension, + .code = EXT_NOTIFY_OPERATION_DENOTIFY, + .dump = cmd_denotify_operation_dump, + .execute = cmd_denotify_operation_execute +}; + +/* + * Command validation context + */ + +struct cmd_denotify_context_data { + struct sieve_ast_argument *match_key_arg; +}; + +/* + * Tag validation + */ + +static bool tag_match_type_is_instance_of +(struct sieve_validator *valdtr, struct sieve_command *cmd, + const struct sieve_extension *ext, const char *identifier, void **data) +{ + return match_type_tag.is_instance_of(valdtr, cmd, ext, identifier, data); +} + +static bool tag_match_type_validate +(struct sieve_validator *valdtr, struct sieve_ast_argument **arg, + struct sieve_command *cmd) +{ + struct cmd_denotify_context_data *cmd_data = + (struct cmd_denotify_context_data *) cmd->data; + struct sieve_ast_argument *tag = *arg; + + i_assert(tag != NULL); + + if ( !match_type_tag.validate(valdtr, arg, cmd) ) + return FALSE; + + if ( *arg == NULL ) { + sieve_argument_validate_error(valdtr, tag, + "the MATCH-TYPE argument (:%s) for the denotify command requires " + "an additional key-string parameter, but no more arguments were found", + sieve_ast_argument_tag(tag)); + return FALSE; + } + + if ( sieve_ast_argument_type(*arg) != SAAT_STRING ) + { + sieve_argument_validate_error(valdtr, *arg, + "the MATCH-TYPE argument (:%s) for the denotify command requires " + "an additional key-string parameter, but %s was found", + sieve_ast_argument_tag(tag), sieve_ast_argument_name(*arg)); + return FALSE; + } + + if ( !sieve_validator_argument_activate(valdtr, cmd, *arg, FALSE) ) + return FALSE; + + tag->argument->def = &match_type_tag; + tag->argument->ext = NULL; + + (*arg)->argument->id_code = OPT_MATCH_KEY; + cmd_data->match_key_arg = *arg; + + *arg = sieve_ast_argument_next(*arg); + + return TRUE; +} + +/* + * Command registration + */ + +static bool cmd_denotify_registered +(struct sieve_validator *valdtr, const struct sieve_extension *ext, + struct sieve_command_registration *cmd_reg) +{ + sieve_validator_register_tag + (valdtr, cmd_reg, ext, &denotify_match_tag, OPT_MATCH_TYPE); + + ext_notify_register_importance_tags(valdtr, cmd_reg, ext, OPT_IMPORTANCE); + + return TRUE; +} + +/* + * Command validation + */ + +static bool cmd_denotify_pre_validate +(struct sieve_validator *valdtr ATTR_UNUSED, + struct sieve_command *cmd) +{ + struct cmd_denotify_context_data *ctx_data; + + /* Assign context */ + ctx_data = p_new(sieve_command_pool(cmd), + struct cmd_denotify_context_data, 1); + cmd->data = (void *) ctx_data; + + return TRUE; +} + +static bool cmd_denotify_validate +(struct sieve_validator *valdtr, struct sieve_command *cmd) +{ + struct cmd_denotify_context_data *ctx_data = + (struct cmd_denotify_context_data *) cmd->data; + struct sieve_ast_argument *key_arg = ctx_data->match_key_arg; + const struct sieve_match_type mcht_default = + SIEVE_MATCH_TYPE_DEFAULT(is_match_type); + const struct sieve_comparator cmp_default = + SIEVE_COMPARATOR_DEFAULT(i_octet_comparator); + + if ( key_arg != NULL ) { + if ( !sieve_match_type_validate + (valdtr, cmd, key_arg, &mcht_default, &cmp_default) ) + return FALSE; + } + + return TRUE; +} + +/* + * Code generation + */ + +static bool cmd_denotify_generate +(const struct sieve_codegen_env *cgenv, struct sieve_command *cmd) +{ + sieve_operation_emit(cgenv->sblock, cmd->ext, &denotify_operation); + + /* Generate arguments */ + return sieve_generate_arguments(cgenv, cmd, NULL); +} + +/* + * Code dump + */ + +static bool cmd_denotify_operation_dump +(const struct sieve_dumptime_env *denv, sieve_size_t *address) +{ + const struct sieve_operation *op = denv->oprtn; + int opt_code = 0; + + sieve_code_dumpf(denv, "%s", sieve_operation_mnemonic(op)); + sieve_code_descend(denv); + + 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 OPT_MATCH_KEY: + opok = sieve_opr_string_dump(denv, address, "key-string"); + break; + case OPT_MATCH_TYPE: + opok = sieve_opr_match_type_dump(denv, address); + break; + case OPT_IMPORTANCE: + opok = sieve_opr_number_dump(denv, address, "importance"); + break; + default: + return FALSE; + } + + if ( !opok ) return FALSE; + } + + return TRUE; +} + +/* + * Code execution + */ + +static int cmd_denotify_operation_execute +(const struct sieve_runtime_env *renv, sieve_size_t *address) +{ + int opt_code = 0; + struct sieve_match_type mcht = + SIEVE_MATCH_TYPE_DEFAULT(is_match_type); + const struct sieve_comparator cmp = + SIEVE_COMPARATOR_DEFAULT(i_octet_comparator); + struct sieve_stringlist *match_key = NULL; + sieve_number_t importance = 0; + struct sieve_match_context *mctx; + struct sieve_result_iterate_context *rictx; + const struct sieve_action *action; + int ret; + + /* + * Read 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 OPT_MATCH_TYPE: + ret = sieve_opr_match_type_read(renv, address, &mcht); + break; + case OPT_MATCH_KEY: + ret = sieve_opr_stringlist_read(renv, address, "match key", &match_key); + break; + case OPT_IMPORTANCE: + ret = sieve_opr_number_read(renv, address, "importance", &importance); + break; + default: + sieve_runtime_trace_error(renv, "unknown optional operand"); + return SIEVE_EXEC_BIN_CORRUPT; + } + + if ( ret <= 0 ) return ret; + } + + /* + * Perform operation + */ + + /* Enforce 0 < importance < 4 (just to be sure) */ + + if ( importance < 1 ) + importance = 1; + else if ( importance > 3 ) + importance = 3; + + /* Trace */ + + sieve_runtime_trace(renv, SIEVE_TRLVL_ACTIONS, "denotify action"); + + /* Either do string matching or just kill all notify actions */ + if ( match_key != NULL ) { + /* Initialize match */ + mctx = sieve_match_begin(renv, &mcht, &cmp); + + /* Iterate through all notify actions and delete those that match */ + rictx = sieve_result_iterate_init(renv->result); + + while ( (action=sieve_result_iterate_next(rictx, NULL)) != NULL ) { + if ( sieve_action_is(action, act_notify_old) ) { + struct ext_notify_action *nact = + (struct ext_notify_action *) action->context; + + if ( importance == 0 || nact->importance == importance ) { + int match; + + if ( (match=sieve_match_value + (mctx, nact->id, strlen(nact->id), match_key)) < 0 ) + break; + + if ( match > 0 ) + sieve_result_iterate_delete(rictx); + } + } + } + + /* Finish match */ + if ( sieve_match_end(&mctx, &ret) < 0 ) + return ret; + + } else { + /* Delete all notify actions */ + rictx = sieve_result_iterate_init(renv->result); + + while ( (action=sieve_result_iterate_next(rictx, NULL)) != NULL ) { + + if ( sieve_action_is(action, act_notify_old) ) { + struct ext_notify_action *nact = + (struct ext_notify_action *) action->context; + + if ( importance == 0 || nact->importance == importance ) + sieve_result_iterate_delete(rictx); + } + } + } + + return SIEVE_EXEC_OK; +} + + + diff --git a/pigeonhole/src/lib-sieve/plugins/notify/cmd-notify.c b/pigeonhole/src/lib-sieve/plugins/notify/cmd-notify.c new file mode 100644 index 0000000..a683c31 --- /dev/null +++ b/pigeonhole/src/lib-sieve/plugins/notify/cmd-notify.c @@ -0,0 +1,900 @@ +/* Copyright (c) 2002-2018 Pigeonhole authors, see the included COPYING file + */ + +#include "lib.h" +#include "array.h" +#include "str.h" +#include "ioloop.h" +#include "str-sanitize.h" +#include "ostream.h" +#include "message-date.h" +#include "mail-storage.h" + +#include "rfc2822.h" + +#include "sieve-common.h" +#include "sieve-stringlist.h" +#include "sieve-code.h" +#include "sieve-extensions.h" +#include "sieve-commands.h" +#include "sieve-actions.h" +#include "sieve-validator.h" +#include "sieve-generator.h" +#include "sieve-interpreter.h" +#include "sieve-dump.h" +#include "sieve-result.h" +#include "sieve-address.h" +#include "sieve-message.h" +#include "sieve-smtp.h" + +#include "ext-notify-common.h" +#include "ext-notify-limits.h" + +#include + +/* Notify command (DEPRECATED) + * + * Syntax: + * notify [":method" string] [":id" string] [":options" string-list] + * [<":low" / ":normal" / ":high">] ["message:" string] + * + */ + +static bool +cmd_notify_registered(struct sieve_validator *valdtr, + const struct sieve_extension *ext, + struct sieve_command_registration *cmd_reg); +static bool +cmd_notify_pre_validate(struct sieve_validator *valdtr, + struct sieve_command *cmd); +static bool +cmd_notify_validate(struct sieve_validator *valdtr, + struct sieve_command *cmd); +static bool +cmd_notify_generate(const struct sieve_codegen_env *cgenv, + struct sieve_command *ctx); + +const struct sieve_command_def cmd_notify_old = { + .identifier = "notify", + .type = SCT_COMMAND, + .positional_args = 0, + .subtests = 0, + .block_allowed = FALSE, + .block_required = FALSE, + .registered = cmd_notify_registered, + .pre_validate = cmd_notify_pre_validate, + .validate = cmd_notify_validate, + .generate = cmd_notify_generate +}; + +/* + * Tagged arguments + */ + +/* Forward declarations */ + +static bool +cmd_notify_validate_string_tag(struct sieve_validator *valdtr, + struct sieve_ast_argument **arg, + struct sieve_command *cmd); +static bool +cmd_notify_validate_stringlist_tag(struct sieve_validator *valdtr, + struct sieve_ast_argument **arg, + struct sieve_command *cmd); + +/* Argument objects */ + +static const struct sieve_argument_def notify_method_tag = { + .identifier = "method", + .validate = cmd_notify_validate_string_tag +}; + +static const struct sieve_argument_def notify_options_tag = { + .identifier = "options", + .validate = cmd_notify_validate_stringlist_tag +}; + +static const struct sieve_argument_def notify_id_tag = { + .identifier = "id", + .validate = cmd_notify_validate_string_tag +}; + +static const struct sieve_argument_def notify_message_tag = { + .identifier = "message", + .validate = cmd_notify_validate_string_tag +}; + +/* + * Notify operation + */ + +static bool +cmd_notify_operation_dump(const struct sieve_dumptime_env *denv, + sieve_size_t *address); +static int +cmd_notify_operation_execute(const struct sieve_runtime_env *renv, + sieve_size_t *address); + +const struct sieve_operation_def notify_old_operation = { + .mnemonic = "NOTIFY", + .ext_def = ¬ify_extension, + .code = EXT_NOTIFY_OPERATION_NOTIFY, + .dump = cmd_notify_operation_dump, + .execute = cmd_notify_operation_execute +}; + +/* Codes for optional operands */ + +enum cmd_notify_optional { + OPT_END, + OPT_MESSAGE, + OPT_IMPORTANCE, + OPT_OPTIONS, + OPT_ID +}; + +/* + * Notify action + */ + +/* Forward declarations */ + +static int +act_notify_check_duplicate(const struct sieve_runtime_env *renv, + const struct sieve_action *act, + const struct sieve_action *act_other); +static void +act_notify_print(const struct sieve_action *action, + const struct sieve_result_print_env *rpenv, bool *keep); +static int +act_notify_commit(const struct sieve_action_exec_env *aenv, + void *tr_context); + +/* Action object */ + +const struct sieve_action_def act_notify_old = { + .name = "notify", + .check_duplicate = act_notify_check_duplicate, + .print = act_notify_print, + .commit = act_notify_commit +}; + +/* + * Command validation context + */ + +struct cmd_notify_context_data { + struct sieve_ast_argument *id; + struct sieve_ast_argument *method; + struct sieve_ast_argument *options; + struct sieve_ast_argument *message; +}; + +/* + * Tag validation + */ + +static bool +cmd_notify_validate_string_tag(struct sieve_validator *valdtr, + struct sieve_ast_argument **arg, + struct sieve_command *cmd) +{ + struct sieve_ast_argument *tag = *arg; + struct cmd_notify_context_data *ctx_data = + (struct cmd_notify_context_data *)cmd->data; + + /* Detach the tag itself */ + *arg = sieve_ast_arguments_detach(*arg, 1); + + /* Check syntax: + * :id + * :method + * :message + */ + if (!sieve_validate_tag_parameter(valdtr, cmd, tag, *arg, NULL, 0, + SAAT_STRING, FALSE)) + return FALSE; + + if (sieve_argument_is(tag, notify_method_tag)) { + ctx_data->method = *arg; + + /* Removed */ + *arg = sieve_ast_arguments_detach(*arg, 1); + } else if (sieve_argument_is(tag, notify_id_tag)) { + ctx_data->id = *arg; + + /* Skip parameter */ + *arg = sieve_ast_argument_next(*arg); + } else if (sieve_argument_is(tag, notify_message_tag)) { + ctx_data->message = *arg; + + /* Skip parameter */ + *arg = sieve_ast_argument_next(*arg); + } + return TRUE; +} + +static bool +cmd_notify_validate_stringlist_tag(struct sieve_validator *valdtr, + struct sieve_ast_argument **arg, + struct sieve_command *cmd) +{ + struct sieve_ast_argument *tag = *arg; + struct cmd_notify_context_data *ctx_data = + (struct cmd_notify_context_data *)cmd->data; + + /* Detach the tag itself */ + *arg = sieve_ast_arguments_detach(*arg,1); + + /* Check syntax: + * :options string-list + */ + if (!sieve_validate_tag_parameter(valdtr, cmd, tag, *arg, NULL, 0, + SAAT_STRING_LIST, FALSE)) + return FALSE; + + /* Assign context */ + ctx_data->options = *arg; + + /* Skip parameter */ + *arg = sieve_ast_argument_next(*arg); + + return TRUE; +} + +/* + * Command registration + */ + +static bool +cmd_notify_registered(struct sieve_validator *valdtr, + const struct sieve_extension *ext, + struct sieve_command_registration *cmd_reg) +{ + sieve_validator_register_tag(valdtr, cmd_reg, ext, + ¬ify_method_tag, 0); + sieve_validator_register_tag(valdtr, cmd_reg, ext, + ¬ify_id_tag, OPT_ID); + sieve_validator_register_tag(valdtr, cmd_reg, ext, + ¬ify_message_tag, OPT_MESSAGE); + sieve_validator_register_tag(valdtr, cmd_reg, ext, + ¬ify_options_tag, OPT_OPTIONS); + + ext_notify_register_importance_tags(valdtr, cmd_reg, ext, + OPT_IMPORTANCE); + + return TRUE; +} + +/* + * Command validation + */ + +static bool +cmd_notify_pre_validate(struct sieve_validator *valdtr ATTR_UNUSED, + struct sieve_command *cmd) +{ + struct cmd_notify_context_data *ctx_data; + + /* Create context */ + ctx_data = p_new(sieve_command_pool(cmd), + struct cmd_notify_context_data, 1); + cmd->data = ctx_data; + + return TRUE; +} + +static int +cmd_notify_address_validate(void *context, struct sieve_ast_argument *arg) +{ + struct sieve_validator *valdtr = (struct sieve_validator *)context; + + if (sieve_argument_is_string_literal(arg)) { + string_t *address = sieve_ast_argument_str(arg); + const char *error; + int result; + + T_BEGIN { + result = (sieve_address_validate_str(address, &error) ? + 1 : -1); + + if (result <= 0) { + sieve_argument_validate_error( + valdtr, arg, + "specified :options address '%s' is invalid for " + "the mailto notify method: %s", + str_sanitize(str_c(address), 128), + error); + } + } T_END; + + return result; + } + + return 1; +} + +static bool +cmd_notify_validate(struct sieve_validator *valdtr, struct sieve_command *cmd) +{ + struct cmd_notify_context_data *ctx_data = + (struct cmd_notify_context_data *)cmd->data; + + /* Check :method argument */ + if (ctx_data->method != NULL) { + const char *method = sieve_ast_argument_strc(ctx_data->method); + + if (strcasecmp(method, "mailto") != 0) { + sieve_command_validate_error( + valdtr, cmd, + "the notify command of the deprecated notify extension " + "only supports the 'mailto' notification method"); + return FALSE; + } + } + + /* Check :options argument */ + if (ctx_data->options != NULL) { + struct sieve_ast_argument *option = ctx_data->options; + + /* Parse and check options */ + if (sieve_ast_stringlist_map( + &option, (void *)valdtr, + cmd_notify_address_validate) <= 0) { + return FALSE; + } + } else { + sieve_command_validate_warning( + valdtr, cmd, + "no :options (and hence recipients) specified for the notify command"); + } + + return TRUE; +} + +/* + * Code generation + */ + +static bool +cmd_notify_generate(const struct sieve_codegen_env *cgenv, + struct sieve_command *cmd) +{ + sieve_operation_emit(cgenv->sblock, cmd->ext, ¬ify_old_operation); + + /* Generate arguments */ + return sieve_generate_arguments(cgenv, cmd, NULL); +} + +/* + * Code dump + */ + +static bool +cmd_notify_operation_dump(const struct sieve_dumptime_env *denv, + sieve_size_t *address) +{ + int opt_code = 0; + + sieve_code_dumpf(denv, "NOTIFY"); + 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 OPT_IMPORTANCE: + opok = sieve_opr_number_dump(denv, address, + "importance"); + break; + case OPT_ID: + opok = sieve_opr_string_dump(denv, address, + "id"); + break; + case OPT_OPTIONS: + opok = sieve_opr_stringlist_dump(denv, address, + "options"); + break; + case OPT_MESSAGE: + opok = sieve_opr_string_dump(denv, address, + "message"); + break; + default: + return FALSE; + } + + if (!opok) + return FALSE; + } + + return TRUE; +} + +/* + * Code execution + */ + + +static int +cmd_notify_operation_execute(const struct sieve_runtime_env *renv, + sieve_size_t *address) +{ + const struct sieve_extension *this_ext = renv->oprtn->ext; + struct ext_notify_action *act; + pool_t pool; + int opt_code = 0; + sieve_number_t importance = 1; + struct sieve_stringlist *options = NULL; + string_t *message = NULL, *id = NULL; + int ret = 0; + + /* + * Read 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 OPT_IMPORTANCE: + ret = sieve_opr_number_read(renv, address, "importance", + &importance); + break; + case OPT_ID: + ret = sieve_opr_string_read(renv, address, "id", &id); + break; + case OPT_MESSAGE: + ret = sieve_opr_string_read(renv, address, "from", + &message); + break; + case OPT_OPTIONS: + ret = sieve_opr_stringlist_read(renv, address, + "options", &options); + break; + default: + sieve_runtime_trace_error( + renv, "unknown optional operand"); + return SIEVE_EXEC_BIN_CORRUPT; + } + + if (ret <= 0) return ret; + } + + /* + * Perform operation + */ + + /* Enforce 0 < importance < 4 (just to be sure) */ + + if (importance < 1) + importance = 1; + else if (importance > 3) + importance = 3; + + /* Trace */ + + sieve_runtime_trace(renv, SIEVE_TRLVL_ACTIONS, "notify action"); + + /* Compose action */ + if (options != NULL) { + string_t *raw_address; + string_t *out_message; + + pool = sieve_result_pool(renv->result); + act = p_new(pool, struct ext_notify_action, 1); + if (id != NULL) + act->id = p_strdup(pool, str_c(id)); + act->importance = importance; + + /* Process message */ + + out_message = t_str_new(1024); + if ((ret = ext_notify_construct_message( + renv, (message == NULL ? NULL : str_c(message)), + out_message)) <= 0) + return ret; + act->message = p_strdup(pool, str_c(out_message)); + + /* Normalize and verify all :options addresses */ + + sieve_stringlist_reset(options); + + p_array_init(&act->recipients, pool, 4); + + raw_address = NULL; + while ((ret = sieve_stringlist_next_item( + options, &raw_address)) > 0) { + const char *error = NULL; + const struct smtp_address *address; + + /* Add if valid address */ + address = sieve_address_parse_str(raw_address, &error); + if (address != NULL) { + const struct ext_notify_recipient *rcpts; + unsigned int rcpt_count, i; + + /* Prevent duplicates */ + rcpts = array_get(&act->recipients, &rcpt_count); + + for (i = 0; i < rcpt_count; i++) { + if (smtp_address_equals(rcpts[i].address, + address)) + break; + } + + /* Add only if unique */ + if (i != rcpt_count) { + sieve_runtime_warning( + renv, NULL, + "duplicate recipient '%s' specified in the :options argument of " + "the deprecated notify command", + str_sanitize(str_c(raw_address), 128)); + + } else if (array_count(&act->recipients) >= + EXT_NOTIFY_MAX_RECIPIENTS) { + sieve_runtime_warning(renv, NULL, + "more than the maximum %u recipients are specified " + "for the deprecated notify command; " + "the rest is discarded", + EXT_NOTIFY_MAX_RECIPIENTS); + break; + + } else { + struct ext_notify_recipient recipient; + + recipient.full = + p_strdup(pool, str_c(raw_address)); + recipient.address = + smtp_address_clone(pool, address); + + array_append(&act->recipients, &recipient, 1); + } + } else { + sieve_runtime_error( + renv, NULL, + "specified :options address '%s' is invalid for " + "the deprecated notify command: %s", + str_sanitize(str_c(raw_address), 128), error); + return SIEVE_EXEC_FAILURE; + } + } + + if (ret < 0) { + sieve_runtime_trace_error( + renv, "invalid options stringlist"); + return SIEVE_EXEC_BIN_CORRUPT; + } + + if (sieve_result_add_action(renv, this_ext, "notify", + &act_notify_old, NULL, (void *)act, + 0, FALSE) < 0) + return SIEVE_EXEC_FAILURE; + } + + return SIEVE_EXEC_OK; +} + +/* + * Action + */ + +/* Runtime verification */ + +static int +act_notify_check_duplicate(const struct sieve_runtime_env *renv ATTR_UNUSED, + const struct sieve_action *act ATTR_UNUSED, + const struct sieve_action *act_other ATTR_UNUSED) +{ + struct ext_notify_action *new_nact, *old_nact; + const struct ext_notify_recipient *new_rcpts; + const struct ext_notify_recipient *old_rcpts; + unsigned int new_count, old_count, i, j; + unsigned int del_start = 0, del_len = 0; + + if (act->context == NULL || act_other->context == NULL) + return 0; + + new_nact = (struct ext_notify_action *)act->context; + old_nact = (struct ext_notify_action *)act_other->context; + + new_rcpts = array_get(&new_nact->recipients, &new_count); + old_rcpts = array_get(&old_nact->recipients, &old_count); + + for (i = 0; i < new_count; i++) { + for (j = 0; j < old_count; j++) { + if (smtp_address_equals(new_rcpts[i].address, + old_rcpts[j].address)) + break; + } + + if (j == old_count) { + /* Not duplicate */ + if (del_len > 0) { + /* Perform pending deletion */ + array_delete(&new_nact->recipients, + del_start, del_len); + + /* Make sure the loop integrity is maintained */ + i -= del_len; + new_rcpts = array_get(&new_nact->recipients, + &new_count); + } + + del_len = 0; + } else { + /* Mark deletion */ + if (del_len == 0) + del_start = i; + del_len++; + } + } + + /* Perform pending deletion */ + if (del_len > 0) + array_delete(&new_nact->recipients, del_start, del_len); + + return (array_count(&new_nact->recipients) > 0 ? 0 : 1); +} + +/* Result printing */ + +static void +act_notify_print(const struct sieve_action *action, + const struct sieve_result_print_env *rpenv, + bool *keep ATTR_UNUSED) +{ + const struct ext_notify_action *act = + (const struct ext_notify_action *)action->context; + const struct ext_notify_recipient *recipients; + unsigned int count, i; + + sieve_result_action_printf( + rpenv, "send (deprecated) notification with method 'mailto':"); + + /* Print main method parameters */ + + sieve_result_printf(rpenv, " => importance : %llu\n", + (unsigned long long)act->importance); + + if (act->message != NULL) { + sieve_result_printf( + rpenv, " => message : %s\n", act->message); + } + if (act->id != NULL) { + sieve_result_printf( + rpenv, " => id : %s \n", act->id); + } + + /* Print mailto: recipients */ + + sieve_result_printf(rpenv, " => recipients :\n"); + + recipients = array_get(&act->recipients, &count); + if (count == 0) { + sieve_result_printf( + rpenv, " NONE, action has no effect\n"); + } else { + for (i = 0; i < count; i++) { + sieve_result_printf( + rpenv, " + To: %s\n", recipients[i].full); + } + } + + /* Finish output with an empty line */ + + sieve_result_printf(rpenv, "\n"); +} + +/* Result execution */ + +static bool contains_8bit(const char *msg) +{ + const unsigned char *s = (const unsigned char *)msg; + + for (; *s != '\0'; s++) { + if ((*s & 0x80) != 0) + return TRUE; + } + return FALSE; +} + +static bool +act_notify_send(const struct sieve_action_exec_env *aenv, + const struct ext_notify_action *act) +{ + const struct sieve_execute_env *eenv = aenv->exec_env; + const struct sieve_script_env *senv = eenv->scriptenv; + const struct ext_notify_recipient *recipients; + struct sieve_smtp_context *sctx; + unsigned int count, i; + struct ostream *output; + string_t *msg, *to, *all; + const char *outmsgid, *error; + int ret; + + /* Get recipients */ + recipients = array_get(&act->recipients, &count); + if (count == 0) { + sieve_result_warning( + aenv, "notify action specifies no recipients; " + "action has no effect"); + return TRUE; + } + + /* Just to be sure */ + if (!sieve_smtp_available(senv)) { + sieve_result_global_warning( + aenv, "notify action has no means to send mail"); + return TRUE; + } + + /* Compose common headers */ + msg = t_str_new(512); + rfc2822_header_write(msg, "X-Sieve", SIEVE_IMPLEMENTATION); + rfc2822_header_write(msg, "Date", message_date_create(ioloop_time)); + + /* Set importance */ + switch (act->importance) { + case 1: + rfc2822_header_write(msg, "X-Priority", "1 (Highest)"); + rfc2822_header_write(msg, "Importance", "High"); + break; + case 3: + rfc2822_header_write(msg, "X-Priority", "5 (Lowest)"); + rfc2822_header_write(msg, "Importance", "Low"); + break; + case 2: + default: + rfc2822_header_write(msg, "X-Priority", "3 (Normal)"); + rfc2822_header_write(msg, "Importance", "Normal"); + break; + } + + rfc2822_header_write(msg, "From", sieve_get_postmaster_address(senv)); + + rfc2822_header_write(msg, "Subject", "[SIEVE] New mail notification"); + + rfc2822_header_write(msg, "Auto-Submitted", "auto-generated (notify)"); + rfc2822_header_write(msg, "Precedence", "bulk"); + + rfc2822_header_write(msg, "MIME-Version", "1.0"); + if (contains_8bit(act->message)) { + rfc2822_header_write(msg, "Content-Type", + "text/plain; charset=utf-8"); + rfc2822_header_write(msg, "Content-Transfer-Encoding", "8bit"); + } else { + rfc2822_header_write(msg, "Content-Type", + "text/plain; charset=us-ascii"); + rfc2822_header_write(msg, "Content-Transfer-Encoding", "7bit"); + } + + outmsgid = sieve_message_get_new_id(eenv->svinst); + rfc2822_header_write(msg, "Message-ID", outmsgid); + + if ((eenv->flags & SIEVE_EXECUTE_FLAG_NO_ENVELOPE) == 0 && + sieve_message_get_sender(aenv->msgctx) != NULL) { + sctx = sieve_smtp_start(senv, sieve_get_postmaster_smtp(senv)); + } else { + sctx = sieve_smtp_start(senv, NULL); + } + + /* Add all recipients (and compose To header field) */ + to = t_str_new(128); + all = t_str_new(256); + for (i = 0; i < count; i++) { + sieve_smtp_add_rcpt(sctx, recipients[i].address); + if (i > 0) + str_append(to, ", "); + str_append(to, recipients[i].full); + if (i < 3) { + if (i > 0) + str_append(all, ", "); + str_append(all, smtp_address_encode_path( + recipients[i].address)); + } else if (i == 3) { + str_printfa(all, ", ... (%u total)", count); + } + } + + rfc2822_header_write_address(msg, "To", str_c(to)); + + /* Generate message body */ + str_printfa(msg, "\r\n%s\r\n", act->message); + + output = sieve_smtp_send(sctx); + o_stream_nsend(output, str_data(msg), str_len(msg)); + + if ((ret = sieve_smtp_finish(sctx, &error)) <= 0) { + if (ret < 0) { + sieve_result_global_error( + aenv, "failed to send mail notification to %s: " + "%s (temporary failure)", str_c(all), + str_sanitize(error, 512)); + } else { + sieve_result_global_log_error( + aenv, "failed to send mail notification to %s: " + "%s (permanent failure)", str_c(all), + str_sanitize(error, 512)); + } + } else { + struct event_passthrough *e = + sieve_action_create_finish_event(aenv)-> + add_str("notify_target", str_c(all)); + + sieve_result_event_log(aenv, e->event(), + "sent mail notification to %s", + str_c(all)); + } + + return TRUE; +} + +static int +act_notify_commit(const struct sieve_action_exec_env *aenv, + void *tr_context ATTR_UNUSED) +{ + const struct sieve_execute_env *eenv = aenv->exec_env; + struct mail *mail = eenv->msgdata->mail; + const struct ext_notify_action *act = + (const struct ext_notify_action *)aenv->action->context; + const char *const *hdsp; + bool result; + int ret; + + /* Is the message an automatic reply ? */ + if ((ret = mail_get_headers(mail, "auto-submitted", &hdsp)) < 0) { + return sieve_result_mail_error( + aenv, mail, + "failed to read `auto-submitted' header field"); + } + + /* Theoretically multiple headers could exist, so lets make sure */ + if (ret > 0) { + while (*hdsp != NULL) { + if (strcasecmp(*hdsp, "no") != 0) { + const struct smtp_address *sender = NULL; + const char *from; + + if ((eenv->flags & SIEVE_EXECUTE_FLAG_NO_ENVELOPE) == 0) + sender = sieve_message_get_sender(aenv->msgctx); + from = (sender == NULL ? "" : + t_strdup_printf(" from <%s>", + smtp_address_encode(sender))); + + sieve_result_global_log( + aenv, + "not sending notification for auto-submitted message%s", + from); + return SIEVE_EXEC_OK; + } + hdsp++; + } + } + + T_BEGIN { + result = act_notify_send(aenv, act); + } T_END; + + if (!result) + return SIEVE_EXEC_FAILURE; + eenv->exec_status->significant_action_executed = TRUE; + return SIEVE_EXEC_OK; +} diff --git a/pigeonhole/src/lib-sieve/plugins/notify/ext-notify-common.c b/pigeonhole/src/lib-sieve/plugins/notify/ext-notify-common.c new file mode 100644 index 0000000..589b21b --- /dev/null +++ b/pigeonhole/src/lib-sieve/plugins/notify/ext-notify-common.c @@ -0,0 +1,361 @@ +/* Copyright (c) 2002-2018 Pigeonhole authors, see the included COPYING file + */ + +#include "lib.h" +#include "str.h" +#include "istream.h" +#include "rfc822-parser.h" +#include "message-parser.h" +#include "message-decoder.h" +#include "mail-storage.h" + +#include "sieve-common.h" +#include "sieve-code.h" +#include "sieve-message.h" +#include "sieve-extensions.h" +#include "sieve-commands.h" +#include "sieve-actions.h" +#include "sieve-validator.h" +#include "sieve-generator.h" +#include "sieve-interpreter.h" +#include "sieve-dump.h" +#include "sieve-result.h" + +#include "ext-notify-common.h" + +#include + +/* + * Importance argument + */ + +static bool +tag_importance_validate(struct sieve_validator *valdtr, + struct sieve_ast_argument **arg, + struct sieve_command *cmd); + +static const struct sieve_argument_def importance_low_tag = { + .identifier = "low", + .validate = tag_importance_validate, +}; + +static const struct sieve_argument_def importance_normal_tag = { + .identifier = "normal", + .validate = tag_importance_validate, +}; + +static const struct sieve_argument_def importance_high_tag = { + .identifier = "high", + .validate = tag_importance_validate, +}; + +static bool +tag_importance_validate(struct sieve_validator *valdtr ATTR_UNUSED, + struct sieve_ast_argument **arg, + struct sieve_command *cmd ATTR_UNUSED) +{ + struct sieve_ast_argument *tag = *arg; + + if (sieve_argument_is(tag, importance_low_tag)) + sieve_ast_argument_number_substitute(tag, 3); + else if (sieve_argument_is(tag, importance_normal_tag)) + sieve_ast_argument_number_substitute(tag, 2); + else + sieve_ast_argument_number_substitute(tag, 1); + + tag->argument = sieve_argument_create(tag->ast, &number_argument, + tag->argument->ext, + tag->argument->id_code); + + /* Skip parameter */ + *arg = sieve_ast_argument_next(*arg); + + return TRUE; +} + +void ext_notify_register_importance_tags( + struct sieve_validator *valdtr, + struct sieve_command_registration *cmd_reg, + const struct sieve_extension *ext, unsigned int id_code) +{ + sieve_validator_register_tag(valdtr, cmd_reg, ext, + &importance_low_tag, id_code); + sieve_validator_register_tag(valdtr, cmd_reg, ext, + &importance_normal_tag, id_code); + sieve_validator_register_tag(valdtr, cmd_reg, ext, + &importance_high_tag, id_code); +} + +/* + * Body extraction + */ + +/* FIXME: overlaps somewhat with body extension */ + +struct ext_notify_message_context { + pool_t pool; + buffer_t *body_text; +}; + +static struct ext_notify_message_context * +ext_notify_get_message_context(const struct sieve_extension *this_ext, + struct sieve_message_context *msgctx) +{ + struct ext_notify_message_context *ctx; + + /* Get message context (contains cached message body information) */ + ctx = (struct ext_notify_message_context *) + sieve_message_context_extension_get(msgctx, this_ext); + + /* Create it if it does not exist already */ + if (ctx == NULL) { + pool_t pool = sieve_message_context_pool(msgctx); + ctx = p_new(pool, struct ext_notify_message_context, 1); + ctx->pool = pool; + ctx->body_text = NULL; + + /* Register context */ + sieve_message_context_extension_set(msgctx, this_ext, + (void *)ctx); + } + + return ctx; +} + +static bool _is_text_content(const struct message_header_line *hdr) +{ + struct rfc822_parser_context parser; + string_t *content_type; + const char *data; + + /* Initialize parsing */ + rfc822_parser_init(&parser, hdr->full_value, hdr->full_value_len, NULL); + (void)rfc822_skip_lwsp(&parser); + + /* Parse content type */ + content_type = t_str_new(64); + if (rfc822_parse_content_type(&parser, content_type) < 0) + return FALSE; + + /* Content-type value must end here, otherwise it is invalid after all + */ + (void)rfc822_skip_lwsp(&parser); + if (parser.data != parser.end && *parser.data != ';') + return FALSE; + + /* Success */ + data = str_c(content_type); + if (str_begins(data, "text/")) + return TRUE; + return FALSE; +} + +static int +cmd_notify_extract_body_text(const struct sieve_runtime_env *renv, + const char **body_text_r, size_t *body_size_r) +{ + const struct sieve_execute_env *eenv = renv->exec_env; + const struct sieve_extension *this_ext = renv->oprtn->ext; + struct ext_notify_message_context *mctx; + struct mail *mail = eenv->msgdata->mail; + struct message_parser_ctx *parser; + struct message_decoder_context *decoder; + struct message_part *parts; + struct message_block block, decoded; + struct istream *input; + bool is_text, save_body; + int ret = 1; + + *body_text_r = NULL; + *body_size_r = 0; + + /* Return cached result if available */ + mctx = ext_notify_get_message_context(this_ext, renv->msgctx); + if (mctx->body_text != NULL) { + *body_text_r = (const char *) + buffer_get_data(mctx->body_text, body_size_r); + return SIEVE_EXEC_OK; + } + + /* Create buffer */ + mctx->body_text = buffer_create_dynamic(mctx->pool, 1024*64); + + /* Get the message stream */ + if (mail_get_stream(mail, NULL, NULL, &input) < 0) { + return sieve_runtime_mail_error(renv, mail, "notify action: " + "failed to read input message"); + } + + /* Initialize body decoder */ + decoder = message_decoder_init(NULL, 0); + + struct message_parser_settings mparser_set = { + .hdr_flags = 0, + .flags = 0, + }; + parser = message_parser_init(mctx->pool, input, &mparser_set); + is_text = TRUE; + save_body = FALSE; + while ((ret = message_parser_parse_next_block(parser, &block)) > 0) { + if (block.hdr != NULL || block.size == 0) { + /* Decode block */ + (void)message_decoder_decode_next_block(decoder, &block, + &decoded); + + /* Check for end of headers */ + if (block.hdr == NULL) { + save_body = is_text; + continue; + } + + /* We're interested of only Content-Type: header */ + if (strcasecmp(block.hdr->name, "Content-Type") != 0) + continue; + + /* Header can have folding whitespace. Acquire the full + value before continuing */ + if (block.hdr->continues) { + block.hdr->use_full_value = TRUE; + continue; + } + + /* Is it a text part? */ + T_BEGIN { + is_text = _is_text_content(block.hdr); + } T_END; + + continue; + } + + /* Read text body */ + if (save_body) { + (void)message_decoder_decode_next_block(decoder, &block, + &decoded); + buffer_append(mctx->body_text, decoded.data, + decoded.size); + is_text = TRUE; + } + } + + /* Cleanup */ + (void)message_parser_deinit(&parser, &parts); + message_decoder_deinit(&decoder); + + if (ret < 0 && input->stream_errno != 0) { + sieve_runtime_critical(renv, NULL, "notify action: " + "failed to read input message", + "notify action: read(%s) failed: %s", + i_stream_get_name(input), + i_stream_get_error(input)); + return SIEVE_EXEC_TEMP_FAILURE; + } + + /* Return status */ + *body_text_r = (const char *)buffer_get_data(mctx->body_text, + body_size_r); + return SIEVE_EXEC_OK; +} + +int ext_notify_construct_message(const struct sieve_runtime_env *renv, + const char *msg_format, + string_t *out_msg) +{ + const struct sieve_execute_env *eenv = renv->exec_env; + const struct sieve_message_data *msgdata = eenv->msgdata; + struct sieve_message_context *msgctx = renv->msgctx; + const struct smtp_address *return_path = + sieve_message_get_sender(msgctx); + const char *p; + int ret; + + if (msg_format == NULL) + msg_format = "$from$: $subject$"; + + /* Scan message for substitutions */ + p = msg_format; + while (*p != '\0') { + const char *header; + + if (strncasecmp(p, "$from$", 6) == 0) { + p += 6; + + /* Fetch sender from original message */ + if ((ret = mail_get_first_header_utf8( + msgdata->mail, "from", &header)) < 0) { + return sieve_runtime_mail_error( + renv, msgdata->mail, + "failed to read header field `from'"); + } + if (ret > 0) + str_append(out_msg, header); + } else if (strncasecmp(p, "$env-from$", 10) == 0) { + p += 10; + + if (return_path != NULL) + smtp_address_write(out_msg, return_path); + } else if (strncasecmp(p, "$subject$", 9) == 0) { + p += 9; + + /* Fetch sender from oriinal message */ + if ((ret = mail_get_first_header_utf8( + msgdata->mail, "subject", &header)) < 0) { + return sieve_runtime_mail_error( + renv, msgdata->mail, + "failed to read header field `subject'"); + } + if (ret > 0) + str_append(out_msg, header); + } else if (strncasecmp(p, "$text", 5) == 0 && + (p[5] == '[' || p[5] == '$')) { + size_t num = 0; + const char *begin = p; + bool valid = TRUE; + + p += 5; + if (*p == '[') { + p += 1; + + while (i_isdigit(*p)) { + num = num * 10 + (*p - '0'); + p++; + } + + if (*p++ != ']' || *p++ != '$') { + str_append_data(out_msg, begin, + p-begin); + valid = FALSE; + } + } else { + p += 1; + } + + if (valid) { + size_t body_size; + const char *body_text; + + if ((ret = cmd_notify_extract_body_text( + renv, &body_text, &body_size)) <= 0) + return ret; + + if (num > 0 && num < body_size) { + str_append_data(out_msg, body_text, + num); + } else { + str_append_data(out_msg, body_text, + body_size); + } + } + } else { + size_t len; + + /* Find next substitution */ + len = strcspn(p + 1, "$") + 1; + + /* Copy normal text */ + str_append_data(out_msg, p, len); + p += len; + } + } + + return SIEVE_EXEC_OK; +} diff --git a/pigeonhole/src/lib-sieve/plugins/notify/ext-notify-common.h b/pigeonhole/src/lib-sieve/plugins/notify/ext-notify-common.h new file mode 100644 index 0000000..09db2cb --- /dev/null +++ b/pigeonhole/src/lib-sieve/plugins/notify/ext-notify-common.h @@ -0,0 +1,66 @@ +#ifndef EXT_NOTIFY_COMMON_H +#define EXT_NOTIFY_COMMON_H + +/* + * Extension + */ + +extern const struct sieve_extension_def notify_extension; + +/* + * Commands + */ + +extern const struct sieve_command_def cmd_notify_old; +extern const struct sieve_command_def cmd_denotify; + +/* + * Arguments + */ + +void ext_notify_register_importance_tags( + struct sieve_validator *valdtr, + struct sieve_command_registration *cmd_reg, + const struct sieve_extension *this_ext, unsigned int id_code); + +/* + * Operations + */ + +extern const struct sieve_operation_def notify_old_operation; +extern const struct sieve_operation_def denotify_operation; + +enum ext_notify_opcode { + EXT_NOTIFY_OPERATION_NOTIFY, + EXT_NOTIFY_OPERATION_DENOTIFY, +}; + +/* + * Actions + */ + +extern const struct sieve_action_def act_notify_old; + +struct ext_notify_recipient { + const char *full; + const struct smtp_address *address; +}; + +ARRAY_DEFINE_TYPE(recipients, struct ext_notify_recipient); + +struct ext_notify_action { + const char *id; + const char *message; + sieve_number_t importance; + + ARRAY_TYPE(recipients) recipients; +}; + +/* + * Message construct + */ + +int ext_notify_construct_message(const struct sieve_runtime_env *renv, + const char *msg_format, string_t *out_msg); + +#endif diff --git a/pigeonhole/src/lib-sieve/plugins/notify/ext-notify-limits.h b/pigeonhole/src/lib-sieve/plugins/notify/ext-notify-limits.h new file mode 100644 index 0000000..5fab7cb --- /dev/null +++ b/pigeonhole/src/lib-sieve/plugins/notify/ext-notify-limits.h @@ -0,0 +1,7 @@ +#ifndef EXT_NOTIFY_LIMITS_H +#define EXT_NOTIFY_LIMITS_H + +#define EXT_NOTIFY_MAX_RECIPIENTS 8 +#define EXT_NOTIFY_MAX_MESSAGE 256 + +#endif diff --git a/pigeonhole/src/lib-sieve/plugins/notify/ext-notify.c b/pigeonhole/src/lib-sieve/plugins/notify/ext-notify.c new file mode 100644 index 0000000..e79e049 --- /dev/null +++ b/pigeonhole/src/lib-sieve/plugins/notify/ext-notify.c @@ -0,0 +1,108 @@ +/* Copyright (c) 2002-2018 Pigeonhole authors, see the included COPYING file + */ + +/* Extension notify + * ---------------- + * + * Authors: Stephan Bosch + * Specification: draft-ietf-sieve-notify-00.txt + * Implementation: full, but deprecated; provided for backwards compatibility + * Status: testing + * + */ + +#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-notify-common.h" + +/* + * Operations + */ + +const struct sieve_operation_def *ext_notify_operations[] = { + ¬ify_old_operation, + &denotify_operation +}; + +/* + * Extension + */ + +static bool ext_notify_validator_load + (const struct sieve_extension *ext, struct sieve_validator *valdtr); + +const struct sieve_extension_def notify_extension = { + .name = "notify", + .validator_load = ext_notify_validator_load, + SIEVE_EXT_DEFINE_OPERATIONS(ext_notify_operations) +}; + +/* + * Extension validation + */ + +static bool ext_notify_validator_check_conflict + (const struct sieve_extension *ext, + struct sieve_validator *valdtr, void *context, + struct sieve_ast_argument *require_arg, + const struct sieve_extension *ext_other, + bool required); +static bool ext_notify_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 notify_validator_extension = { + .ext = ¬ify_extension, + .check_conflict = ext_notify_validator_check_conflict, + .validate = ext_notify_validator_validate +}; + +static bool ext_notify_validator_load +(const struct sieve_extension *ext, struct sieve_validator *valdtr) +{ + /* Register validator extension to check for conflict with enotify */ + sieve_validator_extension_register + (valdtr, ext, ¬ify_validator_extension, NULL); + return TRUE; +} + +static bool ext_notify_validator_check_conflict +(const struct sieve_extension *ext ATTR_UNUSED, + struct sieve_validator *valdtr, void *context ATTR_UNUSED, + struct sieve_ast_argument *require_arg, + const struct sieve_extension *ext_other, + bool required ATTR_UNUSED) +{ + /* Check for conflict with enotify */ + if ( sieve_extension_name_is(ext_other, "enotify") ) { + sieve_argument_validate_error(valdtr, require_arg, + "the (deprecated) notify extension cannot be used " + "together with the enotify extension"); + return FALSE; + } + + return TRUE; +} + +static bool ext_notify_validator_validate +(const struct sieve_extension *ext, + struct sieve_validator *valdtr, void *context ATTR_UNUSED, + struct sieve_ast_argument *require_arg ATTR_UNUSED, + bool required ATTR_UNUSED) +{ + /* No conflicts: register new commands */ + sieve_validator_register_command(valdtr, ext, &cmd_notify_old); + sieve_validator_register_command(valdtr, ext, &cmd_denotify); + return TRUE; +} -- cgit v1.2.3