Example #1
0
static gboolean
save_certain_parts (MuMsg *msg, gboolean attachments_only,
		    const gchar *targetdir, gboolean overwrite, gboolean play)
{
	SaveData sd;

	sd.result	    = TRUE;
	sd.saved_num        = 0;
	sd.attachments_only = attachments_only;
	sd.overwrite	    = overwrite;
	sd.targetdir	    = targetdir;
	sd.play             = play;

	mu_msg_part_foreach (msg, FALSE,
			     (MuMsgPartForeachFunc)save_part_if,
			     &sd);

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

	return sd.result;
}
Example #2
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;
}
Example #3
0
File: mu-cmd.c Project: jleechpe/mu
/* return comma-sep'd list of attachments */
static gchar *
get_attach_str (MuMsg *msg)
{
	gchar *attach;

	attach = NULL;
	mu_msg_part_foreach (msg, MU_MSG_OPTION_NONE,
			     (MuMsgPartForeachFunc)each_part, &attach);
	return attach;
}
Example #4
0
static void
add_parts (JsonBuilder *bob, MuMsg *msg, MuMsgOptions opts)
{
	PartInfo pinfo;

	pinfo.opts = opts;
	bob	   = json_builder_set_member_name (bob, "parts");
	bob	   = json_builder_begin_array (bob);

	mu_msg_part_foreach (msg, opts, (MuMsgPartForeachFunc)each_part, &pinfo);

	bob = json_builder_end_array (bob);
}
Example #5
0
static GMimeObject*
get_mime_object_at_index (MuMsg *msg, MuMsgOptions opts, unsigned index)
{
	DoData ddata;

	ddata.mime_obj  = NULL;
	ddata.index     = index;

	mu_msg_part_foreach (msg, opts,
			     (MuMsgPartForeachFunc)do_it_with_index,
			     &ddata);

	return ddata.mime_obj;
}
Example #6
0
int
get_matching_part_index (MuMsg *msg, MuMsgOptions opts,
			 MuMsgPartMatchFunc func, gpointer user_data)
{
	MatchData mdata;

	mdata.match_func = func;
	mdata.user_data  = user_data;
	mdata.index      = -1;

	mu_msg_part_foreach (msg, opts,
			     (MuMsgPartForeachFunc)check_match,
			     &mdata);
	return mdata.index;
}
Example #7
0
File: mu-msg.c Project: akonring/mu
static char*
get_body (MuMsg *self, MuMsgOptions opts, gboolean want_html)
{
	BodyData bdata;

	bdata.want_html = want_html;
	bdata.gstr	= g_string_sized_new (4096);

	mu_msg_part_foreach (self, opts,
			     (MuMsgPartForeachFunc)accumulate_body,
			     &bdata);

	if (bdata.gstr->len == 0) {
		g_string_free (bdata.gstr, TRUE);
		return NULL;
	} else
		return g_string_free (bdata.gstr, FALSE);
}
Example #8
0
GSList*
mu_msg_find_files (MuMsg *msg, MuMsgOptions opts, const GRegex *pattern)
{
	RxMatchData mdata;

	g_return_val_if_fail (msg, NULL);
	g_return_val_if_fail (pattern, NULL);

	if (!mu_msg_load_msg_file (msg, NULL))
		return NULL;

	mdata._lst = NULL;
	mdata._rx  = pattern;
	mdata._idx = 0;

	mu_msg_part_foreach (msg, opts,
			     (MuMsgPartForeachFunc)match_filename_rx,
			     &mdata);
	return mdata._lst;
}
Example #9
0
static gboolean
show_parts (const char* path, MuConfig *opts, GError **err)
{
	MuMsg* msg;

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

	g_print ("MIME-parts in this message:\n");

	mu_msg_part_foreach
		(msg, FALSE, (MuMsgPartForeachFunc)each_part_show,
		 GUINT_TO_POINTER(!opts->nocolor));

	mu_msg_unref (msg);

	return TRUE;

}
Example #10
0
/* take the attachments of msg, save them as tmp files, and return
 * as sexp (as a string) describing them
 *
 * ((:name <filename> :mime-type <mime-type> :disposition
 *   <attachment|inline>) ... )
 *
 */
static gchar*
include_attachments (MuMsg *msg)
{
	GSList *attlist, *cur;
	GString *gstr;

	attlist = NULL;
	mu_msg_part_foreach (msg, MU_MSG_OPTION_NONE,
			     (MuMsgPartForeachFunc)each_part,
			     &attlist);

	gstr = g_string_sized_new (512);
	gstr = g_string_append_c (gstr, '(');
	for (cur = attlist; cur; cur = g_slist_next (cur))
		g_string_append (gstr, (gchar*)cur->data);
	gstr = g_string_append_c (gstr, ')');

	mu_str_free_list (attlist);

	return g_string_free (gstr, FALSE);
}
Example #11
0
File: mu-cmd.c Project: 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;
}
Example #12
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;
}
Example #13
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;
}
Example #14
0
/* take the attachments of msg, save them as tmp files, and return
 * as sexp (as a string) describing them
 *
 * ((:name <filename> :mime-type <mime-type> :disposition
 *   <attachment|inline>) ... )
 *
 */
static gchar*
include_attachments (MuMsg *msg, MuMsgOptions opts)
{
	GSList  *cur;
	GString *gstr;
	PartInfo pinfo;

	pinfo.attlist = NULL;
	pinfo.opts    = opts;
	mu_msg_part_foreach (msg, opts,
			     (MuMsgPartForeachFunc)each_part,
			     &pinfo);

	gstr = g_string_sized_new (512);
	gstr = g_string_append_c (gstr, '(');
	for (cur = pinfo.attlist; cur; cur = g_slist_next (cur))
		g_string_append (gstr, (gchar*)cur->data);
	gstr = g_string_append_c (gstr, ')');

	mu_str_free_list (pinfo.attlist);

	return g_string_free (gstr, FALSE);
}
Example #15
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;

}