+dnl -----------------
+dnl CHECK FOR CURL
+dnl -----------------
+dnl Look for curl if oauth not disabled (--without-oauth).
+AC_PATH_PROG([curl_config], [curl-config])
+AS_IF([test "x$with_oauth" != xno && test -n "$curl_config"], [
+ save_CFLAGS="$CFLAGS"
+ CFLAGS="$AM_CPPFLAGS $AM_CFLAGS $CFLAGS `$curl_config --cflags`"
+ AC_CHECK_HEADER([curl/curl.h], [
+ HAVE_CURL_H=1
+ AC_CHECK_LIB([curl], [curl_easy_init], [
+ CURLLIB="`$curl_config --libs`"
+ AC_SUBST([CURLLIB])
+ CURL_USER_AGENT="`$curl_config --version | sed 's|^libcurl *|libcurl/|; q'`"
+ AS_IF([test "x$CURL_USER_AGENT" != "x`echo $CURL_USER_AGENT | sed 's/ //'`"],
+ [AC_MSG_WARN([unexpected curl-config --version: $CURL_USER_AGENT])
+ CURL_USER_AGENT=libcurl/UNKNOWN])
+ AC_SUBST([CURL_USER_AGENT])
+ ])
+ ])
+ CFLAGS="$save_CFLAGS"
+ ])
+
+dnl -----------------
+dnl Enable OAuth?
+dnl -----------------
+dnl By default (with_oauth=''), enable OAuth if curl is found.
+dnl If OAuth requested (--with-oauth with_oauth=yes), error if curl not found.
+dnl If OAuth disabled (--without-oauth with_oauth=no), don't enable it.
+oauth_support=no
+OAUTH_SUPPORT=0
+AC_SUBST([OAUTH_SUPPORT])
+AS_IF([test "x$with_oauth" = xyes && test "x$HAVE_CURL_H" = x],
+ [AC_MSG_ERROR([OAuth requested but curl/curl.h not found])],
+ [test "x$with_oauth" = xyes && test "x$CURLLIB" = x],
+ [AC_MSG_ERROR([OAuth requested but curl library not found])],
+ [test "x$with_oauth" != xno && test "x$HAVE_CURL_H" = x1 && test "x$CURLLIB" != x],
+ [AC_DEFINE([OAUTH_SUPPORT], [1], [Support OAuth2 in SMTP auth.])
+ OAUTH_SUPPORT=1
+ oauth_support=yes])
+
+dnl ----------------
+dnl CHECK FLEX FIXUP
+dnl ----------------
+dnl Use AM_LFLAGS make variable setting to work around bugs in flex
+dnl 2.5.36-37 that cause signed/unsigned mismatch,
+dnl http://sourceforge.net/p/flex/bugs/140/
+dnl 2.6.1 bug: https://github.com/westes/flex/issues/97
+AS_IF([test "$LEX" = flex],
+ [AS_CASE([`$LEX -V`],
+ [flex\ 2.5.35], [AM_LFLAGS=\
+'; sed "s/ int n;/ size_t n;/" $@ >$@.tmp && mv -f $@.tmp $@;'],
+ [flex\ 2.5.3[[67]]], [AM_LFLAGS=\
+'; sed "s/\( \)int i;/\1yy_size_t i;/" $@ >$@.tmp && mv -f $@.tmp $@;'],
+ [flex\ 2.6.0], [AM_LFLAGS=\
+'; sed "s/, num_to_read/, (size_t) num_to_read/" $@ >$@.tmp && mv -f $@.tmp $@;'],
+ [flex\ 2.6.1], [AM_LFLAGS=\
+'; sed '\''/\<int num_to_read\>/s/int/size_t/; \
+ s/\<yy_size_t i\>/int i/; \
+ s/int n; \\/yy_size_t n; \\/'\'' $@ >$@.tmp && mv -f $@.tmp $@;'])
+ AC_SUBST([AM_LFLAGS])])
+
+dnl ------------------
+dnl By default we put backend executables in $(libexecdir)/nmh and
+dnl configuration files in $(sysconfdir)/nmh, but let a user override
+dnl these choices by supplying these variables
+dnl ------------------
+
+AC_ARG_VAR([nmhlibexecdir], [The installation directory for backend programs
+used by nmh. Defaults to $(libexecdir)/nmh.])
+AS_IF([test -z ${nmhlibexecdir+x}], [nmhlibexecdir='${libexecdir}/nmh'])
+
+AC_ARG_VAR([nmhetcdir], [The installation directory for configuration files
+used by nmh. Defaults to $(sysconfdir)/nmh.])
+AS_IF([test -z ${nmhetcdir+x}], [nmhetcdir='${sysconfdir}/nmh'])
+
+dnl ------------------
+dnl FOR INTERNAL USE by the NMH test suite
+dnl ------------------
+AC_ARG_VAR([NMHETCDIRINST], [for internal use by nmh test suite])
+AS_IF([test -n "$NMHETCDIRINST"], [nmhetcdirinst=$NMHETCDIRINST]
+ AC_SUBST([nmhetcdirinst]))