aboutsummaryrefslogtreecommitdiff
path: root/lib/pop3.c
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2011-11-29 13:43:46 +0100
committerDaniel Stenberg <daniel@haxx.se>2011-11-29 13:43:46 +0100
commitaf6466643416fd36fea4205d2d7a02a9292e2858 (patch)
treef1b911a54928389f2096105e539811fb0cd36b41 /lib/pop3.c
parent2d72489f0fc2ef6e0f4de88766acfef286605c6a (diff)
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.
Diffstat (limited to 'lib/pop3.c')
-rw-r--r--lib/pop3.c41
1 files changed, 35 insertions, 6 deletions
diff --git a/lib/pop3.c b/lib/pop3.c
index a47717a71..5d06dfcb5 100644
--- a/lib/pop3.c
+++ b/lib/pop3.c
@@ -421,6 +421,16 @@ static CURLcode pop3_state_list_resp(struct connectdata *conn,
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 */
Curl_setup_transfer(conn, FIRSTSOCKET, -1, FALSE, pop3->bytecountp,
-1, NULL); /* no upload here */
@@ -1082,11 +1092,22 @@ CURLcode Curl_pop3_write(struct connectdata *conn,
return CURLE_OK;
}
else if(prev && (prev >= pop3c->eob)) {
- /* write out the body part that didn't match */
- result = Curl_client_write(conn, CLIENTWRITE_BODY, (char*)POP3_EOB,
- prev);
- if(result)
- return result;
+
+ /* 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 */
+ result = Curl_client_write(conn, CLIENTWRITE_BODY, (char*)POP3_EOB,
+ prev);
+ if(result)
+ return result;
+ }
}
}
@@ -1094,7 +1115,15 @@ CURLcode Curl_pop3_write(struct connectdata *conn,
/* while EOB is matching, don't output it! */
return CURLE_OK;
- result = Curl_client_write(conn, CLIENTWRITE_BODY, str, nread);
+ while(nread && pop3c->strip) {
+ nread--;
+ pop3c->strip--;
+ str++;
+ }
+
+ if(nread) {
+ result = Curl_client_write(conn, CLIENTWRITE_BODY, str, nread);
+ }
return result;
}