1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
|
#ifndef SMTP_CLIENT_COMMAND
#define SMTP_CLIENT_COMMAND
struct smtp_reply;
struct smtp_params_mail;
struct smtp_params_rcpt;
struct smtp_client_command;
struct smtp_client_connection;
enum smtp_client_command_state {
SMTP_CLIENT_COMMAND_STATE_NEW = 0,
SMTP_CLIENT_COMMAND_STATE_SUBMITTED,
SMTP_CLIENT_COMMAND_STATE_SENDING,
SMTP_CLIENT_COMMAND_STATE_WAITING,
SMTP_CLIENT_COMMAND_STATE_FINISHED,
SMTP_CLIENT_COMMAND_STATE_ABORTED
};
enum smtp_client_command_flags {
/* The command is sent to server before login (or is the login
command itself). Non-prelogin commands will be queued until login
is successful. */
SMTP_CLIENT_COMMAND_FLAG_PRELOGIN = 0x01,
/* This command may be positioned anywhere in a PIPELINING group. */
SMTP_CLIENT_COMMAND_FLAG_PIPELINE = 0x02,
/* This command has priority and needs to be inserted before anything
else. This is e.g. used to make sure that the initial handshake
commands are sent before any other command that may already be
submitted to the connection. */
SMTP_CLIENT_COMMAND_FLAG_PRIORITY = 0x04
};
/* Called when reply is received for command. */
typedef void smtp_client_command_callback_t(const struct smtp_reply *reply,
void *context);
struct smtp_client_command *
smtp_client_command_new(struct smtp_client_connection *conn,
enum smtp_client_command_flags flags,
smtp_client_command_callback_t *callback,
void *context);
#define smtp_client_command_new(conn, flags, callback, context) \
smtp_client_command_new(conn, flags - \
CALLBACK_TYPECHECK(callback, void (*)( \
const struct smtp_reply *reply, typeof(context))), \
(smtp_client_command_callback_t *)callback, context)
/* Create a plug command, which is a dummy command that blocks the send queue.
This is used by transactions to prevent subsequently submitted
transactions from messing up the command sequence while the present
transaction is still submitting commands. The plug command is aborted once
the send queue is to be released. */
struct smtp_client_command *
smtp_client_command_plug(struct smtp_client_connection *conn,
struct smtp_client_command *after);
void smtp_client_command_ref(struct smtp_client_command *cmd);
bool smtp_client_command_unref(struct smtp_client_command **_cmd)
ATTR_NOWARN_UNUSED_RESULT;
bool smtp_client_command_name_equals(struct smtp_client_command *cmd,
const char *name);
/* Lock the command; no commands after this one will be sent until this one
finishes */
void smtp_client_command_lock(struct smtp_client_command *cmd);
void smtp_client_command_unlock(struct smtp_client_command *cmd);
void smtp_client_command_set_flags(struct smtp_client_command *cmd,
enum smtp_client_command_flags flags);
void smtp_client_command_set_stream(struct smtp_client_command *cmd,
struct istream *input, bool dot);
void smtp_client_command_write(struct smtp_client_command *cmd,
const char *cmd_str);
void smtp_client_command_printf(struct smtp_client_command *cmd,
const char *cmd_fmt, ...) ATTR_FORMAT(2, 3);
void smtp_client_command_vprintf(struct smtp_client_command *cmd,
const char *cmd_fmt, va_list args)
ATTR_FORMAT(2, 0);
void smtp_client_command_submit_after(struct smtp_client_command *cmd,
struct smtp_client_command *after);
void smtp_client_command_submit(struct smtp_client_command *cmd);
void smtp_client_command_abort(struct smtp_client_command **_cmd);
void smtp_client_command_set_abort_callback(struct smtp_client_command *cmd,
void (*callback)(void *context),
void *context);
void smtp_client_command_set_sent_callback(struct smtp_client_command *cmd,
void (*callback)(void *context),
void *context);
void smtp_client_command_set_replies(struct smtp_client_command *cmd,
unsigned int replies);
enum smtp_client_command_state
smtp_client_command_get_state(struct smtp_client_command *cmd) ATTR_PURE;
/*
* Standard commands
*/
/* Send NOOP */
struct smtp_client_command *
smtp_client_command_noop_submit_after(struct smtp_client_connection *conn,
enum smtp_client_command_flags flags,
struct smtp_client_command *after,
smtp_client_command_callback_t *callback,
void *context);
#define smtp_client_command_noop_submit_after(conn, flags, after, \
callback, context) \
smtp_client_command_noop_submit_after(conn, flags - \
CALLBACK_TYPECHECK(callback, void (*)( \
const struct smtp_reply *reply, typeof(context))), \
after, (smtp_client_command_callback_t *)callback, context)
struct smtp_client_command *
smtp_client_command_noop_submit(struct smtp_client_connection *conn,
enum smtp_client_command_flags flags,
smtp_client_command_callback_t *callback,
void *context);
#define smtp_client_command_noop_submit(conn, flags, callback, context) \
smtp_client_command_noop_submit(conn, flags - \
CALLBACK_TYPECHECK(callback, void (*)( \
const struct smtp_reply *reply, typeof(context))), \
(smtp_client_command_callback_t *)callback, context)
/* Send VRFY <param> */
struct smtp_client_command *
smtp_client_command_vrfy_submit_after(struct smtp_client_connection *conn,
enum smtp_client_command_flags flags,
struct smtp_client_command *after,
const char *param,
smtp_client_command_callback_t *callback,
void *context);
#define smtp_client_command_vrfy_submit_after(conn, flags, after, param, \
callback, context) \
smtp_client_command_vrfy_submit_after(conn, flags - \
CALLBACK_TYPECHECK(callback, void (*)( \
const struct smtp_reply *reply, typeof(context))), \
after, param, \
(smtp_client_command_callback_t *)callback, context)
struct smtp_client_command *
smtp_client_command_vrfy_submit(struct smtp_client_connection *conn,
enum smtp_client_command_flags flags,
const char *param,
smtp_client_command_callback_t *callback,
void *context);
#define smtp_client_command_vrfy_submit(conn, flags, param, callback, context) \
smtp_client_command_vrfy_submit(conn, flags - \
CALLBACK_TYPECHECK(callback, void (*)( \
const struct smtp_reply *reply, typeof(context))), \
param, (smtp_client_command_callback_t *)callback, context)
/* Send RSET */
struct smtp_client_command *
smtp_client_command_rset_submit_after(struct smtp_client_connection *conn,
enum smtp_client_command_flags flags,
struct smtp_client_command *after,
smtp_client_command_callback_t *callback,
void *context);
#define smtp_client_command_rset_submit_after(conn, flags, after, \
callback, context) \
smtp_client_command_rset_submit_after(conn, flags - \
CALLBACK_TYPECHECK(callback, void (*)( \
const struct smtp_reply *reply, typeof(context))), \
after, (smtp_client_command_callback_t *)callback, context)
struct smtp_client_command *
smtp_client_command_rset_submit(struct smtp_client_connection *conn,
enum smtp_client_command_flags flags,
smtp_client_command_callback_t *callback,
void *context);
#define smtp_client_command_rset_submit(conn, flags, callback, context) \
smtp_client_command_rset_submit(conn, flags - \
CALLBACK_TYPECHECK(callback, void (*)( \
const struct smtp_reply *reply, typeof(context))), \
(smtp_client_command_callback_t *)callback, context)
/* Send MAIL FROM:<address> <params...> */
struct smtp_client_command *
smtp_client_command_mail_submit_after(struct smtp_client_connection *conn,
enum smtp_client_command_flags flags,
struct smtp_client_command *after,
const struct smtp_address *from,
const struct smtp_params_mail *params,
smtp_client_command_callback_t *callback,
void *context);
#define smtp_client_command_mail_submit_after(conn, flags, after, \
address, params, \
callback, context) \
smtp_client_command_mail_submit_after(conn, flags - \
CALLBACK_TYPECHECK(callback, void (*)( \
const struct smtp_reply *reply, typeof(context))), \
after, address, params, \
(smtp_client_command_callback_t *)callback, context)
struct smtp_client_command *
smtp_client_command_mail_submit(struct smtp_client_connection *conn,
enum smtp_client_command_flags flags,
const struct smtp_address *from,
const struct smtp_params_mail *params,
smtp_client_command_callback_t *callback,
void *context);
#define smtp_client_command_mail_submit(conn, flags, address, params, \
callback, context) \
smtp_client_command_mail_submit(conn, flags - \
CALLBACK_TYPECHECK(callback, void (*)( \
const struct smtp_reply *reply, typeof(context))), \
address, params, \
(smtp_client_command_callback_t *)callback, context)
/* send RCPT TO:<address> parameters */
struct smtp_client_command *
smtp_client_command_rcpt_submit_after(struct smtp_client_connection *conn,
enum smtp_client_command_flags flags,
struct smtp_client_command *after,
const struct smtp_address *to,
const struct smtp_params_rcpt *params,
smtp_client_command_callback_t *callback,
void *context);
#define smtp_client_command_rcpt_submit_after(conn, flags, after, to, params, \
callback, context) \
smtp_client_command_rcpt_submit_after(conn, flags - \
CALLBACK_TYPECHECK(callback, void (*)( \
const struct smtp_reply *reply, typeof(context))), \
after, to, params, \
(smtp_client_command_callback_t *)callback, context)
struct smtp_client_command *
smtp_client_command_rcpt_submit(struct smtp_client_connection *conn,
enum smtp_client_command_flags flags,
const struct smtp_address *to,
const struct smtp_params_rcpt *params,
smtp_client_command_callback_t *callback,
void *context);
#define smtp_client_command_rcpt_submit(conn, flags, to, params, \
callback, context) \
smtp_client_command_rcpt_submit(conn, flags - \
CALLBACK_TYPECHECK(callback, void (*)( \
const struct smtp_reply *reply, typeof(context))), \
to, params, \
(smtp_client_command_callback_t *)callback, context)
/* Send message data using DATA or BDAT (preferred if supported).
This handles the DATA 354 response implicitly. Making sure that the data has
CRLF line endings consistently is the responsibility of the caller.
*/
struct smtp_client_command *
smtp_client_command_data_submit_after(struct smtp_client_connection *conn,
enum smtp_client_command_flags flags,
struct smtp_client_command *after,
struct istream *data,
smtp_client_command_callback_t *callback,
void *context);
#define smtp_client_command_data_submit_after(conn, flags, after, data, \
callback, context) \
smtp_client_command_data_submit_after(conn, flags - \
CALLBACK_TYPECHECK(callback, void (*)( \
const struct smtp_reply *reply, typeof(context))), \
after, data, \
(smtp_client_command_callback_t *)callback, context)
struct smtp_client_command *
smtp_client_command_data_submit(struct smtp_client_connection *conn,
enum smtp_client_command_flags flags,
struct istream *data,
smtp_client_command_callback_t *callback,
void *context);
#define smtp_client_command_data_submit(conn, flags, data, callback, context) \
smtp_client_command_data_submit(conn, flags - \
CALLBACK_TYPECHECK(callback, void (*)( \
const struct smtp_reply *reply, typeof(context))), \
data, (smtp_client_command_callback_t *)callback, context)
#endif
|