Пример #1
0
static void
add_row (GtkListStore * store, MuMsg *msg)
{
	GtkTreeIter treeiter;
	const gchar *datestr, *flagstr;
	gchar *from, *to;
	time_t timeval;

	timeval = mu_msg_get_date (msg);
	datestr = timeval == 0 ? "-" : mu_date_display_s (timeval);
	from = empty_or_display_contact (mu_msg_get_from (msg));
	to = empty_or_display_contact (mu_msg_get_to (msg));
	flagstr = mu_flags_to_str_s (mu_msg_get_flags (msg), MU_FLAG_TYPE_ANY);

	gtk_list_store_append (store, &treeiter);
	gtk_list_store_set (store, &treeiter,
			    MUG_COL_DATESTR, datestr,
			    MUG_COL_MAILDIR, mu_msg_get_maildir (msg),
			    MUG_COL_FLAGSSTR, flagstr,
			    MUG_COL_FROM, from,
			    MUG_COL_TO, to,
			    MUG_COL_SUBJECT, mu_msg_get_subject (msg),
			    MUG_COL_PATH, mu_msg_get_path (msg),
			    MUG_COL_PRIO, mu_msg_get_prio (msg),
			    MUG_COL_FLAGS, mu_msg_get_flags (msg),
			    MUG_COL_TIME, timeval, -1);
	g_free (from);
	g_free (to);
}
Пример #2
0
static void
add_row (GtkTreeStore * store, MuMsg *msg, GtkTreeIter *treeiter)
{
	const gchar *datestr, *flagstr;
	gchar *from, *to;
	time_t timeval;

	timeval = mu_msg_get_date (msg);
	datestr = timeval == 0 ? "-" : mu_date_display_s (timeval);
	from = empty_or_display_contact (mu_msg_get_from (msg));
	to = empty_or_display_contact (mu_msg_get_to (msg));
	flagstr = mu_flags_to_str_s (mu_msg_get_flags (msg), MU_FLAG_TYPE_ANY);

 	/* if (0) { */
	/* 	GtkTreeIter myiter; */
	/* 	if (!gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL(store), */
	/* 						  &myiter, path)) */
	/* 		g_warning ("%s: cannot get iter for %s",
	 * 		__FUNCTION__, path); */
	/* } */

	gtk_tree_store_set (store, treeiter,
			    MUG_COL_DATESTR, datestr,
			    MUG_COL_MAILDIR, mu_msg_get_maildir (msg),
			    MUG_COL_FLAGSSTR, flagstr,
			    MUG_COL_FROM, from,
			    MUG_COL_TO, to,
			    MUG_COL_SUBJECT, mu_msg_get_subject (msg),
			    MUG_COL_PATH, mu_msg_get_path (msg),
			    MUG_COL_PRIO, mu_msg_get_prio (msg),
			    MUG_COL_FLAGS, mu_msg_get_flags (msg),
			    MUG_COL_TIME, timeval, -1);
	g_free (from);
	g_free (to);
}
Пример #3
0
static MuError
move_msgid (MuStore *store, unsigned docid, const char* flagstr, GError **err)
{
	MuMsg *msg;
	MuError rv;
	MuFlags flags;

	rv  = MU_ERROR;
	msg = mu_store_get_msg (store, docid, err);

	if (!msg)
		goto leave;

	flags = flagstr ? get_flags (mu_msg_get_path(msg), flagstr) :
		mu_msg_get_flags (msg);
	if (flags == MU_FLAG_INVALID) {
		mu_util_g_set_error (err, MU_ERROR_IN_PARAMETERS,
				     "invalid flags");
		goto leave;
	}

	rv = do_move (store, docid, msg, NULL, flags, err);

leave:
	if (msg)
		mu_msg_unref (msg);
	if (rv != MU_OK)
		print_and_clear_g_error (err);

	return rv;
}
Пример #4
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");
	}
}
Пример #5
0
static SCM
get_flags_scm (MuMsg *msg)
{
	FlagData fdata;

	fdata.flags = mu_msg_get_flags (msg);
	fdata.lst   = SCM_EOL;

	mu_flags_foreach ((MuFlagsForeachFunc)check_flag, &fdata);

	return fdata.lst;
}
Пример #6
0
/*
 * 'move' moves a message to a different maildir and/or changes its
 * flags. parameters are *either* a 'docid:' or 'msgid:' pointing to
 * the message, a 'maildir:' for the target maildir, and a 'flags:'
 * parameter for the new flags.
 *
 * returns an (:update <new-msg-sexp>)
 *
 */
