summaryrefslogtreecommitdiffstats
path: root/src/lib-smtp/smtp-common.h
blob: ec95dc0ff48b508eb67823617d28df6e9bfd9b5e (plain)
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
#ifndef SMTP_COMMON_H
#define SMTP_COMMON_H

#include "net.h"

/*
 * Limits
 */

#define SMTP_BASE_LINE_LENGTH_LIMIT (512 - 2)

/*
 * SMTP protocols
 */

enum smtp_protocol {
	SMTP_PROTOCOL_SMTP = 0,
	SMTP_PROTOCOL_LMTP
};

static inline const char *
smtp_protocol_name(enum smtp_protocol proto)
{
	switch (proto) {
	case SMTP_PROTOCOL_SMTP:
		return "smtp";
	case SMTP_PROTOCOL_LMTP:
		return "lmtp";
	default:
		break;
	}
	i_unreached();
}

/* SMTP capabilities */

enum smtp_capability {
	SMTP_CAPABILITY_NONE                = 0,

	SMTP_CAPABILITY_AUTH                = BIT(0),
	SMTP_CAPABILITY_STARTTLS            = BIT(1),
	SMTP_CAPABILITY_PIPELINING          = BIT(2),
	SMTP_CAPABILITY_SIZE                = BIT(3),
	SMTP_CAPABILITY_ENHANCEDSTATUSCODES = BIT(4),
	SMTP_CAPABILITY_8BITMIME            = BIT(5),
	SMTP_CAPABILITY_CHUNKING            = BIT(6),
	SMTP_CAPABILITY_BINARYMIME          = BIT(7),
	SMTP_CAPABILITY_BURL                = BIT(8),
	SMTP_CAPABILITY_DSN                 = BIT(9),
	SMTP_CAPABILITY_VRFY                = BIT(10),
	SMTP_CAPABILITY_ETRN                = BIT(11),
	SMTP_CAPABILITY_XCLIENT             = BIT(12),

	SMTP_CAPABILITY__ORCPT              = BIT(24),
};

struct smtp_capability_name {
	const char *name;
	enum smtp_capability capability;
};

struct smtp_capability_extra {
	const char *name;
	const char *const *params;
};

extern const struct smtp_capability_name smtp_capability_names[];

enum smtp_capability smtp_capability_find_by_name(const char *cap_name);

/*
 * SMTP proxy data
 */

enum smtp_proxy_protocol {
	SMTP_PROXY_PROTOCOL_UNKNOWN = 0,
	SMTP_PROXY_PROTOCOL_SMTP,
	SMTP_PROXY_PROTOCOL_ESMTP,
	SMTP_PROXY_PROTOCOL_LMTP
};

struct smtp_proxy_data_field {
	const char *name;
	const char *value;
};
ARRAY_DEFINE_TYPE(smtp_proxy_data_field, struct smtp_proxy_data_field);

struct smtp_proxy_data {
	/* PROTO */
	enum smtp_proxy_protocol proto;
	/* ADDR */
	struct ip_addr source_ip;
	/* PORT */
	in_port_t source_port;
	/* HELO, LOGIN */
	const char *helo, *login;
	/* SESSION */
	const char *session;

	/* TTL: send as this -1, so the default 0 means "don't send it" */
	unsigned int ttl_plus_1;
	/* TIMEOUT: remote is notified that the connection is going to be closed
	   after this many seconds, so it should try to keep lock waits and such
	   lower than this. */
	unsigned int timeout_secs;

	/* additional fields */
	const struct smtp_proxy_data_field *extra_fields;
	unsigned int extra_fields_count;
};

/*
 * SMTP proxy data
 */

void smtp_proxy_data_merge(pool_t pool, struct smtp_proxy_data *dst,
			   const struct smtp_proxy_data *src);

#endif