Skip to content

Commit

Permalink
* use mu_str_ascii_xapian_escape instead of local version; and non-in…
Browse files Browse the repository at this point in the history
…-place version
  • Loading branch information
djcb committed Dec 7, 2010
1 parent 4babb4d commit 39d71b8
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
15 changes: 5 additions & 10 deletions src/mu-store.cc
Expand Up @@ -441,15 +441,12 @@ each_contact_info (MuMsgContact *contact, MsgDoc *data)
}

/* don't normalize e-mail address, but do lowercase it */
if (contact->address && strlen (contact->address)) {
char *lower = g_utf8_strdown (contact->address, -1);

g_strdelimit (lower, "@.", '_'); /* FIXME */

if (contact->address && contact->address[0] != '\0') {
char *escaped =
mu_str_ascii_xapian_escape (contact->address);
data->_doc->add_term
(std::string (*pfxp + lower, 0,
MU_STORE_MAX_TERM_LENGTH));
g_free (lower);
(std::string (*pfxp + escaped, 0, MU_STORE_MAX_TERM_LENGTH));
g_free (escaped);
}
}

Expand Down Expand Up @@ -618,5 +615,3 @@ mu_store_foreach (MuStore *self,

return MU_OK;
}


8 changes: 8 additions & 0 deletions src/mu-str.c
Expand Up @@ -299,6 +299,7 @@ mu_str_date_parse_hdwmy (const char* str)
}



char*
mu_str_ascii_xapian_escape_in_place (char *query)
{
Expand Down Expand Up @@ -334,3 +335,10 @@ mu_str_ascii_xapian_escape_in_place (char *query)
return query;
}

char*
mu_str_ascii_xapian_escape (const char *query)
{
g_return_val_if_fail (query, NULL);

return mu_str_ascii_xapian_escape_in_place (g_strdup(query));
}
17 changes: 16 additions & 1 deletion src/mu-str.h
Expand Up @@ -150,6 +150,7 @@ char* mu_str_normalize (const char *str, gboolean downcase)
* optionally, downcase it. this happen by changing the string; if
* that is not desired, use mu_str_normalize. Works for accented chars
* in Unicode Blocks 'Latin-1 Supplement' and 'Latin Extended-A'
*
*
* @param str a valid utf8 string or NULL
* @param downcase if TRUE, convert the string to lowercase
Expand All @@ -165,7 +166,7 @@ char* mu_str_normalize_in_place (char *str, gboolean downcase);
* replace ':' with '_', if it's not following a xapian-prefix (such
* as 'subject:', 't:' etc, as defined in mu-msg-fields.[ch]).
* changing is done in-place (by changing the argument string). in
* any, case, the string will be downcased.
* any case, the string will be downcased.
*
* works for ascii strings, like e-mail addresses and message-id.
*
Expand All @@ -175,6 +176,20 @@ char* mu_str_normalize_in_place (char *str, gboolean downcase);
*/
char* mu_str_ascii_xapian_escape_in_place (char *query);

/**
* escape the string for use with xapian matching. in practice, if the
* string contains an '@', replace '@', single-'.' with '_'. Also,
* replace ':' with '_', if it's not following a xapian-prefix (such
* as 'subject:', 't:' etc, as defined in mu-msg-fields.[ch]).
*
* works for ascii strings, like e-mail addresses and message-id.
*
* @param query a query string
*
* @return the escaped string (free with g_free) or NULL in case of error
*/
char* mu_str_ascii_xapian_escape (const char *query);

/**
*
* parse strings like 1h, 3w, 2m to mean '1 hour before now', '3 weeks
Expand Down

0 comments on commit 39d71b8

Please sign in to comment.