]> code.delx.au - gnu-emacs/blobdiff - lib-src/pop.c
*** empty log message ***
[gnu-emacs] / lib-src / pop.c
index 46a60195aff1749aa9583db07042d9a7553d41e4..9fcbe4b370cdc3c2744e24005c11785860ec7d05 100644 (file)
@@ -1,12 +1,13 @@
 /* pop.c: client routines for talking to a POP3-protocol post-office server
-   Copyright (c) 1991, 1993, 1996, 1997, 1999 Free Software Foundation, Inc.
+   Copyright (C) 1991, 1993, 1996, 1997, 1999, 2001, 2002, 2003, 2004,
+                 2005, 2006, 2007  Free Software Foundation, Inc.
    Written by 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 2, or (at your option)
+the Free Software Foundation; either version 3, or (at your option)
 any later version.
 
 GNU Emacs is distributed in the hope that it will be useful,
@@ -16,8 +17,8 @@ GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with GNU Emacs; see the file COPYING.  If not, write to
-the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA.  */
+the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA.  */
 
 #ifdef HAVE_CONFIG_H
 #define NO_SHORTNAMES  /* Tell config not to load remap.h */
@@ -76,17 +77,6 @@ extern struct servent *hes_getservbyname (/* char *, char * */);
 # ifdef HAVE_KRB5_H
 #  include <krb5.h>
 # endif
-# ifdef HAVE_DES_H
-#  include <des.h>
-# else
-#  ifdef HAVE_KERBEROSIV_DES_H
-#   include <kerberosIV/des.h>
-#  else
-#   ifdef HAVE_KERBEROS_DES_H
-#    include <kerberos/des.h>
-#   endif
-#  endif
-# endif
 # ifdef HAVE_KRB_H
 #  include <krb.h>
 # else
@@ -145,7 +135,7 @@ static char *find_crlf __P((char *, int));
 #define KPOP_PORT 1109
 #define POP_SERVICE "pop3"     /* we don't want the POP2 port! */
 #ifdef KERBEROS
-#define KPOP_SERVICE "kpop"
+#define KPOP_SERVICE "kpop"    /* never used: look for 20060515 to see why */
 #endif
 
 char pop_error[ERROR_MAX];
@@ -261,7 +251,7 @@ pop_open (host, username, password, flags)
 #else
 #define DONT_NEED_PASSWORD 0
 #endif
+
   if ((! password) && (! DONT_NEED_PASSWORD))
     {
       if (! (flags & POP_NO_GETPASS))
@@ -274,10 +264,11 @@ pop_open (host, username, password, flags)
          return (0);
        }
     }
-  if (password)
+  if (password)                        /* always true, detected 20060515 */
     flags |= POP_NO_KERBEROS;
   else
-    password = username;
+    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)
@@ -560,7 +551,7 @@ pop_list (server, message, IDs, sizes)
  *             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.
@@ -643,7 +634,7 @@ pop_retrieve (server, message, markfrom, msg_buf)
 
   free (ptr);
   return (-1);
-}     
+}
 
 int
 pop_retrieve_first (server, message, response)
@@ -1057,6 +1048,7 @@ socket_connection (host, flags)
   bzero ((char *) &addr, 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
@@ -1083,6 +1075,7 @@ socket_connection (host, flags)
        }
       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);
@@ -1403,12 +1396,24 @@ sendline (server, line)
 {
 #define SENDLINE_ERROR "Error writing to POP server: "
   int ret;
-
-  ret = fullwrite (server->file, line, strlen (line));
-  if (ret >= 0)
-    {                          /* 0 indicates that a blank line was written */
-      ret = fullwrite (server->file, "\r\n", 2);
-    }
+  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 (buf, line);
+  strcat (buf, "\r\n");
+  ret = fullwrite (server->file, buf, strlen (buf));
 
   if (ret < 0)
     {
@@ -1607,3 +1612,6 @@ find_crlf (in_string, len)
 }
 
 #endif /* MAIL_USE_POP */
+
+/* arch-tag: ceb37041-b7ad-49a8-a63d-286618b8367d
+   (do not change this comment) */