struct message_part *part, bool *binary_body_r)
{
struct mail_storage *storage;
- const char *content_type;
+ struct fts_parser_context parser_context;
struct fts_backend_build_key key;
i_assert(ctx->body_parser == NULL);
key.uid = ctx->mail->uid;
key.part = part;
- content_type = ctx->content_type != NULL ?
+ i_zero(&parser_context);
+ parser_context.content_type = ctx->content_type != NULL ?
ctx->content_type : "text/plain";
- if (strncmp(content_type, "multipart/", 10) == 0) {
+ if (strncmp(parser_context.content_type, "multipart/", 10) == 0) {
/* multiparts are never indexed, only their contents */
return FALSE;
}
+ storage = mailbox_get_storage(ctx->mail->box);
+ parser_context.user = mail_storage_get_user(storage);
+ parser_context.content_disposition = ctx->content_disposition;
- storage = mailbox_get_storage(ctx->mail->box);
- if (fts_parser_init(mail_storage_get_user(storage),
- content_type, ctx->content_disposition,
- &ctx->body_parser)) {
+ if (fts_parser_init(&parser_context, &ctx->body_parser)) {
/* extract text using the the returned parser */
*binary_body_r = TRUE;
key.type = FTS_BACKEND_BUILD_KEY_BODY_PART;
- } else if (strncmp(content_type, "text/", 5) == 0 ||
- strncmp(content_type, "message/", 8) == 0) {
+ } else if (strncmp(parser_context.content_type, "text/", 5) == 0 ||
+ strncmp(parser_context.content_type, "message/", 8) == 0) {
/* text body parts */
key.type = FTS_BACKEND_BUILD_KEY_BODY_PART;
ctx->body_parser = fts_parser_text_init();
*binary_body_r = TRUE;
key.type = FTS_BACKEND_BUILD_KEY_BODY_PART_BINARY;
}
- key.body_content_type = content_type;
+ key.body_content_type = parser_context.content_type;
key.body_content_disposition = ctx->content_disposition;
ctx->cur_user_lang = NULL;
if (!fts_backend_update_set_build_key(ctx->update_ctx, &key)) {
};
static struct fts_parser *
-fts_parser_html_try_init(struct mail_user *user ATTR_UNUSED,
- const char *content_type,
- const char *content_disposition ATTR_UNUSED)
+fts_parser_html_try_init(struct fts_parser_context *parser_context)
{
struct html_fts_parser *parser;
- if (!mail_html2text_content_type_match(content_type))
+ if (!mail_html2text_content_type_match(parser_context->content_type))
return NULL;
parser = i_new(struct html_fts_parser, 1);
}
static struct fts_parser *
-fts_parser_script_try_init(struct mail_user *user,
- const char *content_type,
- const char *content_disposition)
+fts_parser_script_try_init(struct fts_parser_context *parser_context)
{
struct script_fts_parser *parser;
const char *filename, *path, *cmd;
int fd;
- parse_content_disposition(content_disposition, &filename);
- if (!script_support_content(user, &content_type, filename))
+ parse_content_disposition(parser_context->content_disposition, &filename);
+ if (!script_support_content(parser_context->user, &parser_context->content_type, filename))
return NULL;
- fd = script_connect(user, &path);
+ fd = script_connect(parser_context->user, &path);
if (fd == -1)
return NULL;
- cmd = t_strdup_printf(SCRIPT_HANDSHAKE"%s\n\n", content_type);
+ cmd = t_strdup_printf(SCRIPT_HANDSHAKE"%s\n\n", parser_context->content_type);
if (write_full(fd, cmd, strlen(cmd)) < 0) {
i_error("write(%s) failed: %m", path);
i_close_fd(&fd);
}
static struct fts_parser *
-fts_parser_tika_try_init(struct mail_user *user, const char *content_type,
- const char *content_disposition)
+fts_parser_tika_try_init(struct fts_parser_context *parser_context)
{
struct tika_fts_parser *parser;
struct http_url *http_url;
struct http_client_request *http_req;
- if (tika_get_http_client_url(user, &http_url) < 0)
+ if (tika_get_http_client_url(parser_context->user, &http_url) < 0)
return NULL;
parser = i_new(struct tika_fts_parser, 1);
parser->parser.v = fts_parser_tika;
- parser->user = user;
+ parser->user = parser_context->user;
http_req = http_client_request(tika_http_client, "PUT",
http_url->host.name,
fts_tika_parser_response, parser);
http_client_request_set_port(http_req, http_url->port);
http_client_request_set_ssl(http_req, http_url->have_ssl);
- if (content_type != NULL)
+ if (parser_context->content_type != NULL)
http_client_request_add_header(http_req, "Content-Type",
- content_type);
- if (content_disposition != NULL)
+ parser_context->content_type);
+ if (parser_context->content_disposition != NULL)
http_client_request_add_header(http_req, "Content-Disposition",
- content_disposition);
+ parser_context->content_disposition);
http_client_request_add_header(http_req, "Accept", "text/plain");
parser->http_req = http_req;
NULL
};
-bool fts_parser_init(struct mail_user *user,
- const char *content_type, const char *content_disposition,
+bool fts_parser_init(struct fts_parser_context *parser_context,
struct fts_parser **parser_r)
{
unsigned int i;
+ i_assert(parser_context->user != NULL);
+ i_assert(parser_context->content_type != NULL);
- if (str_array_find(plaintext_content_types, content_type)) {
+ if (str_array_find(plaintext_content_types, parser_context->content_type)) {
/* we probably don't want/need to allow parsers to handle
plaintext? */
return FALSE;
}
for (i = 0; i < N_ELEMENTS(parsers); i++) {
- *parser_r = parsers[i]->try_init(user, content_type,
- content_disposition);
+ *parser_r = parsers[i]->try_init(parser_context);
if (*parser_r != NULL)
return TRUE;
}
struct message_block;
struct mail_user;
+struct fts_parser_context {
+ /* Can't be NULL */
+ struct mail_user *user;
+ /* Can't be NULL */
+ const char *content_type;
+ const char *content_disposition;
+};
+
struct fts_parser_vfuncs {
- struct fts_parser *(*try_init)(struct mail_user *user,
- const char *content_type,
- const char *content_disposition);
+ struct fts_parser *(*try_init)(struct fts_parser_context *parser_context);
void (*more)(struct fts_parser *parser, struct message_block *block);
int (*deinit)(struct fts_parser *parser);
void (*unload)(void);
extern struct fts_parser_vfuncs fts_parser_script;
extern struct fts_parser_vfuncs fts_parser_tika;
-bool fts_parser_init(struct mail_user *user,
- const char *content_type, const char *content_disposition,
+bool fts_parser_init(struct fts_parser_context *parser_context,
struct fts_parser **parser_r);
struct fts_parser *fts_parser_text_init(void);
unsigned char buf[IO_BLOCK_SIZE];
struct message_block block;
ssize_t ret;
+ struct fts_parser_context parser_context = {.content_type = "text/html"};
lib_init();
- parser = fts_parser_html.try_init(NULL, "text/html", NULL);
+ parser = fts_parser_html.try_init(&parser_context);
i_assert(parser != NULL);
i_zero(&block);