/* 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) { 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) { *sortfield = mu_msg_field_id_from_name (sortfieldstr, FALSE); /* note: shortcuts are not allowed here */ if (*sortfield == MU_MSG_FIELD_ID_NONE) { mu_util_g_set_error (err, MU_ERROR_IN_PARAMETERS, "not a valid sort field: '%s'", sortfield); return MU_G_ERROR_CODE(err); } } else *sortfield = MU_MSG_FIELD_ID_DATE; return MU_OK; }
/* * 'index' (re)indexs maildir at path:<path>, and responds with (:info * index ... ) messages while doing so (see the code) */ static MuError cmd_index (ServerContext *ctx, GHashTable *args, GError **err) { MuIndex *index; const char *argpath; char *path; gboolean cleanup, lazy_check; index = NULL; GET_STRING_OR_ERROR_RETURN (args, "path", &argpath, err); if (!(path = get_checked_path (argpath))) goto leave; set_my_addresses (ctx->store, get_string_from_args (args, "my-addresses", TRUE, NULL)); if (!(index = mu_index_new (ctx->store, err))) goto leave; cleanup = get_bool_from_args (args, "cleanup", TRUE, NULL); lazy_check = get_bool_from_args (args, "lazy-check", TRUE, NULL); index_and_maybe_cleanup (index, path, cleanup, lazy_check, err); leave: g_free (path); if (err && *err) print_and_clear_g_error (err); mu_index_destroy (index); return MU_OK; }
static MuMsgOptions get_encrypted_msg_opts (GHashTable *args) { MuMsgOptions opts; opts = MU_MSG_OPTION_NONE; if (get_bool_from_args (args, "use-agent", FALSE, NULL)) opts |= MU_MSG_OPTION_USE_AGENT; if (get_bool_from_args (args, "extract-encrypted", FALSE, NULL)) opts |= MU_MSG_OPTION_DECRYPT; return opts; }
static MuError cmd_contacts (ServerContext *ctx, GSList *args, GError **err) { MuContacts *contacts; char *sexp; gboolean personal; time_t after; const char *str; personal = get_bool_from_args (args, "personal", TRUE, NULL); str = get_string_from_args (args, "after", TRUE, NULL); after = str ? (time_t)atoi(str) : 0; contacts = mu_contacts_new (mu_runtime_path (MU_RUNTIME_PATH_CONTACTS)); if (!contacts) { print_error (MU_ERROR_INTERNAL, "failed to open contacts cache"); return MU_OK; } /* dump the contacts cache as a giant sexp */ sexp = contacts_to_sexp (contacts, personal, after); print_expr ("%s\n", sexp); g_free (sexp); mu_contacts_destroy (contacts); return MU_OK; }
/* when called with a msgid, we need to take care of possibly multiple * messages with this message id. this is a common case when sending * messages to ourselves (maybe through a mailing list), where there * would a message in the inbox and sent folders with the same id. we * set the flag on both */ static gboolean move_msgid_maybe (ServerContext *ctx, GHashTable *args, GError **err) { GSList *docids, *cur; const char* maildir, *msgid, *flagstr; gboolean new_name; maildir = get_string_from_args (args, "maildir", TRUE, err); msgid = get_string_from_args (args, "msgid", TRUE, err); flagstr = get_string_from_args (args, "flags", TRUE, err); new_name = get_bool_from_args (args, "newname", TRUE, err); /* you cannot use 'maildir' for multiple messages at once */ if (!msgid || !flagstr || maildir) return FALSE; if (!(docids = get_docids_from_msgids (ctx->query, msgid, err))) { print_and_clear_g_error (err); return TRUE; } for (cur = docids; cur; cur = g_slist_next(cur)) if (move_docid (ctx->store, GPOINTER_TO_SIZE(cur->data), flagstr, new_name, err) != MU_OK) break; g_slist_free (docids); return TRUE; }
static MuMsgOptions get_view_msg_opts (GSList *args) { MuMsgOptions opts; opts = MU_MSG_OPTION_VERIFY; if (get_bool_from_args (args, "extract-images", FALSE, NULL)) opts |= MU_MSG_OPTION_EXTRACT_IMAGES; if (get_bool_from_args (args, "use-agent", FALSE, NULL)) opts |= MU_MSG_OPTION_USE_AGENT; if (get_bool_from_args (args, "auto-retrieve-key", FALSE, NULL)) opts |= MU_MSG_OPTION_AUTO_RETRIEVE; if (get_bool_from_args (args, "extract-encrypted", FALSE, NULL)) opts |= MU_MSG_OPTION_DECRYPT; return opts; }
/* parse the find parameters, and return the values as out params */ static MuError get_find_params (GSList *args, MuMsgFieldId *sortfield, int *maxnum, MuQueryFlags *qflags, GError **err) { const char *maxnumstr, *sortfieldstr; /* defaults */ *maxnum = 500; *qflags = MU_QUERY_FLAG_NONE; *sortfield = MU_MSG_FIELD_ID_NONE; /* field to sort by */ sortfieldstr = get_string_from_args (args, "sortfield", TRUE, NULL); if (sortfieldstr) { *sortfield = mu_msg_field_id_from_name (sortfieldstr, FALSE); /* note: shortcuts are not allowed here */ if (*sortfield == MU_MSG_FIELD_ID_NONE) { mu_util_g_set_error (err, MU_ERROR_IN_PARAMETERS, "not a valid sort field: '%s'", sortfield); return MU_G_ERROR_CODE(err); } } else *sortfield = MU_MSG_FIELD_ID_DATE; /* 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; if (get_bool_from_args (args, "include-related", TRUE, NULL)) *qflags |= MU_QUERY_FLAG_INCLUDE_RELATED; if (get_bool_from_args (args, "include-related", TRUE, NULL)) *qflags |= MU_QUERY_FLAG_INCLUDE_RELATED; if (get_bool_from_args (args, "threads", TRUE, NULL)) *qflags |= MU_QUERY_FLAG_THREADS; return MU_OK; }
/* * 'move' moves a message to a different maildir and/or changes its * flags. parameters are *either* a 'docid:' or 'msgid:' pointing to * the message, a 'maildir:' for the target maildir, and a 'flags:' * parameter for the new flags. * * returns an (:update <new-msg-sexp>) * */ static MuError cmd_move (ServerContext *ctx, GHashTable *args, GError **err) { unsigned docid; MuMsg *msg; MuFlags flags; const char *maildir, *flagstr; gboolean new_name; /* check if the move is based on the message id; if so, handle * it in move_msgid_maybe */ if (move_msgid_maybe (ctx, args, err)) return MU_OK; maildir = get_string_from_args (args, "maildir", TRUE, err); flagstr = get_string_from_args (args, "flags", TRUE, err); new_name = get_bool_from_args (args, "newname", TRUE, err); docid = determine_docid (ctx->query, args, err); if (docid == MU_STORE_INVALID_DOCID || !(msg = mu_store_get_msg (ctx->store, docid, err))) { print_and_clear_g_error (err); return MU_OK; } /* if maildir was not specified, take the current one */ if (!maildir) maildir = mu_msg_get_maildir (msg); /* determine the real target flags, which come from the * flags-parameter we received (ie., flagstr), if any, plus * the existing message flags. */ if (flagstr) flags = get_flags (mu_msg_get_path(msg), flagstr); else flags = mu_msg_get_flags (msg); if (flags == MU_FLAG_INVALID) { print_error (MU_ERROR_IN_PARAMETERS, "invalid flags"); goto leave; } if ((do_move (ctx->store, docid, msg, maildir, flags, new_name, err) != MU_OK)) print_and_clear_g_error (err); leave: mu_msg_unref (msg); return MU_OK; }