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 { NULL, 0 }
25 };
26
smtp_capability_find_by_name(const char * cap_name)27 enum smtp_capability smtp_capability_find_by_name(const char *cap_name)
28 {
29 const struct smtp_capability_name *cap;
30 unsigned int i;
31
32 for (i = 0; smtp_capability_names[i].name != NULL; i++) {
33 cap = &smtp_capability_names[i];
34
35 if (strcasecmp(cap_name, cap->name) == 0)
36 return cap->capability;
37 }
38
39 return SMTP_CAPABILITY_NONE;
40 }
41
42 /*
43 * SMTP proxy data
44 */
45
46 static void
smtp_proxy_data_merge_extra_fields(pool_t pool,struct smtp_proxy_data * dst,const struct smtp_proxy_data * src)47 smtp_proxy_data_merge_extra_fields(pool_t pool, struct smtp_proxy_data *dst,
48 const struct smtp_proxy_data *src)
49 {
50 const struct smtp_proxy_data_field *sefields;
51 struct smtp_proxy_data_field *defields;
52 unsigned int i;
53
54 if (src->extra_fields_count == 0)
55 return;
56
57 sefields = src->extra_fields;
58 defields = p_new(pool, struct smtp_proxy_data_field,
59 src->extra_fields_count);
60 for (i = 0; i < src->extra_fields_count; i++) {
61 defields[i].name = p_strdup(pool, sefields[i].name);
62 defields[i].value = p_strdup(pool, sefields[i].value);
63 }
64
65 dst->extra_fields = defields;
66 dst->extra_fields_count = src->extra_fields_count;
67 }
68
smtp_proxy_data_merge(pool_t pool,struct smtp_proxy_data * dst,const struct smtp_proxy_data * src)69 void smtp_proxy_data_merge(pool_t pool, struct smtp_proxy_data *dst,
70 const struct smtp_proxy_data *src)
71 {
72 if (src->proto != SMTP_PROXY_PROTOCOL_UNKNOWN)
73 dst->proto = src->proto;
74 if (src->source_ip.family != 0) {
75 dst->source_ip = src->source_ip;
76 if (src->source_port != 0)
77 dst->source_port = src->source_port;
78 }
79 if (src->helo != NULL && *src->helo != '\0')
80 dst->helo = p_strdup(pool, src->helo);
81 if (src->login != NULL && *src->login != '\0')
82 dst->login = p_strdup(pool, src->login);
83 if (src->ttl_plus_1 > 0)
84 dst->ttl_plus_1 = src->ttl_plus_1;
85 if (src->timeout_secs > 0)
86 dst->timeout_secs = src->timeout_secs;
87
88 smtp_proxy_data_merge_extra_fields(pool, dst, src);
89 };
90