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; }
static MuMsg* get_message (MuMsgIter *iter, time_t after) { MuMsg *msg; if (mu_msg_iter_is_done (iter)) return NULL; msg = mu_msg_iter_get_msg_floating (iter); if (!msg) return NULL; /* error */ if (!mu_msg_is_readable (msg)) { mu_msg_iter_next (iter); return get_message (iter, after); } if (after != 0 && after > mu_msg_get_timestamp (msg)) { mu_msg_iter_next (iter); return get_message (iter, after); } return msg; }
/* 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; }