static bool lmtp_client_send_xclient(struct lmtp_client *client) { string_t *str; unsigned int empty_len; if (client->xclient_args == NULL) { /* not supported */ return FALSE; } if (client->xclient_sent) return FALSE; str = t_str_new(64); str_append(str, "XCLIENT"); empty_len = str_len(str); if (client->set.source_ip.family != 0 && str_array_icase_find(client->xclient_args, "ADDR")) str_printfa(str, " ADDR=%s", net_ip2addr(&client->set.source_ip)); if (client->set.source_port != 0 && str_array_icase_find(client->xclient_args, "PORT")) str_printfa(str, " PORT=%u", client->set.source_port); if (client->set.proxy_ttl != 0 && str_array_icase_find(client->xclient_args, "TTL")) str_printfa(str, " TTL=%u", client->set.proxy_ttl); if (client->set.proxy_timeout_secs != 0 && str_array_icase_find(client->xclient_args, "TIMEOUT")) str_printfa(str, " TIMEOUT=%u", client->set.proxy_timeout_secs); if (str_len(str) == empty_len) return FALSE; str_append(str, "\r\n"); o_stream_nsend(client->output, str_data(str), str_len(str)); return TRUE; }
static bool dsync_mailbox_info_is_excluded(const struct mailbox_info *info, const char *const *exclude_mailboxes) { const char *const *info_specialuses; unsigned int i; if (exclude_mailboxes == NULL) return FALSE; info_specialuses = info->special_use == NULL ? NULL : t_strsplit(info->special_use, " "); for (i = 0; exclude_mailboxes[i] != NULL; i++) { const char *exclude = exclude_mailboxes[i]; if (exclude[0] == '\\') { /* special-use */ if (info_specialuses != NULL && str_array_icase_find(info_specialuses, exclude)) return TRUE; } else { /* mailbox with wildcards */ if (wildcard_match(info->vname, exclude)) return TRUE; } } return FALSE; }
static bool fts_autoindex_exclude_match(struct mailbox *box) { const char *const *exclude_list; unsigned int i; const struct mailbox_settings *set; const char *const *special_use; struct mail_user *user = box->storage->user; exclude_list = fts_exclude_get_patterns(user); if (exclude_list == NULL) return FALSE; set = mailbox_settings_find(mailbox_get_namespace(box), mailbox_get_vname(box)); special_use = set == NULL ? NULL : t_strsplit_spaces(set->special_use, " "); for (i = 0; exclude_list[i] != NULL; i++) { if (exclude_list[i][0] == '\\') { /* \Special-use flag */ if (str_array_icase_find(special_use, exclude_list[i])) return TRUE; } else { /* mailbox name with wildcards */ if (wildcard_match(box->name, exclude_list[i])) return TRUE; } } return FALSE; }
static int proxy_input_banner(struct imap_client *client, struct ostream *output, const char *line) { const char *const *capabilities = NULL; string_t *str; int ret; if (!str_begins(line, "* OK ")) { client_log_err(&client->common, t_strdup_printf( "proxy: Remote returned invalid banner: %s", str_sanitize(line, 160))); return -1; } str = t_str_new(128); if (str_begins(line + 5, "[CAPABILITY ")) { capabilities = t_strsplit(t_strcut(line + 5 + 12, ']'), " "); if (str_array_icase_find(capabilities, "SASL-IR")) client->proxy_sasl_ir = TRUE; if (str_array_icase_find(capabilities, "LOGINDISABLED")) client->proxy_logindisabled = TRUE; i_free(client->proxy_backend_capability); client->proxy_backend_capability = i_strdup(t_strcut(line + 5 + 12, ']')); if (str_array_icase_find(capabilities, "ID") && !client->common.proxy_not_trusted) { client->proxy_sent_state |= IMAP_PROXY_SENT_STATE_ID; proxy_write_id(client, str); if (client->common.proxy_nopipelining) { /* write login or starttls after I OK */ o_stream_nsend(output, str_data(str), str_len(str)); return 0; } } } if ((ret = proxy_write_starttls(client, str)) < 0) { return -1; } else if (ret == 0) { if (proxy_write_login(client, str) < 0) return -1; } o_stream_nsend(output, str_data(str), str_len(str)); return 0; }
static int proxy_input_banner(struct imap_client *client, struct ostream *output, const char *line) { enum login_proxy_ssl_flags ssl_flags; const char *const *capabilities = NULL; string_t *str; if (strncmp(line, "* OK ", 5) != 0) { client_log_err(&client->common, t_strdup_printf( "proxy: Remote returned invalid banner: %s", str_sanitize(line, 160))); return -1; } str = t_str_new(128); if (strncmp(line + 5, "[CAPABILITY ", 12) == 0) { capabilities = t_strsplit(t_strcut(line + 5 + 12, ']'), " "); if (str_array_icase_find(capabilities, "ID")) proxy_write_id(client, str); if (str_array_icase_find(capabilities, "SASL-IR")) client->proxy_sasl_ir = TRUE; if (str_array_icase_find(capabilities, "LOGINDISABLED")) client->proxy_logindisabled = TRUE; i_free(client->proxy_backend_capability); client->proxy_backend_capability = i_strdup(t_strcut(line + 5 + 12, ']')); } ssl_flags = login_proxy_get_ssl_flags(client->common.login_proxy); if ((ssl_flags & PROXY_SSL_FLAG_STARTTLS) != 0) { if (capabilities != NULL && !str_array_icase_find(capabilities, "STARTTLS")) { client_log_err(&client->common, "proxy: Remote doesn't support STARTTLS"); return -1; } str_append(str, "S STARTTLS\r\n"); } else { if (proxy_write_login(client, str) < 0) return -1; } o_stream_nsend(output, str_data(str), str_len(str)); return 0; }
static void cmd_id_handle_keyvalue(struct imap_client *client, const char *key, const char *value) { if (client->common.trusted && !client->id_logged) client_update_info(client, key, value); if (client->cmd_id->log_reply != NULL && (client->cmd_id->log_keys == NULL || str_array_icase_find((void *)client->cmd_id->log_keys, key))) imap_id_log_reply_append(client->cmd_id->log_reply, key, value); }
static void copy_update_trashed(struct client *client, struct mailbox *box, unsigned int count) { const struct mailbox_settings *set; set = mailbox_settings_find(mailbox_get_namespace(box), mailbox_get_vname(box)); if (set != NULL && set->special_use[0] != '\0' && str_array_icase_find(t_strsplit_spaces(set->special_use, " "), "\\Trash")) client->trashed_count += count; }
static int proxy_write_starttls(struct imap_client *client, string_t *str) { enum login_proxy_ssl_flags ssl_flags = login_proxy_get_ssl_flags(client->common.login_proxy); if ((ssl_flags & PROXY_SSL_FLAG_STARTTLS) != 0) { if (client->proxy_backend_capability != NULL && !str_array_icase_find(t_strsplit(client->proxy_backend_capability, " "), "STARTTLS")) { client_log_err(&client->common, "proxy: Remote doesn't support STARTTLS"); return -1; } str_append(str, "S STARTTLS\r\n"); return 1; } return 0; }
const char *imap_id_args_get_log_reply(const struct imap_arg *args, const char *settings) { const char *const *keys, *key, *value; string_t *reply; bool log_all; if (settings == NULL || *settings == '\0') return NULL; if (!imap_arg_get_list(args, &args)) return NULL; log_all = strcmp(settings, "*") == 0; reply = t_str_new(256); keys = t_strsplit_spaces(settings, " "); while (!IMAP_ARG_IS_EOL(&args[0]) && !IMAP_ARG_IS_EOL(&args[1])) { if (!imap_arg_get_string(args, &key)) { /* broken input */ args += 2; continue; } args++; if (strlen(key) > 30) { /* broken: ID spec requires fields to be max. 30 octets */ args++; continue; } if (log_all || str_array_icase_find(keys, key)) { if (!imap_arg_get_nstring(args, &value)) value = ""; else if (value == NULL) value = "NIL"; if (str_len(reply) > 0) str_append(reply, ", "); str_append(reply, str_sanitize(key, 30)); str_append_c(reply, '='); str_append(reply, str_sanitize(value, 80)); } args++; } return str_len(reply) == 0 ? NULL : str_c(reply); }
bool mail_has_attachment_keywords(struct mail *mail) { const char *const *kw = mail_get_keywords(mail); return (str_array_icase_find(kw, MAIL_KEYWORD_HAS_ATTACHMENT) != str_array_icase_find(kw, MAIL_KEYWORD_HAS_NO_ATTACHMENT)); }