quickjs-tart

quickjs-based runtime for wallet-core logic
Log | Files | Refs | README | LICENSE

CURLOPT_UPLOAD_FLAGS.md (2606B)


      1 ---
      2 c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
      3 SPDX-License-Identifier: curl
      4 Title: CURLOPT_UPLOAD_FLAGS
      5 Section: 3
      6 Source: libcurl
      7 See-also:
      8   - CURLOPT_UPLOAD (3)
      9 Protocol:
     10   - IMAP
     11   - IMAPS
     12 Added-in: 8.13.0
     13 ---
     14 
     15 # NAME
     16 
     17 CURLOPT_UPLOAD_FLAGS - upload flags for IMAP
     18 
     19 # SYNOPSIS
     20 
     21 ~~~c
     22 #include <curl/curl.h>
     23 
     24 CURLcode curl_easy_setopt(CURL *handle, CURLOPT_UPLOAD_FLAGS, long bitmask);
     25 ~~~
     26 
     27 # DESCRIPTION
     28 
     29 Pass a long as parameter, which is set to a bitmask, to tell libcurl which
     30 flags to send the server relating to uploaded files. The current supported
     31 flags are **CURLULFLAG_ANSWERED**, which sets the **Answered** flag for IMAP
     32 uploads, **CURLULFLAG_DELETED**, which sets the **Deleted** flag for IMAP
     33 uploads, **CURLULFLAG_DRAFT**, which sets the **Draft** flag for IMAP uploads,
     34 **CURLULFLAG_FLAGGED**, which sets the **Flagged** flag for IMAP uploads, and
     35 **CURLULFLAG_SEEN**, which sets the **Seen** flag for IMAP uploads.
     36 
     37 # DEFAULT
     38 
     39 A bitmask with only the **CURLULFLAG_SEEN** flag set.
     40 
     41 # %PROTOCOLS%
     42 
     43 # EXAMPLE
     44 
     45 ~~~c
     46 static size_t read_cb(char *ptr, size_t size, size_t nmemb, void *userdata)
     47 {
     48   FILE *src = userdata;
     49   /* copy as much data as possible into the 'ptr' buffer, but no more than
     50      'size' * 'nmemb' bytes */
     51   size_t retcode = fread(ptr, size, nmemb, src);
     52 
     53   return retcode;
     54 }
     55 
     56 int main(void)
     57 {
     58   CURL *curl = curl_easy_init();
     59   if(curl) {
     60     FILE *src = fopen("local-file", "r");
     61     curl_off_t fsize = 9876; /* set this to the size of the input file */
     62 
     63     /* we want to use our own read function */
     64     curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_cb);
     65 
     66     /* enable uploading */
     67     curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
     68 
     69     /* specify target */
     70     curl_easy_setopt(curl, CURLOPT_URL, "imap://example.com:993/mailbox");
     71 
     72     /* provide username */
     73     curl_easy_setopt(curl, CURLOPT_USERNAME, "user@example.com");
     74 
     75     /* provide password */
     76     curl_easy_setopt(curl, CURLOPT_PASSWORD, "password");
     77 
     78     /* specify that uploaded mail should be considered flagged */
     79     curl_easy_setopt(curl, CURLOPT_UPLOAD_FLAGS, CURLULFLAG_FLAGGED);
     80 
     81     /* now specify which pointer to pass to our callback */
     82     curl_easy_setopt(curl, CURLOPT_READDATA, src);
     83 
     84     /* Set the size of the file to upload */
     85     curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t)fsize);
     86 
     87     /* perform the upload */
     88     curl_easy_perform(curl);
     89   }
     90 }
     91 ~~~
     92 
     93 # %AVAILABILITY%
     94 
     95 # RETURN VALUE
     96 
     97 curl_easy_setopt(3) returns a CURLcode indicating success or error.
     98 
     99 CURLE_OK (0) means everything was OK, non-zero means an error occurred, see
    100 libcurl-errors(3).