mirror of https://github.com/djcb/mu.git
* mu-msg-sexp: expand, more clearly separate 'full' and 'header' messages
This commit is contained in:
parent
9fb2289252
commit
9f6b3b4035
|
@ -28,10 +28,10 @@ static void
|
|||
append_sexp_attr_list (GString *gstr, const char* elm, const GSList *lst)
|
||||
{
|
||||
const GSList *cur;
|
||||
|
||||
|
||||
if (!lst)
|
||||
return; /* empty list, don't include */
|
||||
|
||||
|
||||
g_string_append_printf (gstr, "\t:%s ( ", elm);
|
||||
|
||||
for (cur = lst; cur; cur = g_slist_next(cur)) {
|
||||
|
@ -42,7 +42,7 @@ append_sexp_attr_list (GString *gstr, const char* elm, const GSList *lst)
|
|||
g_free (str);
|
||||
}
|
||||
|
||||
g_string_append (gstr, ")\n");
|
||||
g_string_append (gstr, ")\n");
|
||||
}
|
||||
|
||||
|
||||
|
@ -50,12 +50,12 @@ static void
|
|||
append_sexp_attr (GString *gstr, const char* elm, const char *str)
|
||||
{
|
||||
gchar *esc;
|
||||
|
||||
|
||||
if (!str || strlen(str) == 0)
|
||||
return; /* empty: don't include */
|
||||
|
||||
esc = mu_str_escape_c_literal (str, TRUE);
|
||||
|
||||
|
||||
g_string_append_printf (gstr, "\t:%s %s\n", elm, esc);
|
||||
g_free (esc);
|
||||
}
|
||||
|
@ -65,12 +65,12 @@ struct _ContactData {
|
|||
gboolean from, to, cc, bcc;
|
||||
GString *gstr;
|
||||
MuMsgContactType prev_ctype;
|
||||
};
|
||||
};
|
||||
typedef struct _ContactData ContactData;
|
||||
|
||||
static gchar*
|
||||
get_name_addr_pair (MuMsgContact *c)
|
||||
{
|
||||
{
|
||||
gchar *name, *addr, *pair;
|
||||
|
||||
name = (char*)mu_msg_contact_name(c);
|
||||
|
@ -103,7 +103,7 @@ each_contact (MuMsgContact *c, ContactData *cdata)
|
|||
{
|
||||
char *pair;
|
||||
MuMsgContactType ctype;
|
||||
|
||||
|
||||
ctype = mu_msg_contact_type (c);
|
||||
|
||||
/* if the current type is not the previous type, close the
|
||||
|
@ -112,11 +112,11 @@ each_contact (MuMsgContact *c, ContactData *cdata)
|
|||
g_string_append (cdata->gstr, ")\n");
|
||||
|
||||
switch (ctype) {
|
||||
|
||||
|
||||
case MU_MSG_CONTACT_TYPE_FROM:
|
||||
add_prefix_maybe (cdata->gstr, &cdata->from, "\t:from (");
|
||||
break;
|
||||
|
||||
|
||||
case MU_MSG_CONTACT_TYPE_TO:
|
||||
add_prefix_maybe (cdata->gstr, &cdata->to, "\t:to (");
|
||||
break;
|
||||
|
@ -128,16 +128,16 @@ each_contact (MuMsgContact *c, ContactData *cdata)
|
|||
case MU_MSG_CONTACT_TYPE_BCC:
|
||||
add_prefix_maybe (cdata->gstr, &cdata->bcc, "\t:bcc (");
|
||||
break;
|
||||
|
||||
|
||||
default: g_return_val_if_reached (FALSE);
|
||||
}
|
||||
|
||||
|
||||
cdata->prev_ctype = ctype;
|
||||
|
||||
|
||||
pair = get_name_addr_pair (c);
|
||||
g_string_append (cdata->gstr, pair);
|
||||
g_free (pair);
|
||||
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -145,12 +145,15 @@ each_contact (MuMsgContact *c, ContactData *cdata)
|
|||
static void
|
||||
append_sexp_contacts (GString *gstr, MuMsg *msg)
|
||||
{
|
||||
ContactData cdata = { FALSE, FALSE, FALSE, FALSE, gstr,
|
||||
(unsigned)-1};
|
||||
|
||||
ContactData cdata;
|
||||
|
||||
cdata.from = cdata.to = cdata.cc = cdata.bcc = FALSE;
|
||||
cdata.gstr = gstr;
|
||||
cdata.prev_ctype = (unsigned)-1;
|
||||
|
||||
mu_msg_contact_foreach (msg, (MuMsgContactForeachFunc)each_contact,
|
||||
&cdata);
|
||||
|
||||
|
||||
if (cdata.from || cdata.to || cdata.cc || cdata.bcc)
|
||||
gstr = g_string_append (gstr, ")\n");
|
||||
}
|
||||
|
@ -182,12 +185,12 @@ static void
|
|||
append_sexp_flags (GString *gstr, MuMsg *msg)
|
||||
{
|
||||
FlagData fdata;
|
||||
|
||||
|
||||
fdata.msgflags = mu_msg_get_flags (msg);
|
||||
fdata.flagstr = NULL;
|
||||
|
||||
|
||||
mu_flags_foreach ((MuFlagsForeachFunc)each_flag, &fdata);
|
||||
if (fdata.flagstr)
|
||||
if (fdata.flagstr)
|
||||
g_string_append_printf (gstr, "\t:flags (%s)\n",
|
||||
fdata.flagstr);
|
||||
g_free (fdata.flagstr);
|
||||
|
@ -197,7 +200,7 @@ static void
|
|||
each_part (MuMsg *msg, MuMsgPart *part, gchar **parts)
|
||||
{
|
||||
const char *fname;
|
||||
|
||||
|
||||
fname = mu_msg_part_file_name (part);
|
||||
if (fname) {
|
||||
char *esc;
|
||||
|
@ -232,15 +235,14 @@ static void
|
|||
append_sexp_message_file_attr (GString *gstr, MuMsg *msg)
|
||||
{
|
||||
append_sexp_attachments (gstr, msg);
|
||||
|
||||
|
||||
append_sexp_attr (gstr, "reply-to",
|
||||
mu_msg_get_header (msg, "Reply-To"));
|
||||
append_sexp_attr_list (gstr, "references", mu_msg_get_references (msg));
|
||||
append_sexp_attr (gstr, "in-reply-to",
|
||||
mu_msg_get_header (msg, "In-Reply-To"));
|
||||
|
||||
append_sexp_attr (gstr, "body-txt",
|
||||
mu_msg_get_body_text(msg));
|
||||
mu_msg_get_body_text(msg));
|
||||
append_sexp_attr (gstr, "body-html",
|
||||
mu_msg_get_body_html(msg));
|
||||
}
|
||||
|
@ -260,25 +262,29 @@ append_sexp_thread_info (GString *gstr, const MuMsgIterThreadInfo *ti)
|
|||
|
||||
|
||||
char*
|
||||
mu_msg_to_sexp (MuMsg *msg, const MuMsgIterThreadInfo *ti, gboolean dbonly)
|
||||
mu_msg_to_sexp (MuMsg *msg, unsigned docid, const MuMsgIterThreadInfo *ti,
|
||||
gboolean headers)
|
||||
{
|
||||
GString *gstr;
|
||||
time_t t;
|
||||
|
||||
gstr = g_string_sized_new (dbonly ? 1024 : 8192);
|
||||
gstr = g_string_sized_new (headers ? 1024 : 8192);
|
||||
g_string_append (gstr, "(\n");
|
||||
|
||||
|
||||
if (docid != 0)
|
||||
g_string_append_printf (gstr, "\t:docid %u\n", docid);
|
||||
|
||||
append_sexp_contacts (gstr, msg);
|
||||
|
||||
|
||||
if (ti)
|
||||
append_sexp_thread_info (gstr, ti);
|
||||
|
||||
|
||||
append_sexp_attr (gstr,
|
||||
"subject", mu_msg_get_subject (msg));
|
||||
|
||||
|
||||
t = mu_msg_get_date (msg);
|
||||
/* weird time format for emacs 29-bit ints...*/
|
||||
g_string_append_printf (gstr,
|
||||
g_string_append_printf (gstr,
|
||||
"\t:date (%u %u 0)\n", (unsigned)(t >> 16),
|
||||
(unsigned)(t & 0xffff));
|
||||
g_string_append_printf (gstr, "\t:size %u\n",
|
||||
|
@ -286,20 +292,28 @@ mu_msg_to_sexp (MuMsg *msg, const MuMsgIterThreadInfo *ti, gboolean dbonly)
|
|||
append_sexp_attr (gstr, "message-id", mu_msg_get_msgid (msg));
|
||||
append_sexp_attr (gstr, "path", mu_msg_get_path (msg));
|
||||
append_sexp_attr (gstr, "maildir", mu_msg_get_maildir (msg));
|
||||
|
||||
|
||||
g_string_append_printf (gstr, "\t:priority %s\n",
|
||||
mu_msg_prio_name(mu_msg_get_prio(msg)));
|
||||
|
||||
|
||||
append_sexp_flags (gstr, msg);
|
||||
|
||||
/* file attr things can only be gotten from the file (ie., mu
|
||||
* view), not from the database (mu find) */
|
||||
if (!dbonly)
|
||||
|
||||
/* headers are retrieved from the database, views from the message file
|
||||
*
|
||||
* file attr things can only be gotten from the file (ie., mu
|
||||
* view), not from the database (mu find). */
|
||||
if (!headers)
|
||||
append_sexp_message_file_attr (gstr, msg);
|
||||
|
||||
g_string_append (gstr, ")\n;;eox\n");
|
||||
|
||||
/* we register whether this a db-only msg or not; this is
|
||||
* useful in the UI to know whether this should be considered
|
||||
* merely a header or a full message */
|
||||
g_string_append_printf (gstr, "\t:msgtype %s\n",
|
||||
headers ? "header" : "view");
|
||||
|
||||
g_string_append (gstr, ")\n;;eox\n");
|
||||
|
||||
return g_string_free (gstr, FALSE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue