1--- 2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3SPDX-License-Identifier: curl 4Title: curl_mime_encoder 5Section: 3 6Source: libcurl 7See-also: 8 - curl_mime_addpart (3) 9 - curl_mime_headers (3) 10 - curl_mime_subparts (3) 11Protocol: 12 - HTTP 13 - IMAP 14 - SMTP 15--- 16 17# NAME 18 19curl_mime_encoder - set a mime part's encoder and content transfer encoding 20 21# SYNOPSIS 22 23~~~c 24#include <curl/curl.h> 25 26CURLcode curl_mime_encoder(curl_mimepart *part, const char *encoding); 27~~~ 28 29# DESCRIPTION 30 31curl_mime_encoder() requests a mime part's content to be encoded before being 32transmitted. 33 34*part* is the part's handle to assign an encoder. 35*encoding* is a pointer to a null-terminated encoding scheme. It may be 36set to NULL to disable an encoder previously attached to the part. The encoding 37scheme storage may safely be reused after this function returns. 38 39Setting a part's encoder multiple times is valid: only the value set by the 40last call is retained. 41 42Upon multipart rendering, the part's content is encoded according to the 43pertaining scheme and a corresponding *"Content-Transfer-Encoding"* header 44is added to the part. 45 46Supported encoding schemes are: 47 48"*binary*": the data is left unchanged, the header is added. 49 50"*8bit*": header added, no data change. 51 52"*7bit*": the data is unchanged, but is each byte is checked 53to be a 7-bit value; if not, a read error occurs. 54 55"*base64*": Data is converted to base64 encoding, then split in 56CRLF-terminated lines of at most 76 characters. 57 58"*quoted-printable*": data is encoded in quoted printable lines of 59at most 76 characters. Since the resulting size of the final data cannot be 60determined prior to reading the original data, it is left as unknown, causing 61chunked transfer in HTTP. For the same reason, this encoder may not be used 62with IMAP. This encoder targets text data that is mostly ASCII and should 63not be used with other types of data. 64 65If the original data is already encoded in such a scheme, a custom 66*Content-Transfer-Encoding* header should be added with 67curl_mime_headers(3) instead of setting a part encoder. 68 69Encoding should not be applied to multiparts, thus the use of this function on 70a part with content set with curl_mime_subparts(3) is strongly 71discouraged. 72 73# EXAMPLE 74 75~~~c 76int main(void) 77{ 78 curl_mime *mime; 79 curl_mimepart *part; 80 81 CURL *curl = curl_easy_init(); 82 if(curl) { 83 /* create a mime handle */ 84 mime = curl_mime_init(curl); 85 86 /* add a part */ 87 part = curl_mime_addpart(mime); 88 89 /* send a file */ 90 curl_mime_filedata(part, "image.png"); 91 92 /* encode file data in base64 for transfer */ 93 curl_mime_encoder(part, "base64"); 94 } 95} 96~~~ 97 98# AVAILABILITY 99 100As long as at least one of HTTP, SMTP or IMAP is enabled. Added in 7.56.0. 101 102# RETURN VALUE 103 104CURLE_OK or a CURL error code upon failure. 105