Mercurial > dovecot > core-2.2
changeset 19758:526084651206
fts: Code cleanup - moved fts_header_has_language() to a global function
author | Timo Sirainen <timo.sirainen@dovecot.fi> |
---|---|
date | Tue, 16 Feb 2016 18:33:46 +0200 |
parents | d7e18400a7ce |
children | ca563b2b6788 |
files | src/plugins/fts/fts-api-private.h src/plugins/fts/fts-api.c src/plugins/fts/fts-build-mail.c |
diffstat | 3 files changed, 22 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/src/plugins/fts/fts-api-private.h Tue Feb 16 17:50:53 2016 +0200 +++ b/src/plugins/fts/fts-api-private.h Tue Feb 16 18:33:46 2016 +0200 @@ -122,6 +122,8 @@ /* Returns TRUE if FTS backend should index the header for optimizing separate lookups */ bool fts_header_want_indexed(const char *hdr_name); +/* Returns TRUE if header's values should be considered to have a language. */ +bool fts_header_has_language(const char *hdr_name); int fts_mailbox_get_guid(struct mailbox *box, const char **guid_r);
--- a/src/plugins/fts/fts-api.c Tue Feb 16 17:50:53 2016 +0200 +++ b/src/plugins/fts/fts-api.c Tue Feb 16 18:33:46 2016 +0200 @@ -491,6 +491,25 @@ return FALSE; } +bool fts_header_has_language(const char *hdr_name) +{ + /* FIXME: should email address headers be detected as different + languages? That mainly contains people's names.. */ + /*if (message_header_is_address(hdr_name)) + return TRUE;*/ + + /* Subject definitely contains language-specific data that can be + detected. Comment and Keywords headers also could contain, although + just about nobody uses those headers. + + For now we assume that other headers contain non-language specific + data that we don't want to filter in special ways. For example + it is good to be able to search for Message-IDs. */ + return strcasecmp(hdr_name, "Subject") == 0 || + strcasecmp(hdr_name, "Comments") == 0 || + strcasecmp(hdr_name, "Keywords") == 0; +} + int fts_mailbox_get_guid(struct mailbox *box, const char **guid_r) { struct mailbox_metadata metadata;
--- a/src/plugins/fts/fts-build-mail.c Tue Feb 16 17:50:53 2016 +0200 +++ b/src/plugins/fts/fts-build-mail.c Tue Feb 16 18:33:46 2016 +0200 @@ -67,25 +67,6 @@ i_strndup(hdr->full_value, hdr->full_value_len); } -static bool header_has_language(const char *name) -{ - /* FIXME: should email address headers be detected as different - languages? That mainly contains people's names.. */ - /*if (message_header_is_address(name)) - return TRUE;*/ - - /* Subject definitely contains language-specific data that can be - detected. Comment and Keywords headers also could contain, although - just about nobody uses those headers. - - For now we assume that other headers contain non-language specific - data that we don't want to filter in special ways. For example - it is good to be able to search for Message-IDs. */ - return strcasecmp(name, "Subject") == 0 || - strcasecmp(name, "Comments") == 0 || - strcasecmp(name, "Keywords") == 0; -} - static void fts_parse_mail_header(struct fts_mail_build_context *ctx, const struct message_block *raw_block) { @@ -157,7 +138,7 @@ human languages, so we have a list of some hardcoded header names and we'll also assume that if there's any 8bit content it's a human language. */ - if (header_has_language(hdr->name) || + if (fts_header_has_language(hdr->name) || data_has_8bit(hdr->full_value, hdr->full_value_len)) ctx->cur_user_lang = NULL; else {