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; }
static MuError run_cmd_cfind (const char* pattern, MuConfigFormat format, gboolean color, GError **err) { gboolean rv; MuContacts *contacts; size_t num; ECData ecdata; ecdata.format = format; ecdata.color = color; contacts = mu_contacts_new (mu_runtime_path(MU_RUNTIME_PATH_CONTACTS)); if (!contacts) { g_set_error (err, MU_ERROR_DOMAIN, MU_ERROR_CONTACTS_CANNOT_RETRIEVE, "could not retrieve contacts"); return MU_ERROR_CONTACTS_CANNOT_RETRIEVE; } print_header (format); rv = mu_contacts_foreach (contacts, (MuContactsForeachFunc)each_contact, &ecdata, pattern, &num); mu_contacts_destroy (contacts); if (num == 0) { g_warning ("no matching contacts found"); return MU_ERROR_NO_MATCHES; } return rv ? MU_OK : MU_ERROR_CONTACTS; }