#define PROTOCOL_ERROR {error(0, 0, "protocol error"); return(PS_ERROR);}
+extern char *strstr(); /* needed on sysV68 R3V7.1. */
+
static int last;
int pop3_ok (FILE *sockfp, char *argbuf)
char buf [POPBUFSIZE+1];
char *bufp;
- if (SockGets(buf, sizeof(buf), sockfp)) {
- if (buf[strlen(buf)-1] == '\n')
- buf[strlen(buf)-1] = '\0';
- if (buf[strlen(buf)-1] == '\r')
- buf[strlen(buf)-1] = '\r';
- if (outlevel == O_VERBOSE)
- error(0, 0, "POP3< %s", buf);
-
+ if ((ok = gen_recv(sockfp, buf, sizeof(buf))) == 0)
+ {
bufp = buf;
if (*bufp == '+' || *bufp == '-')
bufp++;
if (argbuf != NULL)
strcpy(argbuf,bufp);
}
- else
- ok = PS_SOCKET;
return(ok);
}
/* apply for connection authorization */
{
/* build MD5 digest from greeting timestamp + password */
- if (ctl->protocol == P_APOP)
+ if (ctl->server.protocol == P_APOP)
{
char *start,*end;
char *msg;
free(msg);
}
- switch (ctl->protocol) {
+ switch (ctl->server.protocol) {
case P_POP3:
- if ((gen_transact(sockfp,"USER %s", ctl->remotename)) != 0)
+ if ((gen_transact(sockfp, "USER %s", ctl->remotename)) != 0)
PROTOCOL_ERROR
if ((gen_transact(sockfp, "PASS %s", ctl->password)) != 0)
PROTOCOL_ERROR
break;
+ case P_RPOP:
+ if ((gen_transact(sockfp,"USER %s", ctl->remotename)) != 0)
+ PROTOCOL_ERROR
+
+ if ((gen_transact(sockfp, "RPOP %s", ctl->password)) != 0)
+ PROTOCOL_ERROR
+ break;
+
default:
error(0, 0, "Undefined protocol request in POP3_auth");
}
int num;
*newp = 0;
- while (SockGets(buf, sizeof(buf), sockfp))
+ while ((ok = gen_recv(sockfp, buf, sizeof(buf))) == 0)
{
- if (buf[strlen(buf)-1] == '\n')
- buf[strlen(buf)-1] = '\0';
- if (buf[strlen(buf)-1] == '\r')
- buf[strlen(buf)-1] = '\r';
- if (outlevel == O_VERBOSE)
- error(0, 0, "POP3< %s", buf);
if (buf[0] == '.')
break;
else if (sscanf(buf, "%d %s", &num, id) == 2)
{
char buf [POPBUFSIZE+1];
- while (SockGets(buf, sizeof(buf), sockfp))
+ while ((ok = gen_recv(sockfp, buf, sizeof(buf))) == 0)
{
int num, size;
- if (buf[strlen(buf)-1] == '\n')
- buf[strlen(buf)-1] = '\0';
- if (buf[strlen(buf)-1] == '\r')
- buf[strlen(buf)-1] = '\r';
- if (outlevel == O_VERBOSE)
- error(0, 0, "POP3< %s", buf);
if (buf[0] == '.')
break;
else if (sscanf(buf, "%d %d", &num, &size) == 2)
sizes[num - 1] = -1;
}
- return(0);
+ return(ok);
}
}
str_find (&ctl->newsaved, num)));
}
-static int pop3_fetch(FILE *sockfp, int number, int *lenp)
+static int pop3_fetch(FILE *sockfp, struct query *ctl, int number, int *lenp)
/* request nth message */
{
int ok;
*lenp = 0;
else
{
- while (--cp > buf && isdigit(*cp))
+ while (--cp >= buf && isdigit(*cp))
continue;
- *lenp = atoi(cp);
+ *lenp = atoi(++cp);
}
return(0);
}
pop3_fetch, /* request given message */
NULL, /* no message trailer */
pop3_delete, /* how to delete a message */
- NULL, /* no POP3 expunge command */
"QUIT", /* the POP3 exit command */
};
int doPOP3 (struct query *ctl)
/* retrieve messages using POP3 */
{
- if (ctl->mailbox[0]) {
+ if (ctl->mailbox) {
fprintf(stderr,"Option --remote is not supported with POP3\n");
return(PS_SYNTAX);
}