static MuError
cmd_move (ServerContext *ctx, GHashTable *args, GError **err)
{
	unsigned docid;
	MuMsg *msg;
	MuFlags flags;
	const char *maildir, *flagstr;
	gboolean new_name;

	/* check if the move is based on the message id; if so, handle
	 * it in move_msgid_maybe */
	if (move_msgid_maybe (ctx, args, err))
		return MU_OK;

	maildir	 = get_string_from_args (args, "maildir", TRUE, err);
	flagstr	 = get_string_from_args (args, "flags", TRUE, err);
	new_name = get_bool_from_args (args, "newname", TRUE, err);

	docid = determine_docid (ctx->query, args, err);
	if (docid == MU_STORE_INVALID_DOCID ||
	    !(msg = mu_store_get_msg (ctx->store, docid, err))) {
		print_and_clear_g_error (err);
		return MU_OK;
	}

	/* if maildir was not specified, take the current one */
	if (!maildir)
		maildir = mu_msg_get_maildir (msg);

	/* determine the real target flags, which come from the
	 * flags-parameter we received (ie., flagstr), if any, plus
	 * the existing message flags. */
	if (flagstr)
		flags = get_flags (mu_msg_get_path(msg), flagstr);
	else
		flags = mu_msg_get_flags (msg);

	if (flags == MU_FLAG_INVALID) {
		print_error (MU_ERROR_IN_PARAMETERS, "invalid flags");
		goto leave;
	}

	if ((do_move (ctx->store, docid, msg, maildir, flags, new_name, err)
	     != MU_OK))
		print_and_clear_g_error (err);

leave:
	mu_msg_unref (msg);
	return MU_OK;
}
Пример #7
0
static void
add_flags (JsonBuilder *bob, MuMsg *msg)
{
	FlagData fdata;

	fdata.msgflags = mu_msg_get_flags (msg);
	fdata.bob      = bob;

	bob = json_builder_set_member_name (bob, "flags");

	bob = json_builder_begin_array (bob);
	mu_flags_foreach ((MuFlagsForeachFunc)each_flag, &fdata);
	bob = json_builder_end_array (bob);

}
Пример #8
0
static void
json_add_flags(JsonBuilder *builder, MuMsg *msg)
{
        MuFlags flags;
        const char *flags_str;

        flags = mu_msg_get_flags (msg);

        if (flags) {
                flags_str = mu_flags_to_str_s (flags, (MuFlagType)MU_FLAG_TYPE_ANY);
                if (flags_str) {
                json_builder_set_member_name (builder, "flags");
                json_builder_add_string_value (builder, flags_str);
        }
  }
}
Пример #9
0
static gboolean
output_xml (MuMsg *msg, MuMsgIter *iter, MuConfig *opts, GError **err)
{
        g_print ("\t<message>\n");
        print_attr_xml ("from", mu_msg_get_from (msg));
        print_attr_xml ("to", mu_msg_get_to (msg));
        print_attr_xml ("cc", mu_msg_get_cc (msg));
        print_attr_xml ("subject", mu_msg_get_subject (msg));
        g_print ("\t\t<date>%u</date>\n", (unsigned)mu_msg_get_date (msg));
        g_print ("\t\t<size>%u</size>\n", (unsigned)mu_msg_get_size (msg));
        print_attr_xml ("msgid", mu_msg_get_msgid (msg));
        print_attr_xml ("path", mu_msg_get_path (msg));
        print_attr_xml ("maildir", mu_msg_get_maildir (msg));
        print_attr_xml ("flags", mu_flags_to_str_s (mu_msg_get_flags (msg), (MuFlagType)MU_FLAG_TYPE_ANY));

        g_print ("\t</message>\n");

        return TRUE;
}
Пример #10
0
Файл: mu-msg.c Проект: bonega/mu
/*
 * move a msg to another maildir, trying to maintain 'integrity',
 * ie. msg in 'new/' will go to new/, one in cur/ goes to cur/. be
 * super-paranoid here...
 */
gboolean
mu_msg_move_to_maildir (MuMsg *self, const char *maildir,
			MuFlags flags, gboolean ignore_dups, GError **err)
{
	char *newfullpath;
	char *targetmdir;

	g_return_val_if_fail (self, FALSE);
	g_return_val_if_fail (maildir, FALSE);     /* i.e. "/inbox" */

	targetmdir = get_target_mdir (self, maildir, err);
	if (!targetmdir)
		return FALSE;

	newfullpath = mu_maildir_move_message (mu_msg_get_path (self),
					       targetmdir, flags,
					       ignore_dups, err);
	g_free (targetmdir);

	/* update the message path and the flags; they may have
	 * changed */
	if (newfullpath) {
		mu_msg_cache_set_str (self->_cache, MU_MSG_FIELD_ID_PATH, newfullpath,
				      TRUE); /* the cache will free the string */
		mu_msg_cache_set_str (self->_cache, MU_MSG_FIELD_ID_MAILDIR,
				      g_strdup(maildir), TRUE);
		/* the cache will free the string */

		/* the contentflags haven't changed, so make sure they persist */
		flags |= mu_msg_get_flags (self) &
			(MU_FLAG_HAS_ATTACH|MU_FLAG_ENCRYPTED|MU_FLAG_SIGNED);
		/* update the pseudo-flag as well */
		if (!(flags & MU_FLAG_NEW) && (flags & MU_FLAG_SEEN))
			flags &= ~MU_FLAG_UNREAD;
		else
			flags |= MU_FLAG_UNREAD;

		mu_msg_cache_set_num (self->_cache, MU_MSG_FIELD_ID_FLAGS, flags);
	}

	return newfullpath ? TRUE : FALSE;
}