xref: /curl/docs/libcurl/curl_mime_subparts.md (revision 5a488251)
1---
2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
3SPDX-License-Identifier: curl
4Title: curl_mime_subparts
5Section: 3
6Source: libcurl
7See-also:
8  - curl_mime_addpart (3)
9  - curl_mime_init (3)
10Protocol:
11  - HTTP
12  - IMAP
13  - SMTP
14Added-in: 7.56.0
15---
16
17# NAME
18
19curl_mime_subparts - set sub-parts of a multipart mime part
20
21# SYNOPSIS
22
23~~~c
24#include <curl/curl.h>
25
26CURLcode curl_mime_subparts(curl_mimepart *part, curl_mime *subparts);
27~~~
28
29# DESCRIPTION
30
31curl_mime_subparts(3) sets a multipart mime part's content from a mime
32structure.
33
34*part* is a handle to the multipart part.
35
36*subparts* is a mime structure handle holding the sub-parts. After
37curl_mime_subparts(3) succeeds, the mime structure handle belongs to the
38multipart part and must not be freed explicitly. It may however be updated by
39subsequent calls to mime API functions.
40
41Setting a part's contents multiple times is valid: only the value set by the
42last call is retained. It is possible to unassign previous part's contents by
43setting *subparts* to NULL.
44
45# %PROTOCOLS%
46
47# EXAMPLE
48
49~~~c
50
51static char *inline_html = "<title>example</title>";
52static char *inline_text = "once upon the time";
53
54int main(void)
55{
56  CURL *curl = curl_easy_init();
57  if(curl) {
58    struct curl_slist *slist;
59
60    /* The inline part is an alternative proposing the html and the text
61       versions of the email. */
62    curl_mime *alt = curl_mime_init(curl);
63    curl_mimepart *part;
64
65    /* HTML message. */
66    part = curl_mime_addpart(alt);
67    curl_mime_data(part, inline_html, CURL_ZERO_TERMINATED);
68    curl_mime_type(part, "text/html");
69
70    /* Text message. */
71    part = curl_mime_addpart(alt);
72    curl_mime_data(part, inline_text, CURL_ZERO_TERMINATED);
73
74    /* Create the inline part. */
75    part = curl_mime_addpart(alt);
76    curl_mime_subparts(part, alt);
77    curl_mime_type(part, "multipart/alternative");
78    slist = curl_slist_append(NULL, "Content-Disposition: inline");
79    curl_mime_headers(part, slist, 1);
80  }
81}
82~~~
83
84# %AVAILABILITY%
85
86# RETURN VALUE
87
88CURLE_OK or a CURL error code upon failure.
89