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