username = value;
user_given = TRUE;
} else if (str_begins(*ptr, "auth=", &value)) {
- if (strncasecmp(value, "bearer ", 7) == 0 &&
- oauth2_valid_token(value+7)) {
- token = value+7;
+ if (str_begins_icase(value, "bearer ", &value) &&
+ oauth2_valid_token(value)) {
+ token = value;
} else {
e_info(request->mech_event,
"Invalid continued data");
for(ptr = fields; *ptr != NULL; ptr++) {
if (str_begins(*ptr, "auth=", &value)) {
- if (strncasecmp(value, "bearer ", 7) == 0 &&
- oauth2_valid_token(value+7)) {
- token = value+7;
+ if (str_begins_icase(value, "bearer ", &value) &&
+ oauth2_valid_token(value)) {
+ token = value;
} else {
e_info(request->mech_event,
"Invalid continued data");
static bool log_type_find(const char *str, enum log_type *type_r)
{
+ const char *suffix;
unsigned int i;
- size_t len = strlen(str);
for (i = 0; i < LAST_LOG_TYPE; i++) {
- if (strncasecmp(str, failure_log_type_prefixes[i], len) == 0 &&
- failure_log_type_prefixes[i][len] == ':') {
+ if (str_begins_icase(failure_log_type_prefixes[i], str, &suffix) &&
+ suffix[0] == ':') {
*type_r = i;
return TRUE;
}
static bool
client_input_get_compress_algorithm(struct client *client, const char *line)
{
+ const char *algorithm;
+
/* skip tag */
while (*line != ' ' && *line != '\0')
line++;
- if (strncasecmp(line, " COMPRESS ", 10) != 0)
+ if (!str_begins_icase(line, " COMPRESS ", &algorithm))
return FALSE;
- if (compression_lookup_handler(t_str_lcase(line+10),
+ if (compression_lookup_handler(t_str_lcase(algorithm),
&client->handler) <= 0)
- i_fatal("Unsupported compression mechanism: %s", line+10);
+ i_fatal("Unsupported compression mechanism: %s", algorithm);
return TRUE;
}
cmd_id_x_forward_(struct imap_client *client,
const char *key, const char *value)
{
- i_assert(strncasecmp(key, "x-forward-", 10) == 0);
- client_add_forward_field(&client->common, key+10, value);
+ const char *suffix;
+
+ if (!str_begins_icase(key, "x-forward-", &suffix))
+ i_unreached();
+ client_add_forward_field(&client->common, suffix, value);
}
static const struct imap_id_param_handler imap_login_id_params[] = {
static const struct imap_id_param_handler *
imap_id_param_handler_find(const char *key)
{
- for (unsigned int i = 0; imap_login_id_params[i].key != NULL; i++) {
- unsigned int prefix_len = strlen(imap_login_id_params[i].key);
+ const char *suffix;
- if (strncasecmp(imap_login_id_params[i].key, key, prefix_len) == 0 &&
- (key[prefix_len] == '\0' ||
+ for (unsigned int i = 0; imap_login_id_params[i].key != NULL; i++) {
+ if (str_begins_icase(key, imap_login_id_params[i].key, &suffix) &&
+ (suffix[0] == '\0' ||
imap_login_id_params[i].key_is_prefix))
return &imap_login_id_params[i];
}
/* append any forward_ variables to request */
for(const char *const *ptr = client->common.auth_passdb_args; *ptr != NULL; ptr++) {
- if (strncasecmp(*ptr, "forward_", 8) == 0) {
+ const char *suffix;
+ if (str_begins_icase(*ptr, "forward_", &suffix)) {
const char *key = t_strconcat("x-forward-",
- t_strcut((*ptr)+8, '='),
+ t_strcut(suffix, '='),
NULL);
- const char *val = i_strchr_to_next(*ptr, '=');
+ const char *val = i_strchr_to_next(suffix, '=');
str_append_c(str, ' ');
imap_append_string(str, key);
str_append_c(str, ' ');
const char *line)
{
const char *capability;
- bool tagged_capability;
+ bool tagged_capability = FALSE;
- capability = client->proxy_backend_capability;
- tagged_capability = strncasecmp(line, "[CAPABILITY ", 12) == 0;
- if (tagged_capability)
- capability = t_strcut(line + 12, ']');
+ if (!str_begins_icase(line, "[CAPABILITY ", &capability))
+ capability = client->proxy_backend_capability;
+ else {
+ capability = t_strcut(capability, ']');
+ tagged_capability = TRUE;
+ }
if (client->client_ignores_capability_resp_code && capability != NULL) {
/* client has used CAPABILITY command, so it didn't understand
imap_client->proxy_rcvd_state = IMAP_PROXY_RCVD_STATE_LOGIN;
const char *log_line = line;
- if (strncasecmp(log_line, "NO ", 3) == 0)
- log_line += 3;
+ (void)str_begins_icase(log_line, "NO ", &log_line);
enum login_proxy_failure_type failure_type =
LOGIN_PROXY_FAILURE_TYPE_AUTH;
#define STR_NO_IMAP_RESP_CODE_AUTHFAILED "NO ["IMAP_RESP_CODE_AUTHFAILED"]"
login_proxy_get_event(client->login_proxy),
failure_type, log_line);
return -1;
- } else if (strncasecmp(line, "* CAPABILITY ", 13) == 0) {
+ } else if (str_begins_icase(line, "* CAPABILITY ", &line)) {
i_free(imap_client->proxy_backend_capability);
- imap_client->proxy_backend_capability = i_strdup(line + 13);
+ imap_client->proxy_backend_capability = i_strdup(line);
return 0;
} else if (str_begins_with(line, "C ")) {
/* Reply to CAPABILITY command we sent */
return 1;
}
return 0;
- } else if (strncasecmp(line, "I ", 2) == 0) {
+ } else if (str_begins_icase_with(line, "I ")) {
/* Reply to ID command we sent, ignore it unless
pipelining is disabled, in which case send
either STARTTLS or login */
return 1;
}
return 0;
- } else if (strncasecmp(line, "* ID ", 5) == 0) {
+ } else if (str_begins_icase_with(line, "* ID ")) {
/* Reply to ID command we sent, ignore it */
return 0;
} else if (str_begins_with(line, "* BYE ")) {
static void client_ctrl_input(struct client *client)
{
const char *const *args;
- const char *line;
+ const char *line, *value;
int ret;
timeout_reset(client->to_idle);
if (strcasecmp(*args, "debug") == 0) {
client->debug = TRUE;
/* apps=<access-application>[,<access-application,...] */
- } else if (strncasecmp(*args, "apps=", 5) == 0 &&
- (*args)[5] != '\0') {
- const char *const *apps = t_strsplit(*args+5, ",");
+ } else if (str_begins_icase(*args, "apps=", &value) &&
+ value[0] != '\0') {
+ const char *const *apps = t_strsplit(value, ",");
while (*apps != NULL) {
char *app = i_strdup(*apps);
if ((ns->flags & NAMESPACE_FLAG_INBOX_USER) != 0 &&
!str_begins_with(name, "INBOX") &&
- strncasecmp(name, "INBOX", 5) == 0 &&
+ str_begins_icase_with(name, "INBOX") &&
(name[5] == '\0' || name[5] == ns_sep)) {
/* we'll do only case-sensitive comparisons later,
so sanitize INBOX to be uppercase */
ctx->modify_type = MODIFY_REPLACE;
}
- if (strncasecmp(type, "FLAGS", 5) != 0)
+ if (!str_begins_icase(type, "FLAGS", &type))
return FALSE;
- ctx->silent = strcasecmp(type+5, ".SILENT") == 0;
- if (!ctx->silent && type[5] != '\0')
+ ctx->silent = strcasecmp(type, ".SILENT") == 0;
+ if (!ctx->silent && type[0] != '\0')
return FALSE;
return TRUE;
}
unsigned char buf[result_len];
/* only sha1 or sha256 is supported */
- if (strncasecmp(algorithm, "sha1", 4) == 0) {
+ if (str_begins_icase_with(algorithm, "sha1")) {
pbkdf2_hmac_sha1(password_len, password, rounds,
salt_len, salt, result_len, buf);
- } else if (strncasecmp(algorithm, "sha256", 6) == 0) {
+ } else if (str_begins_icase_with(algorithm, "sha256")) {
pbkdf2_hmac_sha256(password_len, password, rounds,
salt_len, salt, result_len, buf);
- } else if (strncasecmp(algorithm, "sha512", 6) == 0) {
+ } else if (str_begins_icase_with(algorithm, "sha512")) {
struct hmac_sha512_ctx ctx;
hmac_sha512_set_key(&ctx, password_len, password);
}
/* see if we want ECDH based or password based encryption */
- if (cipher != NULL && strncasecmp(cipher, "ecdh-", 5) == 0) {
+ if (cipher != NULL && str_begins_icase(cipher, "ecdh-", &cipher2)) {
i_assert(enc_key != NULL);
i_assert(password == NULL);
enctype = DCRYPT_DOVECOT_KEY_ENCRYPT_PK;
- cipher2 = cipher+5;
} else if (cipher != NULL) {
i_assert(enc_key == NULL);
i_assert(password != NULL);
imap_arg_get_list_full(&args[2], &list, &count) && count >= 2 &&
list[count].type == IMAP_ARG_LITERAL_SIZE &&
imap_arg_get_atom(&list[count-1], &name) &&
- strncasecmp(name, "BODY[", 5) == 0) {
+ str_begins_icase_with(name, "BODY[")) {
*parent_arg_r = &args[2];
*idx_r = count;
return TRUE;
static bool imapc_connection_have_auth(struct imapc_connection *conn,
const char *mech_name)
{
+ const char *auth;
char *const *capa;
for (capa = conn->capabilities_list; *capa != NULL; capa++) {
- if (strncasecmp(*capa, "AUTH=", 5) == 0 &&
- strcasecmp((*capa)+5, mech_name) == 0)
+ if (str_begins_icase(*capa, "AUTH=", &auth) &&
+ strcasecmp(auth, mech_name) == 0)
return TRUE;
}
return FALSE;
static int imap_urlauth_input_pending(struct imap_urlauth_connection *conn)
{
struct imap_urlauth_request *urlreq;
- const char *response, *const *args, *bpstruct = NULL;
+ const char *value, *response, *const *args, *bpstruct = NULL;
uoff_t literal_size;
i_assert(conn->targets_head != NULL);
const char *param = args[1], *error = NULL;
if (param != NULL &&
- strncasecmp(param, "error=", 6) == 0 &&
- param[6] != '\0') {
- error = param+6;
- }
+ str_begins_icase(param, "error=", &value) &&
+ value[0] != '\0')
+ error = value;
conn->state = IMAP_URLAUTH_STATE_REQUEST_WAIT;
imap_urlauth_request_fail(conn,
conn->targets_head->requests_head, error);
if (strcasecmp(param, "hasnuls") == 0) {
urlreq->binary_has_nuls = TRUE;
- } else if (strncasecmp(param, "bpstruct=", 9) == 0 &&
- param[9] != '\0') {
- bpstruct = param+9;
+ } else if (str_begins_icase(param, "bpstruct=", &value) &&
+ value[0] != '\0') {
+ bpstruct = value;
}
}
uend = p;
if (*p == ';') {
- if (strncasecmp(p, ";AUTH=", 6) != 0) {
+ if (!str_begins_icase(p, ";AUTH=", &p)) {
parser->error = t_strdup_printf(
"Stray ';' in userinfo `%s'",
auth.enc_userinfo);
return -1;
}
- for (p += 6; *p != '\0'; p++) {
+ for (; *p != '\0'; p++) {
if (*p == ';' || *p == ':') {
parser->error = t_strdup_printf(
"Stray %s in userinfo `%s'",
*/
/* ";EXPIRE=" date-time */
- if (strncasecmp(urlext, ";EXPIRE=", 8) == 0) {
+ if (str_begins_icase(urlext, ";EXPIRE=", &urlext)) {
if ((url_parser->flags & IMAP_URL_PARSE_ALLOW_URLAUTH) == 0) {
parser->error = "`;EXPIRE=' is not allowed in this context";
return -1;
}
- if ((p = strchr(urlext+8, ';')) != NULL) {
- if (!iso8601_date_parse((const unsigned char *)urlext+8,
- p-urlext-8, &expire, &tz)) {
+ if ((p = strchr(urlext, ';')) != NULL) {
+ if (!iso8601_date_parse((const unsigned char *)urlext,
+ p-urlext, &expire, &tz)) {
parser->error = "invalid date-time for `;EXPIRE='";
return -1;
}
}
/* ";URLAUTH=" access */
- if (strncasecmp(urlext, ";URLAUTH=", 9) != 0) {
+ if (!str_begins_icase(urlext, ";URLAUTH=", &urlext)) {
if (expire != (time_t)-1) {
parser->error = "`;EXPIRE=' without `;URLAUTH='";
return -1;
}
return 0;
}
- urlext += 9;
if (url != NULL)
url->uauth_expire = expire;
{
struct uri_parser *parser = &url_parser->parser;
struct imap_url *url = url_parser->url;
- const char *const *segment;
+ const char *const *segment, *suffix;
string_t *mailbox, *section = NULL;
uint32_t uid = 0, uidvalidity = 0;
uoff_t partial_offset = 0, partial_size = 0;
/* Handle ';' */
if (p != NULL) {
/* [uidvalidity] */
- if (strncasecmp(p, ";UIDVALIDITY=", 13) == 0) {
+ if (str_begins_icase(p, ";UIDVALIDITY=", &suffix)) {
/* append last bit of mailbox */
if (*segment != p) {
if (segment > path ||
}
/* ";UIDVALIDITY=" nz-number */
- if (strchr(p+13, ';') != NULL) {
+ if (strchr(suffix, ';') != NULL) {
parser->error = "Encountered stray ';' after UIDVALIDITY";
return -1;
}
/* nz-number */
- if (p[13] == '\0') {
+ if (suffix[0] == '\0') {
parser->error = "Empty UIDVALIDITY value";
return -1;
}
- if (imap_url_parse_number(parser, p+13, &uidvalidity) <= 0)
+ if (imap_url_parse_number(parser, suffix, &uidvalidity) <= 0)
return -1;
if (uidvalidity == 0) {
parser->error = "UIDVALIDITY cannot be zero";
}
/* iuid */
- if (*segment != NULL && strncasecmp(*segment, ";UID=", 5) == 0) {
+ if (*segment != NULL &&
+ str_begins_icase(*segment, ";UID=", &value)) {
/* ";UID=" nz-number */
- value = (*segment)+5;
if ((p = strchr(value,';')) != NULL) {
if (segment[1] != NULL ) {
/* not the last segment, so it cannot be extension like iurlauth */
if (*segment != NULL && uid > 0) {
/* [isection] */
if (section != NULL ||
- strncasecmp(*segment, ";SECTION=", 9) == 0) {
+ str_begins_icase(*segment, ";SECTION=", &value)) {
/* ";SECTION=" enc-section */
if (section == NULL) {
section = t_str_new(256);
- value = (*segment) + 9;
} else {
value = *segment;
}
/* [ipartial] */
if (*segment != NULL &&
- strncasecmp(*segment, ";PARTIAL=", 9) == 0) {
+ str_begins_icase(*segment, ";PARTIAL=", &value)) {
have_partial = TRUE;
/* ";PARTIAL=" partial-range */
- value = (*segment) + 9;
if ((p = strchr(value,';')) != NULL) {
urlext = p;
value = t_strdup_until(value, p);
/* convert using str_to_long() */
str = lua_tostring(L, idx);
- if (strncasecmp(str, "0x", 2) == 0) {
+ if (str_begins_icase(str, "0x", &str)) {
/* hex */
uintmax_t tmp;
- /* skip over leading 0x */
- str += 2;
-
if (str_to_uintmax_hex(str, &tmp) < 0)
break;
struct message_header_line *hdr)
{
struct rfc822_parser_context parser;
- const char *const *results;
+ const char *const *results, *suffix;
string_t *content_type;
int ret;
if (strcasecmp(str_c(content_type), "message/rfc822") == 0)
ctx->part->flags |= MESSAGE_PART_FLAG_MESSAGE_RFC822;
- else if (strncasecmp(str_c(content_type), "text", 4) == 0 &&
- (str_len(content_type) == 4 ||
- str_data(content_type)[4] == '/'))
+ else if (str_begins_icase(str_c(content_type), "text", &suffix) &&
+ (suffix[0] == '\0' || suffix[0] == '/'))
ctx->part->flags |= MESSAGE_PART_FLAG_TEXT;
- else if (strncasecmp(str_c(content_type), "multipart/", 10) == 0) {
+ else if (str_begins_icase(str_c(content_type), "multipart/", &suffix)) {
ctx->part->flags |= MESSAGE_PART_FLAG_MULTIPART;
- if (strcasecmp(str_c(content_type)+10, "digest") == 0)
+ if (strcasecmp(suffix, "digest") == 0)
ctx->part->flags |= MESSAGE_PART_FLAG_MULTIPART_DIGEST;
}
parent_rfc822 = part->parent != NULL &&
(part->parent->flags & MESSAGE_PART_FLAG_MESSAGE_RFC822) != 0;
- if (!parent_rfc822 && strncasecmp(hdr->name, "Content-", 8) != 0)
+ if (!parent_rfc822 && !str_begins_icase_with(hdr->name, "Content-"))
return;
if (part->data == NULL) {
}
part_data = part->data;
- if (strncasecmp(hdr->name, "Content-", 8) == 0) {
+ if (str_begins_icase_with(hdr->name, "Content-")) {
T_BEGIN {
parse_content_header(part_data, pool, hdr);
} T_END;
content_type = t_str_new(64);
(void)rfc822_parse_content_type(&parser, content_type);
ctx->content_type_text =
- strncasecmp(str_c(content_type), "text/", 5) == 0 ||
- strncasecmp(str_c(content_type), "message/", 8) == 0;
+ str_begins_icase_with(str_c(content_type), "text/") ||
+ str_begins_icase_with(str_c(content_type), "message/");
rfc822_parser_deinit(&parser);
}
ctx.plain_output =
buffer_create_dynamic(pool, 1024);
}
- } else if (strncasecmp(ct, "text/", 5) != 0)
+ } else if (!str_begins_icase_with(ct, "text/"))
skip_part = raw_block.part;
} else if (!snippet_generate(&ctx, block.data, block.size))
break;
switch (i_toupper(*p)) {
case 'S':
multiply *= 1;
- if (strncasecmp(p, "secs", strlen(p)) == 0 ||
- strncasecmp(p, "seconds", strlen(p)) == 0)
+ if (str_begins_icase_with("secs", p) ||
+ str_begins_icase_with("seconds", p))
p = "";
break;
case 'M':
multiply *= 60;
- if (strncasecmp(p, "mins", strlen(p)) == 0 ||
- strncasecmp(p, "minutes", strlen(p)) == 0)
+ if (str_begins_icase_with("mins", p) ||
+ str_begins_icase_with("minutes", p))
p = "";
- else if (strncasecmp(p, "msecs", strlen(p)) == 0 ||
- strncasecmp(p, "mseconds", strlen(p)) == 0 ||
- strncasecmp(p, "millisecs", strlen(p)) == 0 ||
- strncasecmp(p, "milliseconds", strlen(p)) == 0) {
+ else if (str_begins_icase_with("msecs", p) ||
+ str_begins_icase_with("mseconds", p) ||
+ str_begins_icase_with("millisecs", p) ||
+ str_begins_icase_with("milliseconds", p)) {
if (milliseconds || (num % 1000) == 0) {
if (!milliseconds) {
/* allow ms also for seconds, as long
break;
case 'H':
multiply *= 60*60;
- if (strncasecmp(p, "hours", strlen(p)) == 0)
+ if (str_begins_icase_with("hours", p))
p = "";
break;
case 'D':
multiply *= 60*60*24;
- if (strncasecmp(p, "days", strlen(p)) == 0)
+ if (str_begins_icase_with("days", p))
p = "";
break;
case 'W':
multiply *= 60*60*24*7;
- if (strncasecmp(p, "weeks", strlen(p)) == 0)
+ if (str_begins_icase_with("weeks", p))
p = "";
break;
}
return;
/* Reverse-path */
- if (params == NULL || strncasecmp(params, "FROM:", 5) != 0) {
+ if (params == NULL || !str_begins_icase(params, "FROM:", ¶ms)) {
smtp_server_reply(cmd, 501, "5.5.4", "Invalid parameters");
return;
}
- if (params[5] != ' ' && params[5] != '\t') {
- params += 5;
+ if (params[0] != ' ' && params[0] != '\t') {
+ /* no whitespace */
} else if ((set->workarounds &
SMTP_SERVER_WORKAROUND_WHITESPACE_BEFORE_PATH) != 0) {
- params += 5;
while (*params == ' ' || *params == '\t')
params++;
} else {
return;
/* ( "<Postmaster@" Domain ">" / "<Postmaster>" / Forward-path ) */
- if (params == NULL || strncasecmp(params, "TO:", 3) != 0) {
+ if (params == NULL || !str_begins_icase(params, "TO:", ¶ms)) {
smtp_server_reply(cmd,
501, "5.5.4", "Invalid parameters");
return;
}
- if (params[3] != ' ' && params[3] != '\t') {
- params += 3;
+ if (params[0] != ' ' && params[0] != '\t') {
+ /* no whitespace */
} else if ((set->workarounds &
SMTP_SERVER_WORKAROUND_WHITESPACE_BEFORE_PATH) != 0) {
- params += 3;
while (*params == ' ' || *params == '\t')
params++;
} else {
bool ipv6 = FALSE;
if (strcasecmp(param.value, "[UNAVAILABLE]") == 0)
continue;
- if (strncasecmp(param.value, "IPV6:", 5) == 0) {
+ if (str_begins_icase(param.value, "IPV6:", ¶m.value))
ipv6 = TRUE;
- param.value += 5;
- }
if (net_addr2ip(param.value, &proxy_data->source_ip) < 0 ||
(ipv6 && proxy_data->source_ip.family != AF_INET6)) {
smtp_server_reply(cmd, 501, "5.5.4",
/* just a single query, send it */
const char *query = ctx->query != NULL ?
ctx->query : sql_statement_get_query(&ctx->stmt->stmt);
- if (strncasecmp(query, "DELETE ", 7) == 0)
+ if (str_begins_icase_with(query, "DELETE "))
query_type = CASSANDRA_QUERY_TYPE_DELETE;
else
query_type = CASSANDRA_QUERY_TYPE_WRITE;
enum cassandra_query_type query_type;
/* just a single query, send it */
- if (strncasecmp(ctx->query, "DELETE ", 7) == 0)
+ if (str_begins_icase_with(ctx->query, "DELETE "))
query_type = CASSANDRA_QUERY_TYPE_DELETE;
else
query_type = CASSANDRA_QUERY_TYPE_WRITE;
size_t pos = str_len(str);
if (!mail_search_arg_to_imap(str, arg, &error))
return FALSE;
- if (strncasecmp(str_c(str) + pos, "OLDER", 5) == 0 ||
- strncasecmp(str_c(str) + pos, "YOUNGER", 7) == 0)
+ if (str_begins_icase_with(str_c(str) + pos, "OLDER") ||
+ str_begins_icase_with(str_c(str) + pos, "YOUNGER"))
return FALSE;
return TRUE;
}
{
enum imapc_features features = 0;
const struct imapc_feature_list *list;
- const char *const *str;
+ const char *const *str, *value;
str = t_strsplit_spaces(set->imapc_features, " ,");
for (; *str != NULL; str++) {
break;
}
}
- if (strncasecmp(*str, "throttle:", 9) == 0) {
- if (imapc_settings_parse_throttle(set, *str + 9, error_r) < 0)
+ if (str_begins_icase(*str, "throttle:", &value)) {
+ if (imapc_settings_parse_throttle(set, value, error_r) < 0)
return -1;
continue;
}
/* don't treat text/ parts as attachments */
return hdr->content_type != NULL &&
- strncasecmp(hdr->content_type, "text/", 5) != 0;
+ !str_begins_icase_with(hdr->content_type, "text/");
}
static int index_attachment_open_temp_fd(void *context)
mail_cache_register_get_list(_mail->box->cache,
pool_datastack_create(), &count);
for (i = 0; i < count; i++) {
- if (strncasecmp(all_cache_fields[i].name, "hdr.", 4) != 0)
+ if (!str_begins_icase_with(all_cache_fields[i].name, "hdr."))
continue;
if (!mail_cache_field_want_add(_mail->transaction->cache_trans,
_mail->seq, i))
idx = mail_cache_register_lookup(cache, name);
if (idx != UINT_MAX) {
field = *mail_cache_register_get_field(cache, idx);
- } else if (strncasecmp(name, "hdr.", 4) == 0) {
+ } else if (str_begins_icase_with(name, "hdr.")) {
/* Do some sanity checking for the header name. Mainly
to make sure there aren't UTF-8 characters that look
like their ASCII equivalents or are completely
break;
case POP3C_CLIENT_STATE_PASS:
if (client->login_callback != NULL) {
- reply = strncasecmp(line, "+OK ", 4) == 0 ? line + 4 :
- strncasecmp(line, "-ERR ", 5) == 0 ? line + 5 :
- line;
+ if (!str_begins_icase(line, "+OK ", &reply) &&
+ !str_begins_icase(line, "-ERR ", &reply))
+ reply = line;
client_login_callback(client, success ?
POP3C_COMMAND_STATE_OK :
POP3C_COMMAND_STATE_ERR, reply);
client->state = POP3C_CLIENT_STATE_CAPA;
break;
case POP3C_CLIENT_STATE_CAPA:
- if (strncasecmp(line, "-ERR", 4) == 0) {
+ if (str_begins_icase_with(line, "-ERR")) {
/* CAPA command not supported. some commands still
support UIDL though. */
client->capabilities |= POP3C_CAPABILITY_UIDL;
if (line == NULL)
return client->input->eof ? -1 : 0;
- if (strncasecmp(line, "+OK", 3) == 0) {
- line += 3;
+ if (str_begins_icase(line, "+OK", &line))
state = POP3C_COMMAND_STATE_OK;
- } else if (strncasecmp(line, "-ERR", 4) == 0) {
- line += 4;
+ else if (str_begins_icase(line, "-ERR", &line))
state = POP3C_COMMAND_STATE_ERR;
- } else {
+ else {
i_error("pop3c(%s): Server sent unrecognized line: %s",
client->set.host, line);
state = POP3C_COMMAND_STATE_ERR;
{
struct mailbox *box;
enum mailbox_existence existence;
+ const char *suffix;
int ret;
- if (strncasecmp(ns->prefix, "INBOX", 5) == 0 &&
- ns->prefix[5] == mail_namespace_get_sep(ns)) {
+ if (str_begins_icase(ns->prefix, "INBOX", &suffix) &&
+ suffix[0] == mail_namespace_get_sep(ns)) {
/* prefix=INBOX/ (or prefix=INBOX/something/) namespace exists.
so we can create children to INBOX. */
ctx->inbox_info.flags &= ENUM_NEGATE(MAILBOX_NOINFERIORS);
(struct ns_list_iterate_context *)_ctx;
struct mail_namespace *ns;
const struct mailbox_info *info;
+ const char *suffix;
bool has_children;
if (ctx->cur_ns == NULL) {
MAILBOX_CHILD_SUBSCRIBED));
return FALSE;
}
- if (strncasecmp(info->vname, "INBOX", 5) == 0 &&
- info->vname[5] == mail_namespace_get_sep(info->ns)) {
+ if (str_begins_icase(info->vname, "INBOX", &suffix) &&
+ suffix[0] == mail_namespace_get_sep(info->ns)) {
/* we know now that INBOX has children */
ctx->inbox_info.flags |= MAILBOX_CHILDREN;
ctx->inbox_info.flags &= ENUM_NEGATE(MAILBOX_NOINFERIORS);
struct mail_namespace *ns = namespaces;
struct mail_namespace *best = NULL;
size_t best_len = 0;
+ const char *suffix;
bool inbox;
- inbox = strncasecmp(box, "INBOX", 5) == 0;
- if (inbox && box[5] == '\0') {
+ inbox = str_begins_icase(box, "INBOX", &suffix);
+ if (inbox && suffix[0] == '\0') {
/* find the INBOX namespace */
while (ns != NULL) {
if ((ns->flags & NAMESPACE_FLAG_INBOX_USER) != 0 &&
static inline bool
mail_namespace_prefix_is_inbox(struct mail_namespace *ns)
{
+ const char *suffix;
+
return (ns->flags & NAMESPACE_FLAG_INBOX_USER) != 0 &&
(ns->prefix_len == 6) &&
- (strncasecmp(ns->prefix, "INBOX", 5) == 0) &&
- (ns->prefix[5] == mail_namespace_get_sep(ns));
+ (str_begins_icase(ns->prefix, "INBOX", &suffix)) &&
+ (suffix[0] == mail_namespace_get_sep(ns));
}
#endif
for (arr = t_strsplit_spaces(value, " ,"); *arr != NULL; arr++) {
const char *name = *arr;
- if (strncasecmp(name, "hdr.", 4) == 0 &&
- !message_header_name_is_valid(name+4)) {
+ if (str_begins_icase(name, "hdr.", &name) &&
+ !message_header_name_is_valid(name)) {
*error_r = t_strdup_printf(
"Invalid %s: %s is not a valid header name",
- key, name + 4);
+ key, name);
return FALSE;
}
}
struct mail_storage *storage;
struct mailbox *box;
enum mail_error open_error = 0;
- const char *errstr = NULL;
+ const char *suffix, *errstr = NULL;
i_assert(uni_utf8_str_is_valid(vname));
- if (strncasecmp(vname, "INBOX", 5) == 0 &&
+ if (str_begins_icase(vname, "INBOX", &suffix) &&
!str_begins_with(vname, "INBOX")) {
/* make sure INBOX shows up in uppercase everywhere. do this
regardless of whether we're in inbox=yes namespace, because
clients expect INBOX to be case insensitive regardless of
server's internal configuration. */
- if (vname[5] == '\0')
+ if (suffix[0] == '\0')
vname = "INBOX";
- else if (vname[5] != mail_namespace_get_sep(list->ns))
+ else if (suffix[0] != mail_namespace_get_sep(list->ns))
/* not INBOX prefix */ ;
else if (strncasecmp(list->ns->prefix, vname, 6) == 0 &&
!str_begins_with(list->ns->prefix, "INBOX")) {
list->ns->prefix);
open_error = MAIL_ERROR_TEMP;
} else {
- vname = t_strconcat("INBOX", vname + 5, NULL);
+ vname = t_strconcat("INBOX", suffix, NULL);
}
}
bool create, bool *created_r)
{
struct mailbox_node **node, *parent;
- const char *name;
+ const char *name, *suffix;
string_t *str;
*created_r = FALSE;
if (path == NULL)
return tree->nodes;
- if (strncasecmp(path, "INBOX", 5) == 0 &&
- (path[5] == '\0' || path[5] == tree->separator))
- path = t_strdup_printf("INBOX%s", path+5);
+ if (str_begins_icase(path, "INBOX", &suffix) &&
+ (suffix[0] == '\0' || suffix[0] == tree->separator))
+ path = t_strdup_printf("INBOX%s", suffix);
parent = NULL;
node = &tree->nodes;
/* Copy forward fields returned from passdb */
fwfields = NULL;
for (const char *const *ptr = fields; *ptr != NULL; ptr++) {
- if (strncasecmp(*ptr, "forward_", 8) != 0)
+ if (!str_begins_icase_with(*ptr, "forward_"))
continue;
if (fwfields == NULL)
}
if (iter->ns->prefix_len > 0 &&
(iter->ns->prefix_len != 6 ||
- strncasecmp(iter->ns->prefix, "INBOX", 5) != 0)) {
+ !str_begins_icase_with(iter->ns->prefix, "INBOX"))) {
/* if the namespace prefix itself exists, count it also */
iter->info.ns = iter->ns;
iter->info.vname = t_strndup(iter->ns->prefix,
static bool cmd_xclient(struct pop3_client *client, const char *args)
{
- const char *const *tmp;
+ const char *const *tmp, *value;
in_port_t remote_port;
bool args_ok = TRUE;
return TRUE;
}
for (tmp = t_strsplit(args, " "); *tmp != NULL; tmp++) {
- if (strncasecmp(*tmp, "ADDR=", 5) == 0) {
- if (net_addr2ip(*tmp + 5, &client->common.ip) < 0)
+ if (str_begins_icase(*tmp, "ADDR=", &value)) {
+ if (net_addr2ip(value, &client->common.ip) < 0)
args_ok = FALSE;
- } else if (strncasecmp(*tmp, "PORT=", 5) == 0) {
- if (net_str2port(*tmp + 5, &remote_port) < 0)
+ } else if (str_begins_icase(*tmp, "PORT=", &value)) {
+ if (net_str2port(value, &remote_port) < 0)
args_ok = FALSE;
else
client->common.remote_port = remote_port;
- } else if (strncasecmp(*tmp, "SESSION=", 8) == 0) {
- const char *value = *tmp + 8;
-
+ } else if (str_begins_icase(*tmp, "SESSION=", &value)) {
if (strlen(value) <= LOGIN_MAX_SESSION_ID_LEN) {
client->common.session_id =
p_strdup(client->common.pool, value);
}
- } else if (strncasecmp(*tmp, "TTL=", 4) == 0) {
- if (str_to_uint(*tmp + 4, &client->common.proxy_ttl) < 0)
+ } else if (str_begins_icase(*tmp, "TTL=", &value)) {
+ if (str_to_uint(value, &client->common.proxy_ttl) < 0)
args_ok = FALSE;
- } else if (strncasecmp(*tmp, "FORWARD=", 8) == 0) {
- size_t value_len = strlen((*tmp)+8);
+ } else if (str_begins_icase(*tmp, "FORWARD=", &value)) {
+ size_t value_len = strlen(value);
client->common.forward_fields =
str_new(client->common.preproxy_pool,
MAX_BASE64_DECODED_SIZE(value_len));
- if (base64_decode((*tmp)+8, value_len,
+ if (base64_decode(value, value_len,
client->common.forward_fields) < 0)
args_ok = FALSE;
}
struct dsasl_client_settings sasl_set;
const unsigned char *sasl_output;
size_t len;
- const char *mech_name, *error;
+ const char *mech_name, *value, *error;
string_t *str = t_str_new(128);
i_assert(client->common.proxy_ttl > 1);
!client->common.proxy_not_trusted) {
string_t *fwd = t_str_new(128);
for(const char *const *ptr = client->common.auth_passdb_args;*ptr != NULL; ptr++) {
- if (strncasecmp(*ptr, "forward_", 8) == 0) {
+ if (str_begins_icase(*ptr, "forward_", &value)) {
if (str_len(fwd) > 0)
str_append_c(fwd, '\t');
- str_append_tabescaped(fwd, (*ptr)+8);
+ str_append_tabescaped(fwd, value);
}
}
static buffer_t *
proxy_compose_xclient_forward(struct submission_client *client)
{
- const char *const *arg;
+ const char *const *arg, *value;
string_t *str;
if (*client->common.auth_passdb_args == NULL)
str = t_str_new(128);
for (arg = client->common.auth_passdb_args; *arg != NULL; arg++) {
- if (strncasecmp(*arg, "forward_", 8) == 0) {
+ if (str_begins_icase(*arg, "forward_", &value)) {
if (str_len(str) > 0)
str_append_c(str, '\t');
- str_append_tabescaped(str, (*arg)+8);
+ str_append_tabescaped(str, value);
}
}
if (str_len(str) == 0)
struct smtp_server_command *command = cmd->cmd;
struct ostream *output;
bool last_line = FALSE, invalid_line = FALSE;
- const char *text = NULL, *enh_code = NULL;
+ const char *suffix, *text = NULL, *enh_code = NULL;
unsigned int status = 0;
i_assert(!client->destroyed);
return -1;
}
- if (strncasecmp(text, "XCLIENT ", 8) == 0) {
+ if (str_begins_icase(text, "XCLIENT ", &suffix)) {
subm_client->proxy_capability |=
SMTP_CAPABILITY_XCLIENT;
i_free_and_null(subm_client->proxy_xclient);
subm_client->proxy_xclient = p_strarray_dup(
- default_pool, t_strsplit_spaces(text + 8, " "));
+ default_pool, t_strsplit_spaces(suffix, " "));
} else if (strcasecmp(text, "STARTTLS") == 0) {
subm_client->proxy_capability |=
SMTP_CAPABILITY_STARTTLS;
- } else if (strncasecmp(text, "AUTH", 4) == 0 &&
- text[4] == ' ' && text[5] != '\0') {
+ } else if (str_begins_icase(text, "AUTH ", &suffix) &&
+ suffix[0] != '\0') {
subm_client->proxy_capability |=
SMTP_CAPABILITY_AUTH;
} else if (strcasecmp(text, "ENHANCEDSTATUSCODES") == 0) {