Skip to content

Commit fec7a85

Browse files
committed
mime: use in curl cli tool instead of form API.
Extended -F option syntax to support multipart mail messages. -F keyword headers= added to include custom headers in parts. Documentation upgraded.
1 parent ce0881e commit fec7a85

17 files changed

+768
-456
lines changed

docs/cmdline-opts/form-string.d

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Long: form-string
2-
Help: Specify HTTP multipart POST data
3-
Protocols: HTTP
2+
Help: Specify multipart MIME data
3+
Protocols: HTTP SMTP IMAP
44
Arg: <name=string>
55
See-also: form
66
---

docs/cmdline-opts/form.d

Lines changed: 59 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
11
Long: form
22
Short: F
33
Arg: <name=content>
4-
Help: Specify HTTP multipart POST data
5-
Protocols: HTTP
4+
Help: Specify multipart MIME data
5+
Protocols: HTTP SMTP IMAP
66
Mutexed: data head upload
77
---
8-
This lets curl emulate a filled-in form in which a user has pressed the submit
9-
button. This causes curl to POST data using the Content-Type
10-
multipart/form-data according to RFC 2388. This enables uploading of binary
8+
For HTTP protocol family, this lets curl emulate a filled-in form in which a
9+
user has pressed the submit button. This causes curl to POST data using the
10+
Content-Type multipart/form-data according to RFC 2388.
11+
12+
For SMTP and IMAP protocols, this is the mean to compose a multipart mail
13+
message to transmit.
14+
15+
This enables uploading of binary
1116
files etc. To force the 'content' part to be a file, prefix the file name with
1217
an @ sign. To just get the content part from a file, prefix the file name with
1318
the symbol <. The difference between @ and < is then that @ makes a file get
1419
attached in the post as a file upload, while the < makes a text field and just
1520
get the contents for that text field from a file.
1621

17-
Example: to send an image to a server, where \&'profile' is the name of the
18-
form-field to which portrait.jpg will be the input:
22+
Example: to send an image to an HTTP server, where \&'profile' is the name of
23+
the form-field to which portrait.jpg will be the input:
1924

2025
curl -F profile=@portrait.jpg https://example.com/upload.cgi
2126

@@ -49,6 +54,53 @@ or
4954
Note that if a filename/path is quoted by double-quotes, any double-quote
5055
or backslash within the filename must be escaped by backslash.
5156

57+
You can add custom headers to the field by setting headers=, like
58+
59+
curl -F "submit=OK;headers=\\"X-submit-type: OK\\"" example.com
60+
61+
or
62+
63+
curl -F "submit=OK;headers=@headerfile" example.com
64+
65+
The headers= keyword may appear more that once and above notes about quoting
66+
apply. When headers are read from a file, Empty lines and lines starting
67+
with '#' are comments and ignored; each header can be folded by splitting
68+
between two words and starting the continuation line with a space; embedded
69+
carriage-returns and trailing spaces are stripped.
70+
Here is an example of a header file contents:
71+
72+
# This file contain two headers.
73+
.br
74+
X-header-1: this is a header
75+
76+
# The following header is folded.
77+
.br
78+
X-header-2: this is
79+
.br
80+
another header
81+
82+
83+
To support sending multipart mail messages, the syntax is extended as follows:
84+
.br
85+
- name can be omitted: the equal sign is the first character of the argument,
86+
.br
87+
- if data starts with '(', this signals to start a new multipart: it can be
88+
followed by a content type specification.
89+
.br
90+
- a multipart can be terminated with a '=)' argument.
91+
92+
Example: the following command sends an SMTP mime e-mail consisting in an
93+
inline part in two alternative formats: plain text and HTML. It attaches a
94+
text file:
95+
96+
curl -F '=(;type=multipart/alternative' \\
97+
.br
98+
-F '=plain text message' \\
99+
.br
100+
-F '= <body>HTML message</body>;type=text/html' \\
101+
.br
102+
-F '=)' -F '=@textfile.txt' ... smtp://example.com
103+
52104
See further examples and details in the MANUAL.
53105

54106
This option can be used multiple times.

src/Makefile.inc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ CURL_CFILES = \
4545
tool_libinfo.c \
4646
tool_main.c \
4747
tool_metalink.c \
48-
tool_mfiles.c \
4948
tool_msgs.c \
5049
tool_operate.c \
5150
tool_operhlp.c \
@@ -86,7 +85,6 @@ CURL_HFILES = \
8685
tool_libinfo.h \
8786
tool_main.h \
8887
tool_metalink.h \
89-
tool_mfiles.h \
9088
tool_msgs.h \
9189
tool_operate.h \
9290
tool_operhlp.h \

src/tool_cfgable.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,11 @@ static void free_config_fields(struct OperationConfig *config)
140140
curl_slist_free_all(config->headers);
141141
curl_slist_free_all(config->proxyheaders);
142142

143-
if(config->httppost) {
144-
curl_formfree(config->httppost);
145-
config->httppost = NULL;
143+
if(config->mimepost) {
144+
curl_mime_free(config->mimepost);
145+
config->mimepost = NULL;
146146
}
147-
config->last_post = NULL;
147+
config->mimecurrent = NULL;
148148

149149
curl_slist_free_all(config->telnet_options);
150150
curl_slist_free_all(config->resolve);

src/tool_cfgable.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ struct OperationConfig {
170170
time_t condtime;
171171
struct curl_slist *headers;
172172
struct curl_slist *proxyheaders;
173-
struct curl_httppost *httppost;
174-
struct curl_httppost *last_post;
173+
curl_mime *mimepost;
174+
curl_mime *mimecurrent;
175175
struct curl_slist *telnet_options;
176176
struct curl_slist *resolve;
177177
struct curl_slist *connect_to;

src/tool_easysrc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* | (__| |_| | _ <| |___
66
* \___|\___/|_| \_\_____|
77
*
8-
* Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
8+
* Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
99
*
1010
* This software is licensed as described in the file COPYING, which
1111
* you should have received as part of this distribution. The terms
@@ -42,7 +42,7 @@ struct slist_wc *easysrc_data = NULL; /* Build slists, forms etc. */
4242
struct slist_wc *easysrc_code = NULL; /* Setopt calls */
4343
struct slist_wc *easysrc_toohard = NULL; /* Unconvertible setopt */
4444
struct slist_wc *easysrc_clean = NULL; /* Clean up allocated data */
45-
int easysrc_form_count = 0;
45+
int easysrc_mime_count = 0;
4646
int easysrc_slist_count = 0;
4747

4848
static const char *const srchead[]={

src/tool_easysrc.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* | (__| |_| | _ <| |___
88
* \___|\___/|_| \_\_____|
99
*
10-
* Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
10+
* Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
1111
*
1212
* This software is licensed as described in the file COPYING, which
1313
* you should have received as part of this distribution. The terms
@@ -32,7 +32,7 @@ extern struct slist_wc *easysrc_code; /* Setopt calls etc. */
3232
extern struct slist_wc *easysrc_toohard; /* Unconvertible setopt */
3333
extern struct slist_wc *easysrc_clean; /* Clean up (reverse order) */
3434

35-
extern int easysrc_form_count; /* Number of curl_httppost variables */
35+
extern int easysrc_mime_count; /* Number of curl_mime variables */
3636
extern int easysrc_slist_count; /* Number of curl_slist variables */
3737

3838
extern CURLcode easysrc_init(void);

0 commit comments

Comments
 (0)