* add skipping-dups support to mu4e

This commit is contained in:
djcb 2012-12-17 22:30:26 +02:00
parent 3353e32c28
commit 7053582dd7
3 changed files with 33 additions and 25 deletions

View File

@ -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 ?

View File

@ -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);

View File

@ -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.