#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 */
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;
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
/*
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];
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);
int ok;
char buf [POPBUFSIZE+1];
- pop3_phase = PHASE_GETRANGE;
-
/* Ensure that the new list is properly empty */
ctl->newsaved = (struct idlist *)NULL;
{
int ok;
- /* pop3_phase = PHASE_GETSIZES */
-
if ((ok = gen_transact(sock, "LIST")) != 0)
return(ok);
else
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);
int ok;
char buf[POPBUFSIZE+1];
- /* pop3_phase = PHASE_FETCH */
-
#ifdef SDPS_ENABLE
/*
* See http://www.demon.net/services/mail/sdps-tech.html
{
int ok;
- /* pop3_phase = PHASE_LOGOUT */
-
ok = gen_transact(sock, "QUIT");
if (!ok)
expunge_uids(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 */