aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--driver.c53
-rw-r--r--fetchmail.h4
-rw-r--r--imap.c52
-rw-r--r--pop2.c32
-rw-r--r--pop3.c58
5 files changed, 101 insertions, 98 deletions
diff --git a/driver.c b/driver.c
index afe07d21..4b030c27 100644
--- a/driver.c
+++ b/driver.c
@@ -852,6 +852,7 @@ const struct method *proto; /* protocol method table */
{
char buf [POPBUFSIZE+1];
int *msgsizes, socket, len, num, count, new, deletions = 0;
+ FILE *sockfp;
/* open a socket to the mail server */
if ((socket = Socket(ctl->servername,
@@ -862,6 +863,8 @@ const struct method *proto; /* protocol method table */
goto closeUp;
}
+ sockfp = fdopen(socket, "r+");
+
#ifdef KERBEROS_V4
if (ctl->authenticate == A_KERBEROS)
{
@@ -873,14 +876,14 @@ const struct method *proto; /* protocol method table */
#endif /* KERBEROS_V4 */
/* accept greeting message from mail server */
- ok = (protocol->parse_response)(socket, buf);
+ ok = (protocol->parse_response)(sockfp, buf);
vtalarm(ctl->timeout);
if (ok != 0)
goto cleanUp;
/* try to get authorized to fetch mail */
shroud = ctl->password;
- ok = (protocol->getauth)(socket, ctl, buf);
+ ok = (protocol->getauth)(sockfp, ctl, buf);
vtalarm(ctl->timeout);
shroud = (char *)NULL;
if (ok == PS_ERROR)
@@ -889,7 +892,7 @@ const struct method *proto; /* protocol method table */
goto cleanUp;
/* compute number of messages and number of new messages waiting */
- if ((protocol->getrange)(socket, ctl, &count, &new) != 0)
+ if ((protocol->getrange)(sockfp, ctl, &count, &new) != 0)
goto cleanUp;
vtalarm(ctl->timeout);
@@ -916,7 +919,7 @@ const struct method *proto; /* protocol method table */
{
msgsizes = (int *)alloca(sizeof(int) * count);
- if ((ok = (proto->getsizes)(socket, count, msgsizes)) != 0)
+ if ((ok = (proto->getsizes)(sockfp, count, msgsizes)) != 0)
return(PS_ERROR);
}
@@ -934,7 +937,7 @@ const struct method *proto; /* protocol method table */
{
int toolarge = msgsizes && msgsizes[num-1]>ctl->limit;
int fetch_it = ctl->fetchall ||
- (!(protocol->is_old && (protocol->is_old)(socket,ctl,num)) && !toolarge);
+ (!(protocol->is_old && (protocol->is_old)(sockfp,ctl,num)) && !toolarge);
/* we may want to reject this message if it's old */
if (!fetch_it)
@@ -949,7 +952,7 @@ const struct method *proto; /* protocol method table */
else
{
/* request a message */
- (protocol->fetch)(socket, num, &len);
+ (protocol->fetch)(sockfp, num, &len);
vtalarm(ctl->timeout);
if (outlevel > O_SILENT)
@@ -964,7 +967,7 @@ const struct method *proto; /* protocol method table */
}
/* read the message and ship it to the output sink */
- ok = gen_readmsg(socket,
+ ok = gen_readmsg(fileno(sockfp),
len,
protocol->delimited,
ctl);
@@ -974,7 +977,7 @@ const struct method *proto; /* protocol method table */
/* tell the server we got it OK and resynchronize */
if (protocol->trail)
- (protocol->trail)(socket, ctl, num);
+ (protocol->trail)(sockfp, ctl, num);
}
/*
@@ -993,7 +996,7 @@ const struct method *proto; /* protocol method table */
deletions++;
if (outlevel > O_SILENT)
fprintf(stderr, " flushed\n");
- ok = (protocol->delete)(socket, ctl, num);
+ ok = (protocol->delete)(sockfp, ctl, num);
vtalarm(ctl->timeout);
if (ok != 0)
goto cleanUp;
@@ -1009,30 +1012,30 @@ const struct method *proto; /* protocol method table */
/* remove all messages flagged for deletion */
if (protocol->expunge_cmd && deletions > 0)
{
- ok = gen_transact(socket, protocol->expunge_cmd);
+ ok = gen_transact(sockfp, protocol->expunge_cmd);
if (ok != 0)
goto cleanUp;
}
- ok = gen_transact(socket, protocol->exit_cmd);
+ ok = gen_transact(sockfp, protocol->exit_cmd);
if (ok == 0)
ok = PS_SUCCESS;
- close(socket);
+ fclose(sockfp);
goto closeUp;
}
else {
- ok = gen_transact(socket, protocol->exit_cmd);
+ ok = gen_transact(sockfp, protocol->exit_cmd);
if (ok == 0)
ok = PS_NOMAIL;
- close(socket);
+ fclose(sockfp);
goto closeUp;
}
cleanUp:
if (ok != 0 && ok != PS_SOCKET)
{
- gen_transact(socket, protocol->exit_cmd);
- close(socket);
+ gen_transact(sockfp, protocol->exit_cmd);
+ fclose(sockfp);
}
}
@@ -1043,13 +1046,13 @@ closeUp:
}
#if defined(HAVE_STDARG_H)
-void gen_send(int socket, char *fmt, ... )
+void gen_send(FILE *sockfp, char *fmt, ... )
/* assemble command in printf(3) style and send to the server */
{
#else
-void gen_send(socket, fmt, va_alist)
+void gen_send(sockfp, fmt, va_alist)
/* assemble command in printf(3) style and send to the server */
-int socket; /* socket to which server is connected */
+FILE *sockfp; /* socket to which server is connected */
const char *fmt; /* printf-style format */
va_dcl {
#endif
@@ -1070,7 +1073,7 @@ va_dcl {
vsprintf(buf + strlen(buf), fmt, ap);
va_end(ap);
- SockPuts(socket, buf);
+ SockPuts(fileno(sockfp), buf);
if (outlevel == O_VERBOSE)
{
@@ -1083,13 +1086,13 @@ va_dcl {
}
#if defined(HAVE_STDARG_H)
-int gen_transact(int socket, char *fmt, ... )
+int gen_transact(FILE *sockfp, char *fmt, ... )
/* assemble command in printf(3) style, send to server, accept a response */
{
#else
-int gen_transact(socket, fmt, va_alist)
+int gen_transact(sockfp, fmt, va_alist)
/* assemble command in printf(3) style, send to server, accept a response */
-int socket; /* socket to which server is connected */
+FILE *sockfp; /* socket to which server is connected */
const char *fmt; /* printf-style format */
va_dcl {
#endif
@@ -1111,7 +1114,7 @@ va_dcl {
vsprintf(buf + strlen(buf), fmt, ap);
va_end(ap);
- SockPuts(socket, buf);
+ SockPuts(fileno(sockfp), buf);
if (outlevel == O_VERBOSE)
{
char *cp;
@@ -1122,7 +1125,7 @@ va_dcl {
}
/* we presume this does its own response echoing */
- ok = (protocol->parse_response)(socket, buf);
+ ok = (protocol->parse_response)(sockfp, buf);
vtalarm(mytimeout);
return(ok);
diff --git a/fetchmail.h b/fetchmail.h
index 356e48f6..3cd5c104 100644
--- a/fetchmail.h
+++ b/fetchmail.h
@@ -150,8 +150,8 @@ extern char *user; /* name of invoking user */
/* prototypes for globally callable functions */
#if defined(HAVE_STDARG_H)
-void gen_send (int socket, char *, ... );
-int gen_transact (int socket, char *, ... );
+void gen_send (FILE *sockfp, char *, ... );
+int gen_transact (FILE *sockfp, char *, ... );
#else
void gen_send ();
int gen_transact ();
diff --git a/imap.c b/imap.c
index 1b2d847d..1c64bdc6 100644
--- a/imap.c
+++ b/imap.c
@@ -18,16 +18,16 @@
static int count, seen, recent, unseen;
-int imap_ok (socket, argbuf)
+int imap_ok (sockfp, argbuf)
/* parse command response */
char *argbuf;
-int socket;
+FILE *sockfp;
{
char buf [POPBUFSIZE+1];
seen = 0;
do {
- if (SockGets(socket, buf, sizeof(buf)) < 0)
+ if (SockGets(fileno(sockfp), buf, sizeof(buf)) < 0)
return(PS_SOCKET);
if (outlevel == O_VERBOSE)
@@ -72,21 +72,21 @@ int socket;
}
}
-int imap_getauth(socket, ctl, buf)
+int imap_getauth(sockfp, ctl, buf)
/* apply for connection authorization */
-int socket;
+FILE *sockfp;
struct query *ctl;
char *buf;
{
/* try to get authorized */
- return(gen_transact(socket,
+ return(gen_transact(sockfp,
"LOGIN %s \"%s\"",
ctl->remotename, ctl->password));
}
-static int imap_getrange(socket, ctl, countp, newp)
+static int imap_getrange(sockfp, ctl, countp, newp)
/* get range of messages to be fetched */
-int socket;
+FILE *sockfp;
struct query *ctl;
int *countp, *newp;
{
@@ -94,7 +94,7 @@ int *countp, *newp;
/* find out how many messages are waiting */
recent = unseen = 0;
- ok = gen_transact(socket,
+ ok = gen_transact(sockfp,
"SELECT %s",
ctl->mailbox[0] ? ctl->mailbox : "INBOX");
if (ok != 0)
@@ -112,16 +112,16 @@ int *countp, *newp;
return(0);
}
-static int imap_getsizes(socket, count, sizes)
+static int imap_getsizes(sockfp, count, sizes)
/* capture the sizes of all messages */
-int socket;
+FILE *sockfp;
int count;
int *sizes;
{
char buf [POPBUFSIZE+1];
- gen_send(socket, "FETCH 1:%d RFC822.SIZE", count);
- while (SockGets(socket, buf, sizeof(buf)) >= 0)
+ gen_send(sockfp, "FETCH 1:%d RFC822.SIZE", count);
+ while (SockGets(fileno(sockfp), buf, sizeof(buf)) >= 0)
{
int num, size;
@@ -138,34 +138,34 @@ int *sizes;
return(0);
}
-static int imap_is_old(socket, ctl, num)
+static int imap_is_old(sockfp, ctl, num)
/* is the given message old? */
-int socket;
+FILE *sockfp;
struct query *ctl;
int num;
{
int ok;
- if ((ok = gen_transact(socket, "FETCH %d FLAGS", num)) != 0)
+ if ((ok = gen_transact(sockfp, "FETCH %d FLAGS", num)) != 0)
exit(PS_ERROR);
return(seen);
}
-static int imap_fetch(socket, number, lenp)
+static int imap_fetch(sockfp, number, lenp)
/* request nth message */
-int socket;
+FILE *sockfp;
int number;
int *lenp;
{
char buf [POPBUFSIZE+1];
int num;
- gen_send(socket, "FETCH %d RFC822", number);
+ gen_send(sockfp, "FETCH %d RFC822", number);
/* looking for FETCH response */
do {
- if (SockGets(socket, buf,sizeof(buf)) < 0)
+ if (SockGets(fileno(sockfp), buf,sizeof(buf)) < 0)
return(PS_SOCKET);
} while
(sscanf(buf+2, "%d FETCH (RFC822 {%d}", &num, lenp) != 2);
@@ -176,27 +176,27 @@ int *lenp;
return(0);
}
-static int imap_trail(socket, ctl, number)
+static int imap_trail(sockfp, ctl, number)
/* discard tail of FETCH response after reading message text */
-int socket;
+FILE *sockfp;
struct query *ctl;
int number;
{
char buf [POPBUFSIZE+1];
- if (SockGets(socket, buf,sizeof(buf)) < 0)
+ if (SockGets(fileno(sockfp), buf,sizeof(buf)) < 0)
return(PS_SOCKET);
else
return(0);
}
-static int imap_delete(socket, ctl, number)
+static int imap_delete(sockfp, ctl, number)
/* set delete flag for given message */
-int socket;
+FILE *sockfp;
struct query *ctl;
int number;
{
- return(gen_transact(socket, "STORE %d +FLAGS (\\Deleted)", number));
+ return(gen_transact(sockfp, "STORE %d +FLAGS (\\Deleted)", number));
}
const static struct method imap =
diff --git a/pop2.c b/pop2.c
index e1804660..67313f88 100644
--- a/pop2.c
+++ b/pop2.c
@@ -16,16 +16,16 @@
static int pound_arg, equal_arg;
-int pop2_ok (socket, argbuf)
+int pop2_ok (sockfp, argbuf)
/* parse POP2 command response */
-int socket;
+FILE *sockfp;
char *argbuf;
{
int ok;
char buf [POPBUFSIZE+1];
pound_arg = equal_arg = -1;
- if (SockGets(socket, buf, sizeof(buf)) >= 0) {
+ if (SockGets(fileno(sockfp), buf, sizeof(buf)) >= 0) {
if (outlevel == O_VERBOSE)
fprintf(stderr,"%s\n",buf);
@@ -55,20 +55,20 @@ char *argbuf;
return(ok);
}
-int pop2_getauth(socket, ctl, buf)
+int pop2_getauth(sockfp, ctl, buf)
/* apply for connection authorization */
-int socket;
+FILE *sockfp;
struct query *ctl;
char *buf;
{
- return(gen_transact(socket,
+ return(gen_transact(sockfp,
"HELO %s %s",
ctl->remotename, ctl->password));
}
-static int pop2_getrange(socket, ctl, countp, newp)
+static int pop2_getrange(sockfp, ctl, countp, newp)
/* get range of messages to be fetched */
-int socket;
+FILE *sockfp;
struct query *ctl;
int *countp, *newp;
{
@@ -82,7 +82,7 @@ int *countp, *newp;
/* maybe the user wanted a non-default folder */
if (ctl->mailbox[0])
{
- int ok = gen_transact(socket, "FOLD %s", ctl->mailbox);
+ int ok = gen_transact(sockfp, "FOLD %s", ctl->mailbox);
if (ok != 0)
return(ok);
@@ -96,32 +96,32 @@ int *countp, *newp;
return(0);
}
-static int pop2_fetch(socket, number, lenp)
+static int pop2_fetch(sockfp, number, lenp)
/* request nth message */
-int socket;
+FILE *sockfp;
int number;
int *lenp;
{
int ok;
*lenp = 0;
- ok = gen_transact(socket, "READ %d", number);
+ ok = gen_transact(sockfp, "READ %d", number);
if (ok)
return(0);
*lenp = equal_arg;
- gen_send(socket, "RETR");
+ gen_send(sockfp, "RETR");
return(ok);
}
-static int pop2_trail(socket, ctl, number)
+static int pop2_trail(sockfp, ctl, number)
/* send acknowledgement for message data */
-int socket;
+FILE *sockfp;
struct query *ctl;
int number;
{
- return(gen_transact(socket, ctl->keep ? "ACKS" : "ACKD"));
+ return(gen_transact(sockfp, ctl->keep ? "ACKS" : "ACKD"));
}
const static struct method pop2 =
diff --git a/pop3.c b/pop3.c
index 30430afb..74173c1f 100644
--- a/pop3.c
+++ b/pop3.c
@@ -22,16 +22,16 @@
static int last;
-int pop3_ok (socket, argbuf)
+int pop3_ok (sockfp, argbuf)
/* parse command response */
-int socket;
+FILE *sockfp;
char *argbuf;
{
int ok;
char buf [POPBUFSIZE+1];
char *bufp;
- if (SockGets(socket, buf, sizeof(buf)) >= 0) {
+ if (SockGets(fileno(sockfp), buf, sizeof(buf)) >= 0) {
if (outlevel == O_VERBOSE)
fprintf(stderr,"%s\n",buf);
@@ -61,9 +61,9 @@ char *argbuf;
return(ok);
}
-int pop3_getauth(socket, ctl, greeting)
+int pop3_getauth(sockfp, ctl, greeting)
/* apply for connection authorization */
-int socket;
+FILE *sockfp;
struct query *ctl;
char *greeting;
{
@@ -101,15 +101,15 @@ char *greeting;
switch (ctl->protocol) {
case P_POP3:
- if ((gen_transact(socket,"USER %s", ctl->remotename)) != 0)
+ if ((gen_transact(sockfp,"USER %s", ctl->remotename)) != 0)
PROTOCOL_ERROR
- if ((gen_transact(socket, "PASS %s", ctl->password)) != 0)
+ if ((gen_transact(sockfp, "PASS %s", ctl->password)) != 0)
PROTOCOL_ERROR
break;
case P_APOP:
- if ((gen_transact(socket, "APOP %s %s",
+ if ((gen_transact(sockfp, "APOP %s %s",
ctl->remotename, ctl->digest)) != 0)
PROTOCOL_ERROR
break;
@@ -122,9 +122,9 @@ char *greeting;
return(0);
}
-static int pop3_getrange(socket, ctl, countp, newp)
+static int pop3_getrange(sockfp, ctl, countp, newp)
/* get range of messages to be fetched */
-int socket;
+FILE *sockfp;
struct query *ctl;
int *countp, *newp;
{
@@ -135,8 +135,8 @@ int *countp, *newp;
ctl->newsaved = (struct idlist *)NULL;
/* get the total message count */
- gen_send(socket, "STAT");
- ok = pop3_ok(socket, buf);
+ gen_send(sockfp, "STAT");
+ ok = pop3_ok(sockfp, buf);
if (ok == 0)
sscanf(buf,"%d %*d", countp);
else
@@ -153,8 +153,8 @@ int *countp, *newp;
{
char id [IDLEN+1];
- gen_send(socket,"LAST");
- ok = pop3_ok(socket, buf);
+ gen_send(sockfp,"LAST");
+ ok = pop3_ok(sockfp, buf);
if (ok == 0)
{
if (sscanf(buf, "%d", &last) == 0)
@@ -164,14 +164,14 @@ int *countp, *newp;
else
{
/* grab the mailbox's UID list */
- if ((ok = gen_transact(socket, "UIDL")) != 0)
+ if ((ok = gen_transact(sockfp, "UIDL")) != 0)
PROTOCOL_ERROR
else
{
int num;
*newp = 0;
- while (SockGets(socket, buf, sizeof(buf)) >= 0)
+ while (SockGets(fileno(sockfp), buf, sizeof(buf)) >= 0)
{
if (outlevel == O_VERBOSE)
fprintf(stderr,"%s\n",buf);
@@ -191,21 +191,21 @@ int *countp, *newp;
return(0);
}
-static int pop3_getsizes(socket, count, sizes)
+static int pop3_getsizes(sockfp, count, sizes)
/* capture the sizes of all messages */
-int socket;
+FILE *sockfp;
int count;
int *sizes;
{
int ok;
- if ((ok = gen_transact(socket, "LIST")) != 0)
+ if ((ok = gen_transact(sockfp, "LIST")) != 0)
return(ok);
else
{
char buf [POPBUFSIZE+1];
- while (SockGets(socket, buf, sizeof(buf)) >= 0)
+ while (SockGets(fileno(sockfp), buf, sizeof(buf)) >= 0)
{
int num, size;
@@ -223,9 +223,9 @@ int *sizes;
}
}
-static int pop3_is_old(socket, ctl, num)
+static int pop3_is_old(sockfp, ctl, num)
/* is the given message old? */
-int socket;
+FILE *sockfp;
struct query *ctl;
int num;
{
@@ -236,17 +236,17 @@ int num;
uid_find (&ctl->newsaved, num)));
}
-static int pop3_fetch(socket, number, lenp)
+static int pop3_fetch(sockfp, number, lenp)
/* request nth message */
-int socket;
+FILE *sockfp;
int number;
int *lenp;
{
int ok;
char buf [POPBUFSIZE+1], *cp;
- gen_send(socket, "RETR %d", number);
- if ((ok = pop3_ok(socket, buf)) != 0)
+ gen_send(sockfp, "RETR %d", number);
+ if ((ok = pop3_ok(sockfp, buf)) != 0)
return(ok);
/* look for "nnn octets" -- there may or may not be preceding cruft */
if ((cp = strstr(buf, " octets")) == (char *)NULL)
@@ -260,13 +260,13 @@ int *lenp;
return(0);
}
-static int pop3_delete(socket, ctl, number)
+static int pop3_delete(sockfp, ctl, number)
/* delete a given message */
-int socket;
+FILE *sockfp;
struct query *ctl;
int number;
{
- return(gen_transact(socket, "DELE %d", number));
+ return(gen_transact(sockfp, "DELE %d", number));
}
const static struct method pop3 =