From 98db04185c3a53bd354e294815c546cff215f169 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Wed, 15 Mar 2017 12:43:48 -0700
Subject: [PATCH 1/2] Drop POP from movemail

These days it's almost malpractice to ship an email client
that supports only unencrypted protocols.  Ask POP3 users
to use GNU Mailutils movemail instead, as it supports TLS.
* INSTALL: Mention Mailutils.
* admin/CPP-DEFINES: Remove symbols no longer needed.
* configure.ac (--with-pop, --with-kerberos, --with-kerberos5)
(--with-hesiod, --with-mailhost, MAIL_USE_POP, KERBEROS, KERBEROS5)
(HESIOD, MAILHOST, LIBHESIOD, LIBRESOLV, RESOLVLIB, COM_ERRLOIB)
(CRYPTOLIB, KRB5LIB, DESLIB, KRB4LIB, HAVE_KERBEROSIV_KRB_H)
(HAVE_KERBEROS_KRB_H, HAVE_KRB5_ERROR_E_TEXT)
(HAVE_KRB5_ERROR_TEXT, HAVE_KRB5_H, HAVE_KRB_H):
Remove.  All uses removed.
* doc/emacs/rmail.texi (Movemail, Remove Mailboxes):
Remove documentation of POP3 with Emacs movemail, since such
usage now requires Mailutils movemail.
* etc/NEWS: Mention this installation change.
* etc/PROBLEMS: Simplify.
* lib-src/Makefile.in (KRB4LIB, DESLIB, KRB5LIB, CRYPTOLIB)
(COM_ERRLIB, LIBHESIOD, LIBRESOLV, pop.o):
Remove.  All uses removed.
* lib-src/movemail.c [MAIL_USE_POP]:
Remove all code depending on this symbol.
* lib-src/pop.c, lib-src/pop.h: Remove.
* lisp/mail/rmail.el (rmail-parse-url):
Do not assume that Emacs movemail supports POP3.
---
 INSTALL              |    9 +-
 admin/CPP-DEFINES    |    7 -
 configure.ac         |  134 ----
 doc/emacs/rmail.texi |   24 +-
 etc/NEWS             |    6 +
 etc/PROBLEMS         |    9 -
 lib-src/Makefile.in  |   24 +-
 lib-src/movemail.c   |  363 +----------
 lib-src/pop.c        | 1699 --------------------------------------------------
 lib-src/pop.h        |   75 ---
 lisp/mail/rmail.el   |    7 +-
 11 files changed, 22 insertions(+), 2335 deletions(-)
 delete mode 100644 lib-src/pop.c
 delete mode 100644 lib-src/pop.h

diff --git a/INSTALL b/INSTALL
index 10b1756..647f72e 100644
--- a/INSTALL
+++ b/INSTALL
@@ -259,12 +259,9 @@ inconvenient for Emacs when running as daemon or running via a remote
 ssh connection.  In order to completely prevent the use of D-Bus, configure
 Emacs with the options '--without-dbus --without-gconf --without-gsettings'.
 
-The Emacs mail reader RMAIL is configured to be able to read mail from
-a POP3 server by default.  Versions of the POP protocol older than
-POP3 are not supported.  For Kerberos-authenticated POP add
-'--with-kerberos', for Hesiod support add '--with-hesiod'.  While POP3
-is always enabled, whether Emacs actually uses POP is controlled by
-individual users--see the Rmail chapter of the Emacs manual.
+To read email via a network protocol like IMAP or POP, you can
+download, build, and install the GNU Mailutils package, so that Emacs
+can use Mailutils 'movemail' program to retrieve mail.
 
 For image support you may have to download, build, and install the
 appropriate image support libraries for image types other than XBM and
diff --git a/admin/CPP-DEFINES b/admin/CPP-DEFINES
index cead305..c146e0b 100644
--- a/admin/CPP-DEFINES
+++ b/admin/CPP-DEFINES
@@ -186,12 +186,6 @@ HAVE_IMAGEMAGICK
 HAVE_INET_SOCKETS
 HAVE_INTTYPES_H
 HAVE_JPEG
-HAVE_KERBEROSIV_KRB_H
-HAVE_KERBEROS_KRB_H
-HAVE_KRB5_ERROR_E_TEXT
-HAVE_KRB5_ERROR_TEXT
-HAVE_KRB5_H
-HAVE_KRB_H
 HAVE_LANGINFO_CODESET
 HAVE_LIBDGC
 HAVE_LIBKSTAT
@@ -364,7 +358,6 @@ IS_ANY_SEP
 IS_DIRECTORY_SEP
 MAIL_USE_FLOCK
 MAIL_USE_LOCKF
-MAIL_USE_POP
 MAIL_USE_SYSTEM_LOCK
 MAXPATHLEN
 NLIST_STRUCT
diff --git a/configure.ac b/configure.ac
index 4d9ba96..f7d44df 100644
--- a/configure.ac
+++ b/configure.ac
@@ -240,44 +240,11 @@ AC_DEFUN
    m4_bpatsubst([with_$1], [[^0-9a-z]], [_])=$with_features])dnl
 ])dnl
 
-OPTION_DEFAULT_ON([pop],[don't support POP mail retrieval with movemail])
-if test "$with_pop" = yes; then
-   AC_DEFINE(MAIL_USE_POP)
-fi
-AH_TEMPLATE(MAIL_USE_POP, [Define to support POP mail retrieval.])dnl
-
-OPTION_DEFAULT_OFF([kerberos],[support Kerberos-authenticated POP])
-if test "$with_kerberos" != no; then
-   AC_DEFINE(KERBEROS)
-fi
-AH_TEMPLATE(KERBEROS,
-	    [Define to support Kerberos-authenticated POP mail retrieval.])dnl
-
-OPTION_DEFAULT_OFF([kerberos5],[support Kerberos version 5 authenticated POP])
-if test "${with_kerberos5}" != no; then
-  if test "${with_kerberos}" = no; then
-    with_kerberos=yes
-    AC_DEFINE(KERBEROS)
-  fi
-  AC_DEFINE(KERBEROS5, 1, [Define to use Kerberos 5 instead of Kerberos 4.])
-fi
-
-OPTION_DEFAULT_OFF([hesiod],[support Hesiod to get the POP server host])
-dnl FIXME hesiod support may not be present, so it seems like an error
-dnl to define, or at least use, this unconditionally.
-if test "$with_hesiod" != no; then
-  AC_DEFINE(HESIOD, 1, [Define to support using a Hesiod database to find the POP server.])
-fi
-
 OPTION_DEFAULT_OFF([mail-unlink],[unlink, rather than empty, mail spool after reading])
 if test "$with_mail_unlink" != no; then
    AC_DEFINE(MAIL_UNLINK_SPOOL, 1, [Define to unlink, rather than empty, mail spool after reading.])
 fi
 
-AC_ARG_WITH([mailhost],[AS_HELP_STRING([--with-mailhost=HOSTNAME],
-    [string giving default POP mail host])],
-    AC_DEFINE_UNQUOTED(MAILHOST, ["$withval"], [String giving fallback POP mail host.]))
-
 AC_ARG_WITH([sound],[AS_HELP_STRING([--with-sound=VALUE],
   [compile with sound support (VALUE one of: yes, alsa, oss, bsd-ossaudio, no;
 default yes).  Only for GNU/Linux, FreeBSD, NetBSD, MinGW, Cygwin.])],
@@ -4064,107 +4031,6 @@ AC_DEFUN
      [emacs_cv_alternate_stack=yes],
      [emacs_cv_alternate_stack=no])])
 
