|
24 | 24 | #include "imap-search.h"
|
25 | 25 | #include "imap-notify.h"
|
26 | 26 | #include "imap-commands.h"
|
| 27 | +#include "imap-capability-list.h" |
27 | 28 |
|
28 | 29 | #include <unistd.h>
|
29 | 30 |
|
@@ -156,17 +157,22 @@ struct client *client_create(int fd_in, int fd_out, const char *session_id,
|
156 | 157 | &client->output);
|
157 | 158 | }
|
158 | 159 |
|
159 |
| - client->capability_string = |
160 |
| - str_new(client->pool, sizeof(CAPABILITY_STRING)+64); |
| 160 | + /* create our capability list */ |
| 161 | + client->capability_list = imap_capability_list_create(NULL); |
161 | 162 |
|
162 | 163 | if (*set->imap_capability == '\0')
|
163 |
| - str_append(client->capability_string, CAPABILITY_STRING); |
| 164 | + imap_capability_list_append_string(client->capability_list, |
| 165 | + CAPABILITY_STRING); |
164 | 166 | else if (*set->imap_capability != '+') {
|
165 |
| - str_append(client->capability_string, set->imap_capability); |
| 167 | + imap_capability_list_append_string(client->capability_list, |
| 168 | + set->imap_capability); |
166 | 169 | } else {
|
167 |
| - str_append(client->capability_string, CAPABILITY_STRING); |
168 |
| - str_append_c(client->capability_string, ' '); |
169 |
| - str_append(client->capability_string, set->imap_capability + 1); |
| 170 | + /* add the capability banner string to the cap list */ |
| 171 | + imap_capability_list_append_string(client->capability_list, |
| 172 | + CAPABILITY_STRING); |
| 173 | + /* add everything after the plus to our cap list */ |
| 174 | + imap_capability_list_append_string(client->capability_list, |
| 175 | + client->set->imap_capability + 1); |
170 | 176 | }
|
171 | 177 | if (client->set->imap_literal_minus)
|
172 | 178 | client_add_capability(client, "LITERAL-");
|
@@ -552,8 +558,36 @@ void client_add_capability(struct client *client, const char *capability)
|
552 | 558 | /* explicit capability - don't change it */
|
553 | 559 | return;
|
554 | 560 | }
|
555 |
| - str_append_c(client->capability_string, ' '); |
556 |
| - str_append(client->capability_string, capability); |
| 561 | + |
| 562 | + /* add it to our capability list as CAP_ALWAYS */ |
| 563 | + imap_capability_list_add(client->capability_list, |
| 564 | + capability, IMAP_CAP_VISIBILITY_ALWAYS); |
| 565 | +} |
| 566 | + |
| 567 | +const char *client_get_capability(struct client *client) |
| 568 | +{ |
| 569 | + string_t *cap_str = t_str_new(256); |
| 570 | + |
| 571 | + /* imap is postauth by definition */ |
| 572 | + uint32_t flags = IMAP_CAP_VISIBILITY_POSTAUTH; |
| 573 | + |
| 574 | + /* is the client secured by means of ssl? */ |
| 575 | + if (client->ssl_secured) |
| 576 | + flags |= IMAP_CAP_VISIBILITY_TLS_ACTIVE; |
| 577 | + else |
| 578 | + flags |= IMAP_CAP_VISIBILITY_TLS_INACTIVE; |
| 579 | + |
| 580 | + /* Are we secured? (localhost? tls? etc) */ |
| 581 | + if (client->secured) |
| 582 | + flags |= IMAP_CAP_VISIBILITY_SECURE; |
| 583 | + else |
| 584 | + flags |= IMAP_CAP_VISIBILITY_INSECURE; |
| 585 | + |
| 586 | + /* build capability string based on IMAP_CAP_VISIBILITY_ flags */ |
| 587 | + imap_capability_list_get_capability(client->capability_list, |
| 588 | + cap_str, flags); |
| 589 | + |
| 590 | + return str_c(cap_str); |
557 | 591 | }
|
558 | 592 |
|
559 | 593 | void client_send_line(struct client *client, const char *data)
|
|
0 commit comments