-gboolean quicksearch_match(QuickSearch *quicksearch, MsgInfo *msginfo)
-{
- gchar *searched_header = NULL;
- gboolean result = FALSE;
-
- if (!quicksearch->active)
- return TRUE;
-
- switch (prefs_common.summary_quicksearch_type) {
- case QUICK_SEARCH_SUBJECT:
- searched_header = msginfo->subject;
- break;
- case QUICK_SEARCH_FROM:
- searched_header = msginfo->from;
- break;
- case QUICK_SEARCH_TO:
- searched_header = msginfo->to;
- break;
- case QUICK_SEARCH_MIXED:
- break;
- case QUICK_SEARCH_EXTENDED:
- break;
- default:
- debug_print("unknown search type (%d)\n", prefs_common.summary_quicksearch_type);
- break;
- }
- quicksearch->matching = TRUE;
- if (prefs_common.summary_quicksearch_type != QUICK_SEARCH_EXTENDED &&
- prefs_common.summary_quicksearch_type != QUICK_SEARCH_MIXED &&
- prefs_common.summary_quicksearch_type != QUICK_SEARCH_TAG &&
- quicksearch->search_string &&
- searched_header && strcasestr(searched_header, quicksearch->search_string) != NULL)
- result = TRUE;
- else if (prefs_common.summary_quicksearch_type == QUICK_SEARCH_MIXED &&
- quicksearch->search_string && (
- (msginfo->to && strcasestr(msginfo->to, quicksearch->search_string) != NULL) ||
- (msginfo->from && strcasestr(msginfo->from, quicksearch->search_string) != NULL) ||
- (msginfo->subject && strcasestr(msginfo->subject, quicksearch->search_string) != NULL) ||
- ((quicksearch->matcher_list != NULL) &&
- matcherlist_match(quicksearch->matcher_list, msginfo)) ))
- result = TRUE;
- else if ((quicksearch->matcher_list != NULL) &&
- matcherlist_match(quicksearch->matcher_list, msginfo))
- result = TRUE;
-
- quicksearch->matching = FALSE;
- if (quicksearch->deferred_free) {
- prepare_matcher(quicksearch);
- }
-
- return result;
-}
-
-/* allow Mutt-like patterns in quick search */
-static gchar *expand_search_string(const gchar *search_string)
-{
- int i = 0;
- gchar term_char, save_char;
- gchar *cmd_start, *cmd_end;
- GString *matcherstr;
- gchar *returnstr = NULL;
- gchar *copy_str;
- gboolean casesens, dontmatch;
- /* list of allowed pattern abbreviations */
- struct {
- gchar *abbreviated; /* abbreviation */
- gchar *command; /* actual matcher command */
- gint numparams; /* number of params for cmd */
- gboolean qualifier; /* do we append regexpcase */
- gboolean quotes; /* do we need quotes */
- }
- cmds[] = {
- { "a", "all", 0, FALSE, FALSE },
- { "ag", "age_greater", 1, FALSE, FALSE },
- { "al", "age_lower", 1, FALSE, FALSE },
- { "b", "body_part", 1, TRUE, TRUE },
- { "B", "message", 1, TRUE, TRUE },
- { "c", "cc", 1, TRUE, TRUE },
- { "C", "to_or_cc", 1, TRUE, TRUE },
- { "D", "deleted", 0, FALSE, FALSE },
- { "e", "header \"Sender\"", 1, TRUE, TRUE },
- { "E", "execute", 1, FALSE, TRUE },
- { "f", "from", 1, TRUE, TRUE },
- { "F", "forwarded", 0, FALSE, FALSE },
- { "h", "headers_part", 1, TRUE, TRUE },
- { "i", "header \"Message-ID\"", 1, TRUE, TRUE },
- { "I", "inreplyto", 1, TRUE, TRUE },
- { "k", "colorlabel", 1, FALSE, FALSE },
- { "L", "locked", 0, FALSE, FALSE },
- { "n", "newsgroups", 1, TRUE, TRUE },
- { "N", "new", 0, FALSE, FALSE },
- { "O", "~new", 0, FALSE, FALSE },
- { "r", "replied", 0, FALSE, FALSE },
- { "R", "~unread", 0, FALSE, FALSE },
- { "s", "subject", 1, TRUE, TRUE },
- { "se", "score_equal", 1, FALSE, FALSE },
- { "sg", "score_greater", 1, FALSE, FALSE },
- { "sl", "score_lower", 1, FALSE, FALSE },
- { "Se", "size_equal", 1, FALSE, FALSE },
- { "Sg", "size_greater", 1, FALSE, FALSE },
- { "Ss", "size_smaller", 1, FALSE, FALSE },
- { "t", "to", 1, TRUE, TRUE },
- { "tg", "tag", 1, TRUE, TRUE },
- { "T", "marked", 0, FALSE, FALSE },
- { "U", "unread", 0, FALSE, FALSE },
- { "x", "header \"References\"", 1, TRUE, TRUE },
- { "X", "test", 1, FALSE, FALSE },
- { "y", "header \"X-Label\"", 1, TRUE, TRUE },
- { "&", "&", 0, FALSE, FALSE },
- { "|", "|", 0, FALSE, FALSE },
- { "p", "partial", 0, FALSE, FALSE },
- { NULL, NULL, 0, FALSE, FALSE }
- };
-
- if (search_string == NULL)
- return NULL;
-
- copy_str = g_strdup(search_string);
-
- matcherstr = g_string_sized_new(16);
- cmd_start = copy_str;
- while (cmd_start && *cmd_start) {
- /* skip all white spaces */
- while (*cmd_start && isspace((guchar)*cmd_start))
- cmd_start++;
- cmd_end = cmd_start;
-
- /* extract a command */
- while (*cmd_end && !isspace((guchar)*cmd_end))
- cmd_end++;
-
- /* save character */
- save_char = *cmd_end;
- *cmd_end = '\0';
-
- dontmatch = FALSE;
- casesens = FALSE;
-
- /* ~ and ! mean logical NOT */
- if (*cmd_start == '~' || *cmd_start == '!')
- {
- dontmatch = TRUE;
- cmd_start++;
- }
- /* % means case sensitive match */
- if (*cmd_start == '%')
- {
- casesens = TRUE;
- cmd_start++;
- }
-
- /* find matching abbreviation */
- for (i = 0; cmds[i].command; i++) {
- if (!strcmp(cmd_start, cmds[i].abbreviated)) {
- /* restore character */
- *cmd_end = save_char;
-
- /* copy command */
- if (matcherstr->len > 0) {
- g_string_append(matcherstr, " ");
- }
- if (dontmatch)
- g_string_append(matcherstr, "~");
- g_string_append(matcherstr, cmds[i].command);
- g_string_append(matcherstr, " ");
-
- /* stop if no params required */
- if (cmds[i].numparams == 0)
- break;
-
- /* extract a parameter, allow quotes */
- while (*cmd_end && isspace((guchar)*cmd_end))
- cmd_end++;
-
- cmd_start = cmd_end;
- if (*cmd_start == '"') {
- term_char = '"';
- cmd_end++;
- }
- else
- term_char = ' ';
-
- /* extract actual parameter */
- while ((*cmd_end) && (*cmd_end != term_char))
- cmd_end++;
-
- if (*cmd_end == '"')
- cmd_end++;
-
- save_char = *cmd_end;
- *cmd_end = '\0';
-
- if (cmds[i].qualifier) {
- if (casesens)
- g_string_append(matcherstr, "regexp ");
- else
- g_string_append(matcherstr, "regexpcase ");
- }
-
- /* do we need to add quotes ? */
- if (cmds[i].quotes && term_char != '"')
- g_string_append(matcherstr, "\"");
-
- /* copy actual parameter */
- g_string_append(matcherstr, cmd_start);
-
- /* do we need to add quotes ? */
- if (cmds[i].quotes && term_char != '"')
- g_string_append(matcherstr, "\"");
-
- /* restore original character */
- *cmd_end = save_char;
-
- break;
- }
- }
-
- if (*cmd_end)
- cmd_end++;
- cmd_start = cmd_end;
- }
-
- g_free(copy_str);
-
- /* return search string if no match is found to allow
- all available filtering expressions in quicksearch */
- if (matcherstr->len > 0) returnstr = matcherstr->str;
- else returnstr = g_strdup(search_string);
-
- g_string_free(matcherstr, FALSE);
- return returnstr;
-}
-
-static gchar *expand_tag_search_string(const gchar *search_string)
-{
- gchar *newstr = NULL;
- gchar **words = search_string ? g_strsplit(search_string, " ", -1):NULL;
- gint i = 0;
- while (words && words[i] && *words[i]) {
- g_strstrip(words[i]);
- if (!newstr) {
- newstr = g_strdup_printf("tag regexpcase \"%s\"", words[i]);
- } else {
- gint o_len = strlen(newstr);
- gint s_len = 18; /* strlen("|tag regexpcase \"\"") */
- gint n_len = s_len + strlen(words[i]);
- newstr = g_realloc(newstr,o_len+n_len+1);
- strcpy(newstr+o_len, "|tag regexpcase \"");
- strcpy(newstr+o_len+(s_len-1), words[i]);
- strcpy(newstr+o_len+s_len, "\"");
- }
- i++;
- }
- g_strfreev(words);
- return newstr;
-}
-