aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--driver.c20
-rw-r--r--fetchmail.h1
-rw-r--r--imap.c49
-rw-r--r--pop2.c11
-rw-r--r--pop3.c28
5 files changed, 41 insertions, 68 deletions
diff --git a/driver.c b/driver.c
index f3ec8ab0..61e6ffae 100644
--- a/driver.c
+++ b/driver.c
@@ -1384,6 +1384,26 @@ va_dcl
}
}
+int gen_recv(sockfp, buf, size)
+/* get one line of input from the server */
+FILE *sockfp; /* socket to which server is connected */
+char *buf; /* buffer to receive input */
+int size; /* length of buffer */
+{
+ if (!SockGets(buf, size, sockfp))
+ return(PS_SOCKET);
+ else
+ {
+ 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, "%s< %s", protocol->name, buf);
+ return(PS_SUCCESS);
+ }
+}
+
#if defined(HAVE_STDARG_H)
int gen_transact(FILE *sockfp, char *fmt, ... )
/* assemble command in printf(3) style, send to server, accept a response */
diff --git a/fetchmail.h b/fetchmail.h
index 729b354e..e18a7b52 100644
--- a/fetchmail.h
+++ b/fetchmail.h
@@ -180,6 +180,7 @@ void error (int status, int errnum, const char *format, ...);
void error_build (const char *format, ...);
void error_complete (int status, int errnum, const char *format, ...);
void gen_send (FILE *sockfp, char *, ... );
+int gen_recv(FILE *sockfp, char *buf, int size);
int gen_transact (FILE *sockfp, char *, ... );
#else
void error ();
diff --git a/imap.c b/imap.c
index 9d9c1f32..720fd7d5 100644
--- a/imap.c
+++ b/imap.c
@@ -32,14 +32,10 @@ int imap_ok (FILE *sockfp, char *argbuf)
seen = 0;
do {
- if (!SockGets(buf, sizeof(buf), sockfp))
- return(PS_SOCKET);
- 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, "IMAP< %s", buf);
+ int ok;
+
+ if (ok = gen_recv(sockfp, buf, sizeof(buf)))
+ return(ok);
/* interpret untagged status responses */
if (strstr(buf, "EXISTS"))
@@ -95,14 +91,8 @@ int imap_getauth(FILE *sockfp, struct query *ctl, char *buf)
/* probe to see if we're running IMAP4 and can use RFC822.PEEK */
gen_send(sockfp, "CAPABILITY");
- if (!SockGets(rbuf, sizeof(rbuf), sockfp))
- return(PS_SOCKET);
- if (rbuf[strlen(buf)-1] == '\n')
- rbuf[strlen(buf)-1] = '\0';
- if (rbuf[strlen(buf)-1] == '\r')
- rbuf[strlen(buf)-1] = '\r';
- if (outlevel == O_VERBOSE)
- error(0, 0, "IMAP< %s", rbuf);
+ if (ok = gen_recv(sockfp, rbuf, sizeof(rbuf)))
+ return(ok);
if (strstr(rbuf, "BAD"))
{
imap_version = IMAP2;
@@ -160,14 +150,10 @@ static int imap_getsizes(FILE *sockfp, int count, int *sizes)
gen_send(sockfp, "FETCH 1:%d RFC822.SIZE", count);
while (SockGets(buf, sizeof(buf), sockfp))
{
- int num, size;
+ int num, size, ok;
- 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, "IMAP< %s", buf);
+ if (ok = gen_recv(sockfp, buf, sizeof(buf)))
+ return(ok);
if (strstr(buf, "OK"))
break;
else if (sscanf(buf, "* %d FETCH (RFC822.SIZE %d)", &num, &size) == 2)
@@ -235,14 +221,10 @@ static int imap_fetch(FILE *sockfp, struct query *ctl, int number, int *lenp)
/* looking for FETCH response */
do {
- if (!SockGets(buf, sizeof(buf), sockfp))
- return(PS_SOCKET);
- 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, "IMAP< %s", buf);
+ int ok;
+
+ if (ok = gen_recv(sockfp, buf, sizeof(buf)))
+ return(ok);
} while
/* third token can be "RFC822" or "BODY[]" */
(sscanf(buf+2, "%d FETCH (%*s {%d}", &num, lenp) != 2);
@@ -261,10 +243,7 @@ static int imap_trail(FILE *sockfp, struct query *ctl, int number)
/* expunges change the fetch numbers */
/* number -= deletecount; */
- if (!SockGets(buf, sizeof(buf), sockfp))
- return(PS_SOCKET);
- else
- return(0);
+ return(gen_recv(sockfp, buf, sizeof(buf)));
}
static int imap_delete(FILE *sockfp, struct query *ctl, int number)
diff --git a/pop2.c b/pop2.c
index fcf907f0..80611a5c 100644
--- a/pop2.c
+++ b/pop2.c
@@ -23,14 +23,9 @@ int pop2_ok (FILE *sockfp, char *argbuf)
char buf [POPBUFSIZE+1];
pound_arg = equal_arg = -1;
- 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, "POP2< %s", buf);
+ if ((ok = gen_recv(sockfp, buf, sizeof(buf))) == 0)
+ {
if (buf[0] == '+')
ok = 0;
else if (buf[0] == '#')
@@ -51,8 +46,6 @@ int pop2_ok (FILE *sockfp, char *argbuf)
if (argbuf != NULL)
strcpy(argbuf,buf);
}
- else
- ok = PS_SOCKET;
return(ok);
}
diff --git a/pop3.c b/pop3.c
index 01b92b84..07fc22de 100644
--- a/pop3.c
+++ b/pop3.c
@@ -32,14 +32,8 @@ 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++;
@@ -60,8 +54,6 @@ int pop3_ok (FILE *sockfp, char *argbuf)
if (argbuf != NULL)
strcpy(argbuf,bufp);
}
- else
- ok = PS_SOCKET;
return(ok);
}
@@ -179,14 +171,8 @@ static int pop3_getrange(FILE *sockfp, struct query *ctl, int*countp, int*newp)
int num;
*newp = 0;
- while (SockGets(buf, sizeof(buf), sockfp))
+ while (!gen_recv(sockfp, buf, sizeof(buf)))
{
- 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)
@@ -216,16 +202,10 @@ static int pop3_getsizes(FILE *sockfp, int count, int *sizes)
{
char buf [POPBUFSIZE+1];
- while (SockGets(buf, sizeof(buf), sockfp))
+ while (!gen_recv(sockfp, buf, sizeof(buf)))
{
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)