static void parse_content_type(struct message_decoder_context *ctx, struct message_header_line *hdr) { struct rfc822_parser_context parser; const char *const *results; string_t *str; if (ctx->content_type != NULL) return; rfc822_parser_init(&parser, hdr->full_value, hdr->full_value_len, NULL); rfc822_skip_lwsp(&parser); str = t_str_new(64); if (rfc822_parse_content_type(&parser, str) < 0) return; ctx->content_type = i_strdup(str_c(str)); rfc2231_parse(&parser, &results); for (; *results != NULL; results += 2) { if (strcasecmp(results[0], "charset") == 0) { ctx->content_charset = i_strdup(results[1]); break; } } }
static void parse_content_type(struct message_search_context *ctx, struct message_header_line *hdr) { struct rfc822_parser_context parser; string_t *content_type; rfc822_parser_init(&parser, hdr->full_value, hdr->full_value_len, NULL); rfc822_skip_lwsp(&parser); 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; }
static void parse_content_type(struct message_parser_ctx *ctx, struct message_header_line *hdr) { struct rfc822_parser_context parser; const char *const *results; string_t *content_type; int ret; if (ctx->part_seen_content_type) return; ctx->part_seen_content_type = TRUE; rfc822_parser_init(&parser, hdr->full_value, hdr->full_value_len, NULL); rfc822_skip_lwsp(&parser); content_type = t_str_new(64); ret = rfc822_parse_content_type(&parser, content_type); 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] == '/')) ctx->part->flags |= MESSAGE_PART_FLAG_TEXT; else if (strncasecmp(str_c(content_type), "multipart/", 10) == 0) { ctx->part->flags |= MESSAGE_PART_FLAG_MULTIPART; if (strcasecmp(str_c(content_type)+10, "digest") == 0) ctx->part->flags |= MESSAGE_PART_FLAG_MULTIPART_DIGEST; } if (ret < 0 || (ctx->part->flags & MESSAGE_PART_FLAG_MULTIPART) == 0 || ctx->last_boundary != NULL) { rfc822_parser_deinit(&parser); return; } rfc2231_parse(&parser, &results); for (; *results != NULL; results += 2) { if (strcasecmp(results[0], "boundary") == 0) { ctx->last_boundary = p_strdup(ctx->parser_pool, results[1]); break; } } rfc822_parser_deinit(&parser); }
static void parse_content_type(struct attachment_istream *astream, const struct message_header_line *hdr) { struct rfc822_parser_context parser; string_t *content_type; if (astream->part.content_type != NULL) return; rfc822_parser_init(&parser, hdr->full_value, hdr->full_value_len, NULL); rfc822_skip_lwsp(&parser); T_BEGIN { content_type = t_str_new(64); (void)rfc822_parse_content_type(&parser, content_type); astream->part.content_type = i_strdup(str_c(content_type)); } T_END; }