-# Do we need the Hesiod library to provide the support routines?
-dnl FIXME?  Should we be skipping this on Darwin too?
-LIBHESIOD=
-LIBRESOLV=
-if test "$with_hesiod" != no ; then
-  # Don't set $LIBS here -- see comments above.  FIXME which comments?
-  resolv=no
-  AC_CHECK_FUNC(res_send, , [AC_CHECK_FUNC(__res_send, ,
-     [AC_CHECK_LIB(resolv, res_send, resolv=yes,
-		  [AC_CHECK_LIB(resolv, __res_send, resolv=yes)])])])
-  if test "$resolv" = yes ; then
-    RESOLVLIB=-lresolv
-  else
-    RESOLVLIB=
-  fi
-  hesiod=no
-  AC_CHECK_FUNC(hes_getmailhost, , [AC_CHECK_LIB(hesiod, hes_getmailhost,
-	hesiod=yes, :, $RESOLVLIB)])
-
-  if test x"$hesiod" = xyes; then
-    LIBHESIOD=-lhesiod
-    LIBRESOLV=$RESOLVLIB
-  fi
-fi
-AC_SUBST(LIBHESIOD)
-AC_SUBST(LIBRESOLV)
-
-# These tell us which Kerberos-related libraries to use.
-COM_ERRLIB=
-CRYPTOLIB=
-KRB5LIB=
-DESLIB=
-KRB4LIB=
-
-if test "${with_kerberos}" != no; then
-  OLD_LIBS=$LIBS
-  AC_CHECK_LIB(com_err, com_err, have_com_err=yes, have_com_err=no)
-  if test $have_com_err = yes; then
-    COM_ERRLIB=-lcom_err
-    LIBS="$COM_ERRLIB $LIBS"
-  fi
-  AC_CHECK_LIB(crypto, mit_des_cbc_encrypt, have_crypto=yes, have_crypto=no)
-  if test $have_crypto = yes; then
-    CRYPTOLIB=-lcrypto
-    LIBS="$CRYPTOLIB $LIBS"
-  fi
-  AC_CHECK_LIB(k5crypto, mit_des_cbc_encrypt, have_k5crypto=yes, have_k5crypto=no)
-  if test $have_k5crypto = yes; then
-    CRYPTOLIB=-lk5crypto
-    LIBS="$CRYPTOLIB $LIBS"
-  fi
-  AC_CHECK_LIB(krb5, krb5_init_context, have_krb5=yes, have_krb5=no)
-  if test $have_krb5=yes; then
-    KRB5LIB=-lkrb5
-    LIBS="$KRB5LIB $LIBS"
-  fi
-  dnl FIXME Simplify.  Does not match 22 logic, thanks to default_off?
-  if test "${with_kerberos5}" = no; then
-    AC_CHECK_LIB(des425, des_cbc_encrypt, have_des425=yes, have_des425=no )
-    if test $have_des425 = yes; then
-      DESLIB=-ldes425
-      LIBS="$DESLIB $LIBS"
-    else
-      AC_CHECK_LIB(des, des_cbc_encrypt, have_des=yes, have_des=no)
-      if test $have_des = yes; then
-        DESLIB=-ldes
-        LIBS="$DESLIB $LIBS"
-      fi
-    fi
-    AC_CHECK_LIB(krb4, krb_get_cred, have_krb4=yes, have_krb4=no)
-    if test $have_krb4 = yes; then
-      KRB4LIB=-lkrb4
-      LIBS="$KRB4LIB $LIBS"
-    else
-      AC_CHECK_LIB(krb, krb_get_cred, have_krb=yes, have_krb=no)
-      if test $have_krb = yes; then
-        KRB4LIB=-lkrb
-        LIBS="$KRB4LIB $LIBS"
-      fi
-    fi
-  fi
-
-  if test "${with_kerberos5}" != no; then
-    AC_CHECK_HEADERS(krb5.h,
-      [AC_CHECK_MEMBERS([krb5_error.text, krb5_error.e_text],,,
-		        [#include <krb5.h>])])
-  else
-    AC_CHECK_HEADERS(krb.h,,
-		     [AC_CHECK_HEADERS(kerberosIV/krb.h,,
-				       [AC_CHECK_HEADERS(kerberos/krb.h)])])
-  fi
-  AC_CHECK_HEADERS(com_err.h)
-  LIBS=$OLD_LIBS
-fi
-
-AC_SUBST(COM_ERRLIB)
-AC_SUBST(CRYPTOLIB)
-AC_SUBST(KRB5LIB)
-AC_SUBST(DESLIB)
-AC_SUBST(KRB4LIB)
-
 AC_CHECK_HEADERS(valgrind/valgrind.h)
 
 AC_CHECK_MEMBERS([struct unipair.unicode], [], [], [[#include <linux/kd.h>]])
diff --git a/doc/emacs/rmail.texi b/doc/emacs/rmail.texi
index d463982..a810eac 100644
--- a/doc/emacs/rmail.texi
+++ b/doc/emacs/rmail.texi
@@ -1387,8 +1387,7 @@ Movemail
 Mailutils version offers additional features.
 
   The Emacs version of @code{movemail} is able to retrieve mail from
-the usual Unix mailbox formats and from remote mailboxes using the
-POP3 protocol.
+the usual Unix mailbox formats.
 
   The Mailutils version is able to handle a wide set of mailbox
 formats, such as plain Unix mailboxes, @code{maildir} and @code{MH}
@@ -1483,19 +1482,14 @@ Remote Mailboxes
 @pindex movemail
 
   Some sites use a method called POP for accessing users' inbox data
-instead of storing the data in inbox files.  By default, the @code{Emacs
-movemail} can work with POP (unless the Emacs @code{configure} script
-was run with the option @samp{--without-pop}).
-
-Similarly, the Mailutils @code{movemail} by default supports POP, unless
-it was configured with the @samp{--disable-pop} option.
-
-Both versions of @code{movemail} only work with POP3, not with older
-versions of POP.
+instead of storing the data in inbox files.  The Mailutils
+@code{movemail} by default supports POP, unless it was configured with
+the @samp{--disable-pop} option.  It works only with POP3, not with
+older versions of POP.
 
 @cindex @env{MAILHOST} environment variable
 @cindex POP mailboxes
-  No matter which flavor of @code{movemail} you use, you can specify
+  You can specify
 a POP inbox by using a POP @dfn{URL} (@pxref{Movemail}).  A POP
 @acronym{URL} is of the form
 @samp{pop://@var{username}@@@var{hostname}}, where
@@ -1514,8 +1508,6 @@ Remote Mailboxes
 @var{:hostname} part, the @env{MAILHOST} environment variable specifies
 the machine on which to look for the POP server.
 
-@c FIXME mention --with-hesiod "support Hesiod to get the POP server host"?
-
 @cindex IMAP mailboxes
   Another method for accessing remote mailboxes is IMAP@.  This method is
 supported only by the Mailutils @code{movemail}.  To specify an IMAP
@@ -1550,9 +1542,7 @@ Remote Mailboxes
 
 @cindex Kerberos POP authentication
   The @code{movemail} program installed at your site may support
-Kerberos authentication (the Emacs @code{movemail} does so if Emacs was
-configured with the option @code{--with-kerberos} or
-@code{--with-kerberos5}).  If it is supported, it is used by default
+Kerberos authentication.  If it is supported, it is used by default
 whenever you attempt to retrieve POP mail when
 @code{rmail-remote-password} and @code{rmail-remote-password-required}
 are unset.
diff --git a/etc/NEWS b/etc/NEWS
index e1b6249..50efac9 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -37,6 +37,12 @@ Use 'configure --with-gnutls=no' to build even when GnuTLS is missing.
 ** GnuTLS version 2.12.2 or later is now required, instead of merely
 version 2.6.6 or later.
 
+** The Emacs-supplied 'movemail' program no longer supports the
+unencrypted POP3 protocol, as it too often is a security risk.  To
+read mail via POP3, please use GNU Mailutils 'movemail' instead; it
+supports POP3 via Transport Layer Security (TLS), which is generally
+recommended over unencrypted POP3.
+
 ** The new option 'configure --enable-gcc-warnings=warn-only' causes
 GCC to issue warnings without stopping the build.  This behavior is
 now the default in developer builds.  As before, use
diff --git a/etc/PROBLEMS b/etc/PROBLEMS
index b892320..d37b364 100644
--- a/etc/PROBLEMS
+++ b/etc/PROBLEMS
@@ -321,15 +321,6 @@ or set the variable 'cannot-suspend' to a non-nil value.
 
 ** Mailers and other helper programs
 
-*** movemail compiled with POP support can't connect to the POP server.
-
-Make sure that the 'pop' entry in /etc/services, or in the services
-NIS map if your machine uses NIS, has the same port number as the
-entry on the POP server.  A common error is for the POP server to be
-listening on port 110, the assigned port for the POP3 protocol, while
-the client is trying to connect on port 109, the assigned port for the
-old POP protocol.
-
 *** RMAIL gets error getting new mail.
 
 RMAIL gets new mail from /usr/spool/mail/$USER using a program
diff --git a/lib-src/Makefile.in b/lib-src/Makefile.in
index d0aa9cc..d78e20e 100644
--- a/lib-src/Makefile.in
+++ b/lib-src/Makefile.in
@@ -182,20 +182,6 @@ MOVE_FLAGS=
 ## Empty if either MAIL_USE_FLOCK or MAIL_USE_LOCKF, else need-blessmail.
 BLESSMAIL_TARGET=@BLESSMAIL_TARGET@
 
-## -lkrb or -lkrb4 if needed
-KRB4LIB=@KRB4LIB@
-## -ldes or -ldes425 if needed
-DESLIB=@DESLIB@
-## -lkrb5 if needed
-KRB5LIB=@KRB5LIB@
-## -lk5crypto or -lcrypto if needed
-CRYPTOLIB=@CRYPTOLIB@
-## -lcom_err if needed
-COM_ERRLIB=@COM_ERRLIB@
-## -lhesiod if needed
-LIBHESIOD=@LIBHESIOD@
-## -lresolv if HAVE_LIBRESOLV
-LIBRESOLV=@LIBRESOLV@
 ## -llockfile if HAVE_LIBLOCKFILE or -lmail if HAVE_LIBMAIL
 LIBS_MAIL=@LIBS_MAIL@
 ## empty or -lrt or -lposix4 if HAVE_CLOCK_GETTIME
@@ -206,8 +192,7 @@ LIB_FDATASYNC =
 LIB_WSOCK32=@LIB_WSOCK32@
 
 ## Extra libraries to use when linking movemail.
-LIBS_MOVE = $(LIBS_MAIL) $(KRB4LIB) $(DESLIB) $(KRB5LIB) $(CRYPTOLIB) \
-            $(COM_ERRLIB) $(LIBHESIOD) $(LIBRESOLV) $(LIB_WSOCK32)
+LIBS_MOVE = $(LIBS_MAIL)
 
 ## Extra libraries when linking emacsclient
 ## (empty or -lcomctl32 for MinGW)
@@ -381,13 +366,10 @@ profile${EXEEXT}:
 make-docfile${EXEEXT}: ${srcdir}/make-docfile.c $(NTLIB) $(config_h)
 	$(AM_V_CCLD)$(CC) ${ALL_CFLAGS} $< $(NTLIB) $(LOADLIBES) -o $@
 
-movemail${EXEEXT}: ${srcdir}/movemail.c pop.o $(NTLIB) $(config_h)
-	$(AM_V_CCLD)$(CC) ${ALL_CFLAGS} ${MOVE_FLAGS} $< pop.o \
+movemail${EXEEXT}: ${srcdir}/movemail.c $(NTLIB) $(config_h)
+	$(AM_V_CCLD)$(CC) ${ALL_CFLAGS} ${MOVE_FLAGS} $< \
 	  $(NTLIB) $(LOADLIBES) $(LIBS_MOVE) -o $@
 
-pop.o: ${srcdir}/pop.c ${srcdir}/pop.h ${srcdir}/../lib/min-max.h $(config_h)
-	$(AM_V_CC)$(CC) -c ${CPP_CFLAGS} ${MOVE_FLAGS} $<
-
 emacsclient${EXEEXT}: ${srcdir}/emacsclient.c $(NTLIB) $(config_h)
 	$(AM_V_CCLD)$(CC) ${ALL_CFLAGS} $< \
 	   -DVERSION="\"${version}\"" $(NTLIB) $(LOADLIBES) $(LIB_FDATASYNC) \
diff --git a/lib-src/movemail.c b/lib-src/movemail.c
index cd12c48..5de3cf3 100644
--- a/lib-src/movemail.c
+++ b/lib-src/movemail.c
@@ -32,29 +32,6 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
    that permit everyone to write lockfiles in it, or you must make movemail
    a setuid or setgid program.  */
 
-/*
- * Modified January, 1986 by Michael R. Gretzinger (Project Athena)
- *
- * Added POP (Post Office Protocol) service.  When compiled -DMAIL_USE_POP
- * movemail will accept input filename arguments of the form
- * "po:username".  This will cause movemail to open a connection to
- * a pop server running on $MAILHOST (environment variable).  Movemail
- * must be setuid to root in order to work with POP.
- *
- * New module: popmail.c
- * Modified routines:
- *	main - added code within #ifdef MAIL_USE_POP; added setuid (getuid ())
- *		after POP code.
- * New routines in movemail.c:
- *	get_errmsg - return pointer to system error message
- *
- * Modified August, 1993 by Jonathan Kamens (OpenVision Technologies)
- *
- * Move all of the POP code into a separate file, "pop.c".
- * Use strerror instead of get_errmsg.
- *
- */
-
 #include <config.h>
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -70,9 +47,6 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #include <signal.h>
 #include <string.h>
 #include "syswait.h"
-#ifdef MAIL_USE_POP
-#include "pop.h"
-#endif
 
 #ifdef MSDOS
 #undef access
@@ -131,13 +105,6 @@ static _Noreturn void fatal (const char *s1, const char *s2, const char *s3);
 static void error (const char *s1, const char *s2, const char *s3);
 static _Noreturn void pfatal_with_name (char *name);
 static _Noreturn void pfatal_and_delete (char *name);
-#ifdef MAIL_USE_POP
-static int popmail (char *, char *, bool, char *, bool);
-static bool pop_retr (popserver, int, FILE *);
-static bool mbx_write (char *, int, FILE *);
-static bool mbx_delimit_begin (FILE *);
-static bool mbx_delimit_end (FILE *);
-#endif
 
 #if (defined MAIL_USE_MAILLOCK						\
      || (!defined DISABLE_DIRECT_ACCESS && !defined MAIL_USE_SYSTEM_LOCK))
@@ -174,26 +141,14 @@ main (int argc, char **argv)
   int desc;
 #endif /* not MAIL_USE_SYSTEM_LOCK */
 
-#ifdef MAIL_USE_POP
-  bool pop_reverse_order = false;
-# define ARGSTR "pr"
-#else /* ! MAIL_USE_POP */
-# define ARGSTR "p"
-#endif /* MAIL_USE_POP */
-
   uid_t real_gid = getgid ();
   uid_t priv_gid = getegid ();
 
   delete_lockname = 0;
 
-  while (0 <= (c = getopt (argc, argv, ARGSTR)))
+  while (0 <= (c = getopt (argc, argv, "p")))
     {
       switch (c) {
-#ifdef MAIL_USE_POP
-      case 'r':
-	pop_reverse_order = true;
-	break;
-#endif
       case 'p':
 	preserve_mail = true;
 	break;
@@ -202,20 +157,9 @@ main (int argc, char **argv)
       }
     }
 
-  if (
-#ifdef MAIL_USE_POP
-      (argc - optind < 2) || (argc - optind > 3)
-#else
-      (argc - optind != 2)
-#endif
-      )
+  if (argc - optind != 2)
     {
-#ifdef MAIL_USE_POP
-      fprintf (stderr, "Usage: movemail [-p] [-r] inbox destfile%s\n",
-	       " [POP-password]");
-#else
       fprintf (stderr, "Usage: movemail [-p] inbox destfile%s\n", "");
-#endif
       return EXIT_FAILURE;
     }
 
@@ -225,22 +169,6 @@ main (int argc, char **argv)
   if (*outname == 0)
     fatal ("Destination file name is empty", 0, 0);
 
-#ifdef MAIL_USE_POP
-  if (!strncmp (inname, "po:", 3))
-    {
-      int status;
-
-      status = popmail (inname + 3, outname, preserve_mail,
-			(argc - optind == 3) ? argv[optind+2] : NULL,
-			pop_reverse_order);
-      return status;
-    }
-
-  if (setuid (getuid ()) < 0)
-    fatal ("Failed to drop privileges", 0, 0);
-
-#endif /* MAIL_USE_POP */
-
 #ifndef DISABLE_DIRECT_ACCESS
 
   char *lockname = 0;
@@ -582,290 +510,3 @@ pfatal_and_delete (char *name)
   unlink (name);
   fatal ("%s for %s", s, name);
 }
-
-/* This is the guts of the interface to the Post Office Protocol.  */
-
-#ifdef MAIL_USE_POP
-
-#ifndef WINDOWSNT
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <netdb.h>
-#else
-#undef _WINSOCKAPI_
-#include <winsock.h>
-#endif
-#include <pwd.h>
-#include <string.h>
-
-/*
- * The full valid syntax for a POP mailbox specification for movemail
- * is "po:username:hostname".  The ":hostname" is optional; if it is
- * omitted, the MAILHOST environment variable will be consulted.  Note
- * that by the time popmail() is called the "po:" has been stripped
- * off of the front of the mailbox name.
- *
- * If the mailbox is in the form "po:username:hostname", then it is
- * modified by this function -- the second colon is replaced by a
- * null.
- *
- * Return a value suitable for passing to `exit'.
- */
-
-static int
-popmail (char *mailbox, char *outfile, bool preserve, char *password,
-	 bool reverse_order)
-{
-  int nmsgs, nbytes;
-  int i;
-  int mbfi;
-  FILE *mbf;
-  popserver server;
-  int start, end, increment;
-  char *user, *hostname;
-
-  user = mailbox;
-  if ((hostname = strchr (mailbox, ':')))
-    *hostname++ = '\0';
-
-  server = pop_open (hostname, user, password, POP_NO_GETPASS);
-  if (! server)
-    {
-      error ("Error connecting to POP server: %s", pop_error, 0);
-      return EXIT_FAILURE;
-    }
-
-  if (pop_stat (server, &nmsgs, &nbytes))
-    {
-      error ("Error getting message count from POP server: %s", pop_error, 0);
-      return EXIT_FAILURE;
-    }
-
-  if (!nmsgs)
-    {
-      pop_close (server);
-      return EXIT_SUCCESS;
-    }
-
-  mbfi = open (outfile, O_WRONLY | O_BINARY | O_CREAT | O_EXCL, 0666);
-  if (mbfi < 0)
-    {
-      pop_close (server);
-      error ("Error in open: %s, %s", strerror (errno), outfile);
-      return EXIT_FAILURE;
-    }
-
-  if (fchown (mbfi, getuid (), -1) != 0)
-    {
-      int fchown_errno = errno;
-      struct stat st;
-      if (fstat (mbfi, &st) != 0 || st.st_uid != getuid ())
-	{
-	  pop_close (server);
-	  error ("Error in fchown: %s, %s", strerror (fchown_errno), outfile);
-	  return EXIT_FAILURE;
-	}
-    }
-
-  mbf = fdopen (mbfi, "wb");
-  if (!mbf)
-    {
-      pop_close (server);
-      error ("Error in fdopen: %s", strerror (errno), 0);
-      close (mbfi);
-      unlink (outfile);
-      return EXIT_FAILURE;
-    }
-
-  if (reverse_order)
-    {
-      start = nmsgs;
-      end = 1;
-      increment = -1;
-    }
-  else
-    {
-      start = 1;
-      end = nmsgs;
-      increment = 1;
-    }
-
-  for (i = start; i * increment <= end * increment; i += increment)
-    if (! (mbx_delimit_begin (mbf)
-	   && pop_retr (server, i, mbf)
-	   && mbx_delimit_end (mbf)
-	   && fflush (mbf) == 0))
-      {
-	if (errno)
-	  error ("Error in POP retrieving: %s", strerror (errno), 0);
-	pop_close (server);
-	fclose (mbf);
-	return EXIT_FAILURE;
-      }
-
-  if (fsync (mbfi) != 0 && errno != EINVAL)
-    {
-      error ("Error in fsync: %s", strerror (errno), 0);
-      fclose (mbf);
-      return EXIT_FAILURE;
-    }
-
-  if (fclose (mbf) != 0)
-    {
-      error ("Error in fclose: %s", strerror (errno), 0);
-      return EXIT_FAILURE;
-    }
-
-  if (! preserve)
-    for (i = 1; i <= nmsgs; i++)
-      {
-	if (pop_delete (server, i))
-	  {
-	    error ("Error from POP server: %s", pop_error, 0);
-	    pop_close (server);
-	    return EXIT_FAILURE;
-	  }
-      }
-
-  if (pop_quit (server))
-    {
-      error ("Error from POP server: %s", pop_error, 0);
-      return EXIT_FAILURE;
-    }
-
-  return EXIT_SUCCESS;
-}
-
-static bool
-pop_retr (popserver server, int msgno, FILE *arg)
-{
-  char *line;
-  int ret;
-
-  if (pop_retrieve_first (server, msgno, &line))
-    {
-      error ("Error from POP server: %s", pop_error, 0);
-      errno = 0;
-      return false;
-    }
-
-  while ((ret = pop_retrieve_next (server, &line)) >= 0)
-    {
-      if (! line)
-	break;
-
-      if (! mbx_write (line, ret, arg))
-	{
-	  int write_errno = errno;
-	  pop_close (server);
-	  errno = write_errno;
-	  return false;
-	}
-    }
-
-  if (ret)
-    {
-      error ("Error from POP server: %s", pop_error, 0);
-      errno = 0;
-      return false;
-    }
-
-  return true;
-}
-
-static bool
-mbx_write (char *line, int len, FILE *mbf)
-{
-#ifdef MOVEMAIL_QUOTE_POP_FROM_LINES
-  /* Do this as a macro instead of using strcmp to save on execution time. */
-  # define IS_FROM_LINE(a) ((a[0] == 'F')	\
-			    && (a[1] == 'r')	\
-			    && (a[2] == 'o')	\
-			    && (a[3] == 'm')	\
-			    && (a[4] == ' '))
-  if (IS_FROM_LINE (line))
-    {
-      if (fputc ('>', mbf) < 0)
-	return false;
-    }
-#endif
-  if (line[0] == '\037')
-    {
-      if (fputs ("^_", mbf) < 0)
-	return false;
-      line++;
-      len--;
-    }
-  return fwrite (line, 1, len, mbf) == len && 0 <= fputc ('\n', mbf);
-}
-
-#ifdef WINDOWSNT
-/* Work around MS-Windows lack of support for %e or %T with a
-   special-purpose strftime that assumes the exact format that
-   movemail uses.  */
-static size_t
-movemail_strftime (char *s, size_t size, char const *format,
-		   struct tm const *tm)
-{
-  char fmt[size + 6], *q;
-  const char *p;
-
-  for (p = format, q = &fmt[0]; *p; )
-    {
-      if (*p == '%' && p[1] == 'e')
-	{
-	  memcpy (q, "%d", 2);
-	  q += 2;
-	  p += 2;
-	}
-      else if (*p == '%' && p[1] == 'T')
-	{
-	  memcpy (q, "%H:%M:%S", 8);
-	  q += 8;
-	  p += 2;
-	}
-      else if (*p == '%' && p[1] == '%')
-	{
-	  memcpy (q, p, 2);
-	  q += 2;
-	  p += 2;
-	}
-      else
-	*q++ = *p++;
-    }
-
-  size_t n = strftime (s, size, fmt, tm);
-  char *mday = s + sizeof "From movemail Sun Jan " - 1;
-  if (*mday == '0')
-    *mday = ' ';
-  return n;
-}
-# undef strftime
-# define strftime movemail_strftime
-#endif
-
-static bool
-mbx_delimit_begin (FILE *mbf)
-{
-  time_t now = time (NULL);
-  struct tm *ltime = localtime (&now);
-  if (!ltime)
-    return false;
-
-  char fromline[100];
-  if (! strftime (fromline, sizeof fromline,
-		  "From movemail %a %b %e %T %Y\n", ltime))
-    {
-      errno = EOVERFLOW;
-      return false;
-    }
-  return 0 <= fputs (fromline, mbf);
-}
-
-static bool
-mbx_delimit_end (FILE *mbf)
-{
-  return 0 <= putc ('\n', mbf);
-}
-
-#endif /* MAIL_USE_POP */
diff --git a/lib-src/pop.c b/lib-src/pop.c
deleted file mode 100644
index 1a85bd2..0000000
--- a/lib-src/pop.c
+++ /dev/null
@@ -1,1699 +0,0 @@
-/* pop.c: client routines for talking to a POP3-protocol post-office server
-
-Copyright (C) 1991, 1993, 1996-1997, 1999, 2001-2017 Free Software
-Foundation, Inc.
-
-Author: Jonathan Kamens <jik@security.ov.com>
-
-This file is part of GNU Emacs.
-
-GNU Emacs is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or (at
-your option) any later version.
-
-GNU Emacs is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
-
-
-#include <config.h>
-
-#ifdef MAIL_USE_POP
-
-#include <sys/types.h>
-#ifdef WINDOWSNT
-#include "ntlib.h"
-#undef _WIN32_WINNT
-#define _WIN32_WINNT 0x0501	/* for getaddrinfo stuff */
-#include <winsock2.h>
-#include <ws2tcpip.h>
-#undef getaddrinfo
-#define getaddrinfo  sys_getaddrinfo
-#undef freeaddrinfo
-#define freeaddrinfo sys_freeaddrinfo
-int sys_getaddrinfo (const char * node, const char * service,
-		     const struct addrinfo * hints, struct addrinfo ** res);
-void sys_freeaddrinfo (struct addrinfo * ai);
-#undef SOCKET_ERROR
-#define RECV(s,buf,len,flags) recv (s,buf,len,flags)
-#define SEND(s,buf,len,flags) send (s,buf,len,flags)
-#define CLOSESOCKET(s) closesocket (s)
-#else
-#include <netinet/in.h>
-#include <sys/socket.h>
-#define RECV(s,buf,len,flags) read (s,buf,len)
-#define SEND(s,buf,len,flags) write (s,buf,len)
-#define CLOSESOCKET(s) close (s)
-#endif
-#include <pop.h>
-
-#ifdef HESIOD
-#include <hesiod.h>
-/*
- * It really shouldn't be necessary to put this declaration here, but
- * the version of hesiod.h that Athena has installed in release 7.2
- * doesn't declare this function; I don't know if the 7.3 version of
- * hesiod.h does.
- */
-extern struct servent *hes_getservbyname (/* char *, char * */);
-#endif
-
-#include <alloca.h>
-#include <pwd.h>
-#include <netdb.h>
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#ifdef KERBEROS
-# ifdef HAVE_KRB5_H
-#  include <krb5.h>
-# endif
-# ifdef HAVE_KRB_H
-#  include <krb.h>
-# else
-#  ifdef HAVE_KERBEROSIV_KRB_H
-#   include <kerberosIV/krb.h>
-#  else
-#   ifdef HAVE_KERBEROS_KRB_H
-#    include <kerberos/krb.h>
-#   endif
-#  endif
-# endif
-# ifdef HAVE_COM_ERR_H
-#  include <com_err.h>
-# endif
-#endif /* KERBEROS */
-
-#include <c-ctype.h>
-#include <min-max.h>
-
-#ifdef KERBEROS
-#ifndef KERBEROS5
-extern int krb_sendauth (/* long, int, KTEXT, char *, char *, char *,
-			    u_long, MSG_DAT *, CREDENTIALS *, Key_schedule,
-			    struct sockaddr_in *, struct sockaddr_in *,
-			    char * */);
-extern char *krb_realmofhost (/* char * */);
-#endif /* ! KERBEROS5 */
-#endif /* KERBEROS */
-
-static int socket_connection (char *, int);
-static int pop_getline (popserver, char **);
-static int sendline (popserver, const char *);
-static int fullwrite (int, char *, int);
-static int getok (popserver);
-#if 0
-static int gettermination (popserver);
-#endif
-static void pop_trash (popserver);
-static char *find_crlf (char *, int);
-
-#define ERROR_MAX 160		/* a pretty arbitrary size, but needs
-				   to be bigger than the original
-				   value of 80 */
-#define POP_PORT 110
-#define POP_SERVICE "pop3"	/* we don't want the POP2 port! */
-#ifdef KERBEROS
-#define KPOP_PORT 1109
-#define KPOP_SERVICE "kpop"	/* never used: look for 20060515 to see why */
-#endif
-
-char pop_error[ERROR_MAX];
-bool pop_debug = false;
-
-/*
- * Function: pop_open (char *host, char *username, char *password,
- * 		       int flags)
- *
- * Purpose: Establishes a connection with a post-office server, and
- * 	completes the authorization portion of the session.
- *
- * Arguments:
- * 	host	The server host with which the connection should be
- * 		established.  Optional.  If omitted, internal
- * 		heuristics will be used to determine the server host,
- * 		if possible.
- * 	username
- * 		The username of the mail-drop to access.  Optional.
- * 		If omitted, internal heuristics will be used to
- * 		determine the username, if possible.
- * 	password
- * 		The password to use for authorization.  If omitted,
- * 		internal heuristics will be used to determine the
- * 		password, if possible.
- * 	flags	A bit mask containing flags controlling certain
- * 		functions of the routine.  Valid flags are defined in
- * 		the file pop.h
- *
- * Return value: Upon successful establishment of a connection, a
- * 	non-null popserver will be returned.  Otherwise, null will be
- * 	returned, and the string variable pop_error will contain an
- * 	explanation of the error.
- */
-popserver
-pop_open (char *host, char *username, char *password, int flags)
-{
-  int sock;
-  popserver server;
-
-  /* Determine the user name */
-  if (! username)
-    {
-      username = getenv ("USER");
-      if (! (username && *username))
-	{
-	  username = getlogin ();
-	  if (! (username && *username))
-	    {
-	      struct passwd *passwd;
-	      passwd = getpwuid (getuid ());
-	      if (passwd && passwd->pw_name && *passwd->pw_name)
-		{
-		  username = passwd->pw_name;
-		}
-	      else
-		{
-		  strcpy (pop_error, "Could not determine username");
-		  return (0);
-		}
-	    }
-	}
-    }
-
-  /*
-   *  Determine the mail host.
-   */
-
-  if (! host)
-    {
-      host = getenv ("MAILHOST");
-    }
-
-#ifdef HESIOD
-  if ((! host) && (! (flags & POP_NO_HESIOD)))
-    {
-      struct hes_postoffice *office;
-      office = hes_getmailhost (username);
-      if (office && office->po_type && (! strcmp (office->po_type, "POP"))
-	  && office->po_name && *office->po_name && office->po_host
-	  && *office->po_host)
-	{
-	  host = office->po_host;
-	  username = office->po_name;
-	}
-    }
-#endif
-
-#ifdef MAILHOST
-  if (! host)
-    {
-      host = MAILHOST;
-    }
-#endif
-
-  if (! host)
-    {
-      strcpy (pop_error, "Could not determine POP server");
-      return (0);
-    }
-
-  /* Determine the password */
-#ifdef KERBEROS
-#define DONT_NEED_PASSWORD (! (flags & POP_NO_KERBEROS))
-#else
-#define DONT_NEED_PASSWORD 0
-#endif
-
-  if ((! password) && (! DONT_NEED_PASSWORD))
-    {
-      if (! (flags & POP_NO_GETPASS))
-	{
-	  password = getpass ("Enter POP password:");
-	}
-      if (! password)
-	{
-	  strcpy (pop_error, "Could not determine POP password");
-	  return (0);
-	}
-    }
-  if (password)			/* always true, detected 20060515 */
-    flags |= POP_NO_KERBEROS;
-  else
-    password = username;	/* dead code, detected 20060515 */
-  /** "kpop" service is  never used: look for 20060515 to see why **/
-
-  sock = socket_connection (host, flags);
-  if (sock == -1)
-    return (0);
-
-  server = (popserver) malloc (sizeof (struct _popserver));
-  if (! server)
-    {
-      strcpy (pop_error, "Out of memory in pop_open");
-      return (0);
-    }
-  server->buffer = (char *) malloc (GETLINE_MIN);
-  if (! server->buffer)
-    {
-      strcpy (pop_error, "Out of memory in pop_open");
-      free ((char *) server);
-      return (0);
-    }
-
-  server->file = sock;
-  server->data = 0;
-  server->buffer_index = 0;
-  server->buffer_size = GETLINE_MIN;
-  server->in_multi = false;
-  server->trash_started = false;
-
-  if (getok (server))
-    return (0);
-
-  /*
-   * I really shouldn't use the pop_error variable like this, but....
-   */
-  if (strlen (username) > ERROR_MAX - 6)
-    {
-      pop_close (server);
-      strcpy (pop_error,
-	      "Username too long; recompile pop.c with larger ERROR_MAX");
-      return (0);
-    }
-  sprintf (pop_error, "USER %s", username);
-
-  if (sendline (server, pop_error) || getok (server))
-    {
-      return (0);
-    }
-
-  if (strlen (password) > ERROR_MAX - 6)
-    {
-      pop_close (server);
-      strcpy (pop_error,
-	      "Password too long; recompile pop.c with larger ERROR_MAX");
-      return (0);
-    }
-  sprintf (pop_error, "PASS %s", password);
-
-  if (sendline (server, pop_error) || getok (server))
-    {
-      return (0);
-    }
-
-  return (server);
-}
-
-/*
- * Function: pop_stat
- *
- * Purpose: Issue the STAT command to the server and return (in the
- * 	value parameters) the number of messages in the maildrop and
- * 	the total size of the maildrop.
- *
- * Return value: 0 on success, or non-zero with an error in pop_error
- * 	in failure.
- *
- * Side effects: On failure, may make further operations on the
- * 	connection impossible.
- */
-int
-pop_stat (popserver server, int *count, int *size)
-{
-  char *fromserver;
-  char *end_ptr;
-
-  if (server->in_multi)
-    {
-      strcpy (pop_error, "In multi-line query in pop_stat");
-      return (-1);
-    }
-
-  if (sendline (server, "STAT") || (pop_getline (server, &fromserver) < 0))
-    return (-1);
-
-  if (strncmp (fromserver, "+OK ", 4))
-    {
-      if (0 == strncmp (fromserver, "-ERR", 4))
-	snprintf (pop_error, ERROR_MAX, "%s", fromserver);
-      else
-	{
-	  strcpy (pop_error,
-		  "Unexpected response from POP server in pop_stat");
-	  pop_trash (server);
-	}
-      return (-1);
-    }
-
-  errno = 0;
-  *count = strtol (&fromserver[4], &end_ptr, 10);
-  /* Check validity of string-to-integer conversion. */
-  if (fromserver + 4 == end_ptr || *end_ptr != ' ' || errno)
-    {
-      strcpy (pop_error, "Unexpected response from POP server in pop_stat");
-      pop_trash (server);
-      return (-1);
-    }
-
-  fromserver = end_ptr;
-
-  errno = 0;
-  *size = strtol (fromserver + 1, &end_ptr, 10);
-  if (fromserver + 1 == end_ptr || errno)
-    {
-      strcpy (pop_error, "Unexpected response from POP server in pop_stat");
-      pop_trash (server);
-      return (-1);
-    }
-
-  return (0);
-}
-
-/*
- * Function: pop_list
- *
- * Purpose: Performs the POP "list" command and returns (in value
- * 	parameters) two malloc'd zero-terminated arrays -- one of
- * 	message IDs, and a parallel one of sizes.
- *
- * Arguments:
- * 	server	The pop connection to talk to.
- * 	message	The number of the one message about which to get
- * 		information, or 0 to get information about all
- * 		messages.
- *
- * Return value: 0 on success, non-zero with error in pop_error on
- * 	failure.
- *
- * Side effects: On failure, may make further operations on the
- * 	connection impossible.
- */
-int
-pop_list (popserver server, int message, int **IDs, int **sizes)
-{
-  int how_many, i;
-  char *fromserver;
-
-  if (server->in_multi)
-    {
-      strcpy (pop_error, "In multi-line query in pop_list");
-      return (-1);
-    }
-
-  if (message)
-    how_many = 1;
-  else
-    {
-      int count, size;
-      if (pop_stat (server, &count, &size))
-	return (-1);
-      how_many = count;
-    }
-
-  *IDs = (int *) malloc ((how_many + 1) * sizeof (int));
-  *sizes = (int *) malloc ((how_many + 1) * sizeof (int));
-  if (! (*IDs && *sizes))
-    {
-      strcpy (pop_error, "Out of memory in pop_list");
-      return (-1);
-    }
-
-  if (message)
-    {
-      sprintf (pop_error, "LIST %d", message);
-      if (sendline (server, pop_error))
-	{
-	  free ((char *) *IDs);
-	  free ((char *) *sizes);
-	  return (-1);
-	}
-      if (pop_getline (server, &fromserver) < 0)
-	{
-	  free ((char *) *IDs);
-	  free ((char *) *sizes);
-	  return (-1);
-	}
-      if (strncmp (fromserver, "+OK ", 4))
-	{
-	  if (! strncmp (fromserver, "-ERR", 4))
-	    snprintf (pop_error, ERROR_MAX, "%s", fromserver);
-	  else
-	    {
-	      strcpy (pop_error,
-		      "Unexpected response from server in pop_list");
-	      pop_trash (server);
-	    }
-	  free ((char *) *IDs);
-	  free ((char *) *sizes);
-	  return (-1);
-	}
-      (*IDs)[0] = atoi (&fromserver[4]);
-      fromserver = strchr (&fromserver[4], ' ');
-      if (! fromserver)
-	{
-	  strcpy (pop_error,
-		  "Badly formatted response from server in pop_list");
-	  pop_trash (server);
-	  free ((char *) *IDs);
-	  free ((char *) *sizes);
-	  return (-1);
-	}
-      (*sizes)[0] = atoi (fromserver);
-      (*IDs)[1] = (*sizes)[1] = 0;
-      return (0);
-    }
-  else
-    {
-      if (pop_multi_first (server, "LIST", &fromserver))
-	{
-	  free ((char *) *IDs);
-	  free ((char *) *sizes);
-	  return (-1);
-	}
-      for (i = 0; i < how_many; i++)
-	{
-	  if (pop_multi_next (server, &fromserver) <= 0)
-	    {
-	      free ((char *) *IDs);
-	      free ((char *) *sizes);
-	      return (-1);
-	    }
-	  (*IDs)[i] = atoi (fromserver);
-	  fromserver = strchr (fromserver, ' ');
-	  if (! fromserver)
-	    {
-	      strcpy (pop_error,
-		      "Badly formatted response from server in pop_list");
-	      free ((char *) *IDs);
-	      free ((char *) *sizes);
-	      pop_trash (server);
-	      return (-1);
-	    }
-	  (*sizes)[i] = atoi (fromserver);
-	}
-      if (pop_multi_next (server, &fromserver) < 0)
-	{
-	  free ((char *) *IDs);
-	  free ((char *) *sizes);
-	  return (-1);
-	}
-      else if (fromserver)
-	{
-	  strcpy (pop_error,
-		  "Too many response lines from server in pop_list");
-	  free ((char *) *IDs);
-	  free ((char *) *sizes);
-	  return (-1);
-	}
-      (*IDs)[i] = (*sizes)[i] = 0;
-      return (0);
-    }
-}
-
-/*
- * Function: pop_retrieve
- *
- * Purpose: Retrieve a specified message from the maildrop.
- *
- * Arguments:
- * 	server	The server to retrieve from.
- * 	message	The message number to retrieve.
- *	markfrom
- * 		If true, then mark the string "From " at the beginning
- * 		of lines with '>'.
- *	msg_buf	Output parameter to which a buffer containing the
- * 		message is assigned.
- *
- * Return value: The number of bytes in msg_buf, which may contain
- * 	embedded nulls, not including its final null, or -1 on error
- * 	with pop_error set.
- *
- * Side effects: May kill connection on error.
- */
-int
-pop_retrieve (popserver server, int message, int markfrom, char **msg_buf)
-{
-  int *IDs, *sizes, bufsize, fromcount = 0, cp = 0;
-  char *ptr, *fromserver;
-  int ret;
-
-  if (server->in_multi)
-    {
-      strcpy (pop_error, "In multi-line query in pop_retrieve");
-      return (-1);
-    }
-
-  if (pop_list (server, message, &IDs, &sizes))
-    return (-1);
-
-  if (pop_retrieve_first (server, message, &fromserver))
-    {
-      return (-1);
-    }
-
-  /*
-   * The "5" below is an arbitrary constant -- I assume that if
-   * there are "From" lines in the text to be marked, there
-   * probably won't be more than 5 of them.  If there are, I
-   * allocate more space for them below.
-   */
-  bufsize = sizes[0] + (markfrom ? 5 : 0);
-  ptr = (char *)malloc (bufsize);
-  free ((char *) IDs);
-  free ((char *) sizes);
-
-  if (! ptr)
-    {
-      strcpy (pop_error, "Out of memory in pop_retrieve");
-      pop_retrieve_flush (server);
-      return (-1);
-    }
-
-  while ((ret = pop_retrieve_next (server, &fromserver)) >= 0)
-    {
-      if (! fromserver)
-	{
-	  ptr[cp] = '\0';
-	  *msg_buf = ptr;
-	  return (cp);
-	}
-      if (markfrom && fromserver[0] == 'F' && fromserver[1] == 'r' &&
-	  fromserver[2] == 'o' && fromserver[3] == 'm' &&
-	  fromserver[4] == ' ')
-	{
-	  if (++fromcount == 5)
-	    {
-	      bufsize += 5;
-	      ptr = (char *)realloc (ptr, bufsize);
-	      if (! ptr)
-		{
-		  strcpy (pop_error, "Out of memory in pop_retrieve");
-		  pop_retrieve_flush (server);
-		  return (-1);
-		}
-	      fromcount = 0;
-	    }
-	  ptr[cp++] = '>';
-	}
-      memcpy (&ptr[cp], fromserver, ret);
-      cp += ret;
-      ptr[cp++] = '\n';
-    }
-
-  free (ptr);
-  return (-1);
-}
-
-int
-pop_retrieve_first (popserver server, int message, char **response)
-{
-  sprintf (pop_error, "RETR %d", message);
-  return (pop_multi_first (server, pop_error, response));
-}
-
-/*
-  Returns a negative number on error, 0 to indicate that the data has
-  all been read (i.e., the server has returned a "." termination
-  line), or a positive number indicating the number of bytes in the
-  returned buffer (which is null-terminated and may contain embedded
-  nulls, but the returned bytecount doesn't include the final null).
-  */
-
-int
-pop_retrieve_next (popserver server, char **line)
-{
-  return (pop_multi_next (server, line));
-}
-
-int
-pop_retrieve_flush (popserver server)
-{
-  return (pop_multi_flush (server));
-}
-
-int
-pop_top_first (popserver server, int message, int lines, char **response)
-{
-  sprintf (pop_error, "TOP %d %d", message, lines);
-  return (pop_multi_first (server, pop_error, response));
-}
-
-/*
-  Returns a negative number on error, 0 to indicate that the data has
-  all been read (i.e., the server has returned a "." termination
-  line), or a positive number indicating the number of bytes in the
-  returned buffer (which is null-terminated and may contain embedded
-  nulls, but the returned bytecount doesn't include the final null).
-  */
-
-int
-pop_top_next (popserver server, char **line)
-{
-  return (pop_multi_next (server, line));
-}
-
-int
-pop_top_flush (popserver server)
-{
-  return (pop_multi_flush (server));
-}
-
-int
-pop_multi_first (popserver server, const char *command, char **response)
-{
-  if (server->in_multi)
-    {
-      strcpy (pop_error,
-	      "Already in multi-line query in pop_multi_first");
-      return (-1);
-    }
-
-  if (sendline (server, command) || (pop_getline (server, response) < 0))
-    {
-      return (-1);
-    }
-
-  if (0 == strncmp (*response, "-ERR", 4))
-    {
-      snprintf (pop_error, ERROR_MAX, "%s", *response);
-      return (-1);
-    }
-  else if (0 == strncmp (*response, "+OK", 3))
-    {
-      for (*response += 3; **response == ' '; (*response)++) /* empty */;
-      server->in_multi = true;
-      return (0);
-    }
-  else
-    {
-      strcpy (pop_error,
-	      "Unexpected response from server in pop_multi_first");
-      return (-1);
-    }
-}
-
-/*
-  Read the next line of data from SERVER and place a pointer to it
-  into LINE.  Return -1 on error, 0 if there are no more lines to read
-  (i.e., the server has returned a line containing only "."), or a
-  positive number indicating the number of bytes in the LINE buffer
-  (not including the final null).  The data in that buffer may contain
-  embedded nulls, but does not contain the final CRLF. When returning
-  0, LINE is set to null. */
-
-int
-pop_multi_next (popserver server, char **line)
-{
-  char *fromserver;
-  int ret;
-
-  if (! server->in_multi)
-    {
-      strcpy (pop_error, "Not in multi-line query in pop_multi_next");
-      return (-1);
-    }
-
-  ret = pop_getline (server, &fromserver);
-  if (ret < 0)
-    {
-      return (-1);
-    }
-
-  if (fromserver[0] == '.')
-    {
-      if (! fromserver[1])
-	{
-	  *line = 0;
-	  server->in_multi = false;
-	  return (0);
-	}
-      else
-	{
-	  *line = fromserver + 1;
-	  return (ret - 1);
-	}
-    }
-  else
-    {
-      *line = fromserver;
-      return (ret);
-    }
-}
-
-int
-pop_multi_flush (popserver server)
-{
-  char *line;
-  int ret;
-
-  if (! server->in_multi)
-    {
-      return (0);
-    }
-
-  while ((ret = pop_multi_next (server, &line)))
-    {
-      if (ret < 0)
-	return (-1);
-    }
-
-  return (0);
-}
-
-/* Function: pop_delete
- *
- * Purpose: Delete a specified message.
- *
- * Arguments:
- * 	server	Server from which to delete the message.
- * 	message	Message to delete.
- *
- * Return value: 0 on success, non-zero with error in pop_error
- * 	otherwise.
- */
-int
-pop_delete (popserver server, int message)
-{
-  if (server->in_multi)
-    {
-      strcpy (pop_error, "In multi-line query in pop_delete");
-      return (-1);
-    }
-
-  sprintf (pop_error, "DELE %d", message);
-
-  if (sendline (server, pop_error) || getok (server))
-    return (-1);
-
-  return (0);
-}
-
-/*
- * Function: pop_noop
- *
- * Purpose: Send a noop command to the server.
- *
- * Argument:
- * 	server	The server to send to.
- *
- * Return value: 0 on success, non-zero with error in pop_error
- * 	otherwise.
- *
- * Side effects: Closes connection on error.
- */
-int
-pop_noop (popserver server)
-{
-  if (server->in_multi)
-    {
-      strcpy (pop_error, "In multi-line query in pop_noop");
-      return (-1);
-    }
-
-  if (sendline (server, "NOOP") || getok (server))
-    return (-1);
-
-  return (0);
-}
-
-/*
- * Function: pop_last
- *
- * Purpose: Find out the highest seen message from the server.
- *
- * Arguments:
- * 	server	The server.
- *
- * Return value: If successful, the highest seen message, which is
- * 	greater than or equal to 0.  Otherwise, a negative number with
- * 	the error explained in pop_error.
- *
- * Side effects: Closes the connection on error.
- */
-int
-pop_last (popserver server)
-{
-  char *fromserver;
-
-  if (server->in_multi)
-    {
-      strcpy (pop_error, "In multi-line query in pop_last");
-      return (-1);
-    }
-
-  if (sendline (server, "LAST"))
-    return (-1);
-
-  if (pop_getline (server, &fromserver) < 0)
-    return (-1);
-
-  if (! strncmp (fromserver, "-ERR", 4))
-    {
-      snprintf (pop_error, ERROR_MAX, "%s", fromserver);
-      return (-1);
-    }
-  else if (strncmp (fromserver, "+OK ", 4))
-    {
-      strcpy (pop_error, "Unexpected response from server in pop_last");
-      pop_trash (server);
-      return (-1);
-    }
-  else
-    {
-      char *end_ptr;
-      int count;
-      errno = 0;
-      count = strtol (&fromserver[4], &end_ptr, 10);
-      if (fromserver + 4 == end_ptr || errno)
-	{
-	  strcpy (pop_error, "Unexpected response from server in pop_last");
-	  pop_trash (server);
-	  return (-1);
-	}
-      return count;
-    }
-}
-
-/*
- * Function: pop_reset
- *
- * Purpose: Reset the server to its initial connect state
- *
- * Arguments:
- * 	server	The server.
- *
- * Return value: 0 for success, non-0 with error in pop_error
- * 	otherwise.
- *
- * Side effects: Closes the connection on error.
- */
-int
-pop_reset (popserver server)
-{
-  if (pop_retrieve_flush (server))
-    {
-      return (-1);
-    }
-
-  if (sendline (server, "RSET") || getok (server))
-    return (-1);
-
-  return (0);
-}
-
-/*
- * Function: pop_quit
- *
- * Purpose: Quit the connection to the server,
- *
- * Arguments:
- * 	server	The server to quit.
- *
- * Return value: 0 for success, non-zero otherwise with error in
- * 	pop_error.
- *
- * Side Effects: The popserver passed in is unusable after this
- * 	function is called, even if an error occurs.
- */
-int
-pop_quit (popserver server)
-{
-  int ret = 0;
-
-  if (server->file >= 0)
-    {
-      if (pop_retrieve_flush (server))
-	{
-	  ret = -1;
-	}
-
-      if (sendline (server, "QUIT") || getok (server))
-	{
-	  ret = -1;
-	}
-
-      close (server->file);
-    }
-
-  free (server->buffer);
-  free ((char *) server);
-
-  return (ret);
-}
-
-#ifdef WINDOWSNT
-static int have_winsock = 0;
-#endif
-
-/*
- * Function: socket_connection
- *
- * Purpose: Opens the network connection with the mail host, without
- * 	doing any sort of I/O with it or anything.
- *
- * Arguments:
- * 	host	The host to which to connect.
- *	flags	Option flags.
- *
- * Return value: A file descriptor indicating the connection, or -1
- * 	indicating failure, in which case an error has been copied
- * 	into pop_error.
- */
-static int
-socket_connection (char *host, int flags)
-{
-  struct addrinfo *res, *it;
-  struct addrinfo hints;
-  int ret;
-  struct servent *servent;
-  struct sockaddr_in addr;
-  char found_port = 0;
-  const char *service;
-  int sock;
-  char *realhost;
-#ifdef KERBEROS
-#ifdef KERBEROS5
-  krb5_error_code rem;
-  krb5_context kcontext = 0;
-  krb5_auth_context auth_context = 0;
-  krb5_ccache ccdef;
-  krb5_principal client, server;
-  krb5_error *err_ret;
-  register char *cp;
-#else
-  KTEXT ticket;
-  MSG_DAT msg_data;
-  CREDENTIALS cred;
-  Key_schedule schedule;
-  int rem;
-#endif /* KERBEROS5 */
-#endif /* KERBEROS */
-
-  int try_count = 0;
-  int connect_ok;
-
-#ifdef WINDOWSNT
-  {
-    WSADATA winsockData;
-    if (WSAStartup (0x101, &winsockData) == 0)
-      have_winsock = 1;
-  }
-#endif
-
-  memset (&addr, 0, sizeof (addr));
-  addr.sin_family = AF_INET;
-
-  /** "kpop" service is  never used: look for 20060515 to see why **/
-#ifdef KERBEROS
-  service = (flags & POP_NO_KERBEROS) ? POP_SERVICE : KPOP_SERVICE;
-#else
-  service = POP_SERVICE;
-#endif
-
-#ifdef HESIOD
-  if (! (flags & POP_NO_HESIOD))
-    {
-      servent = hes_getservbyname (service, "tcp");
-      if (servent)
-	{
-	  addr.sin_port = servent->s_port;
-	  found_port = 1;
-	}
-    }
-#endif
-  if (! found_port)
-    {
-      servent = getservbyname (service, "tcp");
-      if (servent)
-	{
-	  addr.sin_port = servent->s_port;
-	}
-      else
-	{
-  /** "kpop" service is  never used: look for 20060515 to see why **/
-#ifdef KERBEROS
-	  addr.sin_port = htons ((flags & POP_NO_KERBEROS) ?
-				POP_PORT : KPOP_PORT);
-#else
-	  addr.sin_port = htons (POP_PORT);
-#endif
-	}
-    }
-
-#define POP_SOCKET_ERROR "Could not create socket for POP connection: "
-
-  sock = socket (PF_INET, SOCK_STREAM, 0);
-  if (sock < 0)
-    {
-      snprintf (pop_error, ERROR_MAX, "%s%s",
-		POP_SOCKET_ERROR, strerror (errno));
-      return (-1);
-
-    }
-
-  memset (&hints, 0, sizeof (hints));
-  hints.ai_socktype = SOCK_STREAM;
-  hints.ai_flags = AI_CANONNAME;
-  hints.ai_family = AF_INET;
-  do
-    {
-      ret = getaddrinfo (host, service, &hints, &res);
-      try_count++;
-      if (ret != 0 && (ret != EAI_AGAIN || try_count == 5))
-	{
-	  strcpy (pop_error, "Could not determine POP server's address");
-	  return (-1);
-	}
-    } while (ret != 0);
-
-  for (it = res; it; it = it->ai_next)
-    if (it->ai_addrlen == sizeof addr)
-      {
-	struct sockaddr_in *in_a = (struct sockaddr_in *) it->ai_addr;
-	addr.sin_addr = in_a->sin_addr;
-	if (! connect (sock, (struct sockaddr *) &addr, sizeof addr))
-	  break;
-      }
-  connect_ok = it != NULL;
-  if (connect_ok)
-    {
-      realhost = alloca (strlen (it->ai_canonname) + 1);
-      strcpy (realhost, it->ai_canonname);
-    }
-  freeaddrinfo (res);
-
-#define CONNECT_ERROR "Could not connect to POP server: "
-
-  if (! connect_ok)
-    {
-      CLOSESOCKET (sock);
-      snprintf (pop_error, ERROR_MAX, "%s%s", CONNECT_ERROR, strerror (errno));
-      return (-1);
-
-    }
-
-#ifdef KERBEROS
-
-#define KRB_ERROR "Kerberos error connecting to POP server: "
-  if (! (flags & POP_NO_KERBEROS))
-    {
-#ifdef KERBEROS5
-      rem = krb5_init_context (&kcontext);
-      if (rem)
-	{
-	krb5error:
-	  if (auth_context)
-	    krb5_auth_con_free (kcontext, auth_context);
-	  if (kcontext)
-	    krb5_free_context (kcontext);
-	  snprintf (pop_error, ERROR_MAX, "%s%s",
-		    KRB_ERROR, error_message (rem));
-	  CLOSESOCKET (sock);
-	  return (-1);
-	}
-
-      rem = krb5_auth_con_init (kcontext, &auth_context);
-      if (rem)
-	goto krb5error;
-
-      rem = krb5_cc_default (kcontext, &ccdef);
-      if (rem)
-	goto krb5error;
-
-      rem = krb5_cc_get_principal (kcontext, ccdef, &client);
-      if (rem)
-	goto krb5error;
-
-      for (cp = realhost; *cp; cp++)
-	*cp = c_tolower (*cp);
-
-      rem = krb5_sname_to_principal (kcontext, realhost,
-				     POP_SERVICE, FALSE, &server);
-      if (rem)
-	goto krb5error;
-
-      rem = krb5_sendauth (kcontext, &auth_context,
-			   (krb5_pointer) &sock, (char *) "KPOPV1.0",
-			   client, server,
-			  AP_OPTS_MUTUAL_REQUIRED,
-			  0,	/* no checksum */
-			  0,	/* no creds, use ccache instead */
-			  ccdef,
-			  &err_ret,
-			  0,	/* don't need subsession key */
-			  0);	/* don't need reply */
-      krb5_free_principal (kcontext, server);
-      if (rem)
-	{
-	  int pop_error_len = snprintf (pop_error, ERROR_MAX, "%s%s",
-					KRB_ERROR, error_message (rem));
-#if defined HAVE_KRB5_ERROR_TEXT
-	  if (err_ret && err_ret->text.length)
-	    {
-	      int errlen = err_ret->text.length;
-	      snprintf (pop_error + pop_error_len, ERROR_MAX - pop_error_len,
-			" [server says '%.*s']", errlen, err_ret->text.data);
-	    }
-#elif defined HAVE_KRB5_ERROR_E_TEXT
-	  if (err_ret && err_ret->e_text && **err_ret->e_text)
-	    snprintf (pop_error + pop_error_len, ERROR_MAX - pop_error_len,
-		      " [server says '%s']", *err_ret->e_text);
-#endif
-	  if (err_ret)
-	    krb5_free_error (kcontext, err_ret);
-	  krb5_auth_con_free (kcontext, auth_context);
-	  krb5_free_context (kcontext);
-
-	  CLOSESOCKET (sock);
-	  return (-1);
-	}
-#else  /* ! KERBEROS5 */
-      ticket = (KTEXT) malloc (sizeof (KTEXT_ST));
-      rem = krb_sendauth (0L, sock, ticket, "pop", realhost,
-			  (char *) krb_realmofhost (realhost),
-			  (unsigned long) 0, &msg_data, &cred, schedule,
-			  (struct sockaddr_in *) 0,
-			  (struct sockaddr_in *) 0,
-			  "KPOPV0.1");
-      free ((char *) ticket);
-      if (rem != KSUCCESS)
-	{
-	  snprintf (pop_error, ERROR_MAX, "%s%s", KRB_ERROR, krb_err_txt[rem]);
-	  CLOSESOCKET (sock);
-	  return (-1);
-	}
-#endif /* KERBEROS5 */
-    }
-#endif /* KERBEROS */
-
-  return (sock);
-} /* socket_connection */
-
-/*
- * Function: pop_getline
- *
- * Purpose: Get a line of text from the connection and return a
- * 	pointer to it.  The carriage return and linefeed at the end of
- * 	the line are stripped, but periods at the beginnings of lines
- * 	are NOT dealt with in any special way.
- *
- * Arguments:
- * 	server	The server from which to get the line of text.
- *
- * Returns: The number of characters in the line, which is returned in
- * 	LINE, not including the final null.  A return value of 0
- * 	indicates a blank line.  A negative return value indicates an
- * 	error (in which case the contents of LINE are undefined.  In
- * 	case of error, an error message is copied into pop_error.
- *
- * Notes: The line returned is overwritten with each call to pop_getline.
- *
- * Side effects: Closes the connection on error.
- *
- * THE RETURNED LINE MAY CONTAIN EMBEDDED NULLS!
- */
-static int
-pop_getline (popserver server, char **line)
-{
-#define GETLINE_ERROR "Error reading from server: "
-
-  int ret;
-  int search_offset = 0;
-
-  if (server->data)
-    {
-      char *cp = find_crlf (server->buffer + server->buffer_index,
-			    server->data);
-      if (cp)
-	{
-	  int found;
-	  int data_used;
-
-	  found = server->buffer_index;
-	  data_used = (cp + 2) - server->buffer - found;
-
-	  *cp = '\0';		/* terminate the string to be returned */
-	  server->data -= data_used;
-	  server->buffer_index += data_used;
-
-	  if (pop_debug)
-	    /* Embedded nulls will truncate this output prematurely,
-	       but that's OK because it's just for debugging anyway. */
-	    fprintf (stderr, "<<< %s\n", server->buffer + found);
-	  *line = server->buffer + found;
-	  return (data_used - 2);
-	}
-      else
-	{
-	  memmove (server->buffer, server->buffer + server->buffer_index,
-		   server->data);
-	  /* Record the fact that we've searched the data already in
-             the buffer for a CRLF, so that when we search below, we
-             don't have to search the same data twice.  There's a "-
-             1" here to account for the fact that the last character
-             of the data we have may be the CR of a CRLF pair, of
-             which we haven't read the second half yet, so we may have
-             to search it again when we read more data. */
-	  search_offset = server->data - 1;
-	  server->buffer_index = 0;
-	}
-    }
-  else
-    {
-      server->buffer_index = 0;
-    }
-
-  while (1)
-    {
-      /* There's a "- 1" here to leave room for the null that we put
-         at the end of the read data below.  We put the null there so
-         that find_crlf knows where to stop when we call it. */
-      if (server->data == server->buffer_size - 1)
-	{
-	  server->buffer_size += GETLINE_INCR;
-	  server->buffer = (char *)realloc (server->buffer, server->buffer_size);
-	  if (! server->buffer)
-	    {
-	      strcpy (pop_error, "Out of memory in pop_getline");
-	      pop_trash (server);
-	      return (-1);
-	    }
-	}
-      ret = RECV (server->file, server->buffer + server->data,
-		  server->buffer_size - server->data - 1, 0);
-      if (ret < 0)
-	{
-	  snprintf (pop_error, ERROR_MAX, "%s%s",
-		    GETLINE_ERROR, strerror (errno));
-	  pop_trash (server);
-	  return (-1);
-	}
-      else if (ret == 0)
-	{
-	  strcpy (pop_error, "Unexpected EOF from server in pop_getline");
-	  pop_trash (server);
-	  return (-1);
-	}
-      else
-	{
-	  char *cp;
-	  server->data += ret;
-	  server->buffer[server->data] = '\0';
-
-	  cp = find_crlf (server->buffer + search_offset,
-			  server->data - search_offset);
-	  if (cp)
-	    {
-	      int data_used = (cp + 2) - server->buffer;
-	      *cp = '\0';
-	      server->data -= data_used;
-	      server->buffer_index = data_used;
-
-	      if (pop_debug)
-		fprintf (stderr, "<<< %s\n", server->buffer);
-	      *line = server->buffer;
-	      return (data_used - 2);
-	    }
-	  /* As above, the "- 1" here is to account for the fact that
-	     we may have read a CR without its accompanying LF. */
-	  search_offset += ret - 1;
-	}
-    }
-
-  /* NOTREACHED */
-}
-
-/*
- * Function: sendline
- *
- * Purpose: Sends a line of text to the POP server.  The line of text
- * 	passed into this function should NOT have the carriage return
- * 	and linefeed on the end of it.  Periods at beginnings of lines
- * 	will NOT be treated specially by this function.
- *
- * Arguments:
- * 	server	The server to which to send the text.
- * 	line	The line of text to send.
- *
- * Return value: Upon successful completion, a value of 0 will be
- * 	returned.  Otherwise, a non-zero value will be returned, and
- * 	an error will be copied into pop_error.
- *
- * Side effects: Closes the connection on error.
- */
-static int
-sendline (popserver server, const char *line)
-{
-#define SENDLINE_ERROR "Error writing to POP server: "
-  int ret;
-  char *buf;
-
-  /* Combine the string and the CR-LF into one buffer.  Otherwise, two
-     reasonable network stack optimizations, Nagle's algorithm and
-     delayed acks, combine to delay us a fraction of a second on every
-     message we send.  (Movemail writes line without \r\n, client
-     kernel sends packet, server kernel delays the ack to see if it
-     can combine it with data, movemail writes \r\n, client kernel
-     waits because it has unacked data already in its outgoing queue,
-     client kernel eventually times out and sends.)
-
-     This can be something like 0.2s per command, which can add up
-     over a few dozen messages, and is a big chunk of the time we
-     spend fetching mail from a server close by.  */
-  buf = alloca (strlen (line) + 3);
-  strcpy (stpcpy (buf, line), "\r\n");
-  ret = fullwrite (server->file, buf, strlen (buf));
-
-  if (ret < 0)
-    {
-      pop_trash (server);
-      snprintf (pop_error, ERROR_MAX, "%s%s", SENDLINE_ERROR, strerror (errno));
-      return (ret);
-    }
-
-  if (pop_debug)
-    fprintf (stderr, ">>> %s\n", line);
-
-  return (0);
-}
-
-/*
- * Procedure: fullwrite
- *
- * Purpose: Just like write, but keeps trying until the entire string
- * 	has been written.
- *
- * Return value: Same as write.  Pop_error is not set.
- */
-static int
-fullwrite (int fd, char *buf, int nbytes)
-{
-  char *cp;
-  int ret = 0;
-
-  cp = buf;
-  while (nbytes && ((ret = SEND (fd, cp, nbytes, 0)) > 0))
-    {
-      cp += ret;
-      nbytes -= ret;
-    }
-
-  return (ret);
-}
-
-/*
- * Procedure getok
- *
- * Purpose: Reads a line from the server.  If the return indicator is
- * 	positive, return with a zero exit status.  If not, return with
- * 	a negative exit status.
- *
- * Arguments:
- * 	server	The server to read from.
- *
- * Returns: 0 for success, else for failure and puts error in pop_error.
- *
- * Side effects: On failure, may make the connection unusable.
- */
-static int
-getok (popserver server)
-{
-  char *fromline;
-
-  if (pop_getline (server, &fromline) < 0)
-    {
-      return (-1);
-    }
-
-  if (! strncmp (fromline, "+OK", 3))
-    return (0);
-  else if (! strncmp (fromline, "-ERR", 4))
-    {
-      snprintf (pop_error, ERROR_MAX, "%s", fromline);
-      return (-1);
-    }
-  else
-    {
-      strcpy (pop_error,
-	      "Unexpected response from server; expecting +OK or -ERR");
-      pop_trash (server);
-      return (-1);
-    }
-}
-
-#if 0
-/*
- * Function: gettermination
- *
- * Purpose: Gets the next line and verifies that it is a termination
- * 	line (nothing but a dot).
- *
- * Return value: 0 on success, non-zero with pop_error set on error.
- *
- * Side effects: Closes the connection on error.
- */
-static int
-gettermination (server)
-     popserver server;
-{
-  char *fromserver;
-
-  if (pop_getline (server, &fromserver) < 0)
-    return (-1);
-
-  if (strcmp (fromserver, "."))
-    {
-      strcpy (pop_error,
-	      "Unexpected response from server in gettermination");
-      pop_trash (server);
-      return (-1);
-    }
-
-  return (0);
-}
-#endif
-
-/*
- * Function pop_close
- *
- * Purpose: Close a pop connection, sending a "RSET" command to try to
- * 	preserve any changes that were made and a "QUIT" command to
- * 	try to get the server to quit, but ignoring any responses that
- * 	are received.
- *
- * Side effects: The server is unusable after this function returns.
- * 	Changes made to the maildrop since the session was started (or
- * 	since the last pop_reset) may be lost.
- */
-void
-pop_close (popserver server)
-{
-  pop_trash (server);
-  free ((char *) server);
-
-  return;
-}
-
-/*
- * Function: pop_trash
- *
- * Purpose: Like pop_close or pop_quit, but doesn't deallocate the
- * 	memory associated with the server.  It is valid to call
- * 	pop_close or pop_quit after this function has been called.
- */
-static void
-pop_trash (popserver server)
-{
-  if (server->file >= 0)
-    {
-      /* avoid recursion; sendline can call pop_trash */
-      if (server->trash_started)
-	return;
-      server->trash_started = true;
-
-      sendline (server, "RSET");
-      sendline (server, "QUIT");
-
-      CLOSESOCKET (server->file);
-      server->file = -1;
-      if (server->buffer)
-	{
-	  free (server->buffer);
-	  server->buffer = 0;
-	}
-    }
-
-#ifdef WINDOWSNT
-  if (have_winsock)
-    WSACleanup ();
-#endif
-}
-
-/* Return a pointer to the first CRLF in IN_STRING, which can contain
-   embedded nulls and has LEN characters in it not including the final
-   null, or 0 if it does not contain one.  */
-
-static char *
-find_crlf (char *in_string, int len)
-{
-  while (len--)
-    {
-      if (*in_string == '\r')
-	{
-	  if (*++in_string == '\n')
-	    return (in_string - 1);
-	}
-      else
-	in_string++;
-    }
-  return (0);
-}
-
-#ifdef WINDOWSNT
-/* The following 2 functions are only available since XP, so we load
-   them dynamically and provide fallbacks.  */
-
-int (WINAPI *pfn_getaddrinfo) (const char *, const char *,
-			       const struct addrinfo *, struct addrinfo **);
-void (WINAPI *pfn_freeaddrinfo) (struct addrinfo *);
-
-static int
-load_ws2 (void)
-{
-  static int ws2_loaded = 0;
-
-  if (!ws2_loaded)
-    {
-      HANDLE ws2_lib = LoadLibrary ("Ws2_32.dll");
-
-      if (ws2_lib != NULL)
-	{
-	  ws2_loaded = 1;
-	  pfn_getaddrinfo = (void *) GetProcAddress (ws2_lib, "getaddrinfo");
-	  pfn_freeaddrinfo = (void *) GetProcAddress (ws2_lib, "freeaddrinfo");
-	  /* Paranoia: these two functions should go together, so if
-	     one is absent, we cannot use the other.  */
-	  if (pfn_getaddrinfo == NULL)
-	    pfn_freeaddrinfo = NULL;
-	  else if (pfn_freeaddrinfo == NULL)
-	    pfn_getaddrinfo = NULL;
-	}
-    }
-  if (!ws2_loaded)
-    {
-      errno = ENETDOWN;
-      return -1;
-    }
-  return 0;
-}
-
-
-int
-sys_getaddrinfo (const char *node, const char *service,
-		 const struct addrinfo *hints, struct addrinfo **res)
-{
-  int rc;
-
-  if (load_ws2 () != 0)
-    {
-      errno = ENETDOWN;
-      return WSANO_RECOVERY;
-    }
-
-  if (pfn_getaddrinfo)
-    rc = pfn_getaddrinfo (node, service, hints, res);
-  else
-    {
-      int port = 0;
-      struct hostent *host_info;
-      struct gai_storage {
-	struct addrinfo addrinfo;
-	struct sockaddr_in sockaddr_in;
-      } *gai_storage;
-
-      /* We don't support any flags besides AI_CANONNAME.  */
-      if (hints && (hints->ai_flags & ~(AI_CANONNAME)) != 0)
-	return WSAEINVAL;
-      /* NODE cannot be NULL, since pop.c has fallbacks for that.  */
-      if (!node)
-	return WSAHOST_NOT_FOUND;
-
-      if (service)
-	{
-	  const char *protocol =
-	    (hints && hints->ai_socktype == SOCK_DGRAM) ? "udp" : "tcp";
-	  struct servent *srv = getservbyname (service, protocol);
-
-	  if (srv)
-	    port = srv->s_port;
-	  else
-	    return WSAHOST_NOT_FOUND;
-	}
-
-      gai_storage = calloc (1, sizeof *gai_storage);
-      gai_storage->sockaddr_in.sin_port = port;
-      host_info = gethostbyname (node);
-      if (host_info)
-	{
-	  memcpy (&gai_storage->sockaddr_in.sin_addr,
-		  host_info->h_addr, host_info->h_length);
-	  gai_storage->sockaddr_in.sin_family = host_info->h_addrtype;
-	}
-      else
-	{
-	  free (gai_storage);
-	  return WSAHOST_NOT_FOUND;
-	}
-
-      gai_storage->addrinfo.ai_addr =
-	(struct sockaddr *)&gai_storage->sockaddr_in;
-      gai_storage->addrinfo.ai_addrlen = sizeof (gai_storage->sockaddr_in);
-      if (hints && (hints->ai_flags & AI_CANONNAME) != 0)
-	{
-	  gai_storage->addrinfo.ai_canonname = strdup (host_info->h_name);
-	  if (!gai_storage->addrinfo.ai_canonname)
-	    {
-	      free (gai_storage);
-	      return WSA_NOT_ENOUGH_MEMORY;
-	    }
-	}
-      gai_storage->addrinfo.ai_protocol = (hints) ? hints->ai_protocol : 0;
-      gai_storage->addrinfo.ai_socktype = (hints) ? hints->ai_socktype : 0;
-      gai_storage->addrinfo.ai_family = gai_storage->sockaddr_in.sin_family;
-      gai_storage->addrinfo.ai_next = NULL;
-
-      *res = &gai_storage->addrinfo;
-      rc = 0;
-    }
-
-  return rc;
-}
-
-void
-sys_freeaddrinfo (struct addrinfo *ai)
-{
-  if (load_ws2 () != 0)
-    {
-      errno = ENETDOWN;
-      return;
-    }
-
-  if (pfn_freeaddrinfo)
-    pfn_freeaddrinfo (ai);
-  else
-    {
-      if (ai->ai_canonname)
-	free (ai->ai_canonname);
-      free (ai);
-    }
-}
-#endif	/* WINDOWSNT */
-#endif /* MAIL_USE_POP */
diff --git a/lib-src/pop.h b/lib-src/pop.h
deleted file mode 100644
index 474cf1a..0000000
--- a/lib-src/pop.h
+++ /dev/null
@@ -1,75 +0,0 @@
-/* pop.h: Header file for the "pop.c" client POP3 protocol.
-   Copyright (C) 1991, 1993, 2001-2017 Free Software Foundation, Inc.
-
-Author:  Jonathan Kamens <jik@security.ov.com>
-
-This file is part of GNU Emacs.
-
-GNU Emacs is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or (at
-your option) any later version.
-
-GNU Emacs is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
-
-
-#include <stdio.h>
-
-#define GETLINE_MIN 1024	/* the getline buffer starts out this */
-				/* size */
-#define GETLINE_INCR 1024	/* the getline buffer is grown by this */
-				/* size when it needs to grow */
-
-extern char pop_error[];
-extern bool pop_debug;
-
-struct _popserver
-{
-  int file, data;
-  char *buffer;
-  int buffer_size, buffer_index;
-  bool_bf in_multi : 1;
-  bool_bf trash_started : 1;
-};
-
-typedef struct _popserver *popserver;
-
-/*
- * Valid flags for the pop_open function.
- */
-
-#define POP_NO_KERBEROS	(1<<0)
-#define POP_NO_HESIOD	(1<<1)
-#define POP_NO_GETPASS 	(1<<2)
-
-extern popserver pop_open (char *host, char *username, char *password,
-                           int flags);
-extern int pop_stat (popserver server, int *count, int *size);
-extern int pop_list (popserver server, int message, int **IDs,
-                     int **size);
-extern int pop_retrieve (popserver server, int message, int markfrom,
-                         char **);
-extern int pop_retrieve_first (popserver server, int message,
-                               char **response);
-extern int pop_retrieve_next (popserver server, char **line);
-extern int pop_retrieve_flush (popserver server);
-extern int pop_top_first (popserver server, int message, int lines,
-                          char **response);
-extern int pop_top_next (popserver server, char **line);
-extern int pop_top_flush (popserver server);
-extern int pop_multi_first (popserver server, const char *command,
-                            char **response);
-extern int pop_multi_next (popserver server, char **line);
-extern int pop_multi_flush (popserver server);
-extern int pop_delete (popserver server, int message);
-extern int pop_noop (popserver server);
-extern int pop_last (popserver server);
-extern int pop_reset (popserver server);
-extern int pop_quit (popserver server);
-extern void pop_close (popserver);
diff --git a/lisp/mail/rmail.el b/lisp/mail/rmail.el
index 4b72b35..b91b256 100644
--- a/lisp/mail/rmail.el
+++ b/lisp/mail/rmail.el
@@ -1911,12 +1911,7 @@ rmail-parse-url
 	  (setq file (concat proto "://" user "@" host)))
 
 	(if (rmail-movemail-variant-p 'emacs)
-	    (if (string-equal proto "pop")
-		(list (concat "po:" user ":" host)
-		      t
-		      (or pass supplied-password)
-		      got-password)
-	      (error "Emacs movemail does not support %s protocol" proto))
+            (error "Emacs movemail does not support %s protocol" proto)
 	  (list file
 		(or (string-equal proto "pop") (string-equal proto "imap"))
 		(or supplied-password pass)
-- 
2.9.3

