From 7053582dd7d5ffdf0b69437b39fa8b88637c1484 Mon Sep 17 00:00:00 2001 From: djcb Date: Mon, 17 Dec 2012 22:30:26 +0200 Subject: [PATCH] * add skipping-dups support to mu4e --- lib/mu-msg-sexp.c | 2 +- mu/mu-cmd-server.c | 44 ++++++++++++++++++++++++-------------------- mu4e/mu4e-proc.el | 12 ++++++++---- 3 files changed, 33 insertions(+), 25 deletions(-) diff --git a/lib/mu-msg-sexp.c b/lib/mu-msg-sexp.c index c0fc1fe2..c3c4656b 100644 --- a/lib/mu-msg-sexp.c +++ b/lib/mu-msg-sexp.c @@ -356,7 +356,7 @@ static void append_sexp_thread_info (GString *gstr, const MuMsgIterThreadInfo *ti) { g_string_append_printf - (gstr, "\t:thread (:path \"%s\":level %u%s%s%s%s)\n", + (gstr, "\t:thread (:path \"%s\" :level %u%s%s%s%s)\n", ti->threadpath, ti->level, ti->prop & MU_MSG_ITER_THREAD_PROP_FIRST_CHILD ? diff --git a/mu/mu-cmd-server.c b/mu/mu-cmd-server.c index 7c3911f9..b91d2976 100644 --- a/mu/mu-cmd-server.c +++ b/mu/mu-cmd-server.c @@ -842,19 +842,11 @@ cmd_extract (ServerContext *ctx, GSList *args, GError **err) /* parse the find parameters, and return the values as out params */ static MuError -get_find_params (GSList *args, gboolean *threads, MuMsgFieldId *sortfield, - gboolean *reverse, int *maxnum, GError **err) +get_find_params (GSList *args, MuMsgFieldId *sortfield, + int *maxnum, MuQueryFlags *qflags, GError **err) { const char *maxnumstr, *sortfieldstr; - /* maximum number of results */ - maxnumstr = get_string_from_args (args, "maxnum", TRUE, NULL); - *maxnum = maxnumstr ? atoi (maxnumstr) : 0; - - /* whether to show threads or not */ - *threads = get_bool_from_args (args, "threads", TRUE, NULL); - *reverse = get_bool_from_args (args, "reverse", TRUE, NULL); - /* field to sort by */ sortfieldstr = get_string_from_args (args, "sortfield", TRUE, NULL); if (sortfieldstr) { @@ -868,6 +860,23 @@ get_find_params (GSList *args, gboolean *threads, MuMsgFieldId *sortfield, } else *sortfield = MU_MSG_FIELD_ID_DATE; + /* flags */ + *qflags = MU_QUERY_FLAG_NONE; + + if (get_bool_from_args (args, "threads", TRUE, NULL)) { + *qflags |= MU_QUERY_FLAG_THREADS; + *maxnum = -1; + } else { + /* maximum number of results */ + maxnumstr = get_string_from_args (args, "maxnum", TRUE, NULL); + *maxnum = maxnumstr ? atoi (maxnumstr) : 0; + } + + if (get_bool_from_args (args, "reverse", TRUE, NULL)) + *qflags |= MU_QUERY_FLAG_DESCENDING; + if (get_bool_from_args (args, "skip-dups", TRUE, NULL)) + *qflags |= MU_QUERY_FLAG_SKIP_DUPS; + return MU_OK; } @@ -887,14 +896,13 @@ cmd_find (ServerContext *ctx, GSList *args, GError **err) MuMsgIter *iter; unsigned foundnum; int maxnum; - gboolean threads, reverse; MuMsgFieldId sortfield; const char *querystr; MuQueryFlags qflags; GET_STRING_OR_ERROR_RETURN (args, "query", &querystr, err); - if (get_find_params (args, &threads, &sortfield, - &reverse, &maxnum, err) != MU_OK) { + if (get_find_params (args, &sortfield, &maxnum, &qflags, err) + != MU_OK) { print_and_clear_g_error (err); return MU_OK; } @@ -902,14 +910,9 @@ cmd_find (ServerContext *ctx, GSList *args, GError **err) /* note: when we're threading, we get *all* matching messages, * and then only return maxnum; this is so that we maximimize * the change of all messages in a thread showing up */ - qflags = MU_QUERY_FLAG_NONE; - if (threads) - qflags |= MU_QUERY_FLAG_THREADS; - if (reverse) - qflags |= MU_QUERY_FLAG_DESCENDING; iter = mu_query_run (ctx->query, querystr, sortfield, - threads ? -1 : maxnum, qflags, err); + maxnum, qflags, err); if (!iter) { print_and_clear_g_error (err); return MU_OK; @@ -920,7 +923,8 @@ cmd_find (ServerContext *ctx, GSList *args, GError **err) * will ensure that the output of two finds will not be * mixed. */ print_expr ("(:erase t)"); - foundnum = print_sexps (iter, threads, + foundnum = print_sexps (iter, + qflags & MU_QUERY_FLAG_THREADS, maxnum > 0 ? maxnum : G_MAXINT32); print_expr ("(:found %u)", foundnum); mu_msg_iter_destroy (iter); diff --git a/mu4e/mu4e-proc.el b/mu4e/mu4e-proc.el index 7d75168b..9844b4e6 100644 --- a/mu4e/mu4e-proc.el +++ b/mu4e/mu4e-proc.el @@ -317,25 +317,29 @@ In particular, backslashes and double-quotes." (let ((esc (replace-regexp-in-string "\\\\" "\\\\\\\\" query))) (replace-regexp-in-string "\"" "\\\\\"" esc))) -(defun mu4e~proc-find (query threads sortfield sortdir maxnum) +(defun mu4e~proc-find (query threads sortfield sortdir maxnum skip-dups) "Start a database query for QUERY. If THREADS is non-nil, show results in threaded fasion, SORTFIELD is a symbol describing the field to sort by (or nil); see `mu4e~headers-sortfield-choices'. If SORT is `descending', sort Z->A, if it's `ascending', sort A->Z. MAXNUM determines the maximum -number of results to return, or nil for 'unlimited'. For each +number of results to return, or nil for 'unlimited'. If +SKIP-DUPS is non-nil, show only one of duplicate messages. + +For each result found, a function is called, depending on the kind of result. The variables `mu4e-error-func' contain the function that will be called for, resp., a message (header row) or an error." (mu4e~proc-send-command - "find query:\"%s\" threads:%s sortfield:%s reverse:%s maxnum:%d" + "find query:\"%s\" threads:%s sortfield:%s reverse:%s maxnum:%d skip-dups:%s" (mu4e~proc-escape-query query) (if threads "true" "false") ;; sortfield is e.g. ':subject'; this removes the ':' (if (null sortfield) "nil" (substring (symbol-name sortfield) 1)) ;; TODO: use ascending/descending in backend too (it's clearer than 'reverse' (if (eq sortdir 'descending) "true" "false") - (if maxnum maxnum -1))) + (if maxnum maxnum -1) + (if skip-dups "true" "false"))) (defun mu4e~proc-move (docid-or-msgid &optional maildir flags) "Move message identified by DOCID-OR-MSGID.