Exemplo n.º 1
0
/* a summary_len of 0 mean 'don't show summary, show body */
static void
body_or_summary (MuMsg *msg, MuConfig *opts)
{
	const char *body;
	gboolean color;

	color = !opts->nocolor;
	body = mu_msg_get_body_text (msg,
				     mu_config_get_msg_options(opts) |
				     MU_MSG_OPTION_CONSOLE_PASSWORD);
	if (!body) {
		if (mu_msg_get_flags (msg) & MU_FLAG_ENCRYPTED) {
			color_maybe (MU_COLOR_CYAN);
			g_print ("[No body found; "
				 "message has encrypted parts]\n");
		} else {
			color_maybe (MU_COLOR_MAGENTA);
			g_print ("[No body found]\n");
		}
		color_maybe (MU_COLOR_DEFAULT);
		return;
	}

	if (opts->summary_len != 0) {
		gchar *summ;
		summ = mu_str_summarize (body, opts->summary_len);
		print_field ("Summary", summ, color);
		g_free (summ);
	} else {
		mu_util_print_encoded ("%s", body);
		if (!g_str_has_suffix (body, "\n"))
			g_print ("\n");
	}
}
Exemplo n.º 2
0
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;
}
Exemplo n.º 3
0
static gboolean
save_part_with_filename (MuMsg *msg, const char *pattern, MuConfig *opts)
{
	GSList *lst, *cur;
	GRegex *rx;
	gboolean rv;
	MuMsgOptions msgopts;

	msgopts = mu_config_get_msg_options (opts);

	/* 'anchor' the pattern with '^...$' if not already */
	rx = anchored_regex (pattern);
	if (!rx)
		return FALSE;

	lst = mu_msg_find_files (msg, msgopts, rx);
	g_regex_unref (rx);
	if (!lst) {
		g_warning ("no matching attachments found");
		return FALSE;
	}

	for (cur = lst, rv = TRUE; cur; cur = g_slist_next (cur))
		rv = rv && save_part (msg, opts->targetdir,
				      GPOINTER_TO_UINT(cur->data), opts);
	g_slist_free (lst);

	return rv;
}
Exemplo n.º 4
0
/* return comma-sep'd list of attachments */
static gchar *
get_attach_str (MuMsg *msg, MuConfig *opts)
{
	gchar *attach;

	attach = NULL;
	mu_msg_part_foreach (msg, mu_config_get_msg_options(opts),
			     (MuMsgPartForeachFunc)each_part, &attach);
	return attach;
}
Exemplo n.º 5
0
static gboolean
view_msg_sexp (MuMsg *msg, MuConfig *opts)
{
	char *sexp;

	sexp = mu_msg_to_sexp (msg, 0, NULL, mu_config_get_msg_options(opts));
	fputs (sexp, stdout);
	g_free (sexp);

	return TRUE;
}
Exemplo n.º 6
0
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;

}
Exemplo n.º 7
0
static void
print_summary (MuMsg *msg, MuConfig *opts)
{
	const char* body;
	char *summ;
	MuMsgOptions msgopts;

	msgopts = mu_config_get_msg_options (opts);
	body = mu_msg_get_body_text(msg, msgopts);

	if (body)
		summ = mu_str_summarize (body, (unsigned)opts->summary_len);
	else
		summ = NULL;

	g_print ("Summary: ");
	mu_util_fputs_encoded (summ ? summ : "<none>", stdout);
	g_print ("\n");

	g_free (summ);
}
Exemplo n.º 8
0
Arquivo: mu-cmd.c Projeto: jleechpe/mu
MuError
mu_cmd_verify (MuConfig *opts, GError **err)
{
	MuMsg *msg;
	MuMsgOptions msgopts;
	VData vdata;

	g_return_val_if_fail (opts, MU_ERROR_INTERNAL);
	g_return_val_if_fail (opts->cmd == MU_CONFIG_CMD_VERIFY,
			      MU_ERROR_INTERNAL);

	msg = mu_msg_new_from_file (opts->params[1], NULL, err);
	if (!msg)
		return MU_ERROR;

	msgopts = mu_config_get_msg_options (opts);

	vdata.status = MU_MSG_PART_SIG_STATUS_UNKNOWN;
	vdata.opts   = opts;
	vdata.msg    = NULL;

	/* TODO: update for decryption */
	mu_msg_part_foreach (msg, msgopts, (MuMsgPartForeachFunc)each_sig, &vdata);

	/* if there's anything bad, all goodness goes away */
	if (vdata.status & MU_MSG_PART_SIG_STATUS_BAD ||
	    vdata.status & MU_MSG_PART_SIG_STATUS_ERROR)
		vdata.status &= ~MU_MSG_PART_SIG_STATUS_GOOD;

	if (!opts->quiet) {
		gchar *str;
		str = mu_msg_part_sig_statuses_to_string (vdata.status);
		g_print ("verdict: %s\n", str);
		g_free (str);
	}

	mu_msg_unref (msg);

	return vdata.status == MU_MSG_PART_SIG_STATUS_GOOD ? MU_OK : MU_ERROR;
}
Exemplo n.º 9
0
MuError
mu_cmd_verify (MuConfig *opts, GError **err)
{
	MuMsg *msg;
	MuMsgOptions msgopts;
	VData vdata;

	g_return_val_if_fail (opts, MU_ERROR_INTERNAL);
	g_return_val_if_fail (opts->cmd == MU_CONFIG_CMD_VERIFY,
			      MU_ERROR_INTERNAL);

	if (!opts->params[1]) {
		mu_util_g_set_error (err, MU_ERROR_IN_PARAMETERS,
				     "missing message-file parameter");
		return MU_ERROR_IN_PARAMETERS;
	}

	msg = mu_msg_new_from_file (opts->params[1], NULL, err);
	if (!msg)
		return MU_ERROR;

	msgopts = mu_config_get_msg_options (opts) | MU_MSG_OPTION_VERIFY;

	vdata.report  = NULL;
	vdata.combined_status = MU_MSG_PART_SIG_STATUS_UNSIGNED;
	vdata.oneline = FALSE;

	mu_msg_part_foreach (msg, msgopts,
			     (MuMsgPartForeachFunc)each_sig, &vdata);

	if (!opts->quiet)
		print_verdict (&vdata, !opts->nocolor);

	mu_msg_unref (msg);
	g_free (vdata.report);

	return vdata.combined_status == MU_MSG_PART_SIG_STATUS_GOOD ?
		MU_OK : MU_ERROR;
}
Exemplo n.º 10
0
static gboolean
save_certain_parts (MuMsg *msg, MuConfig *opts)
{
	SaveData sd;
	MuMsgOptions msgopts;

	sd.result	    = TRUE;
	sd.saved_num        = 0;
	sd.opts             = opts;

	msgopts = mu_config_get_msg_options (opts);
	mu_msg_part_foreach (msg, msgopts,
			     (MuMsgPartForeachFunc)save_part_if, &sd);

	if (sd.saved_num == 0) {
		g_warning ("no %s extracted from this message",
			   opts->save_attachments ? "attachments" : "parts");
		sd.result = FALSE;
	}

	return sd.result;
}
Exemplo n.º 11
0
Arquivo: mu-cmd.c Projeto: jleechpe/mu
/* a summary_len of 0 mean 'don't show summary, show body */
static void
body_or_summary (MuMsg *msg, MuConfig *opts)
{
	const char *body;
	gboolean color;

	color = !opts->nocolor;
	body = mu_msg_get_body_text (msg,
				     mu_config_get_msg_options(opts));
	if (!body)
		return;

	if (opts->summary_len != 0) {
		gchar *summ;
		summ = mu_str_summarize (body, opts->summary_len);
		print_field ("Summary", summ, color);
		g_free (summ);
	} else {
		color_maybe (MU_COLOR_YELLOW);
		mu_util_print_encoded ("\n%s\n", body);
		color_maybe (MU_COLOR_DEFAULT);
	}
}
Exemplo n.º 12
0
static gboolean
show_parts (const char* path, MuConfig *opts, GError **err)
{
	MuMsg *msg;
	MuMsgOptions msgopts;

	msg = mu_msg_new_from_file (path, NULL, err);
	if (!msg)
		return FALSE;

	msgopts = mu_config_get_msg_options (opts);

	/* TODO: update this for crypto */
	g_print ("MIME-parts in this message:\n");
	mu_msg_part_foreach
		(msg, msgopts,
		 (MuMsgPartForeachFunc)each_part_show,
		 GUINT_TO_POINTER(!opts->nocolor));

	mu_msg_unref (msg);

	return TRUE;

}