static void each_contact_sexp (const char *email, const char *name, gboolean personal, time_t tstamp, SexpData *sdata) { char *escmail; /* (maybe) only include 'personal' contacts */ if (sdata->personal && !personal) return; /* only include newer-than-x contacts */ if (tstamp < sdata->after) return; /* only include *real* e-mail addresses (ignore local * addresses... there's little to complete there anyway...) */ if (!email || !strstr (email, "@")) return; escmail = mu_str_escape_c_literal (email, TRUE); if (name) { char *escname; escname = mu_str_escape_c_literal (name, TRUE); g_string_append_printf (sdata->gstr, "(:name %s :mail %s)\n", escname, escmail); g_free (escname); } else g_string_append_printf (sdata->gstr, "(:mail %s)\n", escmail); g_free (escmail); }
static MuError open_part (MuMsg *msg, unsigned docid, unsigned index, GError **err) { char *targetpath; gboolean rv; targetpath = mu_msg_part_get_cache_path (msg,MU_MSG_OPTION_NONE, index, err); if (!targetpath) return print_and_clear_g_error (err); rv = mu_msg_part_save (msg, MU_MSG_OPTION_USE_EXISTING, targetpath, index, err); if (!rv) { print_and_clear_g_error (err); goto leave; } rv = mu_util_play (targetpath, TRUE,/*allow local*/ FALSE/*allow remote*/, err); if (!rv) print_and_clear_g_error (err); else { gchar *path; path = mu_str_escape_c_literal (targetpath, FALSE); print_expr ("(:info open :message \"%s has been opened\")", path); g_free (path); } leave: g_free (targetpath); return MU_OK; }
/* 'add' adds a message to the database, and takes two parameters: * 'path', which is the full path to the message, and 'maildir', which * is the maildir this message lives in (e.g. "/inbox"). response with * an (:info ...) message with information about the newly added * message (details: see code below) */ static MuError cmd_add (ServerContext *ctx, GSList *args, GError **err) { unsigned docid; const char *maildir, *path; MuMsg *msg; gchar *sexp; GET_STRING_OR_ERROR_RETURN (args, "path", &path, err); GET_STRING_OR_ERROR_RETURN (args, "maildir", &maildir, err); docid = mu_store_add_path (ctx->store, path, maildir, err); if (docid == MU_STORE_INVALID_DOCID) print_and_clear_g_error (err); else { gchar *escpath; escpath = mu_str_escape_c_literal (path, TRUE); print_expr ("(:info add :path %s :docid %u)", escpath, docid); msg = mu_store_get_msg (ctx->store, docid, err); if (msg) { sexp = mu_msg_to_sexp (msg, docid, NULL, MU_MSG_OPTION_VERIFY); print_expr ("(:update %s :move nil)", sexp); mu_msg_unref(msg); g_free (sexp); } g_free (escpath); } return MU_OK; }
static void each_part (MuMsg *msg, MuMsgPart *part, PartInfo *pinfo) { char *att, *cachefile, *encfile; GError *err; /* exclude things that don't look like proper attachments, * unless they're images */ if (!mu_msg_part_maybe_attachment(part)) return; err = NULL; cachefile = mu_msg_part_save_temp (msg, pinfo->opts|MU_MSG_OPTION_OVERWRITE, part->index, &err); if (!cachefile) { print_and_clear_g_error (&err); return; } encfile = mu_str_escape_c_literal(cachefile, TRUE); g_free (cachefile); att = g_strdup_printf ( "(:file-name %s :mime-type \"%s/%s\")", encfile, part->type, part->subtype); pinfo->attlist = g_slist_append (pinfo->attlist, att); g_free (encfile); }
static MuError print_error (MuError errcode, const char *msg) { char *str; str = mu_str_escape_c_literal (msg, TRUE); print_expr ("(:error %u :message %s)", errcode, str); g_free (str); return errcode; }
static MuError temp_part (MuMsg *msg, unsigned docid, unsigned index, GSList *args, GError **err) { const char *what, *param; char *path; GET_STRING_OR_ERROR_RETURN (args, "what", &what, err); param = get_string_from_args (args, "param", TRUE, NULL); path = mu_msg_part_get_cache_path (msg, MU_MSG_OPTION_NONE, index, err); if (!path) print_and_clear_g_error (err); else if (!mu_msg_part_save (msg, MU_MSG_OPTION_USE_EXISTING, path, index, err)) print_and_clear_g_error (err); else { gchar *escpath; escpath = mu_str_escape_c_literal (path, FALSE); if (param) { char *escparam; escparam = mu_str_escape_c_literal (param, FALSE); print_expr ("(:temp \"%s\"" " :what \"%s\"" " :docid %u" " :param \"%s\""")", escpath, what, docid, escparam); g_free (escparam); } else print_expr ("(:temp \"%s\" :what \"%s\" :docid %u)", escpath, what, docid); g_free (escpath); } g_free (path); return MU_OK; }
/* 'add' adds a message to the database, and takes two parameters: * 'path', which is the full path to the message, and 'maildir', which * is the maildir this message lives in (e.g. "/inbox"). response with * an (:info ...) message with information about the newly added * message (details: see code below) */ static MuError cmd_add (ServerContext *ctx, GSList *args, GError **err) { unsigned docid; const char *maildir, *path; GET_STRING_OR_ERROR_RETURN (args, "path", &path, err); GET_STRING_OR_ERROR_RETURN (args, "maildir", &maildir, err); docid = mu_store_add_path (ctx->store, path, maildir, err); if (docid == MU_STORE_INVALID_DOCID) print_and_clear_g_error (err); else { gchar *escpath; escpath = mu_str_escape_c_literal (path, TRUE); print_expr ("(:info add :path %s :docid %u)", escpath, docid); g_free (escpath); } return MU_OK; }
static MuError save_part (MuMsg *msg, unsigned docid, unsigned index, GSList *args, GError **err) { gboolean rv; const gchar *path; gchar *escpath; GET_STRING_OR_ERROR_RETURN (args, "path", &path, err); rv = mu_msg_part_save (msg, MU_MSG_OPTION_OVERWRITE, path, index, err); if (!rv) { print_and_clear_g_error (err); return MU_OK; } escpath = mu_str_escape_c_literal (path, FALSE); print_expr ("(:info save :message \"%s has been saved\")", escpath); g_free (escpath); return MU_OK; }