/src/dovecot/src/lib-smtp/smtp-common.c
Line | Count | Source |
1 | | /* Copyright (c) 2013-2018 Dovecot authors, see the included COPYING file */ |
2 | | |
3 | | #include "lib.h" |
4 | | #include "smtp-common.h" |
5 | | |
6 | | /* |
7 | | * Capabilities |
8 | | */ |
9 | | |
10 | | const struct smtp_capability_name smtp_capability_names[] = { |
11 | | { "AUTH", SMTP_CAPABILITY_AUTH }, |
12 | | { "STARTTLS", SMTP_CAPABILITY_STARTTLS }, |
13 | | { "PIPELINING", SMTP_CAPABILITY_PIPELINING }, |
14 | | { "SIZE", SMTP_CAPABILITY_SIZE }, |
15 | | { "ENHANCEDSTATUSCODES", SMTP_CAPABILITY_ENHANCEDSTATUSCODES }, |
16 | | { "8BITMIME", SMTP_CAPABILITY_8BITMIME }, |
17 | | { "CHUNKING", SMTP_CAPABILITY_CHUNKING }, |
18 | | { "BINARYMIME", SMTP_CAPABILITY_BINARYMIME }, |
19 | | { "BURL", SMTP_CAPABILITY_BURL }, |
20 | | { "DSN", SMTP_CAPABILITY_DSN }, |
21 | | { "VRFY", SMTP_CAPABILITY_VRFY }, |
22 | | { "ETRN", SMTP_CAPABILITY_ETRN }, |
23 | | { "XCLIENT", SMTP_CAPABILITY_XCLIENT }, |
24 | | #ifdef EXPERIMENTAL_MAIL_UTF8 |
25 | | { "SMTPUTF8", SMTP_CAPABILITY_SMTPUTF8 }, |
26 | | #endif |
27 | | { NULL, 0 } |
28 | | }; |
29 | | |
30 | | enum smtp_capability smtp_capability_find_by_name(const char *cap_name) |
31 | 0 | { |
32 | 0 | const struct smtp_capability_name *cap; |
33 | 0 | unsigned int i; |
34 | |
|
35 | 0 | for (i = 0; smtp_capability_names[i].name != NULL; i++) { |
36 | 0 | cap = &smtp_capability_names[i]; |
37 | |
|
38 | 0 | if (strcasecmp(cap_name, cap->name) == 0) |
39 | 0 | return cap->capability; |
40 | 0 | } |
41 | | |
42 | 0 | return SMTP_CAPABILITY_NONE; |
43 | 0 | } |
44 | | |
45 | | /* |
46 | | * SMTP proxy data |
47 | | */ |
48 | | |
49 | | static void |
50 | | smtp_proxy_data_merge_extra_fields(pool_t pool, struct smtp_proxy_data *dst, |
51 | | const struct smtp_proxy_data *src) |
52 | 0 | { |
53 | 0 | const struct smtp_proxy_data_field *sefields; |
54 | 0 | struct smtp_proxy_data_field *defields; |
55 | 0 | unsigned int i; |
56 | |
|
57 | 0 | if (src->extra_fields_count == 0) |
58 | 0 | return; |
59 | | |
60 | 0 | sefields = src->extra_fields; |
61 | 0 | defields = p_new(pool, struct smtp_proxy_data_field, |
62 | 0 | src->extra_fields_count); |
63 | 0 | for (i = 0; i < src->extra_fields_count; i++) { |
64 | 0 | defields[i].name = p_strdup(pool, sefields[i].name); |
65 | 0 | defields[i].value = p_strdup(pool, sefields[i].value); |
66 | 0 | } |
67 | |
|
68 | 0 | dst->extra_fields = defields; |
69 | 0 | dst->extra_fields_count = src->extra_fields_count; |
70 | 0 | } |
71 | | |
72 | | void smtp_proxy_data_merge(pool_t pool, struct smtp_proxy_data *dst, |
73 | | const struct smtp_proxy_data *src) |
74 | 0 | { |
75 | 0 | if (src->proto != SMTP_PROXY_PROTOCOL_UNKNOWN) |
76 | 0 | dst->proto = src->proto; |
77 | 0 | if (src->source_ip.family != 0) { |
78 | 0 | dst->source_ip = src->source_ip; |
79 | 0 | if (src->source_port != 0) |
80 | 0 | dst->source_port = src->source_port; |
81 | 0 | } |
82 | 0 | if (src->dest_ip.family != 0) { |
83 | 0 | dst->dest_ip = src->dest_ip; |
84 | 0 | if (src->dest_port != 0) |
85 | 0 | dst->dest_port = src->dest_port; |
86 | 0 | } |
87 | 0 | if (src->helo != NULL && *src->helo != '\0') |
88 | 0 | dst->helo = p_strdup(pool, src->helo); |
89 | 0 | if (src->login != NULL && *src->login != '\0') |
90 | 0 | dst->login = p_strdup(pool, src->login); |
91 | 0 | if (src->session != NULL && *src->session != '\0') |
92 | 0 | dst->session = p_strdup(pool, src->session); |
93 | 0 | if (src->client_transport != NULL && *src->client_transport != '\0') |
94 | 0 | dst->client_transport = p_strdup(pool, src->client_transport); |
95 | 0 | if (src->local_name != NULL && *src->local_name != '\0') |
96 | 0 | dst->local_name = p_strdup_empty(pool, src->local_name); |
97 | 0 | if (src->ttl_plus_1 > 0) |
98 | 0 | dst->ttl_plus_1 = src->ttl_plus_1; |
99 | 0 | if (src->timeout_secs > 0) |
100 | 0 | dst->timeout_secs = src->timeout_secs; |
101 | |
|
102 | 0 | smtp_proxy_data_merge_extra_fields(pool, dst, src); |
103 | 0 | }; |