mirror of
https://github.com/moparisthebest/curl
synced 2024-12-22 16:18:48 -05:00
POP3: detect when LIST returns no mails
By making sure the function can detect an "end of body" sequence immediately on the first line, test 811 is now enabled.
This commit is contained in:
parent
2d72489f0f
commit
af64666434
29
lib/pop3.c
29
lib/pop3.c
@ -421,6 +421,16 @@ static CURLcode pop3_state_list_resp(struct connectdata *conn,
|
|||||||
return CURLE_RECV_ERROR;
|
return CURLE_RECV_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* This 'OK' line ends with a CR LF pair which is the two first bytes of the
|
||||||
|
EOB string so count this is two matching bytes. This is necessary to make
|
||||||
|
the code detect the EOB if the only data than comes now is %2e CR LF like
|
||||||
|
when there is no body to return. */
|
||||||
|
pop3c->eob = 2;
|
||||||
|
|
||||||
|
/* But since this initial CR LF pair is not part of the actual body, we set
|
||||||
|
the strip counter here so that these bytes won't be delivered. */
|
||||||
|
pop3c->strip = 2;
|
||||||
|
|
||||||
/* POP3 download */
|
/* POP3 download */
|
||||||
Curl_setup_transfer(conn, FIRSTSOCKET, -1, FALSE, pop3->bytecountp,
|
Curl_setup_transfer(conn, FIRSTSOCKET, -1, FALSE, pop3->bytecountp,
|
||||||
-1, NULL); /* no upload here */
|
-1, NULL); /* no upload here */
|
||||||
@ -1082,6 +1092,16 @@ CURLcode Curl_pop3_write(struct connectdata *conn,
|
|||||||
return CURLE_OK;
|
return CURLE_OK;
|
||||||
}
|
}
|
||||||
else if(prev && (prev >= pop3c->eob)) {
|
else if(prev && (prev >= pop3c->eob)) {
|
||||||
|
|
||||||
|
/* strip can only be non-zero for the very first mismatch after CRLF and
|
||||||
|
then both prev and strip are equal and nothing will be output
|
||||||
|
below */
|
||||||
|
while(prev && pop3c->strip) {
|
||||||
|
prev--;
|
||||||
|
pop3c->strip--;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(prev) {
|
||||||
/* write out the body part that didn't match */
|
/* write out the body part that didn't match */
|
||||||
result = Curl_client_write(conn, CLIENTWRITE_BODY, (char*)POP3_EOB,
|
result = Curl_client_write(conn, CLIENTWRITE_BODY, (char*)POP3_EOB,
|
||||||
prev);
|
prev);
|
||||||
@ -1089,12 +1109,21 @@ CURLcode Curl_pop3_write(struct connectdata *conn,
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(pop3c->eob)
|
if(pop3c->eob)
|
||||||
/* while EOB is matching, don't output it! */
|
/* while EOB is matching, don't output it! */
|
||||||
return CURLE_OK;
|
return CURLE_OK;
|
||||||
|
|
||||||
|
while(nread && pop3c->strip) {
|
||||||
|
nread--;
|
||||||
|
pop3c->strip--;
|
||||||
|
str++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(nread) {
|
||||||
result = Curl_client_write(conn, CLIENTWRITE_BODY, str, nread);
|
result = Curl_client_write(conn, CLIENTWRITE_BODY, str, nread);
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
* | (__| |_| | _ <| |___
|
* | (__| |_| | _ <| |___
|
||||||
* \___|\___/|_| \_\_____|
|
* \___|\___/|_| \_\_____|
|
||||||
*
|
*
|
||||||
* Copyright (C) 2009, Daniel Stenberg, <daniel@haxx.se>, et al.
|
* Copyright (C) 2009 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||||
*
|
*
|
||||||
* This software is licensed as described in the file COPYING, which
|
* This software is licensed as described in the file COPYING, which
|
||||||
* you should have received as part of this distribution. The terms
|
* you should have received as part of this distribution. The terms
|
||||||
@ -46,6 +46,7 @@ struct pop3_conn {
|
|||||||
char *mailbox; /* what to RETR */
|
char *mailbox; /* what to RETR */
|
||||||
size_t eob; /* number of bytes of the EOB (End Of Body) that has been
|
size_t eob; /* number of bytes of the EOB (End Of Body) that has been
|
||||||
received thus far */
|
received thus far */
|
||||||
|
size_t strip; /* number of bytes from the start to ignore as non-body */
|
||||||
pop3state state; /* always use pop3.c:state() to change state! */
|
pop3state state; /* always use pop3.c:state() to change state! */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
# test cases are run by runtests.pl. Just add the plain test case numbers, one
|
# test cases are run by runtests.pl. Just add the plain test case numbers, one
|
||||||
# per line.
|
# per line.
|
||||||
# Lines starting with '#' letters are treated as comments.
|
# Lines starting with '#' letters are treated as comments.
|
||||||
811
|
|
||||||
815
|
815
|
||||||
591
|
591
|
||||||
592
|
592
|
||||||
|
Loading…
Reference in New Issue
Block a user