]> code.delx.au - gnu-emacs/blobdiff - lib-src/pop.c
lib-src/emacsclient.c (w32_execvp): Declare execvp to silence the compiler.
[gnu-emacs] / lib-src / pop.c
index 4ac55192fd660ea0acfcfa3de5e16085f95dbc34..b8ed65c3eac0ffd85cb1bc454940ec27f2d985c4 100644 (file)
@@ -1,6 +1,7 @@
 /* pop.c: client routines for talking to a POP3-protocol post-office server
-   Copyright (C) 1991, 1993, 1996, 1997, 1999, 2001, 2002, 2003, 2004,
-                 2005, 2006, 2007, 2008, 2009, 2010, 2011  Free Software Foundation, Inc.
+
+Copyright (C) 1991, 1993, 1996-1997, 1999, 2001-2012
+  Free Software Foundation, Inc.
 
 Author: Jonathan Kamens <jik@security.ov.com>
 
@@ -20,11 +21,7 @@ You should have received a copy of the GNU General Public License
 along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 
 
-#ifdef HAVE_CONFIG_H
 #include <config.h>
-#else
-#define MAIL_USE_POP
-#endif
 
 #ifdef MAIL_USE_POP
 
@@ -33,15 +30,15 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #include "ntlib.h"
 #include <winsock.h>
 #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)
+#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)
+#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>
 
@@ -64,10 +61,7 @@ extern struct servent *hes_getservbyname (/* char *, char * */);
 #include <netdb.h>
 #include <errno.h>
 #include <stdio.h>
-#ifdef STDC_HEADERS
 #include <string.h>
-#define index strchr
-#endif
 #include <unistd.h>
 
 #ifdef KERBEROS
@@ -90,6 +84,8 @@ extern struct servent *hes_getservbyname (/* char *, char * */);
 # endif
 #endif /* KERBEROS */
 
+#include <min-max.h>
+
 #ifdef KERBEROS
 #ifndef KERBEROS5
 extern int krb_sendauth (/* long, int, KTEXT, char *, char *, char *,
@@ -101,7 +97,7 @@ extern char *krb_realmofhost (/* char * */);
 #endif /* KERBEROS */
 
 #ifndef WINDOWSNT
-#if !defined(HAVE_H_ERRNO) || !defined(HAVE_CONFIG_H)
+#ifndef HAVE_H_ERRNO
 extern int h_errno;
 #endif
 #endif
@@ -121,19 +117,15 @@ static char *find_crlf (char *, int);
                                   to be bigger than the original
                                   value of 80 */
 #define POP_PORT 110
-#define KPOP_PORT 1109
 #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];
 int pop_debug = 0;
 
-#ifndef min
-#define min(a,b) (((a) < (b)) ? (a) : (b))
-#endif
-
 /*
  * Function: pop_open (char *host, char *username, char *password,
  *                    int flags)
@@ -350,6 +342,7 @@ pop_stat (popserver server, int *count, int *size)
       if (0 == strncmp (fromserver, "-ERR", 4))
        {
          strncpy (pop_error, fromserver, ERROR_MAX);
+         pop_error[ERROR_MAX-1] = '\0';
        }
       else
        {
@@ -451,7 +444,10 @@ pop_list (popserver server, int message, int **IDs, int **sizes)
       if (strncmp (fromserver, "+OK ", 4))
        {
          if (! strncmp (fromserver, "-ERR", 4))
-           strncpy (pop_error, fromserver, ERROR_MAX);
+           {
+             strncpy (pop_error, fromserver, ERROR_MAX);
+             pop_error[ERROR_MAX-1] = '\0';
+           }
          else
            {
              strcpy (pop_error,
@@ -691,6 +687,7 @@ pop_multi_first (popserver server, const char *command, char **response)
   if (0 == strncmp (*response, "-ERR", 4))
     {
       strncpy (pop_error, *response, ERROR_MAX);
+      pop_error[ERROR_MAX-1] = '\0';
       return (-1);
     }
   else if (0 == strncmp (*response, "+OK", 3))
@@ -864,6 +861,7 @@ pop_last (popserver server)
   if (! strncmp (fromserver, "-ERR", 4))
     {
       strncpy (pop_error, fromserver, ERROR_MAX);
+      pop_error[ERROR_MAX-1] = '\0';
       return (-1);
     }
   else if (strncmp (fromserver, "+OK ", 4))
@@ -1071,7 +1069,7 @@ socket_connection (char *host, int flags)
     }
 
 #ifdef HAVE_GETADDRINFO
-  memset (&hints, 0, sizeof(hints));
+  memset (&hints, 0, sizeof (hints));
   hints.ai_socktype = SOCK_STREAM;
   hints.ai_flags = AI_CANONNAME;
   hints.ai_family = AF_INET;
@@ -1163,7 +1161,7 @@ socket_connection (char *host, int flags)
            krb5_free_context (kcontext);
          strcpy (pop_error, KRB_ERROR);
          strncat (pop_error, error_message (rem),
-                  ERROR_MAX - sizeof(KRB_ERROR));
+                  ERROR_MAX - sizeof (KRB_ERROR));
          CLOSESOCKET (sock);
          return (-1);
        }
@@ -1216,7 +1214,7 @@ socket_connection (char *host, int flags)
                       ERROR_MAX - strlen (pop_error) - 1);
            }
 #elif defined HAVE_KRB5_ERROR_E_TEXT
-         if (err_ret && err_ret->e_text && strlen(*err_ret->e_text))
+         if (err_ret && err_ret->e_text && strlen (*err_ret->e_text))
            {
              strncat (pop_error, " [server says '",
                       ERROR_MAX - strlen (pop_error) - 1);
@@ -1624,6 +1622,3 @@ find_crlf (char *in_string, int len)
 }
 
 #endif /* MAIL_USE_POP */
-
-/* arch-tag: ceb37041-b7ad-49a8-a63d-286618b8367d
-   (do not change this comment) */