static gboolean save_part (MuMsg *msg, const char *targetdir, guint partidx, MuConfig *opts) { GError *err; gchar *filepath; gboolean rv; MuMsgOptions msgopts; err = NULL; rv = FALSE; msgopts = mu_config_get_msg_options (opts); filepath = mu_msg_part_get_path (msg, msgopts, targetdir, partidx, &err); if (!filepath) goto exit; if (!mu_msg_part_save (msg, msgopts, filepath, partidx, &err)) goto exit; if (opts->play) rv = mu_util_play (filepath, TRUE, FALSE, &err); else rv = TRUE; exit: if (err) { g_warning ("error with MIME-part: %s", err->message); g_clear_error (&err); } g_free (filepath); return rv; }
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; }
static gboolean save_part (MuMsg *msg, const char *targetdir, guint partidx, gboolean overwrite, gboolean play) { GError *err; gchar *filepath; filepath = mu_msg_part_filepath (msg, targetdir, partidx); if (!filepath) { g_warning ("failed to get filepath"); return FALSE; } err = NULL; if (!mu_msg_part_save (msg, filepath, partidx, overwrite, FALSE, &err)) { if (err) { g_warning ("failed to save MIME-part: %s", err->message); g_error_free (err); } g_free (filepath); return FALSE; } if (play) mu_util_play (filepath, TRUE, FALSE); g_free (filepath); return TRUE; }
gchar* mu_msg_part_save_temp (MuMsg *msg, MuMsgOptions opts, guint partidx, GError **err) { gchar *filepath; filepath = mu_msg_part_get_cache_path (msg, opts, partidx, err); if (!filepath) return NULL; if (!mu_msg_part_save (msg, opts, filepath, partidx, err)) { g_free (filepath); return NULL; } return filepath; }
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; }
static void save_part_if (MuMsg *msg, MuMsgPart *part, SaveData *sd) { gchar *filepath; gboolean rv; GError *err; MuMsgOptions msgopts; if (ignore_part (msg, part, sd)) return; rv = FALSE; filepath = NULL; err = NULL; msgopts = mu_config_get_msg_options (sd->opts); filepath = mu_msg_part_get_path (msg, msgopts, sd->opts->targetdir, part->index, &err); if (!filepath) goto exit; if (!mu_msg_part_save (msg, msgopts, filepath, part->index, &err)) goto exit; if (sd->opts->play) rv = mu_util_play (filepath, TRUE, FALSE, &err); else rv = TRUE; ++sd->saved_num; exit: if (err) g_warning ("error saving MIME part: %s", err->message); g_free (filepath); g_clear_error (&err); sd->result = rv; }
static void save_part_if (MuMsg *msg, MuMsgPart *part, SaveData *sd) { gchar *filepath; gboolean rv; GError *err; if (ignore_part (msg, part, sd)) return; rv = FALSE; filepath = NULL; err = NULL; filepath = mu_msg_part_filepath (msg, sd->targetdir, part->index, &err); if (!filepath) { g_warning ("failed to get file path: %s", err&&err->message ? err->message : "error"); g_clear_error (&err); goto leave; } if (!mu_msg_part_save (msg, filepath, part->index, sd->overwrite, FALSE, &err)) { g_warning ("failed to save MIME-part: %s", err&&err->message ? err->message : "error"); g_clear_error (&err); goto leave; } if (sd->play && !mu_util_play (filepath, TRUE, FALSE)) goto leave; rv = TRUE; ++sd->saved_num; leave: sd->result = rv; g_free (filepath); }
static char* get_temp_file (MuMsg *msg, MuMsgOptions opts, unsigned index) { char *path; GError *err; err = NULL; path = mu_msg_part_get_cache_path (msg, opts, index, &err); if (!path) goto errexit; if (!mu_msg_part_save (msg, opts, path, index, &err)) goto errexit; return path; errexit: g_warning ("failed to save mime part: %s", err->message ? err->message : "something went wrong"); g_clear_error (&err); g_free (path); return NULL; }
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; }
static char* save_file_for_cid (MuMsg *msg, const char* cid) { gint idx; gchar *filepath; GError *err; g_return_val_if_fail (msg, NULL); g_return_val_if_fail (cid, NULL); idx = mu_msg_find_index_for_cid (msg, MU_MSG_OPTION_NONE, cid); if (idx < 0) { g_warning ("%s: cannot find %s", __FUNCTION__, cid); return NULL; } err = NULL; filepath = mu_msg_part_get_cache_path (msg, MU_MSG_OPTION_NONE, idx, NULL); if (!filepath) goto errexit; if (!mu_msg_part_save (msg, MU_MSG_OPTION_USE_EXISTING, filepath, idx, &err)) goto errexit; return filepath; errexit: g_warning ("%s: failed to save %s: %s", __FUNCTION__, filepath, err&&err->message?err->message:"error"); g_clear_error (&err); g_free (filepath); return NULL; }
static char* save_file_for_cid (MuMsg *msg, const char* cid) { gint idx; gchar *filepath; gboolean rv; GError *err; g_return_val_if_fail (msg, NULL); g_return_val_if_fail (cid, NULL); idx = mu_msg_part_find_cid (msg, cid); if (idx < 0) { g_warning ("%s: cannot find %s", __FUNCTION__, cid); return NULL; } filepath = mu_msg_part_filepath_cache (msg, idx); if (!filepath) { g_warning ("%s: cannot create filepath", filepath); return NULL; } err = NULL; rv = mu_msg_part_save (msg, filepath, idx, FALSE, TRUE, &err); if (!rv) { g_warning ("%s: failed to save %s: %s", __FUNCTION__, filepath, err&&err->message?err->message:"error"); if (err) g_error_free (err); g_free (filepath); filepath = NULL; } return filepath; }