diff options
Diffstat (limited to 'src/pop3')
-rw-r--r-- | src/pop3/Makefile.am | 39 | ||||
-rw-r--r-- | src/pop3/Makefile.in | 887 | ||||
-rw-r--r-- | src/pop3/main.c | 433 | ||||
-rw-r--r-- | src/pop3/pop3-capability.h | 14 | ||||
-rw-r--r-- | src/pop3/pop3-client.c | 869 | ||||
-rw-r--r-- | src/pop3/pop3-client.h | 146 | ||||
-rw-r--r-- | src/pop3/pop3-commands.c | 956 | ||||
-rw-r--r-- | src/pop3/pop3-commands.h | 13 | ||||
-rw-r--r-- | src/pop3/pop3-common.h | 27 | ||||
-rw-r--r-- | src/pop3/pop3-settings.c | 184 | ||||
-rw-r--r-- | src/pop3/pop3-settings.h | 40 |
11 files changed, 3608 insertions, 0 deletions
diff --git a/src/pop3/Makefile.am b/src/pop3/Makefile.am new file mode 100644 index 0000000..fe49741 --- /dev/null +++ b/src/pop3/Makefile.am @@ -0,0 +1,39 @@ +pkglibexecdir = $(libexecdir)/dovecot + +pkglibexec_PROGRAMS = pop3 + +AM_CPPFLAGS = \ + -I$(top_srcdir)/src/lib \ + -I$(top_srcdir)/src/lib-settings \ + -I$(top_srcdir)/src/lib-master \ + -I$(top_srcdir)/src/lib-dict \ + -I$(top_srcdir)/src/lib-mail \ + -I$(top_srcdir)/src/lib-index \ + -I$(top_srcdir)/src/lib-storage \ + $(BINARY_CFLAGS) + +pop3_LDFLAGS = -export-dynamic \ + $(BINARY_LDFLAGS) + +pop3_LDADD = \ + $(LIBDOVECOT_STORAGE) \ + $(LIBDOVECOT) +pop3_DEPENDENCIES = \ + $(LIBDOVECOT_STORAGE_DEPS) \ + $(LIBDOVECOT_DEPS) + +pop3_SOURCES = \ + main.c \ + pop3-client.c \ + pop3-commands.c \ + pop3-settings.c + +headers = \ + pop3-capability.h \ + pop3-client.h \ + pop3-commands.h \ + pop3-common.h \ + pop3-settings.h + +pkginc_libdir=$(pkgincludedir) +pkginc_lib_HEADERS = $(headers) diff --git a/src/pop3/Makefile.in b/src/pop3/Makefile.in new file mode 100644 index 0000000..18675a3 --- /dev/null +++ b/src/pop3/Makefile.in @@ -0,0 +1,887 @@ +# 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@ +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@ +pkglibexec_PROGRAMS = pop3$(EXEEXT) +subdir = src/pop3 +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/m4/ac_checktype2.m4 \ + $(top_srcdir)/m4/ac_typeof.m4 $(top_srcdir)/m4/arc4random.m4 \ + $(top_srcdir)/m4/blockdev.m4 $(top_srcdir)/m4/c99_vsnprintf.m4 \ + $(top_srcdir)/m4/clock_gettime.m4 $(top_srcdir)/m4/crypt.m4 \ + $(top_srcdir)/m4/crypt_xpg6.m4 $(top_srcdir)/m4/dbqlk.m4 \ + $(top_srcdir)/m4/dirent_dtype.m4 $(top_srcdir)/m4/dovecot.m4 \ + $(top_srcdir)/m4/fd_passing.m4 $(top_srcdir)/m4/fdatasync.m4 \ + $(top_srcdir)/m4/flexible_array_member.m4 \ + $(top_srcdir)/m4/glibc.m4 $(top_srcdir)/m4/gmtime_max.m4 \ + $(top_srcdir)/m4/gmtime_tm_gmtoff.m4 \ + $(top_srcdir)/m4/ioloop.m4 $(top_srcdir)/m4/iovec.m4 \ + $(top_srcdir)/m4/ipv6.m4 $(top_srcdir)/m4/libcap.m4 \ + $(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/libwrap.m4 \ + $(top_srcdir)/m4/linux_mremap.m4 $(top_srcdir)/m4/ltoptions.m4 \ + $(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \ + $(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/m4/mmap_write.m4 \ + $(top_srcdir)/m4/mntctl.m4 $(top_srcdir)/m4/modules.m4 \ + $(top_srcdir)/m4/notify.m4 $(top_srcdir)/m4/nsl.m4 \ + $(top_srcdir)/m4/off_t_max.m4 $(top_srcdir)/m4/pkg.m4 \ + $(top_srcdir)/m4/pr_set_dumpable.m4 \ + $(top_srcdir)/m4/q_quotactl.m4 $(top_srcdir)/m4/quota.m4 \ + $(top_srcdir)/m4/random.m4 $(top_srcdir)/m4/rlimit.m4 \ + $(top_srcdir)/m4/sendfile.m4 $(top_srcdir)/m4/size_t_signed.m4 \ + $(top_srcdir)/m4/sockpeercred.m4 $(top_srcdir)/m4/sql.m4 \ + $(top_srcdir)/m4/ssl.m4 $(top_srcdir)/m4/st_tim.m4 \ + $(top_srcdir)/m4/static_array.m4 $(top_srcdir)/m4/test_with.m4 \ + $(top_srcdir)/m4/time_t.m4 $(top_srcdir)/m4/typeof.m4 \ + $(top_srcdir)/m4/typeof_dev_t.m4 \ + $(top_srcdir)/m4/uoff_t_max.m4 $(top_srcdir)/m4/vararg.m4 \ + $(top_srcdir)/m4/want_apparmor.m4 \ + $(top_srcdir)/m4/want_bsdauth.m4 \ + $(top_srcdir)/m4/want_bzlib.m4 \ + $(top_srcdir)/m4/want_cassandra.m4 \ + $(top_srcdir)/m4/want_cdb.m4 \ + $(top_srcdir)/m4/want_checkpassword.m4 \ + $(top_srcdir)/m4/want_clucene.m4 $(top_srcdir)/m4/want_db.m4 \ + $(top_srcdir)/m4/want_gssapi.m4 $(top_srcdir)/m4/want_icu.m4 \ + $(top_srcdir)/m4/want_ldap.m4 $(top_srcdir)/m4/want_lua.m4 \ + $(top_srcdir)/m4/want_lz4.m4 $(top_srcdir)/m4/want_lzma.m4 \ + $(top_srcdir)/m4/want_mysql.m4 $(top_srcdir)/m4/want_pam.m4 \ + $(top_srcdir)/m4/want_passwd.m4 $(top_srcdir)/m4/want_pgsql.m4 \ + $(top_srcdir)/m4/want_prefetch.m4 \ + $(top_srcdir)/m4/want_shadow.m4 \ + $(top_srcdir)/m4/want_sodium.m4 $(top_srcdir)/m4/want_solr.m4 \ + $(top_srcdir)/m4/want_sqlite.m4 \ + $(top_srcdir)/m4/want_stemmer.m4 \ + $(top_srcdir)/m4/want_systemd.m4 \ + $(top_srcdir)/m4/want_textcat.m4 \ + $(top_srcdir)/m4/want_unwind.m4 $(top_srcdir)/m4/want_zlib.m4 \ + $(top_srcdir)/m4/want_zstd.m4 $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +DIST_COMMON = $(srcdir)/Makefile.am $(pkginc_lib_HEADERS) \ + $(am__DIST_COMMON) +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +am__installdirs = "$(DESTDIR)$(pkglibexecdir)" \ + "$(DESTDIR)$(pkginc_libdir)" +PROGRAMS = $(pkglibexec_PROGRAMS) +am_pop3_OBJECTS = main.$(OBJEXT) pop3-client.$(OBJEXT) \ + pop3-commands.$(OBJEXT) pop3-settings.$(OBJEXT) +pop3_OBJECTS = $(am_pop3_OBJECTS) +am__DEPENDENCIES_1 = +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 = +pop3_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(pop3_LDFLAGS) $(LDFLAGS) -o $@ +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)/main.Po ./$(DEPDIR)/pop3-client.Po \ + ./$(DEPDIR)/pop3-commands.Po ./$(DEPDIR)/pop3-settings.Po +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 = $(pop3_SOURCES) +DIST_SOURCES = $(pop3_SOURCES) +am__can_run_installinfo = \ + case $$AM_UPDATE_INFO_DIR in \ + n|no|NO) false;; \ + *) (install-info --version) >/dev/null 2>&1;; \ + esac +am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; +am__vpath_adj = case $$p in \ + $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ + *) f=$$p;; \ + esac; +am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; +am__install_max = 40 +am__nobase_strip_setup = \ + srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` +am__nobase_strip = \ + for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" +am__nobase_list = $(am__nobase_strip_setup); \ + for p in $$list; do echo "$$p $$p"; done | \ + sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ + $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ + if (++n[$$2] == $(am__install_max)) \ + { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ + END { for (dir in files) print dir, files[dir] }' +am__base_list = \ + sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ + sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' +am__uninstall_files_from_dir = { \ + test -z "$$files" \ + || { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \ + || { echo " ( cd '$$dir' && rm -f" $$files ")"; \ + $(am__cd) "$$dir" && rm -f $$files; }; \ + } +HEADERS = $(pkginc_lib_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) +pkglibexecdir = $(libexecdir)/dovecot +ACLOCAL = @ACLOCAL@ +ACLOCAL_AMFLAGS = @ACLOCAL_AMFLAGS@ +AMTAR = @AMTAR@ +AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ +APPARMOR_LIBS = @APPARMOR_LIBS@ +AR = @AR@ +AUTH_CFLAGS = @AUTH_CFLAGS@ +AUTH_LIBS = @AUTH_LIBS@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +BINARY_CFLAGS = @BINARY_CFLAGS@ +BINARY_LDFLAGS = @BINARY_LDFLAGS@ +BISON = @BISON@ +CASSANDRA_CFLAGS = @CASSANDRA_CFLAGS@ +CASSANDRA_LIBS = @CASSANDRA_LIBS@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CDB_LIBS = @CDB_LIBS@ +CFLAGS = @CFLAGS@ +CLUCENE_CFLAGS = @CLUCENE_CFLAGS@ +CLUCENE_LIBS = @CLUCENE_LIBS@ +COMPRESS_LIBS = @COMPRESS_LIBS@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CRYPT_LIBS = @CRYPT_LIBS@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +CXXDEPMODE = @CXXDEPMODE@ +CXXFLAGS = @CXXFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DICT_LIBS = @DICT_LIBS@ +DLLIB = @DLLIB@ +DLLTOOL = @DLLTOOL@ +DSYMUTIL = @DSYMUTIL@ +DUMPBIN = @DUMPBIN@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +EXEEXT = @EXEEXT@ +FGREP = @FGREP@ +FLEX = @FLEX@ +FUZZER_CPPFLAGS = @FUZZER_CPPFLAGS@ +FUZZER_LDFLAGS = @FUZZER_LDFLAGS@ +GREP = @GREP@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +KRB5CONFIG = @KRB5CONFIG@ +KRB5_CFLAGS = @KRB5_CFLAGS@ +KRB5_LIBS = @KRB5_LIBS@ +LD = @LD@ +LDAP_LIBS = @LDAP_LIBS@ +LDFLAGS = @LDFLAGS@ +LD_NO_WHOLE_ARCHIVE = @LD_NO_WHOLE_ARCHIVE@ +LD_WHOLE_ARCHIVE = @LD_WHOLE_ARCHIVE@ +LIBCAP = @LIBCAP@ +LIBDOVECOT = @LIBDOVECOT@ +LIBDOVECOT_COMPRESS = @LIBDOVECOT_COMPRESS@ +LIBDOVECOT_DEPS = @LIBDOVECOT_DEPS@ +LIBDOVECOT_DSYNC = @LIBDOVECOT_DSYNC@ +LIBDOVECOT_LA_LIBS = @LIBDOVECOT_LA_LIBS@ +LIBDOVECOT_LDA = @LIBDOVECOT_LDA@ +LIBDOVECOT_LDAP = @LIBDOVECOT_LDAP@ +LIBDOVECOT_LIBFTS = @LIBDOVECOT_LIBFTS@ +LIBDOVECOT_LIBFTS_DEPS = @LIBDOVECOT_LIBFTS_DEPS@ +LIBDOVECOT_LOGIN = @LIBDOVECOT_LOGIN@ +LIBDOVECOT_LUA = @LIBDOVECOT_LUA@ +LIBDOVECOT_LUA_DEPS = @LIBDOVECOT_LUA_DEPS@ +LIBDOVECOT_SQL = @LIBDOVECOT_SQL@ +LIBDOVECOT_STORAGE = @LIBDOVECOT_STORAGE@ +LIBDOVECOT_STORAGE_DEPS = @LIBDOVECOT_STORAGE_DEPS@ +LIBEXTTEXTCAT_CFLAGS = @LIBEXTTEXTCAT_CFLAGS@ +LIBEXTTEXTCAT_LIBS = @LIBEXTTEXTCAT_LIBS@ +LIBICONV = @LIBICONV@ +LIBICU_CFLAGS = @LIBICU_CFLAGS@ +LIBICU_LIBS = @LIBICU_LIBS@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBSODIUM_CFLAGS = @LIBSODIUM_CFLAGS@ +LIBSODIUM_LIBS = @LIBSODIUM_LIBS@ +LIBTIRPC_CFLAGS = @LIBTIRPC_CFLAGS@ +LIBTIRPC_LIBS = @LIBTIRPC_LIBS@ +LIBTOOL = @LIBTOOL@ +LIBUNWIND_CFLAGS = @LIBUNWIND_CFLAGS@ +LIBUNWIND_LIBS = @LIBUNWIND_LIBS@ +LIBWRAP_LIBS = @LIBWRAP_LIBS@ +LINKED_STORAGE_LDADD = @LINKED_STORAGE_LDADD@ +LIPO = @LIPO@ +LN_S = @LN_S@ +LTLIBICONV = @LTLIBICONV@ +LTLIBOBJS = @LTLIBOBJS@ +LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@ +LUA_CFLAGS = @LUA_CFLAGS@ +LUA_LIBS = @LUA_LIBS@ +MAINT = @MAINT@ +MAKEINFO = @MAKEINFO@ +MANIFEST_TOOL = @MANIFEST_TOOL@ +MKDIR_P = @MKDIR_P@ +MODULE_LIBS = @MODULE_LIBS@ +MODULE_SUFFIX = @MODULE_SUFFIX@ +MYSQL_CFLAGS = @MYSQL_CFLAGS@ +MYSQL_CONFIG = @MYSQL_CONFIG@ +MYSQL_LIBS = @MYSQL_LIBS@ +NM = @NM@ +NMEDIT = @NMEDIT@ +NOPLUGIN_LDFLAGS = @NOPLUGIN_LDFLAGS@ +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@ +PANDOC = @PANDOC@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +PGSQL_CFLAGS = @PGSQL_CFLAGS@ +PGSQL_LIBS = @PGSQL_LIBS@ +PG_CONFIG = @PG_CONFIG@ +PIE_CFLAGS = @PIE_CFLAGS@ +PIE_LDFLAGS = @PIE_LDFLAGS@ +PKG_CONFIG = @PKG_CONFIG@ +PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@ +PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ +QUOTA_LIBS = @QUOTA_LIBS@ +RANLIB = @RANLIB@ +RELRO_LDFLAGS = @RELRO_LDFLAGS@ +RPCGEN = @RPCGEN@ +RUN_TEST = @RUN_TEST@ +SED = @SED@ +SETTING_FILES = @SETTING_FILES@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +SQLITE_CFLAGS = @SQLITE_CFLAGS@ +SQLITE_LIBS = @SQLITE_LIBS@ +SQL_CFLAGS = @SQL_CFLAGS@ +SQL_LIBS = @SQL_LIBS@ +SSL_CFLAGS = @SSL_CFLAGS@ +SSL_LIBS = @SSL_LIBS@ +STRIP = @STRIP@ +SYSTEMD_CFLAGS = @SYSTEMD_CFLAGS@ +SYSTEMD_LIBS = @SYSTEMD_LIBS@ +VALGRIND = @VALGRIND@ +VERSION = @VERSION@ +ZSTD_CFLAGS = @ZSTD_CFLAGS@ +ZSTD_LIBS = @ZSTD_LIBS@ +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_CXX = @ac_ct_CXX@ +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@ +dict_drivers = @dict_drivers@ +docdir = @docdir@ +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@ +rundir = @rundir@ +runstatedir = @runstatedir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +sql_drivers = @sql_drivers@ +srcdir = @srcdir@ +ssldir = @ssldir@ +statedir = @statedir@ +sysconfdir = @sysconfdir@ +systemdservicetype = @systemdservicetype@ +systemdsystemunitdir = @systemdsystemunitdir@ +target_alias = @target_alias@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +AM_CPPFLAGS = \ + -I$(top_srcdir)/src/lib \ + -I$(top_srcdir)/src/lib-settings \ + -I$(top_srcdir)/src/lib-master \ + -I$(top_srcdir)/src/lib-dict \ + -I$(top_srcdir)/src/lib-mail \ + -I$(top_srcdir)/src/lib-index \ + -I$(top_srcdir)/src/lib-storage \ + $(BINARY_CFLAGS) + +pop3_LDFLAGS = -export-dynamic \ + $(BINARY_LDFLAGS) + +pop3_LDADD = \ + $(LIBDOVECOT_STORAGE) \ + $(LIBDOVECOT) + +pop3_DEPENDENCIES = \ + $(LIBDOVECOT_STORAGE_DEPS) \ + $(LIBDOVECOT_DEPS) + +pop3_SOURCES = \ + main.c \ + pop3-client.c \ + pop3-commands.c \ + pop3-settings.c + +headers = \ + pop3-capability.h \ + pop3-client.h \ + pop3-commands.h \ + pop3-common.h \ + pop3-settings.h + +pkginc_libdir = $(pkgincludedir) +pkginc_lib_HEADERS = $(headers) +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/pop3/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --foreign src/pop3/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): +install-pkglibexecPROGRAMS: $(pkglibexec_PROGRAMS) + @$(NORMAL_INSTALL) + @list='$(pkglibexec_PROGRAMS)'; test -n "$(pkglibexecdir)" || list=; \ + if test -n "$$list"; then \ + echo " $(MKDIR_P) '$(DESTDIR)$(pkglibexecdir)'"; \ + $(MKDIR_P) "$(DESTDIR)$(pkglibexecdir)" || exit 1; \ + fi; \ + for p in $$list; do echo "$$p $$p"; done | \ + sed 's/$(EXEEXT)$$//' | \ + while read p p1; do if test -f $$p \ + || test -f $$p1 \ + ; then echo "$$p"; echo "$$p"; else :; fi; \ + done | \ + sed -e 'p;s,.*/,,;n;h' \ + -e 's|.*|.|' \ + -e 'p;x;s,.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/' | \ + sed 'N;N;N;s,\n, ,g' | \ + $(AWK) 'BEGIN { files["."] = ""; dirs["."] = 1 } \ + { d=$$3; if (dirs[d] != 1) { print "d", d; dirs[d] = 1 } \ + if ($$2 == $$4) files[d] = files[d] " " $$1; \ + else { print "f", $$3 "/" $$4, $$1; } } \ + END { for (d in files) print "f", d, files[d] }' | \ + while read type dir files; do \ + if test "$$dir" = .; then dir=; else dir=/$$dir; fi; \ + test -z "$$files" || { \ + echo " $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files '$(DESTDIR)$(pkglibexecdir)$$dir'"; \ + $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files "$(DESTDIR)$(pkglibexecdir)$$dir" || exit $$?; \ + } \ + ; done + +uninstall-pkglibexecPROGRAMS: + @$(NORMAL_UNINSTALL) + @list='$(pkglibexec_PROGRAMS)'; test -n "$(pkglibexecdir)" || list=; \ + files=`for p in $$list; do echo "$$p"; done | \ + sed -e 'h;s,^.*/,,;s/$(EXEEXT)$$//;$(transform)' \ + -e 's/$$/$(EXEEXT)/' \ + `; \ + test -n "$$list" || exit 0; \ + echo " ( cd '$(DESTDIR)$(pkglibexecdir)' && rm -f" $$files ")"; \ + cd "$(DESTDIR)$(pkglibexecdir)" && rm -f $$files + +clean-pkglibexecPROGRAMS: + @list='$(pkglibexec_PROGRAMS)'; test -n "$$list" || exit 0; \ + echo " rm -f" $$list; \ + rm -f $$list || exit $$?; \ + test -n "$(EXEEXT)" || exit 0; \ + list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \ + echo " rm -f" $$list; \ + rm -f $$list + +pop3$(EXEEXT): $(pop3_OBJECTS) $(pop3_DEPENDENCIES) $(EXTRA_pop3_DEPENDENCIES) + @rm -f pop3$(EXEEXT) + $(AM_V_CCLD)$(pop3_LINK) $(pop3_OBJECTS) $(pop3_LDADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/main.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pop3-client.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pop3-commands.Po@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pop3-settings.Po@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 +install-pkginc_libHEADERS: $(pkginc_lib_HEADERS) + @$(NORMAL_INSTALL) + @list='$(pkginc_lib_HEADERS)'; test -n "$(pkginc_libdir)" || list=; \ + if test -n "$$list"; then \ + echo " $(MKDIR_P) '$(DESTDIR)$(pkginc_libdir)'"; \ + $(MKDIR_P) "$(DESTDIR)$(pkginc_libdir)" || exit 1; \ + fi; \ + for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + echo "$$d$$p"; \ + done | $(am__base_list) | \ + while read files; do \ + echo " $(INSTALL_HEADER) $$files '$(DESTDIR)$(pkginc_libdir)'"; \ + $(INSTALL_HEADER) $$files "$(DESTDIR)$(pkginc_libdir)" || exit $$?; \ + done + +uninstall-pkginc_libHEADERS: + @$(NORMAL_UNINSTALL) + @list='$(pkginc_lib_HEADERS)'; test -n "$(pkginc_libdir)" || list=; \ + files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \ + dir='$(DESTDIR)$(pkginc_libdir)'; $(am__uninstall_files_from_dir) + +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 $(PROGRAMS) $(HEADERS) +installdirs: + for dir in "$(DESTDIR)$(pkglibexecdir)" "$(DESTDIR)$(pkginc_libdir)"; do \ + test -z "$$dir" || $(MKDIR_P) "$$dir"; \ + done +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-pkglibexecPROGRAMS \ + mostlyclean-am + +distclean: distclean-am + -rm -f ./$(DEPDIR)/main.Po + -rm -f ./$(DEPDIR)/pop3-client.Po + -rm -f ./$(DEPDIR)/pop3-commands.Po + -rm -f ./$(DEPDIR)/pop3-settings.Po + -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-pkginc_libHEADERS + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: install-pkglibexecPROGRAMS + +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)/main.Po + -rm -f ./$(DEPDIR)/pop3-client.Po + -rm -f ./$(DEPDIR)/pop3-commands.Po + -rm -f ./$(DEPDIR)/pop3-settings.Po + -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: uninstall-pkginc_libHEADERS uninstall-pkglibexecPROGRAMS + +.MAKE: install-am install-strip + +.PHONY: CTAGS GTAGS TAGS all all-am am--depfiles check check-am clean \ + clean-generic clean-libtool clean-pkglibexecPROGRAMS \ + 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-pkginc_libHEADERS \ + install-pkglibexecPROGRAMS 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 \ + uninstall-pkginc_libHEADERS uninstall-pkglibexecPROGRAMS + +.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/src/pop3/main.c b/src/pop3/main.c new file mode 100644 index 0000000..c929cdb --- /dev/null +++ b/src/pop3/main.c @@ -0,0 +1,433 @@ +/* Copyright (c) 2002-2018 Dovecot authors, see the included COPYING file */ + +#include "pop3-common.h" +#include "ioloop.h" +#include "buffer.h" +#include "istream.h" +#include "istream-concat.h" +#include "ostream.h" +#include "path-util.h" +#include "base64.h" +#include "str.h" +#include "process-title.h" +#include "restrict-access.h" +#include "settings-parser.h" +#include "master-service.h" +#include "master-login.h" +#include "master-interface.h" +#include "var-expand.h" +#include "mail-error.h" +#include "mail-user.h" +#include "mail-namespace.h" +#include "mail-storage-service.h" + +#include <stdio.h> +#include <unistd.h> + +#define IS_STANDALONE() \ + (getenv(MASTER_IS_PARENT_ENV) == NULL) + +static bool verbose_proctitle = FALSE; +static struct mail_storage_service_ctx *storage_service; +static struct master_login *master_login = NULL; + +pop3_client_created_func_t *hook_client_created = NULL; + +pop3_client_created_func_t * +pop3_client_created_hook_set(pop3_client_created_func_t *new_hook) +{ + pop3_client_created_func_t *old_hook = hook_client_created; + + hook_client_created = new_hook; + return old_hook; +} + +void pop3_refresh_proctitle(void) +{ + struct client *client; + string_t *title = t_str_new(128); + + if (!verbose_proctitle) + return; + + str_append_c(title, '['); + switch (pop3_client_count) { + case 0: + str_append(title, "idling"); + break; + case 1: + client = pop3_clients; + str_append(title, client->user->username); + if (client->user->conn.remote_ip != NULL) { + str_append_c(title, ' '); + str_append(title, + net_ip2addr(client->user->conn.remote_ip)); + } + if (client->destroyed) + str_append(title, " (deinit)"); + break; + default: + str_printfa(title, "%u connections", pop3_client_count); + break; + } + str_append_c(title, ']'); + process_title_set(str_c(title)); +} + +static void pop3_die(void) +{ + /* do nothing. pop3 connections typically die pretty quick anyway. */ +} + +static void client_add_input(struct client *client, const buffer_t *buf) +{ + struct ostream *output; + + if (buf != NULL && buf->used > 0) { + struct istream *inputs[] = { + i_stream_create_copy_from_data(buf->data, buf->used), + client->input, + NULL + }; + client->input = i_stream_create_concat(inputs); + i_stream_copy_fd(client->input, inputs[1]); + i_stream_unref(&inputs[0]); + i_stream_unref(&inputs[1]); + i_stream_set_input_pending(client->input, TRUE); + } + + output = client->output; + o_stream_ref(output); + o_stream_cork(output); + (void)client_handle_input(client); + o_stream_uncork(output); + o_stream_unref(&output); +} + +static int +client_create_from_input(const struct mail_storage_service_input *input, + int fd_in, int fd_out, struct client **client_r, + const char **error_r) +{ + const char *lookup_error_str = + "-ERR [SYS/TEMP] "MAIL_ERRSTR_CRITICAL_MSG"\r\n"; + struct mail_storage_service_user *user; + struct mail_user *mail_user; + struct pop3_settings *set; + const char *errstr; + + if (mail_storage_service_lookup_next(storage_service, input, + &user, &mail_user, error_r) <= 0) { + if (write(fd_out, lookup_error_str, strlen(lookup_error_str)) < 0) { + /* ignored */ + } + return -1; + } + restrict_access_allow_coredumps(TRUE); + + set = mail_storage_service_user_get_set(user)[1]; + if (set->verbose_proctitle) + verbose_proctitle = TRUE; + + if (settings_var_expand(&pop3_setting_parser_info, set, + mail_user->pool, mail_user_var_expand_table(mail_user), + &errstr) <= 0) { + *error_r = t_strdup_printf("Failed to expand settings: %s", errstr); + mail_user_deinit(&mail_user); + mail_storage_service_user_unref(&user); + return -1; + } + + *client_r = client_create(fd_in, fd_out, mail_user, user, set); + return 0; +} + +static int lock_session(struct client *client) +{ + int ret; + + i_assert(client->user->namespaces != NULL); + i_assert(client->set->pop3_lock_session); + + if ((ret = pop3_lock_session(client)) <= 0) { + client_send_line(client, ret < 0 ? + "-ERR [SYS/TEMP] Failed to create POP3 session lock." : + "-ERR [IN-USE] Mailbox is locked by another POP3 session."); + client_destroy(client, "Couldn't lock POP3 session"); + return -1; + } + + return 0; +} + +#define MSG_BYE_INTERNAL_ERROR "-ERR "MAIL_ERRSTR_CRITICAL_MSG +static int init_namespaces(struct client *client, bool already_logged_in) +{ + const char *error; + + /* finish initializing the user (see comment in main()) */ + if (mail_namespaces_init(client->user, &error) < 0) { + if (!already_logged_in) + client_send_line(client, MSG_BYE_INTERNAL_ERROR); + + i_error("%s", error); + client_destroy(client, error); + return -1; + } + + i_assert(client->inbox_ns == NULL); + client->inbox_ns = mail_namespace_find_inbox(client->user->namespaces); + i_assert(client->inbox_ns != NULL); + + return 0; +} + +static void client_init_session(struct client *client) +{ + const char *error; + + /* + * RFC 1939 requires that the session lock gets acquired before the + * positive response is sent to the client indicating a transition + * to the TRANSACTION state. + * + * Since the session lock is stored under the INBOX's storage + * directory, the locking code requires that the namespaces are + * initialized first. + * + * If the system administrator configured dovecot to not use session + * locks, we can send back the positive response before the + * potentially long-running namespace initialization occurs. This + * avoids the client possibly timing out during authentication due + * to storage initialization taking too long. + */ + if (client->set->pop3_lock_session) { + if (init_namespaces(client, FALSE) < 0) + return; /* no need to propagate an error */ + + if (lock_session(client) < 0) + return; /* no need to propagate an error */ + + if (!IS_STANDALONE()) + client_send_line(client, "+OK Logged in."); + } else { + if (!IS_STANDALONE()) + client_send_line(client, "+OK Logged in."); + + if (init_namespaces(client, TRUE) < 0) + return; /* no need to propagate an error */ + } + + struct event_reason *reason = event_reason_begin("pop3:initialize"); + int ret = client_init_mailbox(client, &error); + event_reason_end(&reason); + + if (ret < 0) { + i_error("%s", error); + client_destroy(client, error); + } +} + +static void main_stdio_run(const char *username) +{ + struct client *client; + struct mail_storage_service_input input; + buffer_t *input_buf; + const char *value, *error, *input_base64; + + i_zero(&input); + input.module = input.service = "pop3"; + input.username = username != NULL ? username : getenv("USER"); + if (input.username == NULL && IS_STANDALONE()) + input.username = getlogin(); + if (input.username == NULL) + i_fatal("USER environment missing"); + if ((value = getenv("IP")) != NULL) + (void)net_addr2ip(value, &input.remote_ip); + if ((value = getenv("LOCAL_IP")) != NULL) + (void)net_addr2ip(value, &input.local_ip); + + input_base64 = getenv("CLIENT_INPUT"); + input_buf = input_base64 == NULL ? NULL : + t_base64_decode_str(input_base64); + + if (client_create_from_input(&input, STDIN_FILENO, STDOUT_FILENO, + &client, &error) < 0) + i_fatal("%s", error); + client_add_input(client, input_buf); + client_create_finish(client); + + client_init_session(client); + /* client may be destroyed now */ +} + +static void +login_client_connected(const struct master_login_client *login_client, + const char *username, const char *const *extra_fields) +{ + struct client *client; + struct mail_storage_service_input input; + enum mail_auth_request_flags flags = login_client->auth_req.flags; + const char *error; + buffer_t input_buf; + + i_zero(&input); + input.module = input.service = "pop3"; + input.local_ip = login_client->auth_req.local_ip; + input.remote_ip = login_client->auth_req.remote_ip; + input.local_port = login_client->auth_req.local_port; + input.remote_port = login_client->auth_req.remote_port; + input.username = username; + input.userdb_fields = extra_fields; + input.session_id = login_client->session_id; + if ((flags & MAIL_AUTH_REQUEST_FLAG_CONN_SECURED) != 0) + input.conn_secured = TRUE; + if ((flags & MAIL_AUTH_REQUEST_FLAG_CONN_SSL_SECURED) != 0) + input.conn_ssl_secured = TRUE; + + buffer_create_from_const_data(&input_buf, login_client->data, + login_client->auth_req.data_size); + if (client_create_from_input(&input, login_client->fd, login_client->fd, + &client, &error) < 0) { + int fd = login_client->fd; + + i_error("%s", error); + i_close_fd(&fd); + master_service_client_connection_destroyed(master_service); + return; + } + client_add_input(client, &input_buf); + client_create_finish(client); + + client_init_session(client); + /* client may be destroyed now */ +} + +static void login_client_failed(const struct master_login_client *client, + const char *errormsg) +{ + const char *msg; + + msg = t_strdup_printf("-ERR [SYS/TEMP] %s\r\n", errormsg); + if (write(client->fd, msg, strlen(msg)) < 0) { + /* ignored */ + } +} + +static void client_connected(struct master_service_connection *conn) +{ + /* when running standalone, we shouldn't even get here */ + i_assert(master_login != NULL); + + master_service_client_connection_accept(conn); + master_login_add(master_login, conn->fd); +} + +int main(int argc, char *argv[]) +{ + static const struct setting_parser_info *set_roots[] = { + &pop3_setting_parser_info, + NULL + }; + struct master_login_settings login_set; + enum master_service_flags service_flags = 0; + enum mail_storage_service_flags storage_service_flags = + MAIL_STORAGE_SERVICE_FLAG_NO_SSL_CA; + const char *username = NULL, *auth_socket_path = "auth-master"; + int c; + + i_zero(&login_set); + login_set.postlogin_timeout_secs = MASTER_POSTLOGIN_TIMEOUT_DEFAULT; + + if (IS_STANDALONE() && getuid() == 0 && + net_getpeername(1, NULL, NULL) == 0) { + printf("-ERR [SYS/PERM] pop3 binary must not be started from " + "inetd, use pop3-login instead.\n"); + return 1; + } + + if (IS_STANDALONE()) { + service_flags |= MASTER_SERVICE_FLAG_STANDALONE | + MASTER_SERVICE_FLAG_STD_CLIENT; + } else { + service_flags |= MASTER_SERVICE_FLAG_KEEP_CONFIG_OPEN; + } + + /* + * We include MAIL_STORAGE_SERVICE_FLAG_NO_NAMESPACES so that the + * mail_user initialization is fast and we can quickly send back the + * OK response to LOGIN/AUTHENTICATE. Otherwise we risk a very slow + * namespace initialization to cause client timeouts on login. + */ + storage_service_flags |= MAIL_STORAGE_SERVICE_FLAG_NO_NAMESPACES; + + master_service = master_service_init("pop3", service_flags, + &argc, &argv, "a:t:u:"); + while ((c = master_getopt(master_service)) > 0) { + switch (c) { + case 'a': + auth_socket_path = optarg; + break; + case 't': + if (str_to_uint(optarg, &login_set.postlogin_timeout_secs) < 0 || + login_set.postlogin_timeout_secs == 0) + i_fatal("Invalid -t parameter: %s", optarg); + break; + case 'u': + storage_service_flags |= + MAIL_STORAGE_SERVICE_FLAG_USERDB_LOOKUP; + username = optarg; + break; + default: + return FATAL_DEFAULT; + } + } + + const char *error; + if (t_abspath(auth_socket_path, &login_set.auth_socket_path, &error) < 0) { + i_fatal("t_abspath(%s) failed: %s", auth_socket_path, error); + } + if (argv[optind] != NULL) { + if (t_abspath(argv[optind], &login_set.postlogin_socket_path, &error) < 0) { + i_fatal("t_abspath(%s) failed: %s", argv[optind], error); + } + } + login_set.callback = login_client_connected; + login_set.failure_callback = login_client_failed; + login_set.update_proctitle = + getenv(MASTER_VERBOSE_PROCTITLE_ENV) != NULL && + master_service_get_client_limit(master_service) == 1; + if (!IS_STANDALONE()) + master_login = master_login_init(master_service, &login_set); + + master_service_set_die_callback(master_service, pop3_die); + + storage_service = + mail_storage_service_init(master_service, + set_roots, storage_service_flags); + master_service_init_finish(master_service); + /* NOTE: login_set.*_socket_path are now invalid due to data stack + having been freed */ + + /* fake that we're running, so we know if client was destroyed + while handling its initial input */ + io_loop_set_running(current_ioloop); + + if (IS_STANDALONE()) { + T_BEGIN { + main_stdio_run(username); + } T_END; + } else { + io_loop_set_running(current_ioloop); + } + + if (io_loop_is_running(current_ioloop)) + master_service_run(master_service, client_connected); + clients_destroy_all(); + + if (master_login != NULL) + master_login_deinit(&master_login); + mail_storage_service_deinit(&storage_service); + master_service_deinit(&master_service); + return 0; +} diff --git a/src/pop3/pop3-capability.h b/src/pop3/pop3-capability.h new file mode 100644 index 0000000..3cd48ce --- /dev/null +++ b/src/pop3/pop3-capability.h @@ -0,0 +1,14 @@ +#ifndef POP3_CAPABILITY_H +#define POP3_CAPABILITY_H + +#define POP3_CAPABILITY_REPLY \ + "CAPA\r\n" \ + "TOP\r\n" \ + "UIDL\r\n" \ + "RESP-CODES\r\n" \ + "PIPELINING\r\n" \ + "AUTH-RESP-CODE\r\n" + +/* + SASL */ + +#endif diff --git a/src/pop3/pop3-client.c b/src/pop3/pop3-client.c new file mode 100644 index 0000000..4bdbea2 --- /dev/null +++ b/src/pop3/pop3-client.c @@ -0,0 +1,869 @@ +/* Copyright (c) 2002-2018 Dovecot authors, see the included COPYING file */ + +#include "pop3-common.h" +#include "array.h" +#include "ioloop.h" +#include "net.h" +#include "iostream.h" +#include "istream.h" +#include "ostream.h" +#include "iostream-rawlog.h" +#include "crc32.h" +#include "str.h" +#include "llist.h" +#include "hostpid.h" +#include "file-dotlock.h" +#include "var-expand.h" +#include "master-service.h" +#include "mail-storage.h" +#include "mail-storage-service.h" +#include "mail-autoexpunge.h" +#include "pop3-commands.h" +#include "mail-search-build.h" +#include "mail-namespace.h" + +#include <unistd.h> + +/* max. length of input command line (spec says 512) */ +#define MAX_INBUF_SIZE 2048 + +/* Disconnect client when it sends too many bad commands in a row */ +#define CLIENT_MAX_BAD_COMMANDS 20 + +/* Disconnect client after idling this many milliseconds */ +#define CLIENT_IDLE_TIMEOUT_MSECS (10*60*1000) +/* If client starts idling for this many milliseconds, commit the current + transaction. This allows the mailbox to become unlocked. */ +#define CLIENT_COMMIT_TIMEOUT_MSECS (10*1000) + +#define POP3_LOCK_FNAME "dovecot-pop3-session.lock" +#define POP3_SESSION_DOTLOCK_STALE_TIMEOUT_SECS (60*5) + +extern struct pop3_client_vfuncs pop3_client_vfuncs; + +struct pop3_module_register pop3_module_register = { 0 }; + +struct client *pop3_clients; +unsigned int pop3_client_count; + +static enum mail_sort_type pop3_sort_program[] = { + MAIL_SORT_POP3_ORDER, + MAIL_SORT_END +}; + +static const struct dotlock_settings session_dotlock_set = { + .timeout = 10, + .stale_timeout = POP3_SESSION_DOTLOCK_STALE_TIMEOUT_SECS, + .lock_suffix = "", + .use_io_notify = TRUE +}; + +static void client_input(struct client *client); +static int client_output(struct client *client); + +static void client_commit_timeout(struct client *client) +{ + if (client->cmd != NULL) { + /* Can't commit while commands are running */ + return; + } + + (void)mailbox_transaction_commit(&client->trans); + client->trans = mailbox_transaction_begin(client->mailbox, 0, __func__); +} + +static void client_idle_timeout(struct client *client) +{ + if (client->cmd != NULL) { + client_destroy(client, t_strdup_printf( + "Client has not read server output for for %"PRIdTIME_T" secs", + ioloop_time - client->last_output)); + } else { + client_send_line(client, "-ERR Disconnected for inactivity."); + client_destroy(client, t_strdup_printf( + "Inactivity - no input for %"PRIdTIME_T" secs", + ioloop_time - client->last_input)); + } +} + +static int +pop3_mail_get_size(struct client *client, struct mail *mail, uoff_t *size_r) +{ + int ret; + + if (!client->set->pop3_fast_size_lookups) + return mail_get_virtual_size(mail, size_r); + + /* first try to get the virtual size */ + mail->lookup_abort = MAIL_LOOKUP_ABORT_READ_MAIL; + ret = mail_get_virtual_size(mail, size_r); + mail->lookup_abort = MAIL_LOOKUP_ABORT_NEVER; + if (ret == 0) + return 0; + + if (mailbox_get_last_mail_error(mail->box) != MAIL_ERROR_LOOKUP_ABORTED) + return -1; + + /* virtual size not available with a fast lookup. + fallback to trying the physical size */ + mail->lookup_abort = MAIL_LOOKUP_ABORT_READ_MAIL; + ret = mail_get_physical_size(mail, size_r); + mail->lookup_abort = MAIL_LOOKUP_ABORT_NEVER; + if (ret == 0) + return 0; + + if (mailbox_get_last_mail_error(mail->box) != MAIL_ERROR_LOOKUP_ABORTED) + return -1; + + /* no way to quickly get the size. fallback to doing a slow virtual + size lookup */ + return mail_get_virtual_size(mail, size_r); +} + +static void +msgnum_to_seq_map_add(ARRAY_TYPE(uint32_t) *msgnum_to_seq_map, + struct client *client, struct mail *mail, + unsigned int msgnum) +{ + uint32_t seq; + + if (mail->seq == msgnum+1) + return; + + if (!array_is_created(msgnum_to_seq_map)) + i_array_init(msgnum_to_seq_map, client->messages_count); + + /* add any messages between this and the previous one that had + a POP3 order defined */ + seq = array_count(msgnum_to_seq_map) + 1; + for (; seq <= msgnum; seq++) + array_push_back(msgnum_to_seq_map, &seq); + array_push_back(msgnum_to_seq_map, &mail->seq); +} + +static int read_mailbox(struct client *client, uint32_t *failed_uid_r) +{ + struct mailbox_status status; + struct mailbox_transaction_context *t; + struct mail_search_args *search_args; + struct mail_search_arg *sarg; + struct mail_search_context *ctx; + struct mail *mail; + uoff_t size; + ARRAY(uoff_t) message_sizes; + ARRAY_TYPE(uint32_t) msgnum_to_seq_map = ARRAY_INIT; + unsigned int msgnum; + int ret = 1; + + *failed_uid_r = 0; + + mailbox_get_open_status(client->mailbox, STATUS_UIDVALIDITY, &status); + client->uid_validity = status.uidvalidity; + client->messages_count = status.messages; + + t = mailbox_transaction_begin(client->mailbox, 0, __func__); + + search_args = mail_search_build_init(); + if (client->deleted_kw != NULL) { + sarg = mail_search_build_add(search_args, SEARCH_KEYWORDS); + sarg->match_not = TRUE; + sarg->value.str = p_strdup(search_args->pool, + client->set->pop3_deleted_flag); + i_array_init(&client->all_seqs, 32); + } else { + mail_search_build_add_all(search_args); + } + mail_search_args_init(search_args, client->mailbox, TRUE, NULL); + + ctx = mailbox_search_init(t, search_args, pop3_sort_program, + client->set->pop3_fast_size_lookups ? 0 : + MAIL_FETCH_VIRTUAL_SIZE, NULL); + mail_search_args_unref(&search_args); + + client->last_seen_pop3_msn = 0; + client->total_size = 0; + i_array_init(&message_sizes, client->messages_count); + + msgnum = 0; + while (mailbox_search_next(ctx, &mail)) { + if (pop3_mail_get_size(client, mail, &size) < 0) { + ret = mail->expunged ? 0 : -1; + *failed_uid_r = mail->uid; + break; + } + if (array_is_created(&client->all_seqs)) + seq_range_array_add(&client->all_seqs, mail->seq); + msgnum_to_seq_map_add(&msgnum_to_seq_map, client, mail, msgnum); + + if ((mail_get_flags(mail) & MAIL_SEEN) != 0) + client->last_seen_pop3_msn = msgnum + 1; + client->total_size += size; + if (client->highest_seq < mail->seq) + client->highest_seq = mail->seq; + + array_push_back(&message_sizes, &size); + msgnum++; + } + + if (mailbox_search_deinit(&ctx) < 0) + ret = -1; + + if (ret <= 0) { + /* commit the transaction instead of rolling back to make sure + we don't lose data (virtual sizes) added to cache file */ + (void)mailbox_transaction_commit(&t); + array_free(&message_sizes); + if (array_is_created(&msgnum_to_seq_map)) + array_free(&msgnum_to_seq_map); + return ret; + } + i_assert(msgnum <= client->messages_count); + client->messages_count = msgnum; + + if (!array_is_created(&client->all_seqs)) { + i_array_init(&client->all_seqs, 1); + seq_range_array_add_range(&client->all_seqs, 1, msgnum); + } + + client->trans = t; + client->message_sizes = + array_free_without_data(&message_sizes); + if (array_is_created(&msgnum_to_seq_map)) { + client->msgnum_to_seq_map_count = + array_count(&msgnum_to_seq_map); + client->msgnum_to_seq_map = + array_free_without_data(&msgnum_to_seq_map); + } + return 1; +} + +static int init_pop3_deleted_flag(struct client *client, const char **error_r) +{ + const char *deleted_keywords[2]; + + if (client->set->pop3_deleted_flag[0] == '\0') + return 0; + + deleted_keywords[0] = client->set->pop3_deleted_flag; + deleted_keywords[1] = NULL; + if (mailbox_keywords_create(client->mailbox, deleted_keywords, + &client->deleted_kw) < 0) { + *error_r = t_strdup_printf( + "pop3_deleted_flags: Invalid keyword '%s': %s", + client->set->pop3_deleted_flag, + mailbox_get_last_internal_error(client->mailbox, NULL)); + return -1; + } + return 0; +} + +static int init_mailbox(struct client *client, const char **error_r) +{ + uint32_t failed_uid = 0, last_failed_uid = 0; + int i, ret = -1; + + for (i = 0;; i++) { + if (mailbox_sync(client->mailbox, + MAILBOX_SYNC_FLAG_FULL_READ) < 0) { + ret = -1; + break; + } + + ret = read_mailbox(client, &failed_uid); + if (ret > 0) + return 0; + if (i == 2) + break; + + /* well, sync and try again. maybe it works the second time. */ + last_failed_uid = failed_uid; + failed_uid = 0; + } + + if (ret < 0) { + *error_r = mailbox_get_last_internal_error(client->mailbox, NULL); + client_send_storage_error(client); + } else { + if (failed_uid == last_failed_uid && failed_uid != 0) { + /* failed twice in same message */ + *error_r = t_strdup_printf( + "Getting size of message UID=%u failed", + failed_uid); + } else { + *error_r = "Can't sync mailbox: " + "Messages keep getting expunged"; + } + client_send_line(client, "-ERR [SYS/TEMP] Couldn't sync mailbox."); + } + return -1; +} + +static enum uidl_keys parse_uidl_keymask(const char *format) +{ + enum uidl_keys mask = 0; + + for (; *format != '\0'; format++) { + if (format[0] == '%' && format[1] != '\0') { + switch (var_get_key(++format)) { + case 'v': + mask |= UIDL_UIDVALIDITY; + break; + case 'u': + mask |= UIDL_UID; + break; + case 'm': + mask |= UIDL_MD5; + break; + case 'f': + mask |= UIDL_FILE_NAME; + break; + case 'g': + mask |= UIDL_GUID; + break; + } + } + } + return mask; +} + +static void pop3_lock_session_refresh(struct client *client) +{ + if (file_dotlock_touch(client->session_dotlock) < 0) { + client_send_line(client, + "-ERR [SYS/TEMP] Couldn't update POP3 session lock."); + client_destroy(client, "Couldn't lock POP3 session"); + } +} + +int pop3_lock_session(struct client *client) +{ + const struct mail_storage_settings *mail_set = + mail_storage_service_user_get_mail_set(client->service_user); + struct dotlock_settings dotlock_set; + enum mailbox_list_path_type type; + const char *dir, *path; + int ret; + + if (mailbox_list_get_root_path(client->inbox_ns->list, + MAILBOX_LIST_PATH_TYPE_INDEX, &dir)) { + type = MAILBOX_LIST_PATH_TYPE_INDEX; + } else if (mailbox_list_get_root_path(client->inbox_ns->list, + MAILBOX_LIST_PATH_TYPE_DIR, &dir)) { + type = MAILBOX_LIST_PATH_TYPE_DIR; + } else { + i_error("pop3_lock_session: Storage has no root/index directory, " + "can't create a POP3 session lock file"); + return -1; + } + if (mailbox_list_mkdir_root(client->inbox_ns->list, dir, type) < 0) { + i_error("pop3_lock_session: Couldn't create root directory %s: %s", + dir, mailbox_list_get_last_internal_error(client->inbox_ns->list, NULL)); + return -1; + } + path = t_strdup_printf("%s/"POP3_LOCK_FNAME, dir); + + dotlock_set = session_dotlock_set; + dotlock_set.use_excl_lock = mail_set->dotlock_use_excl; + dotlock_set.nfs_flush = mail_set->mail_nfs_storage; + + ret = file_dotlock_create(&dotlock_set, path, 0, + &client->session_dotlock); + if (ret < 0) + i_error("file_dotlock_create(%s) failed: %m", path); + else if (ret > 0) { + client->to_session_dotlock_refresh = + timeout_add(POP3_SESSION_DOTLOCK_STALE_TIMEOUT_SECS*1000, + pop3_lock_session_refresh, client); + } + return ret; +} + +struct client *client_create(int fd_in, int fd_out, + struct mail_user *user, + struct mail_storage_service_user *service_user, + const struct pop3_settings *set) +{ + struct client *client; + pool_t pool; + + /* always use nonblocking I/O */ + net_set_nonblock(fd_in, TRUE); + net_set_nonblock(fd_out, TRUE); + + pool = pool_alloconly_create("pop3 client", 256); + client = p_new(pool, struct client, 1); + client->pool = pool; + client->service_user = service_user; + client->v = pop3_client_vfuncs; + client->set = set; + client->fd_in = fd_in; + client->fd_out = fd_out; + client->input = i_stream_create_fd(fd_in, MAX_INBUF_SIZE); + client->output = o_stream_create_fd(fd_out, SIZE_MAX); + o_stream_set_no_error_handling(client->output, TRUE); + o_stream_set_flush_callback(client->output, client_output, client); + + p_array_init(&client->module_contexts, client->pool, 5); + client->last_input = ioloop_time; + client->to_idle = timeout_add(CLIENT_IDLE_TIMEOUT_MSECS, + client_idle_timeout, client); + client->to_commit = timeout_add(CLIENT_COMMIT_TIMEOUT_MSECS, + client_commit_timeout, client); + + client->user = user; + + client->mail_set = mail_user_set_get_storage_set(user); + client->uidl_keymask = + parse_uidl_keymask(client->mail_set->pop3_uidl_format); + if (client->uidl_keymask == 0) + i_fatal("Invalid pop3_uidl_format"); + + if (var_has_key(set->pop3_logout_format, 'u', "uidl_change")) { + /* logging uidl_change. we need hashes of the UIDLs */ + client->message_uidls_save = TRUE; + } else if (strcmp(set->pop3_uidl_duplicates, "allow") != 0) { + /* UIDL duplicates aren't allowed, so we'll need to + keep track of them */ + client->message_uidls_save = TRUE; + } + + pop3_client_count++; + DLLIST_PREPEND(&pop3_clients, client); + + if (hook_client_created != NULL) + hook_client_created(&client); + + return client; +} + +void client_create_finish(struct client *client) +{ + if (client->set->rawlog_dir[0] != '\0') { + (void)iostream_rawlog_create(client->set->rawlog_dir, + &client->input, &client->output); + } + client->io = io_add_istream(client->input, client_input, client); +} + +int client_init_mailbox(struct client *client, const char **error_r) +{ + enum mailbox_flags flags; + const char *ident, *errmsg; + + /* refresh proctitle before a potentially long-running init_mailbox() */ + pop3_refresh_proctitle(); + + flags = MAILBOX_FLAG_POP3_SESSION; + if (!client->set->pop3_no_flag_updates) + flags |= MAILBOX_FLAG_DROP_RECENT; + client->mailbox = mailbox_alloc(client->inbox_ns->list, "INBOX", flags); + if (mailbox_open(client->mailbox) < 0) { + *error_r = t_strdup_printf("Couldn't open INBOX: %s", + mailbox_get_last_internal_error(client->mailbox, NULL)); + client_send_storage_error(client); + return -1; + } + + if (init_pop3_deleted_flag(client, &errmsg) < 0 || + init_mailbox(client, &errmsg) < 0) { + *error_r = t_strdup_printf("Couldn't init INBOX: %s", errmsg); + return -1; + } + + if (!client->set->pop3_no_flag_updates && client->messages_count > 0) + client->seen_bitmask = i_malloc(MSGS_BITMASK_SIZE(client)); + + ident = mail_user_get_anvil_userip_ident(client->user); + if (ident != NULL) { + master_service_anvil_send(master_service, t_strconcat( + "CONNECT\t", my_pid, "\tpop3/", ident, "\n", NULL)); + client->anvil_sent = TRUE; + } + return 0; +} + +static const char *client_build_uidl_change_string(struct client *client) +{ + uint32_t i, old_hash, new_hash; + unsigned int old_msg_count, new_msg_count; + + if (client->message_uidls == NULL) { + /* UIDL command not given */ + return ""; + } + + /* 1..new-1 were probably left to mailbox by previous POP3 session */ + old_msg_count = client->lowest_retr_pop3_msn > 0 ? + client->lowest_retr_pop3_msn - 1 : client->messages_count; + for (i = 0, old_hash = 0; i < old_msg_count; i++) + old_hash ^= crc32_str(client->message_uidls[i]); + + /* assume all except deleted messages were sent to POP3 client */ + if (!client->deleted) { + for (i = 0, new_hash = 0; i < client->messages_count; i++) + new_hash ^= crc32_str(client->message_uidls[i]); + } else { + for (i = 0, new_hash = 0; i < client->messages_count; i++) { + if ((client->deleted_bitmask[i / CHAR_BIT] & + (1 << (i % CHAR_BIT))) != 0) + continue; + new_hash ^= crc32_str(client->message_uidls[i]); + } + } + + new_msg_count = client->messages_count - client->deleted_count; + if (old_hash == new_hash && old_msg_count == new_msg_count) + return t_strdup_printf("%u/%08x", old_msg_count, old_hash); + else { + return t_strdup_printf("%u/%08x -> %u/%08x", + old_msg_count, old_hash, + new_msg_count, new_hash); + } +} + +static const char *client_stats(struct client *client) +{ + const char *uidl_change = ""; + if (var_has_key(client->set->pop3_logout_format, + 'o', "uidl_change")) + uidl_change = client_build_uidl_change_string(client); + + const struct var_expand_table logout_tab[] = { + { 'p', dec2str(client->top_bytes), "top_bytes" }, + { 't', dec2str(client->top_count), "top_count" }, + { 'b', dec2str(client->retr_bytes), "retr_bytes" }, + { 'r', dec2str(client->retr_count), "retr_count" }, + { 'd', !client->delete_success ? "0" : + dec2str(client->deleted_count), "deleted_count" }, + { 'm', dec2str(client->messages_count), "message_count" }, + { 's', dec2str(client->total_size), "message_bytes" }, + { 'i', dec2str(client->input->v_offset), "input" }, + { 'o', dec2str(client->output->offset), "output" }, + { 'u', uidl_change, "uidl_change" }, + { '\0', !client->delete_success ? "0" : + dec2str(client->deleted_size), "deleted_bytes" }, + { '\0', NULL, NULL } + }; + const struct var_expand_table *user_tab = + mail_user_var_expand_table(client->user); + const struct var_expand_table *tab = + t_var_expand_merge_tables(logout_tab, user_tab); + string_t *str; + const char *error; + + str = t_str_new(128); + if (var_expand_with_funcs(str, client->set->pop3_logout_format, + tab, mail_user_var_expand_func_table, + client->user, &error) < 0) { + i_error("Failed to expand pop3_logout_format=%s: %s", + client->set->pop3_logout_format, error); + } + return str_c(str); +} + +void client_destroy(struct client *client, const char *reason) +{ + client->v.destroy(client, reason); +} + +static void client_default_destroy(struct client *client, const char *reason) +{ + i_assert(!client->destroyed); + + client->destroyed = TRUE; + + if (client->seen_change_count > 0) + (void)client_update_mails(client); + + if (!client->disconnected) { + if (reason == NULL) { + reason = io_stream_get_disconnect_reason(client->input, + client->output); + } + i_info("Disconnected: %s %s", reason, client_stats(client)); + } + + if (client->cmd != NULL) { + /* deinitialize command */ + i_stream_close(client->input); + o_stream_close(client->output); + client->cmd(client); + i_assert(client->cmd == NULL); + } + + if (client->trans != NULL) { + /* client didn't QUIT, but we still want to save any changes + done in this transaction. especially the cached virtual + message sizes. */ + (void)mailbox_transaction_commit(&client->trans); + } + if (array_is_created(&client->all_seqs)) + array_free(&client->all_seqs); + if (client->deleted_kw != NULL) + mailbox_keywords_unref(&client->deleted_kw); + if (client->mailbox != NULL) + mailbox_free(&client->mailbox); + if (client->anvil_sent) { + master_service_anvil_send(master_service, t_strconcat( + "DISCONNECT\t", my_pid, "\tpop3/", + mail_user_get_anvil_userip_ident(client->user), + "\n", NULL)); + } + + if (client->session_dotlock != NULL) + file_dotlock_delete(&client->session_dotlock); + timeout_remove(&client->to_session_dotlock_refresh); + + pool_unref(&client->uidl_pool); + i_free(client->message_sizes); + i_free(client->deleted_bitmask); + i_free(client->seen_bitmask); + i_free(client->msgnum_to_seq_map); + + io_remove(&client->io); + timeout_remove(&client->to_idle); + timeout_remove(&client->to_commit); + + i_stream_destroy(&client->input); + o_stream_destroy(&client->output); + + fd_close_maybe_stdio(&client->fd_in, &client->fd_out); + + /* Autoexpunging might run for a long time. Disconnect the client + before it starts, and refresh proctitle so it's clear that it's + doing autoexpunging. We've also sent DISCONNECT to anvil already, + because this is background work and shouldn't really be counted + as an active POP3 session for the user. */ + pop3_refresh_proctitle(); + mail_user_autoexpunge(client->user); + mail_user_deinit(&client->user); + mail_storage_service_user_unref(&client->service_user); + + pop3_client_count--; + DLLIST_REMOVE(&pop3_clients, client); + pool_unref(&client->pool); + + master_service_client_connection_destroyed(master_service); + pop3_refresh_proctitle(); +} + +static void client_destroy_timeout(struct client *client) +{ + client_destroy(client, NULL); +} + +void client_disconnect(struct client *client, const char *reason) +{ + if (client->disconnected) + return; + + client->disconnected = TRUE; + i_info("Disconnected: %s %s", reason, client_stats(client)); + + (void)o_stream_flush(client->output); + + i_stream_close(client->input); + o_stream_close(client->output); + + timeout_remove(&client->to_idle); + client->to_idle = timeout_add(0, client_destroy_timeout, client); +} + +void client_send_line(struct client *client, const char *fmt, ...) +{ + va_list va; + ssize_t ret; + + if (client->output->closed) + return; + + va_start(va, fmt); + + T_BEGIN { + string_t *str; + + str = t_str_new(256); + str_vprintfa(str, fmt, va); + str_append(str, "\r\n"); + + ret = o_stream_send(client->output, + str_data(str), str_len(str)); + i_assert(ret < 0 || (size_t)ret == str_len(str)); + } T_END; + if (ret >= 0) { + if (!POP3_CLIENT_OUTPUT_FULL(client)) + client->last_output = ioloop_time; + else if (client->io != NULL) { + /* no more input until client has read + our output */ + io_remove(&client->io); + + /* If someone happens to flush output, we want to get + our IO handler back in flush callback */ + o_stream_set_flush_pending(client->output, TRUE); + } + } + va_end(va); +} + +void client_send_storage_error(struct client *client) +{ + const char *errstr; + enum mail_error error; + + if (mailbox_is_inconsistent(client->mailbox)) { + client_send_line(client, "-ERR [SYS/TEMP] Mailbox is in inconsistent " + "state, please relogin."); + client_disconnect(client, "Mailbox is in inconsistent state."); + return; + } + + errstr = mailbox_get_last_error(client->mailbox, &error); + switch (error) { + case MAIL_ERROR_TEMP: + case MAIL_ERROR_NOQUOTA: + case MAIL_ERROR_INUSE: + client_send_line(client, "-ERR [SYS/TEMP] %s", errstr); + break; + default: + client_send_line(client, "-ERR [SYS/PERM] %s", errstr); + break; + } +} + +bool client_handle_input(struct client *client) +{ + char *line, *args; + int ret; + + o_stream_cork(client->output); + while (!client->output->closed && + (line = i_stream_next_line(client->input)) != NULL) { + args = strchr(line, ' '); + if (args != NULL) + *args++ = '\0'; + + const struct pop3_command *cmd = pop3_command_find(line); + if (cmd == NULL) { + client_send_line(client, "-ERR Unknown command: %s", line); + ret = -1; + } else T_BEGIN { + const char *reason_code = + event_reason_code_prefix("pop3", "cmd_", + cmd->name); + struct event_reason *reason = + event_reason_begin(reason_code); + ret = client_command_execute(client, cmd, + args != NULL ? args : ""); + event_reason_end(&reason); + } T_END; + if (ret >= 0) { + client->bad_counter = 0; + if (client->cmd != NULL) { + o_stream_set_flush_pending(client->output, + TRUE); + client->waiting_input = TRUE; + break; + } + } else if (++client->bad_counter > CLIENT_MAX_BAD_COMMANDS) { + client_send_line(client, "-ERR Too many bad commands."); + client_disconnect(client, "Too many bad commands."); + } + } + o_stream_uncork(client->output); + + if (client->output->closed) { + client_destroy(client, NULL); + return FALSE; + } + return TRUE; +} + +static void client_input(struct client *client) +{ + if (client->cmd != NULL) { + /* we're still processing a command. wait until it's + finished. */ + io_remove(&client->io); + client->waiting_input = TRUE; + return; + } + + client->waiting_input = FALSE; + client->last_input = ioloop_time; + timeout_reset(client->to_idle); + if (client->to_commit != NULL) + timeout_reset(client->to_commit); + + switch (i_stream_read(client->input)) { + case -1: + /* disconnected */ + client_destroy(client, NULL); + return; + case -2: + /* line too long, kill it */ + client_send_line(client, "-ERR Input line too long."); + client_destroy(client, "Input line too long"); + return; + } + + (void)client_handle_input(client); +} + +static int client_output(struct client *client) +{ + if (o_stream_flush(client->output) < 0) { + client_destroy(client, NULL); + return 1; + } + + client->last_output = ioloop_time; + timeout_reset(client->to_idle); + if (client->to_commit != NULL) + timeout_reset(client->to_commit); + + if (client->cmd != NULL) + client->cmd(client); + + if (client->cmd == NULL) { + if (o_stream_get_buffer_used_size(client->output) < + POP3_OUTBUF_THROTTLE_SIZE/2 && client->io == NULL && + !client->input->closed) { + /* enable input again */ + client->io = io_add_istream(client->input, client_input, + client); + } + if (client->io != NULL && client->waiting_input) { + if (!client_handle_input(client)) { + /* client got destroyed */ + return 1; + } + } + } + + if (client->cmd != NULL) { + /* command not finished yet */ + return 0; + } else if (client->io == NULL) { + /* data still in output buffer, get back here to add IO */ + return 0; + } else { + return 1; + } +} + +void clients_destroy_all(void) +{ + while (pop3_clients != NULL) { + mail_storage_service_io_activate_user(pop3_clients->service_user); + if (pop3_clients->cmd == NULL) { + client_send_line(pop3_clients, + "-ERR [SYS/TEMP] Server shutting down."); + } + client_destroy(pop3_clients, "Server shutting down."); + } +} + +struct pop3_client_vfuncs pop3_client_vfuncs = { + client_default_destroy +}; diff --git a/src/pop3/pop3-client.h b/src/pop3/pop3-client.h new file mode 100644 index 0000000..5cb3f46 --- /dev/null +++ b/src/pop3/pop3-client.h @@ -0,0 +1,146 @@ +#ifndef POP3_CLIENT_H +#define POP3_CLIENT_H + +#include "seq-range-array.h" + +struct client; +struct mail_storage; +struct mail_storage_service_ctx; + +typedef void command_func_t(struct client *client); + +#define MSGS_BITMASK_SIZE(client) \ + (MALLOC_ADD((client)->messages_count, (CHAR_BIT-1)) / CHAR_BIT) + +/* Stop reading input when output buffer has this many bytes. Once the buffer + size has dropped to half of it, start reading input again. */ +#define POP3_OUTBUF_THROTTLE_SIZE 4096 + +#define POP3_CLIENT_OUTPUT_FULL(client) \ + (o_stream_get_buffer_used_size((client)->output) >= POP3_OUTBUF_THROTTLE_SIZE) + +struct pop3_client_vfuncs { + void (*destroy)(struct client *client, const char *reason); + +}; + +/* + pop3_msn = 1..n in the POP3 protocol + msgnum = 0..n-1 = pop3_msn-1 + seq = 1..n = mail's sequence number in lib-storage. when pop3 sort ordering + is used, msgnum_to_seq_map[] can be used for translation. +*/ +struct client { + struct client *prev, *next; + + struct pop3_client_vfuncs v; + + int fd_in, fd_out; + struct io *io; + struct istream *input; + struct ostream *output; + struct timeout *to_idle, *to_commit; + + command_func_t *cmd; + void *cmd_context; + + pool_t pool; + struct mail_storage_service_user *service_user; + struct mail_user *user; + struct mail_namespace *inbox_ns; + struct mailbox *mailbox; + struct mailbox_transaction_context *trans; + struct mail_keywords *deleted_kw; + + struct timeout *to_session_dotlock_refresh; + struct dotlock *session_dotlock; + + time_t last_input, last_output; + unsigned int bad_counter; + unsigned int highest_expunged_fetch_msgnum; + + unsigned int uid_validity; + unsigned int messages_count; + unsigned int deleted_count, seen_change_count; + uoff_t total_size; + uoff_t deleted_size; + uint32_t last_seen_pop3_msn, lowest_retr_pop3_msn; + + /* All sequences currently visible in the mailbox. */ + ARRAY_TYPE(seq_range) all_seqs; + uint32_t highest_seq; + + /* [msgnum] contains mail seq. anything after it has seq = msgnum+1 */ + uint32_t *msgnum_to_seq_map; + uint32_t msgnum_to_seq_map_count; + + uoff_t top_bytes; + uoff_t retr_bytes; + unsigned int top_count; + unsigned int retr_count; + + /* [msgnum] */ + const char **message_uidls; + uoff_t *message_sizes; + /* [msgnum/8] & msgnum%8 */ + unsigned char *deleted_bitmask; + unsigned char *seen_bitmask; + + /* settings: */ + const struct pop3_settings *set; + const struct mail_storage_settings *mail_set; + pool_t uidl_pool; + enum uidl_keys uidl_keymask; + + /* Module-specific contexts. */ + ARRAY(union pop3_module_context *) module_contexts; + + bool destroyed:1; + bool disconnected:1; + bool deleted:1; + bool waiting_input:1; + bool anvil_sent:1; + bool message_uidls_save:1; + bool delete_success:1; + bool quit_seen:1; +}; + +struct pop3_module_register { + unsigned int id; +}; + +union pop3_module_context { + struct pop3_client_vfuncs super; + struct pop3_module_register *reg; +}; +extern struct pop3_module_register pop3_module_register; + +extern struct client *pop3_clients; +extern unsigned int pop3_client_count; + +/* Create new client with specified input/output handles. socket specifies + if the handle is a socket. */ +struct client *client_create(int fd_in, int fd_out, + struct mail_user *user, + struct mail_storage_service_user *service_user, + const struct pop3_settings *set); +void client_create_finish(struct client *client); +int client_init_mailbox(struct client *client, const char **error_r); +void client_destroy(struct client *client, const char *reason) ATTR_NULL(2); + +/* Disconnect client connection */ +void client_disconnect(struct client *client, const char *reason); + +/* Send a line of data to client */ +void client_send_line(struct client *client, const char *fmt, ...) + ATTR_FORMAT(2, 3); +void client_send_storage_error(struct client *client); + +bool client_handle_input(struct client *client); +bool client_update_mails(struct client *client); + +void clients_destroy_all(void); + +int pop3_lock_session(struct client *client); + +#endif diff --git a/src/pop3/pop3-commands.c b/src/pop3/pop3-commands.c new file mode 100644 index 0000000..b0261e6 --- /dev/null +++ b/src/pop3/pop3-commands.c @@ -0,0 +1,956 @@ +/* Copyright (c) 2002-2018 Dovecot authors, see the included COPYING file */ + +#include "pop3-common.h" +#include "array.h" +#include "istream.h" +#include "ostream.h" +#include "hash.h" +#include "str.h" +#include "var-expand.h" +#include "message-size.h" +#include "mail-storage.h" +#include "mail-storage-settings.h" +#include "mail-search-build.h" +#include "pop3-capability.h" +#include "pop3-commands.h" + +static enum mail_sort_type pop3_sort_program[] = { + MAIL_SORT_POP3_ORDER, + MAIL_SORT_END +}; + +static uint32_t msgnum_to_seq(struct client *client, uint32_t msgnum) +{ + return msgnum < client->msgnum_to_seq_map_count ? + client->msgnum_to_seq_map[msgnum] : msgnum+1; +} + +static const char *get_msgnum(struct client *client, const char *args, + unsigned int *msgnum, bool thenspace) +{ + unsigned int num; + + if (*args < '0' || *args > '9') { + client_send_line(client, + "-ERR Invalid message number: %s", args); + return NULL; + } + if (str_parse_uint(args, &num, &args) < 0) { + client_send_line(client, + "-ERR Message number too large: %s", args); + return NULL; + } + if (*args != (thenspace ? ' ' : '\0')) { + client_send_line(client, + "-ERR Noise after message number: %s", args); + return NULL; + } + if (num == 0 || num > client->messages_count) { + client_send_line(client, + "-ERR There's no message %u.", num); + return NULL; + } + num--; + + if (client->deleted) { + if ((client->deleted_bitmask[num / CHAR_BIT] & + (1 << (num % CHAR_BIT))) != 0) { + client_send_line(client, "-ERR Message is deleted."); + return NULL; + } + } + + while (*args == ' ') args++; + + *msgnum = num; + return args; +} + +static const char *get_size(struct client *client, const char *args, + uoff_t *size, bool thenspace) +{ + uoff_t num; + + if (*args < '0' || *args > '9') { + client_send_line(client, "-ERR Invalid size: %s", + args); + return NULL; + } + if (str_parse_uoff(args, &num, &args) < 0) { + client_send_line(client, "-ERR Size too large: %s", + args); + return NULL; + } + if (*args != (thenspace ? ' ' : '\0')) { + client_send_line(client, "-ERR Noise after size: %s", args); + return NULL; + } + + while (*args == ' ') args++; + + *size = num; + return args; +} + +static int cmd_capa(struct client *client, const char *args ATTR_UNUSED) +{ + client_send_line(client, "+OK\r\n"POP3_CAPABILITY_REPLY"."); + return 1; +} + +static int cmd_dele(struct client *client, const char *args) +{ + unsigned int msgnum; + + if (get_msgnum(client, args, &msgnum, FALSE) == NULL) + return -1; + + if (!client->deleted) { + client->deleted_bitmask = i_malloc(MSGS_BITMASK_SIZE(client)); + client->deleted = TRUE; + } + + client->deleted_bitmask[msgnum / CHAR_BIT] |= 1 << (msgnum % CHAR_BIT); + client->deleted_count++; + client->deleted_size += client->message_sizes[msgnum]; + client_send_line(client, "+OK Marked to be deleted."); + return 1; +} + +struct cmd_list_context { + unsigned int msgnum; +}; + +static void cmd_list_callback(struct client *client) +{ + struct cmd_list_context *ctx = client->cmd_context; + + for (; ctx->msgnum != client->messages_count; ctx->msgnum++) { + if (client->output->closed) + break; + if (POP3_CLIENT_OUTPUT_FULL(client)) { + /* buffer full */ + return; + } + + if (client->deleted) { + if ((client->deleted_bitmask[ctx->msgnum / CHAR_BIT] & + (1 << (ctx->msgnum % CHAR_BIT))) != 0) + continue; + } + + client_send_line(client, "%u %"PRIuUOFF_T, ctx->msgnum+1, + client->message_sizes[ctx->msgnum]); + } + + client_send_line(client, "."); + + i_free(ctx); + client->cmd = NULL; +} + +static int cmd_list(struct client *client, const char *args) +{ + struct cmd_list_context *ctx; + + if (*args == '\0') { + ctx = i_new(struct cmd_list_context, 1); + client_send_line(client, "+OK %u messages:", + client->messages_count - client->deleted_count); + + client->cmd = cmd_list_callback; + client->cmd_context = ctx; + cmd_list_callback(client); + } else { + unsigned int msgnum; + + if (get_msgnum(client, args, &msgnum, FALSE) == NULL) + return -1; + + client_send_line(client, "+OK %u %"PRIuUOFF_T, msgnum+1, + client->message_sizes[msgnum]); + } + + return 1; +} + +static int cmd_last(struct client *client, const char *args ATTR_UNUSED) +{ + if (client->set->pop3_enable_last) + client_send_line(client, "+OK %u", client->last_seen_pop3_msn); + else + client_send_line(client, "-ERR LAST command not enabled"); + return 1; +} + +static int cmd_noop(struct client *client, const char *args ATTR_UNUSED) +{ + client_send_line(client, "+OK"); + return 1; +} + +static struct mail_search_args * +pop3_search_build_seqset(ARRAY_TYPE(seq_range) *seqset) +{ + struct mail_search_args *search_args; + struct mail_search_arg *sarg; + + search_args = mail_search_build_init(); + sarg = mail_search_build_add(search_args, SEARCH_SEQSET); + sarg->value.seqset = *seqset; + return search_args; +} + +static struct mail_search_args * +pop3_search_build(struct client *client, uint32_t seq) +{ + struct mail_search_args *search_args; + + if (seq == 0) + return pop3_search_build_seqset(&client->all_seqs); + + search_args = mail_search_build_init(); + mail_search_build_add_seqset(search_args, seq, seq); + return search_args; +} + +static int client_verify_ordering(struct client *client, + struct mail *mail, uint32_t msgnum) +{ + uint32_t seq; + + seq = msgnum_to_seq(client, msgnum); + if (seq != mail->seq) { + i_error("Message ordering changed unexpectedly " + "(msg #%u: storage seq %u -> %u)", + msgnum+1, seq, mail->seq); + return -1; + } + return 0; +} + +static void client_expunge(struct client *client, struct mail *mail) +{ + switch (client->set->parsed_delete_type) { + case POP3_DELETE_TYPE_EXPUNGE: + mail_expunge(mail); + break; + case POP3_DELETE_TYPE_FLAG: + i_assert(client->deleted_kw != NULL); + mail_update_keywords(mail, MODIFY_ADD, client->deleted_kw); + break; + } +} + +bool client_update_mails(struct client *client) +{ + struct mail_search_args *search_args; + struct mail_search_context *ctx; + struct mail *mail; + ARRAY_TYPE(seq_range) deleted_msgs, seen_msgs; + uint32_t msgnum, bit; + bool ret = TRUE; + + if (mailbox_is_readonly(client->mailbox)) { + /* silently ignore */ + return TRUE; + } + + /* translate msgnums to sequences (in case POP3 ordering is + different) */ + t_array_init(&deleted_msgs, 8); + if (client->deleted_bitmask != NULL && client->quit_seen) { + for (msgnum = 0; msgnum < client->messages_count; msgnum++) { + bit = 1 << (msgnum % CHAR_BIT); + if ((client->deleted_bitmask[msgnum / CHAR_BIT] & bit) != 0) + seq_range_array_add(&deleted_msgs, msgnum_to_seq(client, msgnum)); + } + } + t_array_init(&seen_msgs, 8); + if (client->seen_bitmask != NULL) { + for (msgnum = 0; msgnum < client->messages_count; msgnum++) { + bit = 1 << (msgnum % CHAR_BIT); + if ((client->seen_bitmask[msgnum / CHAR_BIT] & bit) != 0) + seq_range_array_add(&seen_msgs, msgnum_to_seq(client, msgnum)); + } + } + + if (array_count(&deleted_msgs) > 0) { + /* expunge DELEted mails */ + search_args = pop3_search_build_seqset(&deleted_msgs); + ctx = mailbox_search_init(client->trans, search_args, NULL, 0, NULL); + mail_search_args_unref(&search_args); + + while (mailbox_search_next(ctx, &mail)) + client_expunge(client, mail); + if (mailbox_search_deinit(&ctx) < 0) + ret = FALSE; + /* don't bother setting \Seen flags for deleted messages */ + seq_range_array_invert(&deleted_msgs, 1, client->highest_seq); + seq_range_array_intersect(&seen_msgs, &deleted_msgs); + } + + if (array_count(&seen_msgs) > 0) { + /* add \Seen flags for RETRed mails */ + search_args = pop3_search_build_seqset(&seen_msgs); + ctx = mailbox_search_init(client->trans, search_args, NULL, 0, NULL); + mail_search_args_unref(&search_args); + + while (mailbox_search_next(ctx, &mail)) + mail_update_flags(mail, MODIFY_ADD, MAIL_SEEN); + if (mailbox_search_deinit(&ctx) < 0) + ret = FALSE; + } + + client->seen_change_count = 0; + return ret; +} + +static int cmd_quit(struct client *client, const char *args ATTR_UNUSED) +{ + client->quit_seen = TRUE; + if (client->deleted || client->seen_bitmask != NULL) { + if (!client_update_mails(client)) { + client_send_storage_error(client); + client_disconnect(client, + "Storage error during logout."); + return 1; + } + } + + if (mailbox_transaction_commit(&client->trans) < 0 || + mailbox_sync(client->mailbox, MAILBOX_SYNC_FLAG_FULL_WRITE) < 0) { + client_send_storage_error(client); + client_disconnect(client, "Storage error during logout."); + return 1; + } else { + client->delete_success = TRUE; + } + + if (!client->deleted) + client_send_line(client, "+OK Logging out."); + else + client_send_line(client, "+OK Logging out, messages deleted."); + + client_disconnect(client, "Logged out"); + return 1; +} + +struct fetch_context { + struct mail *mail; + struct istream *stream; + uoff_t body_lines; + + uoff_t *byte_counter; + uoff_t byte_counter_offset; + + unsigned char last; + bool cr_skipped, in_body; +}; + +static void fetch_deinit(struct fetch_context *ctx) +{ + mail_free(&ctx->mail); + i_free(ctx); +} + +static void fetch_callback(struct client *client) +{ + struct fetch_context *ctx = client->cmd_context; + const unsigned char *data; + unsigned char add; + size_t i, size; + int ret; + + while ((ctx->body_lines > 0 || !ctx->in_body) && + i_stream_read_more(ctx->stream, &data, &size) > 0) { + if (size > 4096) + size = 4096; + + add = '\0'; + for (i = 0; i < size; i++) { + if ((data[i] == '\r' || data[i] == '\n') && + !ctx->in_body) { + if (i == 0 && (ctx->last == '\0' || + ctx->last == '\n')) + ctx->in_body = TRUE; + else if (i > 0 && data[i-1] == '\n') + ctx->in_body = TRUE; + } + + if (data[i] == '\n') { + if ((i == 0 && ctx->last != '\r') || + (i > 0 && data[i-1] != '\r')) { + /* missing CR */ + add = '\r'; + break; + } + + if (ctx->in_body) { + if (--ctx->body_lines == 0) { + i++; + break; + } + } + } else if (data[i] == '.' && + ((i == 0 && ctx->last == '\n') || + (i > 0 && data[i-1] == '\n'))) { + /* escape the dot */ + add = '.'; + break; + } else if (data[i] == '\0' && + (client->set->parsed_workarounds & + WORKAROUND_OUTLOOK_NO_NULS) != 0) { + add = 0x80; + break; + } + } + + if (i > 0) { + if (o_stream_send(client->output, data, i) < 0) + break; + ctx->last = data[i-1]; + i_stream_skip(ctx->stream, i); + } + + if (o_stream_get_buffer_used_size(client->output) >= 4096) { + if ((ret = o_stream_flush(client->output)) < 0) + break; + if (ret == 0) { + /* continue later */ + return; + } + } + + if (add != '\0') { + if (o_stream_send(client->output, &add, 1) < 0) + break; + + ctx->last = add; + if (add == 0x80) + i_stream_skip(ctx->stream, 1); + } + } + + if (ctx->last != '\n') { + /* didn't end with CRLF */ + o_stream_nsend(client->output, "\r\n", 2); + } + + if (!ctx->in_body && + (client->set->parsed_workarounds & WORKAROUND_OE_NS_EOH) != 0) { + /* Add the missing end of headers line. */ + o_stream_nsend(client->output, "\r\n", 2); + } + + *ctx->byte_counter += + client->output->offset - ctx->byte_counter_offset; + + client_send_line(client, "."); + fetch_deinit(ctx); + client->cmd = NULL; +} + +static int client_reply_msg_expunged(struct client *client, unsigned int msgnum) +{ + client_send_line(client, "-ERR Message %u expunged.", msgnum + 1); + if (msgnum <= client->highest_expunged_fetch_msgnum) { + /* client tried to fetch an expunged message again. + treat this as error so we'll eventually disconnect the + client instead of letting it loop forever. */ + return -1; + } + client->highest_expunged_fetch_msgnum = msgnum; + return 1; +} + +static int fetch(struct client *client, unsigned int msgnum, uoff_t body_lines, + const char *reason, uoff_t *byte_counter) +{ + struct fetch_context *ctx; + int ret; + + ctx = i_new(struct fetch_context, 1); + ctx->byte_counter = byte_counter; + ctx->byte_counter_offset = client->output->offset; + ctx->mail = mail_alloc(client->trans, + MAIL_FETCH_STREAM_HEADER | + MAIL_FETCH_STREAM_BODY, NULL); + mail_set_seq(ctx->mail, msgnum_to_seq(client, msgnum)); + + if (mail_get_stream_because(ctx->mail, NULL, NULL, reason, &ctx->stream) < 0) { + ret = client_reply_msg_expunged(client, msgnum); + fetch_deinit(ctx); + return ret; + } + + if (body_lines == UOFF_T_MAX && client->seen_bitmask != NULL) { + if ((mail_get_flags(ctx->mail) & MAIL_SEEN) == 0) { + /* mark the message seen with RETR command */ + client->seen_bitmask[msgnum / CHAR_BIT] |= + 1 << (msgnum % CHAR_BIT); + client->seen_change_count++; + } + } + + ctx->body_lines = body_lines; + if (body_lines == UOFF_T_MAX) { + client_send_line(client, "+OK %"PRIuUOFF_T" octets", + client->message_sizes[msgnum]); + } else { + client_send_line(client, "+OK"); + ctx->body_lines++; /* internally we count the empty line too */ + } + + client->cmd = fetch_callback; + client->cmd_context = ctx; + fetch_callback(client); + return 1; +} + +static int cmd_retr(struct client *client, const char *args) +{ + unsigned int msgnum; + + if (get_msgnum(client, args, &msgnum, FALSE) == NULL) + return -1; + + if (client->lowest_retr_pop3_msn > msgnum+1 || + client->lowest_retr_pop3_msn == 0) + client->lowest_retr_pop3_msn = msgnum+1; + if (client->last_seen_pop3_msn < msgnum+1) + client->last_seen_pop3_msn = msgnum+1; + + client->retr_count++; + return fetch(client, msgnum, UOFF_T_MAX, "RETR", &client->retr_bytes); +} + +static int cmd_rset(struct client *client, const char *args ATTR_UNUSED) +{ + struct mail_search_context *search_ctx; + struct mail *mail; + struct mail_search_args *search_args; + + client->last_seen_pop3_msn = 0; + + if (client->deleted) { + client->deleted = FALSE; + memset(client->deleted_bitmask, 0, MSGS_BITMASK_SIZE(client)); + client->deleted_count = 0; + client->deleted_size = 0; + } + if (client->seen_change_count > 0) { + memset(client->seen_bitmask, 0, MSGS_BITMASK_SIZE(client)); + client->seen_change_count = 0; + } + + if (client->set->pop3_enable_last) { + /* remove all \Seen flags (as specified by RFC 1460) */ + search_args = pop3_search_build(client, 0); + search_ctx = mailbox_search_init(client->trans, + search_args, NULL, 0, NULL); + mail_search_args_unref(&search_args); + + while (mailbox_search_next(search_ctx, &mail)) + mail_update_flags(mail, MODIFY_REMOVE, MAIL_SEEN); + (void)mailbox_search_deinit(&search_ctx); + + (void)mailbox_transaction_commit(&client->trans); + client->trans = mailbox_transaction_begin(client->mailbox, 0, + __func__); + } + + client_send_line(client, "+OK"); + return 1; +} + +static int cmd_stat(struct client *client, const char *args ATTR_UNUSED) +{ + client_send_line(client, "+OK %u %"PRIuUOFF_T, + client->messages_count - client->deleted_count, + client->total_size - client->deleted_size); + return 1; +} + +static int cmd_top(struct client *client, const char *args) +{ + unsigned int msgnum; + uoff_t max_lines; + + args = get_msgnum(client, args, &msgnum, TRUE); + if (args == NULL) + return -1; + if (get_size(client, args, &max_lines, FALSE) == NULL) + return -1; + + client->top_count++; + return fetch(client, msgnum, max_lines, "TOP", &client->top_bytes); +} + +struct cmd_uidl_context { + struct mail_search_context *search_ctx; + struct mail *mail; + uint32_t msgnum; + bool list_all; +}; + +static int +pop3_get_uid(struct client *client, struct mail *mail, string_t *str, + bool *permanent_uidl_r) +{ + char uid_str[MAX_INT_STRLEN] = { 0 }; + const char *uidl; + const char *hdr_md5 = NULL, *filename = NULL, *guid = NULL; + + if (mail_get_special(mail, MAIL_FETCH_UIDL_BACKEND, &uidl) == 0 && + *uidl != '\0') { + str_append(str, uidl); + /* UIDL is already permanent */ + *permanent_uidl_r = TRUE; + return 0; + } + + *permanent_uidl_r = FALSE; + + if (client->set->pop3_reuse_xuidl && + mail_get_first_header(mail, "X-UIDL", &uidl) > 0) { + str_append(str, uidl); + return 0; + } + + if ((client->uidl_keymask & UIDL_UID) != 0) { + if (i_snprintf(uid_str, sizeof(uid_str), "%u", mail->uid) < 0) + i_unreached(); + } + if ((client->uidl_keymask & UIDL_MD5) != 0) { + if (mail_get_special(mail, MAIL_FETCH_HEADER_MD5, + &hdr_md5) < 0) { + i_error("UIDL: Header MD5 lookup failed: %s", + mailbox_get_last_internal_error(mail->box, NULL)); + return -1; + } else if (hdr_md5[0] == '\0') { + i_error("UIDL: Header MD5 not found " + "(pop3_uidl_format=%%m not supported by storage?)"); + return -1; + } + } + if ((client->uidl_keymask & UIDL_FILE_NAME) != 0) { + if (mail_get_special(mail, MAIL_FETCH_STORAGE_ID, + &filename) < 0) { + i_error("UIDL: File name lookup failed: %s", + mailbox_get_last_internal_error(mail->box, NULL)); + return -1; + } else if (filename[0] == '\0') { + i_error("UIDL: File name not found " + "(pop3_uidl_format=%%f not supported by storage?)"); + return -1; + } + } + if ((client->uidl_keymask & UIDL_GUID) != 0) { + if (mail_get_special(mail, MAIL_FETCH_GUID, + &guid) < 0) { + i_error("UIDL: Message GUID lookup failed: %s", + mailbox_get_last_internal_error(mail->box, NULL)); + return -1; + } else if (guid[0] == '\0') { + i_error("UIDL: Message GUID not found " + "(pop3_uidl_format=%%g not supported by storage?)"); + return -1; + } + } + + const struct var_expand_table tab[] = { + { 'v', dec2str(client->uid_validity), "uidvalidity" }, + { 'u', uid_str, "uid" }, + { 'm', hdr_md5, "md5" }, + { 'f', filename, "filename" }, + { 'g', guid, "guid" }, + { '\0', NULL, NULL } + }; + const char *error; + + if (var_expand(str, client->mail_set->pop3_uidl_format, + tab, &error) <= 0) { + i_error("UIDL: Failed to expand pop3_uidl_format=%s: %s", + client->mail_set->pop3_uidl_format, error); + return -1; + } + return 0; +} + +static bool +list_uidls_saved_iter(struct client *client, struct cmd_uidl_context *ctx) +{ + bool found = FALSE; + + while (ctx->msgnum < client->messages_count) { + uint32_t msgnum = ctx->msgnum++; + + if (client->deleted) { + if ((client->deleted_bitmask[msgnum / CHAR_BIT] & + (1 << (msgnum % CHAR_BIT))) != 0) + continue; + } + found = TRUE; + + client_send_line(client, + ctx->list_all ? "%u %s" : "+OK %u %s", + msgnum+1, client->message_uidls[msgnum]); + if (client->output->closed || !ctx->list_all) + break; + if (POP3_CLIENT_OUTPUT_FULL(client)) { + /* output is being buffered, continue when there's + more space */ + return FALSE; + } + } + /* finished */ + client->cmd = NULL; + + if (ctx->list_all) + client_send_line(client, "."); + i_free(ctx); + return found; +} + +static bool list_uids_iter(struct client *client, struct cmd_uidl_context *ctx) +{ + string_t *str; + bool permanent_uidl, found = FALSE; + bool failed = FALSE; + + if (client->message_uidls != NULL) + return list_uidls_saved_iter(client, ctx); + + str = t_str_new(128); + while (mailbox_search_next(ctx->search_ctx, &ctx->mail)) { + uint32_t msgnum = ctx->msgnum++; + + if (client_verify_ordering(client, ctx->mail, msgnum) < 0) { + failed = TRUE; + break; + } + if (client->deleted) { + if ((client->deleted_bitmask[msgnum / CHAR_BIT] & + (1 << (msgnum % CHAR_BIT))) != 0) + continue; + } + found = TRUE; + + str_truncate(str, 0); + if (pop3_get_uid(client, ctx->mail, str, &permanent_uidl) < 0) { + failed = TRUE; + break; + } + if (client->set->pop3_save_uidl && !permanent_uidl) + mail_update_pop3_uidl(ctx->mail, str_c(str)); + + client_send_line(client, ctx->list_all ? "%u %s" : "+OK %u %s", + msgnum+1, str_c(str)); + if (client->output->closed) + break; + if (POP3_CLIENT_OUTPUT_FULL(client) && ctx->list_all) { + /* output is being buffered, continue when there's + more space */ + return FALSE; + } + } + + /* finished */ + (void)mailbox_search_deinit(&ctx->search_ctx); + + client->cmd = NULL; + + if (ctx->list_all && !failed) + client_send_line(client, "."); + i_free(ctx); + if (failed) + client_disconnect(client, "POP3 UIDLs couldn't be listed"); + return found || failed; +} + +static void cmd_uidl_callback(struct client *client) +{ + struct cmd_uidl_context *ctx = client->cmd_context; + + (void)list_uids_iter(client, ctx); +} + +HASH_TABLE_DEFINE_TYPE(uidl_counter, char *, void *); + +static void +uidl_rename_duplicate(string_t *uidl, HASH_TABLE_TYPE(uidl_counter) prev_uidls) +{ + char *key; + void *value; + unsigned int counter; + + while (hash_table_lookup_full(prev_uidls, str_c(uidl), &key, &value)) { + /* duplicate. the value contains the number of duplicates. */ + counter = POINTER_CAST_TO(value, unsigned int) + 1; + hash_table_update(prev_uidls, key, POINTER_CAST(counter)); + str_printfa(uidl, "-%u", counter); + /* the second lookup really should return NULL, but just in + case of some weird UIDLs do this as many times as needed */ + } +} + +static void client_uidls_save(struct client *client) +{ + struct mail_search_context *search_ctx; + struct mail_search_args *search_args; + struct mail *mail; + HASH_TABLE_TYPE(uidl_counter) prev_uidls; + const char **seq_uidls; + string_t *str; + char *uidl; + enum mail_fetch_field wanted_fields; + uint32_t msgnum; + bool permanent_uidl, uidl_duplicates_rename, failed = FALSE; + + i_assert(client->message_uidls == NULL); + + search_args = pop3_search_build(client, 0); + wanted_fields = 0; + if ((client->uidl_keymask & UIDL_MD5) != 0) + wanted_fields |= MAIL_FETCH_HEADER_MD5; + + search_ctx = mailbox_search_init(client->trans, search_args, + NULL, wanted_fields, NULL); + mail_search_args_unref(&search_args); + + uidl_duplicates_rename = + strcmp(client->set->pop3_uidl_duplicates, "rename") == 0; + if (uidl_duplicates_rename) + hash_table_create(&prev_uidls, default_pool, 0, str_hash, + strcmp); + client->uidl_pool = pool_alloconly_create("message uidls", 1024); + + /* first read all the UIDLs into a temporary [seq] array */ + seq_uidls = i_new(const char *, client->highest_seq); + str = t_str_new(128); + while (mailbox_search_next(search_ctx, &mail)) { + str_truncate(str, 0); + if (pop3_get_uid(client, mail, str, &permanent_uidl) < 0) { + failed = TRUE; + break; + } + if (uidl_duplicates_rename) + uidl_rename_duplicate(str, prev_uidls); + + uidl = p_strdup(client->uidl_pool, str_c(str)); + if (client->set->pop3_save_uidl && !permanent_uidl) + mail_update_pop3_uidl(mail, uidl); + + i_assert(mail->seq <= client->highest_seq); + seq_uidls[mail->seq-1] = uidl; + if (uidl_duplicates_rename) + hash_table_update(prev_uidls, uidl, POINTER_CAST(1)); + } + (void)mailbox_search_deinit(&search_ctx); + if (uidl_duplicates_rename) + hash_table_destroy(&prev_uidls); + + if (failed) { + pool_unref(&client->uidl_pool); + i_free(seq_uidls); + return; + } + /* map UIDLs to msgnums (in case POP3 sort ordering is different) */ + client->message_uidls = p_new(client->uidl_pool, const char *, + MALLOC_ADD(client->messages_count, 1)); + for (msgnum = 0; msgnum < client->messages_count; msgnum++) { + client->message_uidls[msgnum] = + seq_uidls[msgnum_to_seq(client, msgnum) - 1]; + } + i_free(seq_uidls); +} + +static struct cmd_uidl_context * +cmd_uidl_init(struct client *client, uint32_t seq) +{ + struct cmd_uidl_context *ctx; + struct mail_search_args *search_args; + enum mail_fetch_field wanted_fields; + + if (client->message_uidls_save && client->message_uidls == NULL && + client->messages_count > 0) + client_uidls_save(client); + + ctx = i_new(struct cmd_uidl_context, 1); + ctx->list_all = seq == 0; + + if (client->message_uidls == NULL) { + wanted_fields = 0; + if ((client->uidl_keymask & UIDL_MD5) != 0) + wanted_fields |= MAIL_FETCH_HEADER_MD5; + + search_args = pop3_search_build(client, seq); + ctx->search_ctx = mailbox_search_init(client->trans, search_args, + pop3_sort_program, + wanted_fields, NULL); + mail_search_args_unref(&search_args); + } + + if (seq == 0) { + client->cmd = cmd_uidl_callback; + client->cmd_context = ctx; + } + return ctx; +} + +static int cmd_uidl(struct client *client, const char *args) +{ + struct cmd_uidl_context *ctx; + uint32_t seq; + + if (*args == '\0') { + client_send_line(client, "+OK"); + ctx = cmd_uidl_init(client, 0); + (void)list_uids_iter(client, ctx); + } else { + unsigned int msgnum; + + if (get_msgnum(client, args, &msgnum, FALSE) == NULL) + return -1; + + seq = msgnum_to_seq(client, msgnum); + ctx = cmd_uidl_init(client, seq); + ctx->msgnum = msgnum; + if (!list_uids_iter(client, ctx)) + return client_reply_msg_expunged(client, msgnum); + } + + return 1; +} + +static const struct pop3_command pop3_commands[] = { + { "capa", cmd_capa }, + { "dele", cmd_dele }, + { "list", cmd_list }, + { "last", cmd_last }, + { "noop", cmd_noop }, + { "quit", cmd_quit }, + { "retr", cmd_retr }, + { "rset", cmd_rset }, + { "stat", cmd_stat }, + { "top", cmd_top }, + { "uidl", cmd_uidl }, +}; + +const struct pop3_command *pop3_command_find(const char *name) +{ + for (unsigned int i = 0; i < N_ELEMENTS(pop3_commands); i++) { + if (strcasecmp(pop3_commands[i].name, name) == 0) + return &pop3_commands[i]; + } + return NULL; +} + +int client_command_execute(struct client *client, + const struct pop3_command *cmd, const char *args) +{ + while (*args == ' ') args++; + + return cmd->func(client, args); +} diff --git a/src/pop3/pop3-commands.h b/src/pop3/pop3-commands.h new file mode 100644 index 0000000..37dd229 --- /dev/null +++ b/src/pop3/pop3-commands.h @@ -0,0 +1,13 @@ +#ifndef POP3_COMMANDS_H +#define POP3_COMMANDS_H + +struct pop3_command { + const char *name; + int (*func)(struct client *client, const char *args); +}; + +const struct pop3_command *pop3_command_find(const char *name); +int client_command_execute(struct client *client, + const struct pop3_command *cmd, const char *args); + +#endif diff --git a/src/pop3/pop3-common.h b/src/pop3/pop3-common.h new file mode 100644 index 0000000..eb3f521 --- /dev/null +++ b/src/pop3/pop3-common.h @@ -0,0 +1,27 @@ +#ifndef POP3_COMMON_H +#define POP3_COMMON_H + +enum uidl_keys { + UIDL_UIDVALIDITY = 0x01, + UIDL_UID = 0x02, + UIDL_MD5 = 0x04, + UIDL_FILE_NAME = 0x08, + UIDL_GUID = 0x10 +}; + +#include "lib.h" +#include "pop3-client.h" +#include "pop3-settings.h" + +typedef void pop3_client_created_func_t(struct client **client); + +extern pop3_client_created_func_t *hook_client_created; + +/* Sets the hook_client_created and returns the previous hook, + which the new_hook should call if it's non-NULL. */ +pop3_client_created_func_t * +pop3_client_created_hook_set(pop3_client_created_func_t *new_hook); + +void pop3_refresh_proctitle(void); + +#endif diff --git a/src/pop3/pop3-settings.c b/src/pop3/pop3-settings.c new file mode 100644 index 0000000..0606dc8 --- /dev/null +++ b/src/pop3/pop3-settings.c @@ -0,0 +1,184 @@ +/* Copyright (c) 2005-2018 Dovecot authors, see the included COPYING file */ + +#include "lib.h" +#include "buffer.h" +#include "settings-parser.h" +#include "service-settings.h" +#include "mail-storage-settings.h" +#include "pop3-settings.h" + +#include <stddef.h> +#include <unistd.h> + +static bool pop3_settings_verify(void *_set, pool_t pool, + const char **error_r); + +/* <settings checks> */ +static struct file_listener_settings pop3_unix_listeners_array[] = { + { "login/pop3", 0666, "", "" } +}; +static struct file_listener_settings *pop3_unix_listeners[] = { + &pop3_unix_listeners_array[0] +}; +static buffer_t pop3_unix_listeners_buf = { + { { pop3_unix_listeners, sizeof(pop3_unix_listeners) } } +}; +/* </settings checks> */ + +struct service_settings pop3_service_settings = { + .name = "pop3", + .protocol = "pop3", + .type = "", + .executable = "pop3", + .user = "", + .group = "", + .privileged_group = "", + .extra_groups = "$default_internal_group", + .chroot = "", + + .drop_priv_before_exec = FALSE, + + .process_min_avail = 0, + .process_limit = 1024, + .client_limit = 1, + .service_count = 1, + .idle_kill = 0, + .vsz_limit = UOFF_T_MAX, + + .unix_listeners = { { &pop3_unix_listeners_buf, + sizeof(pop3_unix_listeners[0]) } }, + .fifo_listeners = ARRAY_INIT, + .inet_listeners = ARRAY_INIT +}; + +#undef DEF +#undef DEFLIST +#define DEF(type, name) \ + SETTING_DEFINE_STRUCT_##type(#name, name, struct pop3_settings) +#define DEFLIST(field, name, defines) \ + { .type = SET_DEFLIST, .key = name, \ + .offset = offsetof(struct pop3_settings, field), \ + .list_info = defines } + +static const struct setting_define pop3_setting_defines[] = { + DEF(BOOL, verbose_proctitle), + DEF(STR_VARS, rawlog_dir), + + DEF(BOOL, pop3_no_flag_updates), + DEF(BOOL, pop3_enable_last), + DEF(BOOL, pop3_reuse_xuidl), + DEF(BOOL, pop3_save_uidl), + DEF(BOOL, pop3_lock_session), + DEF(BOOL, pop3_fast_size_lookups), + DEF(STR, pop3_client_workarounds), + DEF(STR, pop3_logout_format), + DEF(ENUM, pop3_uidl_duplicates), + DEF(STR, pop3_deleted_flag), + DEF(ENUM, pop3_delete_type), + + SETTING_DEFINE_LIST_END +}; + +static const struct pop3_settings pop3_default_settings = { + .verbose_proctitle = FALSE, + .rawlog_dir = "", + + .pop3_no_flag_updates = FALSE, + .pop3_enable_last = FALSE, + .pop3_reuse_xuidl = FALSE, + .pop3_save_uidl = FALSE, + .pop3_lock_session = FALSE, + .pop3_fast_size_lookups = FALSE, + .pop3_client_workarounds = "", + .pop3_logout_format = "top=%t/%p, retr=%r/%b, del=%d/%m, size=%s", + .pop3_uidl_duplicates = "allow:rename", + .pop3_deleted_flag = "", + .pop3_delete_type = "default:expunge:flag" +}; + +static const struct setting_parser_info *pop3_setting_dependencies[] = { + &mail_user_setting_parser_info, + NULL +}; + +const struct setting_parser_info pop3_setting_parser_info = { + .module_name = "pop3", + .defines = pop3_setting_defines, + .defaults = &pop3_default_settings, + + .type_offset = SIZE_MAX, + .struct_size = sizeof(struct pop3_settings), + + .parent_offset = SIZE_MAX, + + .check_func = pop3_settings_verify, + .dependencies = pop3_setting_dependencies +}; + +/* <settings checks> */ +struct pop3_client_workaround_list { + const char *name; + enum pop3_client_workarounds num; +}; + +static const struct pop3_client_workaround_list pop3_client_workaround_list[] = { + { "outlook-no-nuls", WORKAROUND_OUTLOOK_NO_NULS }, + { "oe-ns-eoh", WORKAROUND_OE_NS_EOH }, + { NULL, 0 } +}; + +static int +pop3_settings_parse_workarounds(struct pop3_settings *set, + const char **error_r) +{ + enum pop3_client_workarounds client_workarounds = 0; + const struct pop3_client_workaround_list *list; + const char *const *str; + + str = t_strsplit_spaces(set->pop3_client_workarounds, " ,"); + for (; *str != NULL; str++) { + list = pop3_client_workaround_list; + for (; list->name != NULL; list++) { + if (strcasecmp(*str, list->name) == 0) { + client_workarounds |= list->num; + break; + } + } + if (list->name == NULL) { + *error_r = t_strdup_printf("pop3_client_workarounds: " + "Unknown workaround: %s", *str); + return -1; + } + } + set->parsed_workarounds = client_workarounds; + return 0; +} + +static bool +pop3_settings_verify(void *_set, pool_t pool ATTR_UNUSED, const char **error_r) +{ + struct pop3_settings *set = _set; + + if (pop3_settings_parse_workarounds(set, error_r) < 0) + return FALSE; + if (strcmp(set->pop3_delete_type, "default") == 0) { + if (set->pop3_deleted_flag[0] == '\0') + set->parsed_delete_type = POP3_DELETE_TYPE_EXPUNGE; + else + set->parsed_delete_type = POP3_DELETE_TYPE_FLAG; + } else if (strcmp(set->pop3_delete_type, "expunge") == 0) { + set->parsed_delete_type = POP3_DELETE_TYPE_EXPUNGE; + } else if (strcmp(set->pop3_delete_type, "flag") == 0) { + if (set->pop3_deleted_flag[0] == '\0') { + *error_r = "pop3_delete_type=flag, but pop3_deleted_flag not set"; + return FALSE; + } + set->parsed_delete_type = POP3_DELETE_TYPE_FLAG; + } else { + *error_r = t_strdup_printf("pop3_delete_type: Unknown value '%s'", + set->pop3_delete_type); + return FALSE; + } + return TRUE; +} +/* </settings checks> */ diff --git a/src/pop3/pop3-settings.h b/src/pop3/pop3-settings.h new file mode 100644 index 0000000..cf50f98 --- /dev/null +++ b/src/pop3/pop3-settings.h @@ -0,0 +1,40 @@ +#ifndef POP3_SETTINGS_H +#define POP3_SETTINGS_H + +struct mail_user_settings; + +/* <settings checks> */ +enum pop3_client_workarounds { + WORKAROUND_OUTLOOK_NO_NULS = 0x01, + WORKAROUND_OE_NS_EOH = 0x02 +}; +enum pop3_delete_type { + POP3_DELETE_TYPE_EXPUNGE = 0, + POP3_DELETE_TYPE_FLAG, +}; +/* </settings checks> */ + +struct pop3_settings { + bool verbose_proctitle; + const char *rawlog_dir; + + /* pop3: */ + bool pop3_no_flag_updates; + bool pop3_enable_last; + bool pop3_reuse_xuidl; + bool pop3_save_uidl; + bool pop3_lock_session; + bool pop3_fast_size_lookups; + const char *pop3_client_workarounds; + const char *pop3_logout_format; + const char *pop3_uidl_duplicates; + const char *pop3_deleted_flag; + const char *pop3_delete_type; + + enum pop3_client_workarounds parsed_workarounds; + enum pop3_delete_type parsed_delete_type; +}; + +extern const struct setting_parser_info pop3_setting_parser_info; + +#endif |