buffer_t *encoding_buf;
- char *content_charset;
+ char *content_type, *content_charset;
enum message_cte message_cte;
unsigned int binary_input:1;
buffer_free(&ctx->buf);
buffer_free(&ctx->buf2);
i_free(ctx->charset_trans_charset);
+ i_free(ctx->content_type);
i_free(ctx->content_charset);
i_free(ctx);
}
const char *const *results;
string_t *str;
- if (ctx->content_charset != NULL)
+ 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)
+ 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) {
}
}
+const char *
+message_decoder_current_content_type(struct message_decoder_context *ctx)
+{
+ return ctx->content_type;
+}
+
void message_decoder_decode_reset(struct message_decoder_context *ctx)
{
+ i_free_and_null(ctx->content_type);
i_free_and_null(ctx->content_charset);
ctx->message_cte = MESSAGE_CTE_78BIT;
buffer_set_used_size(ctx->encoding_buf, 0);
test_end();
}
+static void test_message_decoder_current_content_type(void)
+{
+ struct message_decoder_context *ctx;
+ struct message_part part, part2, part3;
+ struct message_header_line hdr;
+ struct message_block input, output;
+
+ test_begin("message_decoder_current_content_type()");
+
+ memset(&part, 0, sizeof(part));
+ part2 = part3 = part;
+
+ memset(&input, 0, sizeof(input));
+ memset(&output, 0xff, sizeof(output));
+ input.part = ∂
+
+ ctx = message_decoder_init(NULL, 0);
+ test_assert(message_decoder_current_content_type(ctx) == NULL);
+
+ /* multipart/mixed */
+ memset(&hdr, 0, sizeof(hdr));
+ hdr.name = "Content-Type";
+ hdr.name_len = strlen(hdr.name);
+ hdr.full_value = (const void *)"multipart/mixed; boundary=x";
+ hdr.full_value_len = strlen((const char *)hdr.full_value);
+ input.hdr = &hdr;
+ test_assert(message_decoder_decode_next_block(ctx, &input, &output));
+
+ input.hdr = NULL;
+ test_assert(message_decoder_decode_next_block(ctx, &input, &output));
+ test_assert(strcmp(message_decoder_current_content_type(ctx), "multipart/mixed") == 0);
+
+ /* child 1 */
+ input.part = &part2;
+ hdr.full_value = (const void *)"text/plain";
+ hdr.full_value_len = strlen((const char *)hdr.full_value);
+ input.hdr = &hdr;
+ test_assert(message_decoder_decode_next_block(ctx, &input, &output));
+
+ input.hdr = NULL;
+ test_assert(message_decoder_decode_next_block(ctx, &input, &output));
+ test_assert(strcmp(message_decoder_current_content_type(ctx), "text/plain") == 0);
+
+ /* child 2 */
+ input.part = &part3;
+ hdr.full_value = (const void *)"application/pdf";
+ hdr.full_value_len = strlen((const char *)hdr.full_value);
+ input.hdr = &hdr;
+ test_assert(message_decoder_decode_next_block(ctx, &input, &output));
+
+ input.hdr = NULL;
+ test_assert(message_decoder_decode_next_block(ctx, &input, &output));
+ test_assert(strcmp(message_decoder_current_content_type(ctx), "application/pdf") == 0);
+
+ /* reset */
+ message_decoder_decode_reset(ctx);
+ test_assert(message_decoder_current_content_type(ctx) == NULL);
+
+ message_decoder_deinit(&ctx);
+
+ test_end();
+}
+
int main(void)
{
static void (*test_functions[])(void) = {
test_message_decoder,
+ test_message_decoder_current_content_type,
NULL
};
return test_run(test_functions);