summaryrefslogtreecommitdiffstats
path: root/src/lmtp/lmtp-client.h
blob: 0e7d963e4392db5d169d53de2502783a2f86f2ad (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
120
121
122
123
124
#ifndef CLIENT_H
#define CLIENT_H

#include "net.h"
#include "smtp-server.h"

#define CLIENT_MAIL_DATA_MAX_INMEMORY_SIZE (1024*128)

struct mail_storage;
struct mail_deliver_context;
union lmtp_module_context;
struct lmtp_recipient;
struct client;

struct lmtp_local_deliver_context {
	struct mail *src_mail;
	const char *session_id;
	struct timeval delivery_time_started;

	struct mail_user *rcpt_user;
	const char *rcpt_default_mailbox;

	const struct mail_storage_settings *mail_set;
	const struct smtp_submit_settings *smtp_set;
	const struct lda_settings *lda_set;

	struct mail_deliver_session *session;
};

struct client_state {
	enum smtp_server_state state;
	char *args;
	unsigned int session_id_seq;

	struct istream *data_input;
	uoff_t data_size;

	struct timeval data_end_timeval;

	struct ostream *mail_data_output;

	const char *added_headers_local;
	const char *added_headers_proxy;
};

struct lmtp_client_vfuncs {
	void (*destroy)(struct client *client);

	void (*trans_start)(struct client *client,
			    struct smtp_server_transaction *trans);
	void (*trans_free)(struct client *client,
			   struct smtp_server_transaction *trans);

	int (*cmd_mail)(struct client *client, struct smtp_server_cmd_ctx *cmd,
			struct smtp_server_cmd_mail *data);
	int (*cmd_rcpt)(struct client *client, struct smtp_server_cmd_ctx *cmd,
			struct lmtp_recipient *lrcpt);
	int (*cmd_data)(struct client *client,
			struct smtp_server_cmd_ctx *cmd,
			struct smtp_server_transaction *trans,
			struct istream *data_input, uoff_t data_size);

	int (*local_deliver)(struct client *client,
			     struct lmtp_recipient *lrcpt,
			     struct smtp_server_cmd_ctx *cmd,
			     struct smtp_server_transaction *trans,
			     struct lmtp_local_deliver_context *lldctx);
};

struct client {
	struct client *prev, *next;
	pool_t pool;

	struct lmtp_client_vfuncs v;
	struct event *event;

	const struct setting_parser_info *user_set_info;
	const struct mail_user_settings *user_set;
	const struct lda_settings *unexpanded_lda_set;
	const struct lmtp_settings *lmtp_set;
	const struct master_service_settings *service_set;

	struct smtp_server_connection *conn;

	struct ip_addr remote_ip, local_ip, real_local_ip, real_remote_ip;
	in_port_t remote_port, local_port, real_local_port, real_remote_port;

	struct mail_user *raw_mail_user;
	const char *my_domain;

	pool_t state_pool;
	struct client_state state;
	struct istream *dot_input;
	struct lmtp_local *local;
	struct lmtp_proxy *proxy;

	/* Module-specific contexts. */
	ARRAY(union lmtp_module_context *) module_contexts;

	bool disconnected:1;
	bool destroyed:1;
};

struct lmtp_module_register {
	unsigned int id;
};

union lmtp_module_context {
	struct lmtp_client_vfuncs super;
	struct lmtp_module_register *reg;
};
extern struct lmtp_module_register lmtp_module_register;

struct client *client_create(int fd_in, int fd_out,
			     const struct master_service_connection *conn);
void client_destroy(struct client **client, const char *enh_code,
		    const char *reason) ATTR_NULL(2, 3);

void client_state_reset(struct client *client);
void client_update_data_state(struct client *client, const char *new_args);

void clients_destroy(void);

#endif