#include "config.h"
#ifdef POP2_ENABLE
#include <stdio.h>
#if defined(STDC_HEADERS)
#include <stdlib.h>
#endif
#include "fetchmail.h"
#include "socket.h"
static int pound_arg, equal_arg;
static int pop2_ok (int sock, char *argbuf)
{
int ok;
char buf [POPBUFSIZE+1];
pound_arg = equal_arg = -1;
if ((ok = gen_recv(sock, buf, sizeof(buf))) == 0)
{
if (buf[0] == '+')
ok = 0;
else if (buf[0] == '#')
{
pound_arg = atoi(buf+1);
ok = 0;
}
else if (buf[0] == '=')
{
equal_arg = atoi(buf+1);
ok = 0;
}
else if (buf[0] == '-')
ok = PS_ERROR;
else
ok = PS_PROTOCOL;
if (argbuf != NULL)
strcpy(argbuf,buf);
}
return(ok);
}
static int pop2_getauth(int sock, struct query *ctl, char *buf)
{
int status;
strcpy(shroud, ctl->password);
status = gen_transact(sock,
"HELO %s %s",
ctl->remotename, ctl->password);
shroud[0] = '\0';
}
static int pop2_getrange(int sock, struct query *ctl, const char *folder,
int *countp, int *newp, int *bytes)
{
if (folder)
{
int ok = gen_transact(sock, "FOLD %s", folder);
if (ok != 0)
return(ok);
if (pound_arg == -1)
return(PS_ERROR);
}
else
if (pound_arg == -1)
return(PS_ERROR);
*countp = pound_arg;
*bytes = *newp = -1;
return(0);
}
static int pop2_fetch(int sock, struct query *ctl, int number, int *lenp)
{
int ok;
*lenp = 0;
ok = gen_transact(sock, "READ %d", number);
if (ok)
return(0);
*lenp = equal_arg;
gen_send(sock, "RETR");
return(ok);
}
static int pop2_trail(int sock, struct query *ctl, int number)
{
return(gen_transact(sock, ctl->keep ? "ACKS" : "ACKD"));
}
static int pop2_logout(int sock, struct query *ctl)
{
return(gen_transact(sock, "QUIT"));
}
const static struct method pop2 =
{
"POP2",
#if INET6_ENABLE
"pop2",
"pop2",
#else
109,
109,
#endif
FALSE,
FALSE,
pop2_ok,
pop2_getauth,
pop2_getrange,
NULL,
NULL,
pop2_fetch,
NULL,
pop2_trail,
NULL,
pop2_logout,
FALSE,
};
int doPOP2 (struct query *ctl)
{
peek_capable = FALSE;
return(do_protocol(ctl, &pop2));
}
#endif