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