1#ifndef HEADER_CURL_SMTP_H
2#define HEADER_CURL_SMTP_H
3/***************************************************************************
4 * _ _ ____ _
5 * Project ___| | | | _ \| |
6 * / __| | | | |_) | |
7 * | (__| |_| | _ <| |___
8 * \___|\___/|_| \_\_____|
9 *
10 * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
11 *
12 * This software is licensed as described in the file COPYING, which
13 * you should have received as part of this distribution. The terms
14 * are also available at https://curl.se/docs/copyright.html.
15 *
16 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
17 * copies of the Software, and permit persons to whom the Software is
18 * furnished to do so, under the terms of the COPYING file.
19 *
20 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21 * KIND, either express or implied.
22 *
23 * SPDX-License-Identifier: curl
24 *
25 ***************************************************************************/
26
27#include "pingpong.h"
28#include "curl_sasl.h"
29
30/****************************************************************************
31 * SMTP unique setup
32 ***************************************************************************/
33typedef enum {
34 SMTP_STOP, /* do nothing state, stops the state machine */
35 SMTP_SERVERGREET, /* waiting for the initial greeting immediately after
36 a connect */
37 SMTP_EHLO,
38 SMTP_HELO,
39 SMTP_STARTTLS,
40 SMTP_UPGRADETLS, /* asynchronously upgrade the connection to SSL/TLS
41 (multi mode only) */
42 SMTP_AUTH,
43 SMTP_COMMAND, /* VRFY, EXPN, NOOP, RSET and HELP */
44 SMTP_MAIL, /* MAIL FROM */
45 SMTP_RCPT, /* RCPT TO */
46 SMTP_DATA,
47 SMTP_POSTDATA,
48 SMTP_QUIT,
49 SMTP_LAST /* never used */
50} smtpstate;
51
52/* This SMTP struct is used in the Curl_easy. All SMTP data that is
53 connection-oriented must be in smtp_conn to properly deal with the fact that
54 perhaps the Curl_easy is changed between the times the connection is
55 used. */
56struct SMTP {
57 curl_pp_transfer transfer;
58 char *custom; /* Custom Request */
59 struct curl_slist *rcpt; /* Recipient list */
60 int rcpt_last_error; /* The last error received for RCPT TO command */
61 size_t eob; /* Number of bytes of the EOB (End Of Body) that
62 have been received so far */
63 BIT(rcpt_had_ok); /* Whether any of RCPT TO commands (depends on
64 total number of recipients) succeeded so far */
65 BIT(trailing_crlf); /* Specifies if the trailing CRLF is present */
66};
67
68/* smtp_conn is used for struct connection-oriented data in the connectdata
69 struct */
70struct smtp_conn {
71 struct pingpong pp;
72 struct SASL sasl; /* SASL-related storage */
73 smtpstate state; /* Always use smtp.c:state() to change state! */
74 char *domain; /* Client address/name to send in the EHLO */
75 BIT(ssldone); /* Is connect() over SSL done? */
76 BIT(tls_supported); /* StartTLS capability supported by server */
77 BIT(size_supported); /* If server supports SIZE extension according to
78 RFC 1870 */
79 BIT(utf8_supported); /* If server supports SMTPUTF8 extension according
80 to RFC 6531 */
81 BIT(auth_supported); /* AUTH capability supported by server */
82};
83
84extern const struct Curl_handler Curl_handler_smtp;
85extern const struct Curl_handler Curl_handler_smtps;
86
87/* this is the 5-bytes End-Of-Body marker for SMTP */
88#define SMTP_EOB "\x0d\x0a\x2e\x0d\x0a"
89#define SMTP_EOB_LEN 5
90#define SMTP_EOB_FIND_LEN 3
91
92/* if found in data, replace it with this string instead */
93#define SMTP_EOB_REPL "\x0d\x0a\x2e\x2e"
94#define SMTP_EOB_REPL_LEN 4
95
96CURLcode Curl_smtp_escape_eob(struct Curl_easy *data,
97 const ssize_t nread,
98 const ssize_t offset);
99
100#endif /* HEADER_CURL_SMTP_H */
101