From 58f5e39d342f09804c3746bfd781b818ffd71bc8 Mon Sep 17 00:00:00 2001 From: djcb Date: Tue, 25 Dec 2012 11:58:32 +0200 Subject: [PATCH] * add support for finding related messages to mu-find, mu4e, this does *not* include the actual implementation though --- lib/mu-query.h | 11 ++++++----- mu/mu-cmd-find.c | 2 ++ mu/mu-cmd-server.c | 2 ++ mu/mu-config.c | 3 +++ mu/mu-config.h | 2 ++ mu4e/mu4e-headers.el | 12 +++++++++++- mu4e/mu4e-proc.el | 31 +++++++++++++++++++------------ 7 files changed, 45 insertions(+), 18 deletions(-) diff --git a/lib/mu-query.h b/lib/mu-query.h index 52ad844a..c13eb1b1 100644 --- a/lib/mu-query.h +++ b/lib/mu-query.h @@ -68,12 +68,13 @@ char* mu_query_version (MuQuery *store) enum _MuQueryFlags { MU_QUERY_FLAG_NONE = 0, - MU_QUERY_FLAG_THREADS = 1 << 0, /* <** add threading info */ - MU_QUERY_FLAG_DESCENDING = 1 << 1, /* <** sort z->a */ - MU_QUERY_FLAG_SKIP_UNREADABLE = 1 << 2, /* <** skip unreadable msgs */ - MU_QUERY_FLAG_SKIP_DUPS = 1 << 3 /* <** skip duplicate msgs */ + MU_QUERY_FLAG_THREADS = 1 << 0, /**< add threading info */ + MU_QUERY_FLAG_DESCENDING = 1 << 1, /**< sort z->a */ + MU_QUERY_FLAG_SKIP_UNREADABLE = 1 << 2, /**< skip unreadable msgs */ + MU_QUERY_FLAG_SKIP_DUPS = 1 << 3, /**< skip duplicate msgs */ + MU_QUERY_FLAG_INCLUDE_RELATED = 1 << 4 /**< include related msgs */ }; -typedef enum _MuQueryFlags MuQueryFlags; +typedef enum _MuQueryFlags MuQueryFlags; /** * run a Xapian query; for the syntax, please refer to the mu-find diff --git a/mu/mu-cmd-find.c b/mu/mu-cmd-find.c index 0435627d..03da09ed 100644 --- a/mu/mu-cmd-find.c +++ b/mu/mu-cmd-find.c @@ -129,6 +129,8 @@ run_query (MuQuery *xapian, const gchar *query, MuConfig *opts, GError **err) qflags |= MU_QUERY_FLAG_DESCENDING; if (opts->skip_dups) qflags |= MU_QUERY_FLAG_SKIP_DUPS; + if (opts->include_related) + qflags |= MU_QUERY_FLAG_INCLUDE_RELATED; iter = mu_query_run (xapian, query, sortid, -1, qflags, err); return iter; diff --git a/mu/mu-cmd-server.c b/mu/mu-cmd-server.c index f2c5c712..e7c983cb 100644 --- a/mu/mu-cmd-server.c +++ b/mu/mu-cmd-server.c @@ -874,6 +874,8 @@ get_find_params (GSList *args, MuMsgFieldId *sortfield, *qflags |= MU_QUERY_FLAG_DESCENDING; if (get_bool_from_args (args, "skip-dups", TRUE, NULL)) *qflags |= MU_QUERY_FLAG_SKIP_DUPS; + if (get_bool_from_args (args, "include-related", TRUE, NULL)) + *qflags |= MU_QUERY_FLAG_INCLUDE_RELATED; return MU_OK; } diff --git a/mu/mu-config.c b/mu/mu-config.c index 78313892..80ecfbc4 100644 --- a/mu/mu-config.c +++ b/mu/mu-config.c @@ -216,6 +216,9 @@ config_options_group_find (void) {"skip-dups", 'u', 0, G_OPTION_ARG_NONE, &MU_CONFIG.skip_dups, "show only the first of messages duplicates (false)", NULL}, + {"include-related", 'r', 0, G_OPTION_ARG_NONE, + &MU_CONFIG.include_related, + "include related messages in results (false)", NULL}, {"linksdir", 0, 0, G_OPTION_ARG_STRING, &MU_CONFIG.linksdir, "output as symbolic links to a target maildir", ""}, {"clearlinks", 0, 0, G_OPTION_ARG_NONE, &MU_CONFIG.clearlinks, diff --git a/mu/mu-config.h b/mu/mu-config.h index c7c25a71..bcab1681 100644 --- a/mu/mu-config.h +++ b/mu/mu-config.h @@ -143,6 +143,8 @@ struct _MuConfig { * messages with the same * msgid, show only the first * one */ + gboolean include_related; /* included related messages + * in results */ /* for find and cind */ time_t after; /* only show messages or * adresses last seen after diff --git a/mu4e/mu4e-headers.el b/mu4e/mu4e-headers.el index 1a690f4c..ad4f4b99 100644 --- a/mu4e/mu4e-headers.el +++ b/mu4e/mu4e-headers.el @@ -106,6 +106,15 @@ and offlineimap." :type 'boolean :group 'mu4e-headers) +(defcustom mu4e-headers-include-related nil + "With this option set to non-nil, not just return the matches for +a searches, but also messages that are related (through their +references) to these messages. This can be useful e.g. to include +sent messages into message threads." + :type 'boolean + :group 'mu4e-headers) + + ;; marks for headers of the form; each is a cons-cell (basic . fancy) @@ -854,7 +863,8 @@ the query history stack." mu4e~headers-sort-field mu4e~headers-sort-direction (unless mu4e-headers-full-search mu4e-search-results-limit) - mu4e-headers-skip-duplicates))) + mu4e-headers-skip-duplicates + mu4e-headers-include-related))) (defun mu4e~headers-redraw-get-view-window () "Close all windows, redraw the headers buffer based on the value diff --git a/mu4e/mu4e-proc.el b/mu4e/mu4e-proc.el index 9844b4e6..773350f3 100644 --- a/mu4e/mu4e-proc.el +++ b/mu4e/mu4e-proc.el @@ -317,29 +317,36 @@ 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 skip-dups) +(defun mu4e~proc-find (query threads sortfield sortdir maxnum skip-dups include-related) "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'. If -SKIP-DUPS is non-nil, show only one of duplicate messages. +number of results to return, or nil for 'unlimited'. If SKIP-DUPS +is non-nil, show only one of duplicate messages (see +`mu4e-headers-skip-duplicates'). If INCLUDE-RELATED is non-nil, +include messages related to the messages matching the search +query (see `mu4e-headers-include-related'). 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 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 skip-dups "true" "false"))) + (format + (concat + "find query:\"%s\" threads:%s sortfield:%s reverse:%s maxnum:%d " + "skip-dups:%s include-related:%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 skip-dups "true" "false") + (if include-related "true" "false")))) (defun mu4e~proc-move (docid-or-msgid &optional maildir flags) "Move message identified by DOCID-OR-MSGID.