]> Pileus Git - ~andy/fetchmail/blobdiff - pop3.c
Version bump.
[~andy/fetchmail] / pop3.c
diff --git a/pop3.c b/pop3.c
index 6a33c2f28e9d28ef40410e6006af779f04d80e66..9eae1441888758c9a2fee28872af495834552e47 100644 (file)
--- a/pop3.c
+++ b/pop3.c
 #include  "socket.h"
 #include  "i18n.h"
 
-#if OPIE
+#if OPIE_ENABLE
 #include <opie.h>
-#endif /* OPIE */
+#endif /* OPIE_ENABLE */
 
 #ifndef strstr         /* glibc-2.1 declares this as a macro */
 extern char *strstr(); /* needed on sysV68 R3V7.1. */
 #endif /* strstr */
 
-static int pop3_phase;
-#define PHASE_GETAUTH  0
-#define PHASE_GETRANGE 1
-#define PHASE_GETSIZES 2
-#define PHASE_FETCH    3
-#define PHASE_LOGOUT   4
 static int last;
 #ifdef SDPS_ENABLE
 char *sdps_envfrom;
 char *sdps_envto;
 #endif /* SDPS_ENABLE */
 
-#if OPIE
+#if OPIE_ENABLE
 static char lastok[POPBUFSIZE+1];
-#endif /* OPIE */
+#endif /* OPIE_ENABLE */
 
 int pop3_ok (int sock, char *argbuf)
 /* parse command response */
