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