diff options
Diffstat (limited to '')
-rw-r--r-- | src/plugins/pop3-migration/Makefile.am | 41 | ||||
-rw-r--r-- | src/plugins/pop3-migration/Makefile.in | 872 | ||||
-rw-r--r-- | src/plugins/pop3-migration/pop3-migration-plugin.c | 1058 | ||||
-rw-r--r-- | src/plugins/pop3-migration/pop3-migration-plugin.h | 13 | ||||
-rw-r--r-- | src/plugins/pop3-migration/test-pop3-migration-plugin.c | 63 |
5 files changed, 2047 insertions, 0 deletions
diff --git a/src/plugins/pop3-migration/Makefile.am b/src/plugins/pop3-migration/Makefile.am new file mode 100644 index 0000000..f58d065 --- /dev/null +++ b/src/plugins/pop3-migration/Makefile.am @@ -0,0 +1,41 @@ +AM_CPPFLAGS = \ + -I$(top_srcdir)/src/lib \ + -I$(top_srcdir)/src/lib-test \ + -I$(top_srcdir)/src/lib-mail \ + -I$(top_srcdir)/src/lib-index \ + -I$(top_srcdir)/src/lib-storage \ + -I$(top_srcdir)/src/lib-storage/index + +NOPLUGIN_LDFLAGS = +lib05_pop3_migration_plugin_la_LDFLAGS = -module -avoid-version + +module_LTLIBRARIES = \ + lib05_pop3_migration_plugin.la + +lib05_pop3_migration_plugin_la_SOURCES = \ + pop3-migration-plugin.c + +noinst_HEADERS = \ + pop3-migration-plugin.h + +noinst_PROGRAMS = $(test_programs) + +test_programs = \ + test-pop3-migration-plugin + +test_libs = \ + $(LIBDOVECOT_STORAGE) \ + $(LIBDOVECOT) +test_deps = \ + $(module_LTLIBRARIES) \ + $(LIBDOVECOT_STORAGE_DEPS) \ + $(LIBDOVECOT_DEPS) + +test_pop3_migration_plugin_SOURCES = test-pop3-migration-plugin.c +test_pop3_migration_plugin_LDADD = pop3-migration-plugin.lo $(test_libs) +test_pop3_migration_plugin_DEPENDENCIES = $(test_deps) + +check-local: + for bin in $(test_programs); do \ + if ! $(RUN_TEST) ./$$bin; then exit 1; fi; \ + done diff --git a/src/plugins/pop3-migration/Makefile.in b/src/plugins/pop3-migration/Makefile.in new file mode 100644 index 0000000..70a8e00 --- /dev/null +++ b/src/plugins/pop3-migration/Makefile.in @@ -0,0 +1,872 @@ +# Makefile.in generated by automake 1.16.1 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994-2018 Free Software Foundation, Inc. + +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + + + +VPATH = @srcdir@ +am__is_gnu_make = { \ + if test -z '$(MAKELEVEL)'; then \ + false; \ + elif test -n '$(MAKE_HOST)'; then \ + true; \ + elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ + true; \ + else \ + false; \ + fi; \ +} +am__make_running_with_option = \ + case $${target_option-} in \ + ?) ;; \ + *) echo "am__make_running_with_option: internal error: invalid" \ + "target option '$${target_option-}' specified" >&2; \ + exit 1;; \ + esac; \ + has_opt=no; \ + sane_makeflags=$$MAKEFLAGS; \ + if $(am__is_gnu_make); then \ + sane_makeflags=$$MFLAGS; \ + else \ + case $$MAKEFLAGS in \ + *\\[\ \ ]*) \ + bs=\\; \ + sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \ + | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \ + esac; \ + fi; \ + skip_next=no; \ + strip_trailopt () \ + { \ + flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \ + }; \ + for flg in $$sane_makeflags; do \ + test $$skip_next = yes && { skip_next=no; continue; }; \ + case $$flg in \ + *=*|--*) continue;; \ + -*I) strip_trailopt 'I'; skip_next=yes;; \ + -*I?*) strip_trailopt 'I';; \ + -*O) strip_trailopt 'O'; skip_next=yes;; \ + -*O?*) strip_trailopt 'O';; \ + -*l) strip_trailopt 'l'; skip_next=yes;; \ + -*l?*) strip_trailopt 'l';; \ + -[dEDm]) skip_next=yes;; \ + -[JT]) skip_next=yes;; \ + esac; \ + case $$flg in \ + *$$target_option*) has_opt=yes; break;; \ + esac; \ + done; \ + test $$has_opt = yes +am__make_dryrun = (target_option=n; $(am__make_running_with_option)) +am__make_keepgoing = (target_option=k; $(am__make_running_with_option)) +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +noinst_PROGRAMS = $(am__EXEEXT_1) +subdir = src/plugins/pop3-migration +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 $(noinst_HEADERS) \ + $(am__DIST_COMMON) +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +am__EXEEXT_1 = test-pop3-migration-plugin$(EXEEXT) +PROGRAMS = $(noinst_PROGRAMS) +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; }; \ + } +am__installdirs = "$(DESTDIR)$(moduledir)" +LTLIBRARIES = $(module_LTLIBRARIES) +lib05_pop3_migration_plugin_la_LIBADD = +am_lib05_pop3_migration_plugin_la_OBJECTS = pop3-migration-plugin.lo +lib05_pop3_migration_plugin_la_OBJECTS = \ + $(am_lib05_pop3_migration_plugin_la_OBJECTS) +AM_V_lt = $(am__v_lt_@AM_V@) +am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) +am__v_lt_0 = --silent +am__v_lt_1 = +lib05_pop3_migration_plugin_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \ + $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \ + $(AM_CFLAGS) $(CFLAGS) \ + $(lib05_pop3_migration_plugin_la_LDFLAGS) $(LDFLAGS) -o $@ +am_test_pop3_migration_plugin_OBJECTS = \ + test-pop3-migration-plugin.$(OBJEXT) +test_pop3_migration_plugin_OBJECTS = \ + $(am_test_pop3_migration_plugin_OBJECTS) +am__DEPENDENCIES_1 = +am__DEPENDENCIES_2 = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) +AM_V_P = $(am__v_P_@AM_V@) +am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) +am__v_P_0 = false +am__v_P_1 = : +AM_V_GEN = $(am__v_GEN_@AM_V@) +am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@) +am__v_GEN_0 = @echo " GEN " $@; +am__v_GEN_1 = +AM_V_at = $(am__v_at_@AM_V@) +am__v_at_ = $(am__v_at_@AM_DEFAULT_V@) +am__v_at_0 = @ +am__v_at_1 = +DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir) +depcomp = $(SHELL) $(top_srcdir)/depcomp +am__maybe_remake_depfiles = depfiles +am__depfiles_remade = ./$(DEPDIR)/pop3-migration-plugin.Plo \ + ./$(DEPDIR)/test-pop3-migration-plugin.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 = $(lib05_pop3_migration_plugin_la_SOURCES) \ + $(test_pop3_migration_plugin_SOURCES) +DIST_SOURCES = $(lib05_pop3_migration_plugin_la_SOURCES) \ + $(test_pop3_migration_plugin_SOURCES) +am__can_run_installinfo = \ + case $$AM_UPDATE_INFO_DIR in \ + n|no|NO) false;; \ + *) (install-info --version) >/dev/null 2>&1;; \ + esac +HEADERS = $(noinst_HEADERS) +am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) +# Read a list of newline-separated strings from the standard input, +# and print each of them once, without duplicates. Input order is +# *not* preserved. +am__uniquify_input = $(AWK) '\ + BEGIN { nonempty = 0; } \ + { items[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in items) print i; }; } \ +' +# Make sure the list of sources is unique. This is necessary because, +# e.g., the same source file might be shared among _SOURCES variables +# for different programs/libraries. +am__define_uniq_tagged_files = \ + list='$(am__tagged_files)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | $(am__uniquify_input)` +ETAGS = etags +CTAGS = ctags +am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/depcomp +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +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 = +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-test \ + -I$(top_srcdir)/src/lib-mail \ + -I$(top_srcdir)/src/lib-index \ + -I$(top_srcdir)/src/lib-storage \ + -I$(top_srcdir)/src/lib-storage/index + +lib05_pop3_migration_plugin_la_LDFLAGS = -module -avoid-version +module_LTLIBRARIES = \ + lib05_pop3_migration_plugin.la + +lib05_pop3_migration_plugin_la_SOURCES = \ + pop3-migration-plugin.c + +noinst_HEADERS = \ + pop3-migration-plugin.h + +test_programs = \ + test-pop3-migration-plugin + +test_libs = \ + $(LIBDOVECOT_STORAGE) \ + $(LIBDOVECOT) + +test_deps = \ + $(module_LTLIBRARIES) \ + $(LIBDOVECOT_STORAGE_DEPS) \ + $(LIBDOVECOT_DEPS) + +test_pop3_migration_plugin_SOURCES = test-pop3-migration-plugin.c +test_pop3_migration_plugin_LDADD = pop3-migration-plugin.lo $(test_libs) +test_pop3_migration_plugin_DEPENDENCIES = $(test_deps) +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/plugins/pop3-migration/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --foreign src/plugins/pop3-migration/Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): + +clean-noinstPROGRAMS: + @list='$(noinst_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 + +install-moduleLTLIBRARIES: $(module_LTLIBRARIES) + @$(NORMAL_INSTALL) + @list='$(module_LTLIBRARIES)'; test -n "$(moduledir)" || list=; \ + list2=; for p in $$list; do \ + if test -f $$p; then \ + list2="$$list2 $$p"; \ + else :; fi; \ + done; \ + test -z "$$list2" || { \ + echo " $(MKDIR_P) '$(DESTDIR)$(moduledir)'"; \ + $(MKDIR_P) "$(DESTDIR)$(moduledir)" || exit 1; \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(moduledir)'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(moduledir)"; \ + } + +uninstall-moduleLTLIBRARIES: + @$(NORMAL_UNINSTALL) + @list='$(module_LTLIBRARIES)'; test -n "$(moduledir)" || list=; \ + for p in $$list; do \ + $(am__strip_dir) \ + echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(moduledir)/$$f'"; \ + $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(moduledir)/$$f"; \ + done + +clean-moduleLTLIBRARIES: + -test -z "$(module_LTLIBRARIES)" || rm -f $(module_LTLIBRARIES) + @list='$(module_LTLIBRARIES)'; \ + locs=`for p in $$list; do echo $$p; done | \ + sed 's|^[^/]*$$|.|; s|/[^/]*$$||; s|$$|/so_locations|' | \ + sort -u`; \ + test -z "$$locs" || { \ + echo rm -f $${locs}; \ + rm -f $${locs}; \ + } + +lib05_pop3_migration_plugin.la: $(lib05_pop3_migration_plugin_la_OBJECTS) $(lib05_pop3_migration_plugin_la_DEPENDENCIES) $(EXTRA_lib05_pop3_migration_plugin_la_DEPENDENCIES) + $(AM_V_CCLD)$(lib05_pop3_migration_plugin_la_LINK) -rpath $(moduledir) $(lib05_pop3_migration_plugin_la_OBJECTS) $(lib05_pop3_migration_plugin_la_LIBADD) $(LIBS) + +test-pop3-migration-plugin$(EXEEXT): $(test_pop3_migration_plugin_OBJECTS) $(test_pop3_migration_plugin_DEPENDENCIES) $(EXTRA_test_pop3_migration_plugin_DEPENDENCIES) + @rm -f test-pop3-migration-plugin$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(test_pop3_migration_plugin_OBJECTS) $(test_pop3_migration_plugin_LDADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pop3-migration-plugin.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test-pop3-migration-plugin.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 + +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 + $(MAKE) $(AM_MAKEFLAGS) check-local +check: check-am +all-am: Makefile $(PROGRAMS) $(LTLIBRARIES) $(HEADERS) +installdirs: + for dir in "$(DESTDIR)$(moduledir)"; 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-moduleLTLIBRARIES \ + clean-noinstPROGRAMS mostlyclean-am + +distclean: distclean-am + -rm -f ./$(DEPDIR)/pop3-migration-plugin.Plo + -rm -f ./$(DEPDIR)/test-pop3-migration-plugin.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-moduleLTLIBRARIES + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -f ./$(DEPDIR)/pop3-migration-plugin.Plo + -rm -f ./$(DEPDIR)/test-pop3-migration-plugin.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-moduleLTLIBRARIES + +.MAKE: check-am install-am install-strip + +.PHONY: CTAGS GTAGS TAGS all all-am am--depfiles check check-am \ + check-local clean clean-generic clean-libtool \ + clean-moduleLTLIBRARIES clean-noinstPROGRAMS 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-moduleLTLIBRARIES \ + install-pdf install-pdf-am install-ps install-ps-am \ + install-strip installcheck installcheck-am installdirs \ + maintainer-clean maintainer-clean-generic mostlyclean \ + mostlyclean-compile mostlyclean-generic mostlyclean-libtool \ + pdf pdf-am ps ps-am tags tags-am uninstall uninstall-am \ + uninstall-moduleLTLIBRARIES + +.PRECIOUS: Makefile + + +check-local: + for bin in $(test_programs); do \ + if ! $(RUN_TEST) ./$$bin; then exit 1; fi; \ + done + +# 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/plugins/pop3-migration/pop3-migration-plugin.c b/src/plugins/pop3-migration/pop3-migration-plugin.c new file mode 100644 index 0000000..362597a --- /dev/null +++ b/src/plugins/pop3-migration/pop3-migration-plugin.c @@ -0,0 +1,1058 @@ +/* Copyright (c) 2007-2018 Dovecot authors, see the included COPYING file */ + +#include "lib.h" +#include "array.h" +#include "istream.h" +#include "istream-header-filter.h" +#include "str.h" +#include "sha1.h" +#include "message-size.h" +#include "message-header-hash.h" +#include "message-header-parser.h" +#include "mail-cache.h" +#include "mail-namespace.h" +#include "mail-search-build.h" +#include "index-storage.h" +#include "index-mail.h" +#include "pop3-migration-plugin.h" + +#define POP3_MIGRATION_CONTEXT(obj) \ + MODULE_CONTEXT(obj, pop3_migration_storage_module) +#define POP3_MIGRATION_CONTEXT_REQUIRE(obj) \ + MODULE_CONTEXT_REQUIRE(obj, pop3_migration_storage_module) +#define POP3_MIGRATION_MAIL_CONTEXT(obj) \ + MODULE_CONTEXT_REQUIRE(obj, pop3_migration_mail_module) + +struct msg_map_common { + /* sha1(header) - set only when needed */ + unsigned char hdr_sha1[SHA1_RESULTLEN]; + bool hdr_sha1_set:1; +}; + +struct pop3_uidl_map { + struct msg_map_common common; + + uint32_t pop3_seq; + uint32_t imap_uid; + + /* UIDL */ + const char *pop3_uidl; + /* LIST size */ + uoff_t size; +}; + +struct imap_msg_map { + struct msg_map_common common; + + uint32_t uid, pop3_seq; + uoff_t psize; + const char *pop3_uidl; +}; + +struct pop3_migration_mail_storage { + union mail_storage_module_context module_ctx; + + const char *pop3_box_vname; + ARRAY(struct pop3_uidl_map) pop3_uidl_map; + + bool all_mailboxes:1; + bool pop3_all_hdr_sha1_set:1; + bool ignore_missing_uidls:1; + bool ignore_extra_uidls:1; + bool skip_size_check:1; + bool skip_uidl_cache:1; +}; + +struct pop3_migration_mailbox { + union mailbox_module_context module_ctx; + + ARRAY(struct imap_msg_map) imap_msg_map; + unsigned int first_unfound_idx; + + struct mail_cache_field cache_field; + + bool cache_field_registered:1; + bool uidl_synced:1; + bool uidl_sync_failed:1; +}; + +/* NOTE: these headers must be sorted */ +static const char *hdr_hash_skip_headers[] = { + "Content-Length", + "Return-Path", /* Yahoo IMAP has Return-Path, Yahoo POP3 doesn't */ + "Status", + "X-IMAP", + "X-IMAPbase", + "X-Keywords", + "X-Message-Flag", + "X-Status", + "X-UID", + "X-UIDL", + "X-Yahoo-Newman-Property" +}; +const char *pop3_migration_plugin_version = DOVECOT_ABI_VERSION; + +static MODULE_CONTEXT_DEFINE_INIT(pop3_migration_storage_module, + &mail_storage_module_register); +static MODULE_CONTEXT_DEFINE_INIT(pop3_migration_mail_module, + &mail_module_register); + +static int imap_msg_map_uid_cmp(const struct imap_msg_map *map1, + const struct imap_msg_map *map2) +{ + if (map1->uid < map2->uid) + return -1; + if (map1->uid > map2->uid) + return 1; + return 0; +} + +static int pop3_uidl_map_pop3_seq_cmp(const struct pop3_uidl_map *map1, + const struct pop3_uidl_map *map2) +{ + if (map1->pop3_seq < map2->pop3_seq) + return -1; + if (map1->pop3_seq > map2->pop3_seq) + return 1; + return 0; +} + +static int pop3_uidl_map_uidl_cmp(const struct pop3_uidl_map *map1, + const struct pop3_uidl_map *map2) +{ + return strcmp(map1->pop3_uidl, map2->pop3_uidl); +} + +static int imap_msg_map_uidl_cmp(const struct imap_msg_map *map1, + const struct imap_msg_map *map2) +{ + return null_strcmp(map1->pop3_uidl, map2->pop3_uidl); +} + +static int pop3_uidl_map_hdr_cmp(const struct pop3_uidl_map *map1, + const struct pop3_uidl_map *map2) +{ + return memcmp(map1->common.hdr_sha1, map2->common.hdr_sha1, + sizeof(map1->common.hdr_sha1)); +} + +static int imap_msg_map_hdr_cmp(const struct imap_msg_map *map1, + const struct imap_msg_map *map2) +{ + return memcmp(map1->common.hdr_sha1, map2->common.hdr_sha1, + sizeof(map1->common.hdr_sha1)); +} + +struct pop3_hdr_context { + bool have_eoh; + bool stop; +}; + +static bool header_name_is_valid(const char *name) +{ + unsigned int i; + + for (i = 0; name[i] != '\0'; i++) { + if ((uint8_t)name[i] <= 0x20 || name[i] >= 0x7f) + return FALSE; + } + return TRUE; +} + +static bool header_value_want_skip(const struct message_header_line *hdr) +{ + for (size_t i = 0; i < hdr->value_len; i++) { + if (hdr->value[i] != ' ' && hdr->value[i] != '\t') + return FALSE; + } + /* "header: \r\n \r\n" - Zimbra's BODY[HEADER] strips this line away. */ + return TRUE; +} + +static void +pop3_header_filter_callback(struct header_filter_istream *input ATTR_UNUSED, + struct message_header_line *hdr, + bool *matched, struct pop3_hdr_context *ctx) +{ + if (hdr == NULL) + return; + if (hdr->eoh) { + ctx->have_eoh = TRUE; + if (ctx->stop) + *matched = TRUE; + } else { + if (hdr->value_len > 0 && hdr->middle_len == 0 && hdr->name_len == 0 && + i_memspn(hdr->value, hdr->value_len, "\r", 1U) == hdr->value_len) { + /* CR+CR+LF - some servers stop the header processing + here while others don't. To make sure they can be + matched correctly we want to stop here entirely. */ + ctx->stop = TRUE; + } else if (!hdr->continued && hdr->middle_len == 0) { + /* not a valid "key: value" header - + Zimbra's BODY[HEADER] strips this line away. */ + *matched = TRUE; + } else if (hdr->continued && header_value_want_skip(hdr)) { + *matched = TRUE; + } + if (ctx->stop) + *matched = TRUE; + else if (!header_name_is_valid(hdr->name)) { + /* Yahoo IMAP drops headers with invalid names, while + Yahoo POP3 preserves them. Drop them all. */ + *matched = TRUE; + } + } +} + +int pop3_migration_get_hdr_sha1(uint32_t mail_seq, struct istream *input, + unsigned char sha1_r[STATIC_ARRAY SHA1_RESULTLEN], + bool *have_eoh_r) +{ + const unsigned char *data; + size_t size; + struct message_header_hash_context hash_ctx; + struct sha1_ctxt sha1_ctx; + struct pop3_hdr_context hdr_ctx; + + i_zero(&hdr_ctx); + /* hide headers that might change or be different in IMAP vs. POP3 */ + input = i_stream_create_header_filter(input, HEADER_FILTER_HIDE_BODY | + HEADER_FILTER_EXCLUDE | HEADER_FILTER_NO_CR, + hdr_hash_skip_headers, + N_ELEMENTS(hdr_hash_skip_headers), + pop3_header_filter_callback, &hdr_ctx); + + sha1_init(&sha1_ctx); + i_zero(&hash_ctx); + while (i_stream_read_more(input, &data, &size) > 0) { + message_header_hash_more(&hash_ctx, &hash_method_sha1, &sha1_ctx, + MESSAGE_HEADER_HASH_MAX_VERSION, + data, size); + i_stream_skip(input, size); + } + if (input->stream_errno != 0) { + i_error("pop3_migration: Failed to read header for msg %u: %s", + mail_seq, i_stream_get_error(input)); + i_stream_unref(&input); + return -1; + } + sha1_result(&sha1_ctx, sha1_r); + i_stream_unref(&input); + + *have_eoh_r = hdr_ctx.have_eoh; + return 0; +} + +static unsigned int get_cache_idx(struct mail *mail) +{ + struct pop3_migration_mailbox *mbox = POP3_MIGRATION_CONTEXT_REQUIRE(mail->box); + + if (mbox->cache_field_registered) + return mbox->cache_field.idx; + + mbox->cache_field.name = "pop3-migration.hdr"; + mbox->cache_field.type = MAIL_CACHE_FIELD_FIXED_SIZE; + mbox->cache_field.field_size = SHA1_RESULTLEN; + mail_cache_register_fields(mail->box->cache, &mbox->cache_field, 1); + mbox->cache_field_registered = TRUE; + return mbox->cache_field.idx; +} + +static int +get_hdr_sha1(struct mail *mail, unsigned char sha1_r[STATIC_ARRAY SHA1_RESULTLEN]) +{ + struct istream *input; + const char *errstr; + enum mail_error error; + bool have_eoh; + int ret; + + if (mail_get_hdr_stream(mail, NULL, &input) < 0) { + errstr = mailbox_get_last_internal_error(mail->box, &error); + i_error("pop3_migration: Failed to get header for msg %u: %s", + mail->seq, errstr); + return error == MAIL_ERROR_EXPUNGED ? 0 : -1; + } + if (pop3_migration_get_hdr_sha1(mail->seq, input, sha1_r, &have_eoh) < 0) + return -1; + if (have_eoh) { + struct index_mail *imail = (struct index_mail *)mail; + + index_mail_cache_add_idx(imail, get_cache_idx(mail), + sha1_r, SHA1_RESULTLEN); + return 1; + } + + /* The empty "end of headers" line is missing. Either this means that + the headers ended unexpectedly (which is ok) or that the remote + server is buggy. Some servers have problems with + + 1) header line continuations that contain only whitespace and + 2) headers that have no ":". The header gets truncated when such + line is reached. + + At least Oracle IMS IMAP FETCH BODY[HEADER] handles 1) by not + returning the whitespace line and 2) by returning the line but + truncating the rest. POP3 TOP instead returns the entire header. + This causes the IMAP and POP3 hashes not to match. + + If there's LF+CR+CR+LF in the middle of headers, Courier IMAP's + FETCH BODY[HEADER] stops after that, but Courier POP3's TOP doesn't. + + So we'll try to avoid this by falling back to full FETCH BODY[] + (and/or RETR) and we'll parse the header ourself from it. This + should work around any similar bugs in all IMAP/POP3 servers. */ + if (mail_get_stream_because(mail, NULL, NULL, "pop3-migration", &input) < 0) { + errstr = mailbox_get_last_internal_error(mail->box, &error); + i_error("pop3_migration: Failed to get body for msg %u: %s", + mail->seq, errstr); + return error == MAIL_ERROR_EXPUNGED ? 0 : -1; + } + ret = pop3_migration_get_hdr_sha1(mail->seq, input, sha1_r, &have_eoh); + if (ret == 0) { + if (!have_eoh) + i_warning("pop3_migration: Truncated email with UID %u stored as truncated", mail->uid); + struct index_mail *imail = (struct index_mail *)mail; + index_mail_cache_add_idx(imail, get_cache_idx(mail), + sha1_r, SHA1_RESULTLEN); + return 1; + } else { + return -1; + } +} + +static bool +get_cached_hdr_sha1(struct mail *mail, buffer_t *cache_buf, + unsigned char sha1_r[STATIC_ARRAY SHA1_RESULTLEN]) +{ + struct index_mail *imail = (struct index_mail *)mail; + + buffer_set_used_size(cache_buf, 0); + if (index_mail_cache_lookup_field(imail, cache_buf, + get_cache_idx(mail)) > 0 && + cache_buf->used == SHA1_RESULTLEN) { + memcpy(sha1_r, cache_buf->data, cache_buf->used); + return TRUE; + } + return FALSE; +} + +static struct mailbox *pop3_mailbox_alloc(struct mail_storage *storage) +{ + struct pop3_migration_mail_storage *mstorage = + POP3_MIGRATION_CONTEXT_REQUIRE(storage); + struct mail_namespace *ns; + struct mailbox *box; + + ns = mail_namespace_find(storage->user->namespaces, + mstorage->pop3_box_vname); + i_assert(ns != NULL); + box = mailbox_alloc(ns->list, mstorage->pop3_box_vname, + MAILBOX_FLAG_READONLY | MAILBOX_FLAG_POP3_SESSION); + return box; +} + +static int pop3_map_read(struct mail_storage *storage, struct mailbox *pop3_box) +{ + struct pop3_migration_mail_storage *mstorage = + POP3_MIGRATION_CONTEXT_REQUIRE(storage); + struct mailbox_transaction_context *t; + struct mail_search_args *search_args; + struct mail_search_context *ctx; + struct mail *mail; + struct pop3_uidl_map *map; + const char *uidl; + uoff_t size = UOFF_T_MAX; + int ret = 0; + + if (array_is_created(&mstorage->pop3_uidl_map)) { + /* already read these, just reset the imap_uids */ + array_foreach_modifiable(&mstorage->pop3_uidl_map, map) + map->imap_uid = 0; + return 0; + } + i_array_init(&mstorage->pop3_uidl_map, 128); + + if (mailbox_sync(pop3_box, 0) < 0) { + i_error("pop3_migration: Couldn't sync mailbox %s: %s", + pop3_box->vname, mailbox_get_last_internal_error(pop3_box, NULL)); + return -1; + } + + t = mailbox_transaction_begin(pop3_box, 0, __func__); + search_args = mail_search_build_init(); + mail_search_build_add_all(search_args); + ctx = mailbox_search_init(t, search_args, NULL, + mstorage->skip_size_check ? 0 : + MAIL_FETCH_PHYSICAL_SIZE, NULL); + mail_search_args_unref(&search_args); + + while (mailbox_search_next(ctx, &mail)) { + /* get the size with LIST instead of RETR */ + mail->lookup_abort = MAIL_LOOKUP_ABORT_READ_MAIL; + + if (mstorage->skip_size_check) + ; + else if (mail_get_physical_size(mail, &size) < 0) { + i_error("pop3_migration: Failed to get size for msg %u: %s", + mail->seq, + mailbox_get_last_internal_error(pop3_box, NULL)); + ret = -1; + break; + } + mail->lookup_abort = MAIL_LOOKUP_ABORT_NEVER; + + if (mail_get_special(mail, MAIL_FETCH_UIDL_BACKEND, &uidl) < 0) { + i_error("pop3_migration: Failed to get UIDL for msg %u: %s", + mail->seq, + mailbox_get_last_internal_error(pop3_box, NULL)); + ret = -1; + break; + } + if (*uidl == '\0') { + i_warning("pop3_migration: UIDL for msg %u is empty", + mail->seq); + continue; + } + + map = array_append_space(&mstorage->pop3_uidl_map); + map->pop3_seq = mail->seq; + map->pop3_uidl = p_strdup(storage->pool, uidl); + map->size = size; + } + + if (mailbox_search_deinit(&ctx) < 0) { + i_error("pop3_migration: Failed to search all POP3 mails: %s", + mailbox_get_last_internal_error(pop3_box, NULL)); + ret = -1; + } + (void)mailbox_transaction_commit(&t); + return ret; +} + +static void +pop3_map_read_cached_hdr_hashes(struct mailbox_transaction_context *t, + struct mail_search_args *search_args, + struct array *msg_map) +{ + struct mail_search_context *ctx; + struct mail *mail; + struct msg_map_common *map; + buffer_t *cache_buf; + + ctx = mailbox_search_init(t, search_args, NULL, 0, NULL); + cache_buf = t_buffer_create(SHA1_RESULTLEN); + + while (mailbox_search_next(ctx, &mail)) { + map = array_idx_modifiable_i(msg_map, mail->seq-1); + + if (get_cached_hdr_sha1(mail, cache_buf, map->hdr_sha1)) + map->hdr_sha1_set = TRUE; + } + + if (mailbox_search_deinit(&ctx) < 0) { + i_warning("pop3_migration: Failed to search all cached POP3 header hashes: %s - ignoring", + mailbox_get_last_internal_error(t->box, NULL)); + } +} + +static void map_remove_found_seqs(struct mail_search_arg *search_arg, + struct array *msg_map, uint32_t seq1) +{ + const struct msg_map_common *map; + uint32_t seq, count = array_count_i(msg_map); + + i_assert(search_arg->type == SEARCH_SEQSET); + + for (seq = seq1; seq <= count; seq++) { + map = array_idx_i(msg_map, seq-1); + if (map->hdr_sha1_set) + seq_range_array_remove(&search_arg->value.seqset, seq); + } +} + +static int +map_read_hdr_hashes(struct mailbox *box, struct array *msg_map, uint32_t seq1) +{ + struct mailbox_transaction_context *t; + struct mail_search_args *search_args; + struct mail_search_context *ctx; + struct mail *mail; + struct msg_map_common *map; + int ret = 0; + + t = mailbox_transaction_begin(box, 0, __func__); + /* get all the cached hashes */ + search_args = mail_search_build_init(); + mail_search_build_add_seqset(search_args, seq1, array_count_i(msg_map)); + pop3_map_read_cached_hdr_hashes(t, search_args, msg_map); + /* read all the non-cached hashes. doing this in two passes allows + us to set wanted_fields=MAIL_FETCH_STREAM_HEADER, which allows + prefetching to work without downloading all the headers even + for mails that already are cached. */ + map_remove_found_seqs(search_args->args, msg_map, seq1); + ctx = mailbox_search_init(t, search_args, NULL, + MAIL_FETCH_STREAM_HEADER, NULL); + mail_search_args_unref(&search_args); + + while (mailbox_search_next(ctx, &mail)) { + map = array_idx_modifiable_i(msg_map, mail->seq-1); + + if ((ret = get_hdr_sha1(mail, map->hdr_sha1)) < 0) { + ret = -1; + break; + } + if (ret > 0) + map->hdr_sha1_set = TRUE; + } + + if (mailbox_search_deinit(&ctx) < 0) { + i_error("pop3_migration: Failed to search all mail headers: %s", + mailbox_get_last_internal_error(box, NULL)); + ret = -1; + } + (void)mailbox_transaction_commit(&t); + return ret < 0 ? -1 : 0; +} + +static int +pop3_map_read_hdr_hashes(struct mail_storage *storage, struct mailbox *pop3_box, + unsigned first_seq) +{ + struct pop3_migration_mail_storage *mstorage = + POP3_MIGRATION_CONTEXT_REQUIRE(storage); + + if (mstorage->pop3_all_hdr_sha1_set) + return 0; + if (mstorage->all_mailboxes) { + /* we may be matching against multiple mailboxes. + read all the hashes only once. */ + first_seq = 1; + } + + if (map_read_hdr_hashes(pop3_box, &mstorage->pop3_uidl_map.arr, + first_seq) < 0) + return -1; + + if (first_seq == 1) + mstorage->pop3_all_hdr_sha1_set = TRUE; + return 0; +} + +static int imap_map_read(struct mailbox *box) +{ + struct pop3_migration_mailbox *mbox = POP3_MIGRATION_CONTEXT_REQUIRE(box); + struct index_mailbox_context *ibox = INDEX_STORAGE_CONTEXT(box); + struct pop3_migration_mail_storage *mstorage = + POP3_MIGRATION_CONTEXT_REQUIRE(box->storage); + const unsigned int uidl_cache_idx = + ibox->cache_fields[MAIL_CACHE_POP3_UIDL].idx; + struct mailbox_status status; + struct mailbox_transaction_context *t; + struct mail_search_args *search_args; + struct mail_search_context *ctx; + struct mail *mail; + struct imap_msg_map *map; + uoff_t psize = UOFF_T_MAX; + string_t *uidl; + int ret = 0; + + mailbox_get_open_status(box, STATUS_MESSAGES, &status); + + i_assert(!array_is_created(&mbox->imap_msg_map)); + p_array_init(&mbox->imap_msg_map, box->pool, status.messages); + + t = mailbox_transaction_begin(box, 0, __func__); + search_args = mail_search_build_init(); + mail_search_build_add_all(search_args); + ctx = mailbox_search_init(t, search_args, NULL, + mstorage->skip_size_check ? 0 : + MAIL_FETCH_PHYSICAL_SIZE, NULL); + mail_search_args_unref(&search_args); + + uidl = t_str_new(64); + while (mailbox_search_next(ctx, &mail)) { + if (mstorage->skip_size_check) + ; + else if (mail_get_physical_size(mail, &psize) < 0) { + i_error("pop3_migration: Failed to get psize for imap uid %u: %s", + mail->uid, + mailbox_get_last_internal_error(box, NULL)); + ret = -1; + break; + } + + if (!mstorage->skip_uidl_cache) { + str_truncate(uidl, 0); + (void)mail_cache_lookup_field(mail->transaction->cache_view, + uidl, mail->seq, uidl_cache_idx); + } + + map = array_append_space(&mbox->imap_msg_map); + map->uid = mail->uid; + map->psize = psize; + map->pop3_uidl = p_strdup_empty(box->pool, str_c(uidl)); + } + + if (mailbox_search_deinit(&ctx) < 0) { + i_error("pop3_migration: Failed to search all IMAP mails: %s", + mailbox_get_last_internal_error(box, NULL)); + ret = -1; + } + (void)mailbox_transaction_commit(&t); + return ret; +} + +static int imap_map_read_hdr_hashes(struct mailbox *box) +{ + struct pop3_migration_mailbox *mbox = POP3_MIGRATION_CONTEXT_REQUIRE(box); + + return map_read_hdr_hashes(box, &mbox->imap_msg_map.arr, + mbox->first_unfound_idx+1); +} + +static void pop3_uidl_assign_cached(struct mailbox *box) +{ + struct pop3_migration_mailbox *mbox = POP3_MIGRATION_CONTEXT_REQUIRE(box); + struct pop3_migration_mail_storage *mstorage = + POP3_MIGRATION_CONTEXT_REQUIRE(box->storage); + struct pop3_uidl_map *pop3_map; + struct imap_msg_map *imap_map; + unsigned int imap_idx, pop3_idx, pop3_count, imap_count; + int ret; + + if (mstorage->skip_uidl_cache) + return; + + array_sort(&mstorage->pop3_uidl_map, pop3_uidl_map_uidl_cmp); + array_sort(&mbox->imap_msg_map, imap_msg_map_uidl_cmp); + + pop3_map = array_get_modifiable(&mstorage->pop3_uidl_map, &pop3_count); + imap_map = array_get_modifiable(&mbox->imap_msg_map, &imap_count); + + /* see if we can match the messages using sizes */ + for (imap_idx = pop3_idx = 0; imap_idx < imap_count; imap_idx++) { + if (imap_map[imap_idx].pop3_uidl == NULL) + continue; + + ret = 1; + for (; pop3_idx < pop3_count; pop3_idx++) { + ret = strcmp(imap_map[imap_idx].pop3_uidl, + pop3_map[pop3_idx].pop3_uidl); + if (ret >= 0) + break; + } + if (ret == 0) { + imap_map[imap_idx].pop3_seq = + pop3_map[pop3_idx].pop3_seq; + pop3_map[pop3_idx].imap_uid = imap_map[imap_idx].uid; + } + } +} + +static bool pop3_uidl_assign_by_size(struct mailbox *box) +{ + struct pop3_migration_mailbox *mbox = POP3_MIGRATION_CONTEXT_REQUIRE(box); + struct pop3_migration_mail_storage *mstorage = + POP3_MIGRATION_CONTEXT_REQUIRE(box->storage); + struct pop3_uidl_map *pop3_map; + struct imap_msg_map *imap_map; + unsigned int i, pop3_count, imap_count, count; + unsigned int size_match = 0, uidl_match = 0; + + pop3_map = array_get_modifiable(&mstorage->pop3_uidl_map, &pop3_count); + imap_map = array_get_modifiable(&mbox->imap_msg_map, &imap_count); + count = I_MIN(pop3_count, imap_count); + + /* see if we can match the messages using sizes */ + for (i = 0; i < count; i++) { + if (imap_map[i].pop3_uidl != NULL) { + /* some of the UIDLs were already found cached. */ + if (strcmp(pop3_map[i].pop3_uidl, imap_map[i].pop3_uidl) == 0) { + uidl_match++; + continue; + } + /* mismatch - can't trust the sizes */ + break; + } + + if (pop3_map[i].size != imap_map[i].psize || + mstorage->skip_size_check) + break; + if (i+1 < count && pop3_map[i].size == pop3_map[i+1].size) { + /* two messages with same size, don't trust them */ + break; + } + + size_match++; + pop3_map[i].imap_uid = imap_map[i].uid; + imap_map[i].pop3_uidl = pop3_map[i].pop3_uidl; + imap_map[i].pop3_seq = pop3_map[i].pop3_seq; + } + mbox->first_unfound_idx = i; + e_debug(box->event, "pop3_migration: cached uidls=%u, size matches=%u, total=%u", + uidl_match, size_match, count); + return i == count && imap_count == pop3_count; +} + +static int +pop3_uidl_assign_by_hdr_hash(struct mailbox *box, struct mailbox *pop3_box) +{ + struct pop3_migration_mail_storage *mstorage = + POP3_MIGRATION_CONTEXT_REQUIRE(box->storage); + struct pop3_migration_mailbox *mbox = POP3_MIGRATION_CONTEXT_REQUIRE(box); + struct pop3_uidl_map *pop3_map; + struct imap_msg_map *imap_map; + unsigned int pop3_idx, imap_idx, pop3_count, imap_count; + unsigned int first_seq, missing_uids_count; + uint32_t first_missing_idx = 0, first_missing_seq = (uint32_t)-1; + int ret; + + first_seq = mbox->first_unfound_idx+1; + if (pop3_map_read_hdr_hashes(box->storage, pop3_box, first_seq) < 0 || + imap_map_read_hdr_hashes(box) < 0) + return -1; + + array_sort(&mstorage->pop3_uidl_map, pop3_uidl_map_hdr_cmp); + array_sort(&mbox->imap_msg_map, imap_msg_map_hdr_cmp); + + pop3_map = array_get_modifiable(&mstorage->pop3_uidl_map, &pop3_count); + imap_map = array_get_modifiable(&mbox->imap_msg_map, &imap_count); + + pop3_idx = imap_idx = 0; + while (pop3_idx < pop3_count && imap_idx < imap_count) { + if (!pop3_map[pop3_idx].common.hdr_sha1_set || + pop3_map[pop3_idx].imap_uid != 0) { + pop3_idx++; + continue; + } + if (!imap_map[imap_idx].common.hdr_sha1_set || + imap_map[imap_idx].pop3_uidl != NULL) { + imap_idx++; + continue; + } + ret = memcmp(pop3_map[pop3_idx].common.hdr_sha1, + imap_map[imap_idx].common.hdr_sha1, + sizeof(pop3_map[pop3_idx].common.hdr_sha1)); + if (ret < 0) + pop3_idx++; + else if (ret > 0) + imap_idx++; + else { + pop3_map[pop3_idx].imap_uid = imap_map[imap_idx].uid; + imap_map[imap_idx].pop3_uidl = + pop3_map[pop3_idx].pop3_uidl; + imap_map[imap_idx].pop3_seq = + pop3_map[pop3_idx].pop3_seq; + } + } + missing_uids_count = 0; + for (pop3_idx = 0; pop3_idx < pop3_count; pop3_idx++) { + if (pop3_map[pop3_idx].imap_uid != 0) { + /* matched */ + } else if (!pop3_map[pop3_idx].common.hdr_sha1_set) { + /* we treated this mail as expunged - ignore */ + } else { + uint32_t seq = pop3_map[pop3_idx].pop3_seq; + if (first_missing_seq > seq) { + first_missing_seq = seq; + first_missing_idx = pop3_idx; + } + missing_uids_count++; + } + } + if (missing_uids_count > 0 && !mstorage->all_mailboxes) { + string_t *str = t_str_new(128); + bool all_imap_mails_found = FALSE; + + str_printfa(str, "pop3_migration: %u POP3 messages have no " + "matching IMAP messages (first POP3 msg %u UIDL %s)", + missing_uids_count, first_missing_seq, + pop3_map[first_missing_idx].pop3_uidl); + if (imap_count + missing_uids_count == pop3_count) { + str_append(str, " - all IMAP messages were found " + "(POP3 contains more than IMAP INBOX - you may want to set pop3_migration_all_mailboxes=yes)"); + all_imap_mails_found = TRUE; + } + if (all_imap_mails_found && mstorage->ignore_extra_uidls) { + /* pop3 had more mails than imap. maybe it was just + that a new mail was just delivered. */ + } else if (!mstorage->ignore_missing_uidls) { + str_append(str, " - set pop3_migration_ignore_missing_uidls=yes"); + if (all_imap_mails_found) + str_append(str, " or pop3_migration_ignore_extra_uidls=yes"); + i_error("%s to continue anyway", str_c(str)); + return -1; + } + i_warning("%s", str_c(str)); + } else + e_debug(box->event, "pop3_migration: %u mails matched by headers", pop3_count); + array_sort(&mstorage->pop3_uidl_map, pop3_uidl_map_pop3_seq_cmp); + array_sort(&mbox->imap_msg_map, imap_msg_map_uid_cmp); + return 0; +} + +static void imap_uidls_add_to_cache(struct mailbox *box) +{ + struct pop3_migration_mailbox *mbox = POP3_MIGRATION_CONTEXT_REQUIRE(box); + struct mailbox_transaction_context *t; + struct mail *mail; + struct index_mail *imail; + struct imap_msg_map *imap_map; + unsigned int i, count; + unsigned int field_idx; + + t = mailbox_transaction_begin(box, 0, __func__); + mail = mail_alloc(t, 0, NULL); + imail = INDEX_MAIL(mail); + field_idx = imail->ibox->cache_fields[MAIL_CACHE_POP3_UIDL].idx; + + imap_map = array_get_modifiable(&mbox->imap_msg_map, &count); + for (i = 0; i < count; i++) { + if (imap_map[i].pop3_uidl == NULL) + continue; + + if (!mail_set_uid(mail, imap_map[i].uid)) + i_unreached(); + if (mail_cache_field_can_add(t->cache_trans, mail->seq, field_idx)) { + index_mail_cache_add_idx(imail, field_idx, + imap_map[i].pop3_uidl, strlen(imap_map[i].pop3_uidl)+1); + } + } + mail_free(&mail); + (void)mailbox_transaction_commit(&t); +} + +static int pop3_migration_uidl_sync(struct mailbox *box) +{ + struct pop3_migration_mailbox *mbox = POP3_MIGRATION_CONTEXT_REQUIRE(box); + struct pop3_migration_mail_storage *mstorage = + POP3_MIGRATION_CONTEXT_REQUIRE(box->storage); + struct mailbox *pop3_box; + + pop3_box = pop3_mailbox_alloc(box->storage); + /* the POP3 server isn't connected to yet. handle all IMAP traffic + first before connecting, so POP3 server won't disconnect us due to + idling. */ + if (imap_map_read(box) < 0 || + pop3_map_read(box->storage, pop3_box) < 0) { + mailbox_free(&pop3_box); + return -1; + } + + pop3_uidl_assign_cached(box); + + array_sort(&mstorage->pop3_uidl_map, pop3_uidl_map_pop3_seq_cmp); + array_sort(&mbox->imap_msg_map, imap_msg_map_uid_cmp); + + if (!pop3_uidl_assign_by_size(box)) { + /* everything wasn't assigned, figure out the rest with + header hashes */ + if (pop3_uidl_assign_by_hdr_hash(box, pop3_box) < 0) { + mailbox_free(&pop3_box); + return -1; + } + } + + if (!mstorage->skip_uidl_cache) + imap_uidls_add_to_cache(box); + + mbox->uidl_synced = TRUE; + mailbox_free(&pop3_box); + return 0; +} + +static int pop3_migration_uidl_sync_if_needed(struct mailbox *box) +{ + struct pop3_migration_mailbox *mbox = POP3_MIGRATION_CONTEXT_REQUIRE(box); + int ret = 0; + + if (mbox->uidl_synced) + return 0; + + if (mbox->uidl_sync_failed) + ret = -1; + else { + struct event_reason *reason = + event_reason_begin("pop3_migration:uidl_sync"); + ret = pop3_migration_uidl_sync(box); + event_reason_end(&reason); + } + if (ret < 0) { + mbox->uidl_sync_failed = TRUE; + mail_storage_set_error(box->storage, MAIL_ERROR_TEMP, + "POP3 UIDLs couldn't be synced"); + return -1; + } + return 0; +} + +static int +pop3_migration_get_special(struct mail *_mail, enum mail_fetch_field field, + const char **value_r) +{ + struct mail_private *mail = (struct mail_private *)_mail; + union mail_module_context *mmail = POP3_MIGRATION_MAIL_CONTEXT(mail); + struct pop3_migration_mailbox *mbox = POP3_MIGRATION_CONTEXT_REQUIRE(_mail->box); + struct imap_msg_map map_key, *map; + + if (field == MAIL_FETCH_UIDL_BACKEND || + field == MAIL_FETCH_POP3_ORDER) { + if (pop3_migration_uidl_sync_if_needed(_mail->box) < 0) + return -1; + + i_zero(&map_key); + map_key.uid = _mail->uid; + map = array_bsearch(&mbox->imap_msg_map, &map_key, + imap_msg_map_uid_cmp); + if (map != NULL && map->pop3_uidl != NULL) { + if (field == MAIL_FETCH_UIDL_BACKEND) + *value_r = map->pop3_uidl; + else + *value_r = t_strdup_printf("%u", map->pop3_seq); + return 0; + } + /* not found from POP3 server, fallback to default */ + } + return mmail->super.get_special(_mail, field, value_r); +} + +static void pop3_migration_mail_allocated(struct mail *_mail) +{ + struct pop3_migration_mail_storage *mstorage = + POP3_MIGRATION_CONTEXT(_mail->box->storage); + struct mail_private *mail = (struct mail_private *)_mail; + struct mail_vfuncs *v = mail->vlast; + union mail_module_context *mmail; + struct mail_namespace *ns; + + if (mstorage == NULL || + (!mstorage->all_mailboxes && !_mail->box->inbox_user)) { + /* assigns UIDLs only for INBOX */ + return; + } + + ns = mail_namespace_find(_mail->box->storage->user->namespaces, + mstorage->pop3_box_vname); + if (ns == mailbox_get_namespace(_mail->box)) { + /* we're accessing the pop3-migration namespace itself */ + return; + } + + mmail = p_new(mail->pool, union mail_module_context, 1); + mmail->super = *v; + mail->vlast = &mmail->super; + + v->get_special = pop3_migration_get_special; + MODULE_CONTEXT_SET_SELF(mail, pop3_migration_mail_module, mmail); +} + +static struct mail_search_context * +pop3_migration_mailbox_search_init(struct mailbox_transaction_context *t, + struct mail_search_args *args, + const enum mail_sort_type *sort_program, + enum mail_fetch_field wanted_fields, + struct mailbox_header_lookup_ctx *wanted_headers) +{ + struct pop3_migration_mailbox *mbox = POP3_MIGRATION_CONTEXT_REQUIRE(t->box); + struct pop3_migration_mail_storage *mstorage = + POP3_MIGRATION_CONTEXT_REQUIRE(t->box->storage); + + if ((wanted_fields & (MAIL_FETCH_UIDL_BACKEND | + MAIL_FETCH_POP3_ORDER)) != 0 && + (mstorage->all_mailboxes || t->box->inbox_user)) { + /* Start POP3 UIDL syncing before the search, so we'll do it + before we start sending any FETCH BODY[]s to IMAP. It + shouldn't matter much, except this works around a bug in + Yahoo IMAP where it sometimes breaks its state when doing + a FETCH BODY[] followed by FETCH BODY[HEADER].. */ + (void)pop3_migration_uidl_sync_if_needed(t->box); + } + + return mbox->module_ctx.super.search_init(t, args, sort_program, + wanted_fields, wanted_headers); +} + +static void pop3_migration_mailbox_allocated(struct mailbox *box) +{ + struct pop3_migration_mail_storage *mstorage = + POP3_MIGRATION_CONTEXT(box->storage); + struct mailbox_vfuncs *v = box->vlast; + struct pop3_migration_mailbox *mbox; + + if (mstorage == NULL) + return; + + mbox = p_new(box->pool, struct pop3_migration_mailbox, 1); + mbox->module_ctx.super = *v; + box->vlast = &mbox->module_ctx.super; + + v->search_init = pop3_migration_mailbox_search_init; + + MODULE_CONTEXT_SET(box, pop3_migration_storage_module, mbox); +} + +static void pop3_migration_mail_storage_destroy(struct mail_storage *storage) +{ + struct pop3_migration_mail_storage *mstorage = + POP3_MIGRATION_CONTEXT_REQUIRE(storage); + + if (array_is_created(&mstorage->pop3_uidl_map)) + array_free(&mstorage->pop3_uidl_map); + + mstorage->module_ctx.super.destroy(storage); +} + +static void pop3_migration_mail_storage_created(struct mail_storage *storage) +{ + struct pop3_migration_mail_storage *mstorage; + struct mail_storage_vfuncs *v = storage->vlast; + const char *pop3_box_vname; + + pop3_box_vname = mail_user_plugin_getenv(storage->user, + "pop3_migration_mailbox"); + if (pop3_box_vname == NULL) { + e_debug(storage->user->event, "pop3_migration: No pop3_migration_mailbox setting - disabled"); + return; + } + + mstorage = p_new(storage->pool, struct pop3_migration_mail_storage, 1); + mstorage->module_ctx.super = *v; + storage->vlast = &mstorage->module_ctx.super; + v->destroy = pop3_migration_mail_storage_destroy; + + mstorage->pop3_box_vname = p_strdup(storage->pool, pop3_box_vname); + mstorage->all_mailboxes = + mail_user_plugin_getenv_bool(storage->user, + "pop3_migration_all_mailboxes"); + mstorage->ignore_missing_uidls = + mail_user_plugin_getenv_bool(storage->user, + "pop3_migration_ignore_missing_uidls"); + mstorage->ignore_extra_uidls = + mail_user_plugin_getenv_bool(storage->user, + "pop3_migration_ignore_extra_uidls"); + mstorage->skip_size_check = + mail_user_plugin_getenv_bool(storage->user, + "pop3_migration_skip_size_check"); + mstorage->skip_uidl_cache = + mail_user_plugin_getenv_bool(storage->user, + "pop3_migration_skip_uidl_cache"); + + MODULE_CONTEXT_SET(storage, pop3_migration_storage_module, mstorage); +} + +static struct mail_storage_hooks pop3_migration_mail_storage_hooks = { + .mail_allocated = pop3_migration_mail_allocated, + .mailbox_allocated = pop3_migration_mailbox_allocated, + .mail_storage_created = pop3_migration_mail_storage_created +}; + +void pop3_migration_plugin_init(struct module *module) +{ + mail_storage_hooks_add(module, &pop3_migration_mail_storage_hooks); +} + +void pop3_migration_plugin_deinit(void) +{ + mail_storage_hooks_remove(&pop3_migration_mail_storage_hooks); +} diff --git a/src/plugins/pop3-migration/pop3-migration-plugin.h b/src/plugins/pop3-migration/pop3-migration-plugin.h new file mode 100644 index 0000000..1dc84e0 --- /dev/null +++ b/src/plugins/pop3-migration/pop3-migration-plugin.h @@ -0,0 +1,13 @@ +#ifndef POP3_MIGRATION_PLUGIN_H +#define POP3_MIGRATION_PLUGIN_H + +struct module; + +void pop3_migration_plugin_init(struct module *module); +void pop3_migration_plugin_deinit(void); + +int pop3_migration_get_hdr_sha1(uint32_t mail_seq, struct istream *input, + unsigned char sha1_r[STATIC_ARRAY SHA1_RESULTLEN], + bool *have_eoh_r); + +#endif diff --git a/src/plugins/pop3-migration/test-pop3-migration-plugin.c b/src/plugins/pop3-migration/test-pop3-migration-plugin.c new file mode 100644 index 0000000..f8e52d8 --- /dev/null +++ b/src/plugins/pop3-migration/test-pop3-migration-plugin.c @@ -0,0 +1,63 @@ +/* Copyright (c) 2015-2018 Dovecot authors, see the included COPYING file */ + +#include "lib.h" +#include "sha1.h" +#include "hex-binary.h" +#include "istream.h" +#include "test-common.h" +#include "pop3-migration-plugin.h" + +static void test_pop3_migration_get_hdr_sha1(void) +{ + static const struct { + const char *input; + const char *sha1; + bool have_eoh; + } tests[] = { + { "", "da39a3ee5e6b4b0d3255bfef95601890afd80709", FALSE }, + { "\n", "adc83b19e793491b1c6ea0fd8b46cd9f32e592fc", TRUE }, + { "a: \r\n", "a3871371f2d468493005286282ae10549dab2c57", FALSE }, + { "a: b\r\n", "44ef6a20971148dd54a161f79814e22e2d098ddb", FALSE }, + { "a: b \r\n", "44ef6a20971148dd54a161f79814e22e2d098ddb", FALSE }, + { "a: b \r\n", "44ef6a20971148dd54a161f79814e22e2d098ddb", FALSE }, + { "a: b \r\n", "44ef6a20971148dd54a161f79814e22e2d098ddb", FALSE }, + { "a: b\r\n\r\n", "938b96404495cced816e3a4f6031734eab4e71b3", TRUE }, + { "a: b\r\n\r\r\n", "44ef6a20971148dd54a161f79814e22e2d098ddb", FALSE }, + { "a: b\r\n\r\r\nc: d\r\n\r\n", "44ef6a20971148dd54a161f79814e22e2d098ddb", TRUE }, + { "a: b\r\n \r\n", "44ef6a20971148dd54a161f79814e22e2d098ddb", FALSE }, + { "a: b\r\n \r\n", "44ef6a20971148dd54a161f79814e22e2d098ddb", FALSE }, + { "a: b\r\n\t\r\n", "44ef6a20971148dd54a161f79814e22e2d098ddb", FALSE }, + { "a: b\t\t\t\t\r\n", "44ef6a20971148dd54a161f79814e22e2d098ddb", FALSE }, + { "a: b\nfoo\n", "44ef6a20971148dd54a161f79814e22e2d098ddb", FALSE }, + + { "a: b\nc: d\n", "4dbea2c1bdd1323e15931382c1835200d9286230", FALSE }, + { "a:b\nc:d\n", "4dbea2c1bdd1323e15931382c1835200d9286230", FALSE }, + { "a: b\nfoo\nc: d\n", "4dbea2c1bdd1323e15931382c1835200d9286230", FALSE }, + }; + struct istream *input; + unsigned char digest[SHA1_RESULTLEN]; + unsigned int i; + bool have_eoh; + + test_begin("pop3 migration get hdr sha1"); + + for (i = 0; i < N_ELEMENTS(tests); i++) { + input = i_stream_create_from_data(tests[i].input, + strlen(tests[i].input)); + test_assert_idx(pop3_migration_get_hdr_sha1(1, input, digest, &have_eoh) == 0, i); + test_assert_idx(strcasecmp(binary_to_hex(digest, sizeof(digest)), tests[i].sha1) == 0, i); + test_assert_idx(tests[i].have_eoh == have_eoh, i); + i_stream_unref(&input); + } + + test_end(); +} + +int main(void) +{ + static void (*const test_functions[])(void) = { + test_pop3_migration_get_hdr_sha1, + NULL + }; + return test_run(test_functions); +} |