@@ -68,26 +62,40 @@ int pop3_ok (int sock, char *argbuf)
 
        if (strcmp(buf,"+OK") == 0)
        {
-#if OPIE
+#if OPIE_ENABLE
            strcpy(lastok, bufp);
-#endif /* OPIE */
+#endif /* OPIE_ENABLE */
            ok = 0;
        }
        else if (strncmp(buf,"-ERR", 4) == 0)
        {
-           if (pop3_phase > PHASE_GETAUTH) 
+           if (stage > STAGE_GETAUTH) 
                ok = PS_PROTOCOL;
            /*
             * We're checking for "lock busy", "unable to lock", 
-            * "already locked" etc. here.  This indicates that we
-            * have to wait for the server to clean up before we
-            * can poll again.
+            * "already locked", "wait a few minutes" etc. here. 
+            * This indicates that we have to wait for the server to
+            * unwedge itself before we can poll again.
             *
             * PS_LOCKBUSY check empirically verified with two recent
-            * versions the Berkeley popper;    QPOP (version 2.2)  and
+            * versions of the Berkeley popper; QPOP (version 2.2)  and
             * QUALCOMM Pop server derived from UCB (version 2.1.4-R3)
+            * These are caught by the case-indifferent "lock" check.
+            * The "wait" catches "mail storage services unavailable,
+            * wait a few minutes and try again" on the InterMail server.
+            *
+            * If these aren't picked up on correctly, fetchmail will 
+            * think there is an authentication failure and wedge the
+            * connection in order to prevent futile polls.
+            *
+            * Gad, what a kluge.
             */
-           else if (strstr(bufp,"lock")||strstr(bufp,"Lock")||strstr(bufp,"LOCK"))
+           else if (strstr(bufp,"lock")
+                    || strstr(bufp,"Lock")
+                    || strstr(bufp,"LOCK")
+                    || strstr(bufp,"wait")
+                    /* these are blessed by RFC 2449 */
+                    || strstr(bufp,"[IN-USE]")||strstr(bufp,"[LOGIN-DELAY]"))
                ok = PS_LOCKBUSY;
            else
                ok = PS_AUTHFAIL;
@@ -110,11 +118,9 @@ int pop3_getauth(int sock, struct query *ctl, char *greeting)
     int ok;
     char *start,*end;
     char *msg;
-#if OPIE
+#if OPIE_ENABLE
     char *challenge;
-#endif /* OPIE */
-
-    pop3_phase = PHASE_GETAUTH;
+#endif /* OPIE_ENABLE */
 
 #ifdef SDPS_ENABLE
     /*
@@ -126,45 +132,46 @@ int pop3_getauth(int sock, struct query *ctl, char *greeting)
         ctl->server.sdps = TRUE;
 #endif /* SDPS_ENABLE */
 
+    /* 
+     * In theory, we ought to probe with CAPA here (RFC 2449).
+     * But AFAIK this commpand is not widely implemented, and
+     * we have our own tests for optional commands, and it seems
+     * vanishingly unlikely that the RFC 2449 extended responses
+     * [IN-USE] and [LOGIN-DELAY] will ever be accidentally spoofed.
+     * So we'll not bother, and save ourselves the overhead.
+     */
+
     switch (ctl->server.protocol) {
     case P_POP3:
-        ok = gen_transact(sock, "USER %s", ctl->remotename);
-
 #ifdef RPA_ENABLE
-        /*
-         * CompuServe has changed its RPA behavior.  Used to be they didn't
-         * accept PASS, but I'm told this changed in mid-November 1997.
-         */
-        if (strstr(greeting, "csi.com")
-            && (start = strchr(ctl->remotename, '@'))
-            && !strcmp("@compuserve.com", start))
-        {
-             /* temporary fix to get back out of cleartext authentication */
-             gen_transact(sock, "PASS %s", "dummypass");
-  
-            /* AUTH command should return a list of available mechanisms */
-            if (gen_transact(sock, "AUTH") == 0)
-            {
-                char buffer[10];
-                flag has_rpa = FALSE;
-
-                while ((ok = gen_recv(sock, buffer, sizeof(buffer))) == 0)
-                {
-                    if (buffer[0] == '.')
-                        break;
-                    if (strncasecmp(buffer, "rpa", 3) == 0)
-                        has_rpa = TRUE;
-                }
-                if (has_rpa && !POP3_auth_rpa(ctl->remotename, 
-                                              ctl->password, sock))
-                    return(PS_SUCCESS);
-            }
-
-            return(PS_AUTHFAIL);
-        }
+       /* CompuServe POP3 Servers as of 990730 want AUTH first for RPA */
+       if (strstr(ctl->remotename, "@compuserve.com"))
+       {
+           /* AUTH command should return a list of available mechanisms */
+           if (gen_transact(sock, "AUTH") == 0)
+           {
+               char buffer[10];
+               flag has_rpa = FALSE;
+
+               while ((ok = gen_recv(sock, buffer, sizeof(buffer))) == 0)
+               {
+                   if (buffer[0] == '.')
+                       break;
+                   if (strncasecmp(buffer, "rpa", 3) == 0)
+                       has_rpa = TRUE;
+               }
+               if (has_rpa && !POP3_auth_rpa(ctl->remotename, 
+                                             ctl->password, sock))
+                   return(PS_SUCCESS);
+           }
+
+           return(PS_AUTHFAIL);
+       }
+       else /* not a CompuServe account */
 #endif /* RPA_ENABLE */
+           ok = gen_transact(sock, "USER %s", ctl->remotename);
 
-#if OPIE
+#if OPIE_ENABLE
        /* see RFC1938: A One-Time Password System */
        if (challenge = strstr(lastok, "otp-")) {
          char response[OPIE_RESPONSE_MAX+1];
@@ -187,7 +194,7 @@ int pop3_getauth(int sock, struct query *ctl, char *greeting)
          ok = gen_transact(sock, "PASS %s", response);
          break;
        }
-#endif /* OPIE */
+#endif /* OPIE_ENABLE */
 
        /* ordinary validation, no one-time password or RPA */ 
        ok = gen_transact(sock, "PASS %s", ctl->password);
@@ -381,8 +388,6 @@ static int pop3_getrange(int sock,
     int ok;
     char buf [POPBUFSIZE+1];
 
-    pop3_phase = PHASE_GETRANGE;
-
     /* Ensure that the new list is properly empty */
     ctl->newsaved = (struct idlist *)NULL;
 
@@ -474,8 +479,6 @@ static int pop3_getsizes(int sock, int count, int *sizes)
 {
     int        ok;
 
-    /* pop3_phase = PHASE_GETSIZES */
-
     if ((ok = gen_transact(sock, "LIST")) != 0)
        return(ok);
     else
@@ -519,8 +522,6 @@ static int pop_fetch_headers(int sock, struct query *ctl,int number,int *lenp)
     int ok;
     char buf[POPBUFSIZE+1];
 
-    /* pop3_phase = PHASE_FETCH */
-
     gen_send(sock, "TOP %d 0", number);
     if ((ok = pop3_ok(sock, buf)) != 0)
        return(ok);
@@ -537,8 +538,6 @@ static int pop3_fetch(int sock, struct query *ctl, int number, int *lenp)
     int ok;
     char buf[POPBUFSIZE+1];
 
-    /* pop3_phase = PHASE_FETCH */
-
 #ifdef SDPS_ENABLE
     /*
      * See http://www.demon.net/services/mail/sdps-tech.html
@@ -627,8 +626,6 @@ static int pop3_logout(int sock, struct query *ctl)
 {
     int ok;
 
-    /* pop3_phase = PHASE_LOGOUT */
-
     ok = gen_transact(sock, "QUIT");
     if (!ok)
        expunge_uids(ctl);
@@ -639,11 +636,13 @@ static int pop3_logout(int sock, struct query *ctl)
 const static struct method pop3 =
 {
     "POP3",            /* Post Office Protocol v3 */
-#if INET6
+#if INET6_ENABLE
     "pop3",            /* standard POP3 port */
-#else /* INET6 */
+    "pop3s",           /* ssl POP3 port */
+#else /* INET6_ENABLE */
     110,               /* standard POP3 port */
-#endif /* INET6 */
+    995,               /* ssl POP3 port */
+#endif /* INET6_ENABLE */
     FALSE,             /* this is not a tagged protocol */
     TRUE,              /* this uses a message delimiter */
     pop3_ok,           /* parse command response */