aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--driver.c8
-rw-r--r--fetchmail.h8
-rw-r--r--imap.c19
-rw-r--r--pop3.c20
4 files changed, 18 insertions, 37 deletions
diff --git a/driver.c b/driver.c
index c934ea74..05d91b73 100644
--- a/driver.c
+++ b/driver.c
@@ -80,6 +80,7 @@ extern char *strstr(); /* needed on sysV68 R3V7.1. */
int batchcount; /* count of messages sent in current batch */
flag peek_capable; /* can we peek for better error recovery? */
int pass; /* how many times have we re-polled? */
+int stage; /* where are we? */
int phase; /* where are we, for error-logging purposes? */
static const struct method *protocol;
@@ -1664,6 +1665,7 @@ const int maxfetch; /* maximum number of messages to fetch */
goto cleanUp;
/* try to get authorized to fetch mail */
+ stage = STAGE_GETAUTH;
if (protocol->getauth)
{
if (protocol->password_canonify)
@@ -1737,6 +1739,7 @@ const int maxfetch; /* maximum number of messages to fetch */
}
/* compute # of messages and number of new messages waiting */
+ stage = STAGE_GETRANGE;
ok = (protocol->getrange)(mailserver_socket, ctl, idp->id, &count, &new, &bytes);
if (ok != 0)
goto cleanUp;
@@ -1835,6 +1838,7 @@ const int maxfetch; /* maximum number of messages to fetch */
for (i = 0; i < count; i++)
msgsizes[i] = -1;
+ stage = STAGE_GETSIZES;
ok = (proto->getsizes)(mailserver_socket, count, msgsizes);
if (ok != 0)
goto cleanUp;
@@ -1848,6 +1852,7 @@ const int maxfetch; /* maximum number of messages to fetch */
}
/* read, forward, and delete messages */
+ stage = STAGE_FETCH;
for (num = 1; num <= count; num++)
{
flag toolarge = NUM_NONZERO(ctl->limit)
@@ -2188,7 +2193,10 @@ const int maxfetch; /* maximum number of messages to fetch */
cleanUp:
/* we only get here on error */
if (ok != 0 && ok != PS_SOCKET)
+ {
+ stage = STAGE_LOGOUT;
(protocol->logout_cmd)(mailserver_socket, ctl);
+ }
SockClose(mailserver_socket);
}
diff --git a/fetchmail.h b/fetchmail.h
index c5cc8671..805021a3 100644
--- a/fetchmail.h
+++ b/fetchmail.h
@@ -394,6 +394,14 @@ int gen_transact ();
#define FORWARDING_WAIT 4 /* waiting for listener response */
extern int phase;
+/* response hooks can use this to identify the query stage */
+#define STAGE_GETAUTH 0
+#define STAGE_GETRANGE 1
+#define STAGE_GETSIZES 2
+#define STAGE_FETCH 3
+#define STAGE_LOGOUT 4
+extern int stage;
+
/* mark values for name lists */
#define XMIT_ACCEPT 1 /* accepted; matches local domain or name */
#define XMIT_REJECT 2 /* rejected; no match */
diff --git a/imap.c b/imap.c
index df787da6..eb57bf4a 100644
--- a/imap.c
+++ b/imap.c
@@ -62,13 +62,6 @@ extern char *strstr(); /* needed on sysV68 R3V7.1. */
#define IMAP4 0 /* IMAP4 rev 0, RFC1730 */
#define IMAP4rev1 1 /* IMAP4 rev 1, RFC2060 */
-static int imap_phase;
-#define PHASE_GETAUTH 0
-#define PHASE_GETRANGE 1
-#define PHASE_GETSIZES 2
-#define PHASE_FETCH 3
-#define PHASE_LOGOUT 4
-
static int count, seen, recent, unseen, deletions, imap_version, preauth;
static int expunged, expunge_period;
static char capabilities[MSGBUFSIZE+1];
@@ -152,7 +145,7 @@ int imap_ok(int sock, char *argbuf)
return(PS_ERROR);
else if (strncmp(cp, "NO", 2) == 0)
{
- if (imap_phase == PHASE_GETAUTH)
+ if (stage == STAGE_GETAUTH)
return(PS_AUTHFAIL); /* RFC2060, 6.2.2 */
else
return(PS_ERROR);
@@ -863,8 +856,6 @@ int imap_getauth(int sock, struct query *ctl, char *greeting)
{
int ok = 0;
- imap_phase = PHASE_GETAUTH;
-
/* probe to see if we're running IMAP4 and can use RFC822.PEEK */
capabilities[0] = '\0';
if ((ok = gen_transact(sock, "CAPABILITY")) == PS_SUCCESS)
@@ -1042,8 +1033,6 @@ static int imap_getrange(int sock,
{
int ok;
- imap_phase = PHASE_GETRANGE;
-
/* find out how many messages are waiting */
*bytes = recent = unseen = -1;
@@ -1109,8 +1098,6 @@ static int imap_getsizes(int sock, int count, int *sizes)
{
char buf [MSGBUFSIZE+1];
- imap_phase = PHASE_GETSIZES;
-
/*
* Some servers (as in, PMDF5.1-9.1 under OpenVMS 6.1)
* won't accept 1:1 as valid set syntax. Some implementors
@@ -1132,8 +1119,6 @@ static int imap_getsizes(int sock, int count, int *sizes)
sizes[num - 1] = size;
}
- imap_phase = PHASE_FETCH;
-
return(PS_SUCCESS);
}
@@ -1331,8 +1316,6 @@ static int imap_delete(int sock, struct query *ctl, int number)
static int imap_logout(int sock, struct query *ctl)
/* send logout command */
{
- imap_phase = PHASE_LOGOUT;
-
/* if any un-expunged deletions remain, ship an expunge now */
if (deletions)
internal_expunge(sock);
diff --git a/pop3.c b/pop3.c
index f619a919..9974973a 100644
--- a/pop3.c
+++ b/pop3.c
@@ -29,12 +29,6 @@
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;
@@ -75,7 +69,7 @@ int pop3_ok (int sock, char *argbuf)
}
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",
@@ -126,8 +120,6 @@ int pop3_getauth(int sock, struct query *ctl, char *greeting)
char *challenge;
#endif /* OPIE_ENABLE */
- pop3_phase = PHASE_GETAUTH;
-
#ifdef SDPS_ENABLE
/*
* This needs to catch both demon.co.uk and demon.net.
@@ -385,8 +377,6 @@ static int pop3_getrange(int sock,
int ok;
char buf [POPBUFSIZE+1];
- pop3_phase = PHASE_GETRANGE;
-
/* Ensure that the new list is properly empty */
ctl->newsaved = (struct idlist *)NULL;
@@ -478,8 +468,6 @@ static int pop3_getsizes(int sock, int count, int *sizes)
{
int ok;
- /* pop3_phase = PHASE_GETSIZES */
-
if ((ok = gen_transact(sock, "LIST")) != 0)
return(ok);
else
@@ -523,8 +511,6 @@ static int pop_fetch_headers(int sock, struct query *ctl,int number,int *lenp)
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);
@@ -541,8 +527,6 @@ static int pop3_fetch(int sock, struct query *ctl, int number, int *lenp)
int ok;
char buf[POPBUFSIZE+1];
- /* pop3_phase = PHASE_FETCH */
-
#ifdef SDPS_ENABLE
/*
* See http://www.demon.net/services/mail/sdps-tech.html
@@ -631,8 +615,6 @@ static int pop3_logout(int sock, struct query *ctl)
{
int ok;
- /* pop3_phase = PHASE_LOGOUT */
-
ok = gen_transact(sock, "QUIT");
if (!ok)
expunge_uids(ctl);