]> granicus.if.org Git - curl/commitdiff
examples/imap-append: Set size of data to be uploaded
authorJay Satiro <raysatiro@yahoo.com>
Wed, 14 Sep 2016 05:55:13 +0000 (01:55 -0400)
committerJay Satiro <raysatiro@yahoo.com>
Sun, 18 Sep 2016 06:19:17 +0000 (02:19 -0400)
Prior to this commit this example failed with error
'Cannot APPEND with unknown input file size'.

Bug: https://github.com/curl/curl/issues/1008
Reported-by: lukaszgn@users.noreply.github.com
Closes https://github.com/curl/curl/pull/1011

docs/examples/imap-append.c

index 3f832897d0a8fea5f53d3a938c539b6c62caf164..bbf9fe436d8f75ed2626fdefc1041b1a0e9587fc 100644 (file)
@@ -85,6 +85,8 @@ int main(void)
 {
   CURL *curl;
   CURLcode res = CURLE_OK;
+  const char **p;
+  long infilesize;
   struct upload_status upload_ctx;
 
   upload_ctx.lines_read = 0;
@@ -107,6 +109,12 @@ int main(void)
     curl_easy_setopt(curl, CURLOPT_READDATA, &upload_ctx);
     curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
 
+    infilesize = 0;
+    for(p = payload_text; *p; ++p) {
+      infilesize += (long)strlen(*p);
+    }
+    curl_easy_setopt(curl, CURLOPT_INFILESIZE, infilesize);
+
     /* Perform the append */
     res = curl_easy_perform(curl);