/* step 1: create the containers, connect them, and fill the id_table */ static GHashTable* create_containers (MuMsgIter *iter) { GHashTable *id_table; id_table = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, (GDestroyNotify)mu_container_destroy); for (mu_msg_iter_reset (iter); !mu_msg_iter_is_done (iter); mu_msg_iter_next (iter)) { MuContainer *c; MuMsg *msg; unsigned docid; /* 1.A */ msg = mu_msg_iter_get_msg_floating (iter); /* don't unref */ docid = mu_msg_iter_get_docid (iter); c = find_or_create (id_table, msg, docid); /* 1.B and C */ if (c) handle_references (id_table, c); } return id_table; }
static unsigned print_sexps (MuMsgIter *iter, gboolean threads, unsigned maxnum) { unsigned u; u = 0; while (!mu_msg_iter_is_done (iter) && u < maxnum && !MU_TERMINATE) { MuMsg *msg; msg = mu_msg_iter_get_msg_floating (iter); if (mu_msg_is_readable (msg)) { char *sexp; const MuMsgIterThreadInfo* ti; ti = threads ? mu_msg_iter_get_thread_info (iter) : NULL; sexp = mu_msg_to_sexp (msg, mu_msg_iter_get_docid (iter), ti, MU_MSG_OPTION_HEADERS_ONLY); print_expr ("%s", sexp); g_free (sexp); ++u; } mu_msg_iter_next (iter); } return u; }
/* get a *list* of all messages with the given message id */ static GSList* get_docids_from_msgids (MuQuery *query, const char *str, GError **err) { gchar *querystr; MuMsgIter *iter; GSList *lst; querystr = g_strdup_printf ("msgid:%s", str); iter = mu_query_run (query, querystr, FALSE, MU_MSG_FIELD_ID_NONE, FALSE,-1 /*unlimited*/, err); g_free (querystr); if (!iter || mu_msg_iter_is_done (iter)) { mu_util_g_set_error (err, MU_ERROR_NO_MATCHES, "could not find message %s", str); return NULL; } lst = NULL; do { lst = g_slist_prepend (lst, GSIZE_TO_POINTER(mu_msg_iter_get_docid (iter))); } while (mu_msg_iter_next (iter)); mu_msg_iter_destroy (iter); return lst; }
/* NOTE: this assumes there is only _one_ docid (message) for the * particular message id */ static unsigned get_docid_from_msgid (MuQuery *query, const char *str, GError **err) { gchar *querystr; unsigned docid; MuMsgIter *iter; querystr = g_strdup_printf ("msgid:%s", str); iter = mu_query_run (query, querystr, FALSE, MU_MSG_FIELD_ID_NONE, FALSE, 1, err); g_free (querystr); docid = MU_STORE_INVALID_DOCID; if (!iter || mu_msg_iter_is_done (iter)) mu_util_g_set_error (err, MU_ERROR_NO_MATCHES, "could not find message %s", str); else { MuMsg *msg; msg = mu_msg_iter_get_msg_floating (iter); if (!mu_msg_is_readable(msg)) { mu_util_g_set_error (err, MU_ERROR_FILE_CANNOT_READ, "'%s' is not readable", mu_msg_get_path(msg)); } else docid = mu_msg_iter_get_docid (iter); mu_msg_iter_destroy (iter); } return docid; }
static gboolean output_sexp (MuMsg *msg, MuMsgIter *iter, MuConfig *opts, GError **err) { char *sexp; const MuMsgIterThreadInfo *ti; ti = opts->threads ? mu_msg_iter_get_thread_info (iter) : NULL; sexp = mu_msg_to_sexp (msg, mu_msg_iter_get_docid (iter), ti, MU_MSG_OPTION_HEADERS_ONLY); fputs (sexp, stdout); g_free (sexp); return TRUE; }
static void thread_indent (MuMsgIter *iter) { const MuMsgIterThreadInfo *ti; const char* threadpath; int i; gboolean is_root, first_child, empty_parent, is_dup; ti = mu_msg_iter_get_thread_info (iter); if (!ti) { g_warning ("cannot get thread-info for message %u", mu_msg_iter_get_docid (iter)); return; } threadpath = ti->threadpath; /* fputs (threadpath, stdout); */ /* fputs (" ", stdout); */ is_root = ti->prop & MU_MSG_ITER_THREAD_PROP_ROOT; first_child = ti->prop & MU_MSG_ITER_THREAD_PROP_FIRST_CHILD; empty_parent = ti->prop & MU_MSG_ITER_THREAD_PROP_EMPTY_PARENT; is_dup = ti->prop & MU_MSG_ITER_THREAD_PROP_DUP; /* FIXME: count the colons... */ for (i = 0; *threadpath; ++threadpath) i += (*threadpath == ':') ? 1 : 0; /* indent */ while (i --> 0) fputs (" ", stdout); if (!is_root) { fputs (first_child ? "`" : "|", stdout); fputs (empty_parent ? "*> " : is_dup ? "=> " : "-> ", stdout); } }