mirror of https://github.com/djcb/mu.git
* add skipping-dups support to mu4e
This commit is contained in:
parent
3353e32c28
commit
7053582dd7
|
@ -356,7 +356,7 @@ static void
|
||||||
append_sexp_thread_info (GString *gstr, const MuMsgIterThreadInfo *ti)
|
append_sexp_thread_info (GString *gstr, const MuMsgIterThreadInfo *ti)
|
||||||
{
|
{
|
||||||
g_string_append_printf
|
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->threadpath,
|
||||||
ti->level,
|
ti->level,
|
||||||
ti->prop & MU_MSG_ITER_THREAD_PROP_FIRST_CHILD ?
|
ti->prop & MU_MSG_ITER_THREAD_PROP_FIRST_CHILD ?
|
||||||
|
|
|
@ -842,19 +842,11 @@ cmd_extract (ServerContext *ctx, GSList *args, GError **err)
|
||||||
|
|
||||||
/* parse the find parameters, and return the values as out params */
|
/* parse the find parameters, and return the values as out params */
|
||||||
static MuError
|
static MuError
|
||||||
get_find_params (GSList *args, gboolean *threads, MuMsgFieldId *sortfield,
|
get_find_params (GSList *args, MuMsgFieldId *sortfield,
|
||||||
gboolean *reverse, int *maxnum, GError **err)
|
int *maxnum, MuQueryFlags *qflags, GError **err)
|
||||||
{
|
{
|
||||||
const char *maxnumstr, *sortfieldstr;
|
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 */
|
/* field to sort by */
|
||||||
sortfieldstr = get_string_from_args (args, "sortfield", TRUE, NULL);
|
sortfieldstr = get_string_from_args (args, "sortfield", TRUE, NULL);
|
||||||
if (sortfieldstr) {
|
if (sortfieldstr) {
|
||||||
|
@ -868,6 +860,23 @@ get_find_params (GSList *args, gboolean *threads, MuMsgFieldId *sortfield,
|
||||||
} else
|
} else
|
||||||
*sortfield = MU_MSG_FIELD_ID_DATE;
|
*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;
|
return MU_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -887,14 +896,13 @@ cmd_find (ServerContext *ctx, GSList *args, GError **err)
|
||||||
MuMsgIter *iter;
|
MuMsgIter *iter;
|
||||||
unsigned foundnum;
|
unsigned foundnum;
|
||||||
int maxnum;
|
int maxnum;
|
||||||
gboolean threads, reverse;
|
|
||||||
MuMsgFieldId sortfield;
|
MuMsgFieldId sortfield;
|
||||||
const char *querystr;
|
const char *querystr;
|
||||||
MuQueryFlags qflags;
|
MuQueryFlags qflags;
|
||||||
|
|
||||||
GET_STRING_OR_ERROR_RETURN (args, "query", &querystr, err);
|
GET_STRING_OR_ERROR_RETURN (args, "query", &querystr, err);
|
||||||
if (get_find_params (args, &threads, &sortfield,
|
if (get_find_params (args, &sortfield, &maxnum, &qflags, err)
|
||||||
&reverse, &maxnum, err) != MU_OK) {
|
!= MU_OK) {
|
||||||
print_and_clear_g_error (err);
|
print_and_clear_g_error (err);
|
||||||
return MU_OK;
|
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,
|
/* note: when we're threading, we get *all* matching messages,
|
||||||
* and then only return maxnum; this is so that we maximimize
|
* and then only return maxnum; this is so that we maximimize
|
||||||
* the change of all messages in a thread showing up */
|
* 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,
|
iter = mu_query_run (ctx->query, querystr, sortfield,
|
||||||
threads ? -1 : maxnum, qflags, err);
|
maxnum, qflags, err);
|
||||||
if (!iter) {
|
if (!iter) {
|
||||||
print_and_clear_g_error (err);
|
print_and_clear_g_error (err);
|
||||||
return MU_OK;
|
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
|
* will ensure that the output of two finds will not be
|
||||||
* mixed. */
|
* mixed. */
|
||||||
print_expr ("(:erase t)");
|
print_expr ("(:erase t)");
|
||||||
foundnum = print_sexps (iter, threads,
|
foundnum = print_sexps (iter,
|
||||||
|
qflags & MU_QUERY_FLAG_THREADS,
|
||||||
maxnum > 0 ? maxnum : G_MAXINT32);
|
maxnum > 0 ? maxnum : G_MAXINT32);
|
||||||
print_expr ("(:found %u)", foundnum);
|
print_expr ("(:found %u)", foundnum);
|
||||||
mu_msg_iter_destroy (iter);
|
mu_msg_iter_destroy (iter);
|
||||||
|
|
|
@ -317,25 +317,29 @@ In particular, backslashes and double-quotes."
|
||||||
(let ((esc (replace-regexp-in-string "\\\\" "\\\\\\\\" query)))
|
(let ((esc (replace-regexp-in-string "\\\\" "\\\\\\\\" query)))
|
||||||
(replace-regexp-in-string "\"" "\\\\\"" esc)))
|
(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.
|
"Start a database query for QUERY.
|
||||||
If THREADS is non-nil, show results in threaded fasion, SORTFIELD
|
If THREADS is non-nil, show results in threaded fasion, SORTFIELD
|
||||||
is a symbol describing the field to sort by (or nil); see
|
is a symbol describing the field to sort by (or nil); see
|
||||||
`mu4e~headers-sortfield-choices'. If SORT is `descending', sort
|
`mu4e~headers-sortfield-choices'. If SORT is `descending', sort
|
||||||
Z->A, if it's `ascending', sort A->Z. MAXNUM determines the maximum
|
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 found, a function is called, depending on the kind of
|
||||||
result. The variables `mu4e-error-func' contain the function that
|
result. The variables `mu4e-error-func' contain the function that
|
||||||
will be called for, resp., a message (header row) or an error."
|
will be called for, resp., a message (header row) or an error."
|
||||||
(mu4e~proc-send-command
|
(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)
|
(mu4e~proc-escape-query query)
|
||||||
(if threads "true" "false")
|
(if threads "true" "false")
|
||||||
;; sortfield is e.g. ':subject'; this removes the ':'
|
;; sortfield is e.g. ':subject'; this removes the ':'
|
||||||
(if (null sortfield) "nil" (substring (symbol-name sortfield) 1))
|
(if (null sortfield) "nil" (substring (symbol-name sortfield) 1))
|
||||||
;; TODO: use ascending/descending in backend too (it's clearer than 'reverse'
|
;; TODO: use ascending/descending in backend too (it's clearer than 'reverse'
|
||||||
(if (eq sortdir 'descending) "true" "false")
|
(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)
|
(defun mu4e~proc-move (docid-or-msgid &optional maildir flags)
|
||||||
"Move message identified by DOCID-OR-MSGID.
|
"Move message identified by DOCID-OR-MSGID.
|
||||||
|
|
Loading…
Reference in New Issue