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)
|
append_sexp_attr_list (GString *gstr, const char* elm, const GSList *lst)
|
||||||
{
|
{
|
||||||
const GSList *cur;
|
const GSList *cur;
|
||||||
|
|
||||||
if (!lst)
|
if (!lst)
|
||||||
return; /* empty list, don't include */
|
return; /* empty list, don't include */
|
||||||
|
|
||||||
g_string_append_printf (gstr, "\t:%s ( ", elm);
|
g_string_append_printf (gstr, "\t:%s ( ", elm);
|
||||||
|
|
||||||
for (cur = lst; cur; cur = g_slist_next(cur)) {
|
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_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)
|
append_sexp_attr (GString *gstr, const char* elm, const char *str)
|
||||||
{
|
{
|
||||||
gchar *esc;
|
gchar *esc;
|
||||||
|
|
||||||
if (!str || strlen(str) == 0)
|
if (!str || strlen(str) == 0)
|
||||||
return; /* empty: don't include */
|
return; /* empty: don't include */
|
||||||
|
|
||||||
esc = mu_str_escape_c_literal (str, TRUE);
|
esc = mu_str_escape_c_literal (str, TRUE);
|
||||||
|
|
||||||
g_string_append_printf (gstr, "\t:%s %s\n", elm, esc);
|
g_string_append_printf (gstr, "\t:%s %s\n", elm, esc);
|
||||||
g_free (esc);
|
g_free (esc);
|
||||||
}
|
}
|
||||||
|
@ -65,12 +65,12 @@ struct _ContactData {
|
||||||
gboolean from, to, cc, bcc;
|
gboolean from, to, cc, bcc;
|
||||||
GString *gstr;
|
GString *gstr;
|
||||||
MuMsgContactType prev_ctype;
|
MuMsgContactType prev_ctype;
|
||||||
};
|
};
|
||||||
typedef struct _ContactData ContactData;
|
typedef struct _ContactData ContactData;
|
||||||
|
|
||||||
static gchar*
|
static gchar*
|
||||||
get_name_addr_pair (MuMsgContact *c)
|
get_name_addr_pair (MuMsgContact *c)
|
||||||
{
|
{
|
||||||
gchar *name, *addr, *pair;
|
gchar *name, *addr, *pair;
|
||||||
|
|
||||||
name = (char*)mu_msg_contact_name(c);
|
name = (char*)mu_msg_contact_name(c);
|
||||||
|
@ -103,7 +103,7 @@ each_contact (MuMsgContact *c, ContactData *cdata)
|
||||||
{
|
{
|
||||||
char *pair;
|
char *pair;
|
||||||
MuMsgContactType ctype;
|
MuMsgContactType ctype;
|
||||||
|
|
||||||
ctype = mu_msg_contact_type (c);
|
ctype = mu_msg_contact_type (c);
|
||||||
|
|
||||||
/* if the current type is not the previous type, close the
|
/* 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");
|
g_string_append (cdata->gstr, ")\n");
|
||||||
|
|
||||||
switch (ctype) {
|
switch (ctype) {
|
||||||
|
|
||||||
case MU_MSG_CONTACT_TYPE_FROM:
|
case MU_MSG_CONTACT_TYPE_FROM:
|
||||||
add_prefix_maybe (cdata->gstr, &cdata->from, "\t:from (");
|
add_prefix_maybe (cdata->gstr, &cdata->from, "\t:from (");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MU_MSG_CONTACT_TYPE_TO:
|
case MU_MSG_CONTACT_TYPE_TO:
|
||||||
add_prefix_maybe (cdata->gstr, &cdata->to, "\t:to (");
|
add_prefix_maybe (cdata->gstr, &cdata->to, "\t:to (");
|
||||||
break;
|
break;
|
||||||
|
@ -128,16 +128,16 @@ each_contact (MuMsgContact *c, ContactData *cdata)
|
||||||
case MU_MSG_CONTACT_TYPE_BCC:
|
case MU_MSG_CONTACT_TYPE_BCC:
|
||||||
add_prefix_maybe (cdata->gstr, &cdata->bcc, "\t:bcc (");
|
add_prefix_maybe (cdata->gstr, &cdata->bcc, "\t:bcc (");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default: g_return_val_if_reached (FALSE);
|
default: g_return_val_if_reached (FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
cdata->prev_ctype = ctype;
|
cdata->prev_ctype = ctype;
|
||||||
|
|
||||||
pair = get_name_addr_pair (c);
|
pair = get_name_addr_pair (c);
|
||||||
g_string_append (cdata->gstr, pair);
|
g_string_append (cdata->gstr, pair);
|
||||||
g_free (pair);
|
g_free (pair);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,12 +145,15 @@ each_contact (MuMsgContact *c, ContactData *cdata)
|
||||||
static void
|
static void
|
||||||
append_sexp_contacts (GString *gstr, MuMsg *msg)
|
append_sexp_contacts (GString *gstr, MuMsg *msg)
|
||||||
{
|
{
|
||||||
ContactData cdata = { FALSE, FALSE, FALSE, FALSE, gstr,
|
ContactData cdata;
|
||||||
(unsigned)-1};
|
|
||||||
|
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,
|
mu_msg_contact_foreach (msg, (MuMsgContactForeachFunc)each_contact,
|
||||||
&cdata);
|
&cdata);
|
||||||
|
|
||||||
if (cdata.from || cdata.to || cdata.cc || cdata.bcc)
|
if (cdata.from || cdata.to || cdata.cc || cdata.bcc)
|
||||||
gstr = g_string_append (gstr, ")\n");
|
gstr = g_string_append (gstr, ")\n");
|
||||||
}
|
}
|
||||||
|
@ -182,12 +185,12 @@ static void
|
||||||
append_sexp_flags (GString *gstr, MuMsg *msg)
|
append_sexp_flags (GString *gstr, MuMsg *msg)
|
||||||
{
|
{
|
||||||
FlagData fdata;
|
FlagData fdata;
|
||||||
|
|
||||||
fdata.msgflags = mu_msg_get_flags (msg);
|
fdata.msgflags = mu_msg_get_flags (msg);
|
||||||
fdata.flagstr = NULL;
|
fdata.flagstr = NULL;
|
||||||
|
|
||||||
mu_flags_foreach ((MuFlagsForeachFunc)each_flag, &fdata);
|
mu_flags_foreach ((MuFlagsForeachFunc)each_flag, &fdata);
|
||||||
if (fdata.flagstr)
|
if (fdata.flagstr)
|
||||||
g_string_append_printf (gstr, "\t:flags (%s)\n",
|
g_string_append_printf (gstr, "\t:flags (%s)\n",
|
||||||
fdata.flagstr);
|
fdata.flagstr);
|
||||||
g_free (fdata.flagstr);
|
g_free (fdata.flagstr);
|
||||||
|
@ -197,7 +200,7 @@ static void
|
||||||
each_part (MuMsg *msg, MuMsgPart *part, gchar **parts)
|
each_part (MuMsg *msg, MuMsgPart *part, gchar **parts)
|
||||||
{
|
{
|
||||||
const char *fname;
|
const char *fname;
|
||||||
|
|
||||||
fname = mu_msg_part_file_name (part);
|
fname = mu_msg_part_file_name (part);
|
||||||
if (fname) {
|
if (fname) {
|
||||||
char *esc;
|
char *esc;
|
||||||
|
@ -232,15 +235,14 @@ static void
|
||||||
append_sexp_message_file_attr (GString *gstr, MuMsg *msg)
|
append_sexp_message_file_attr (GString *gstr, MuMsg *msg)
|
||||||
{
|
{
|
||||||
append_sexp_attachments (gstr, msg);
|
append_sexp_attachments (gstr, msg);
|
||||||
|
|
||||||
append_sexp_attr (gstr, "reply-to",
|
append_sexp_attr (gstr, "reply-to",
|
||||||
mu_msg_get_header (msg, "Reply-To"));
|
mu_msg_get_header (msg, "Reply-To"));
|
||||||
append_sexp_attr_list (gstr, "references", mu_msg_get_references (msg));
|
append_sexp_attr_list (gstr, "references", mu_msg_get_references (msg));
|
||||||
append_sexp_attr (gstr, "in-reply-to",
|
append_sexp_attr (gstr, "in-reply-to",
|
||||||
mu_msg_get_header (msg, "In-Reply-To"));
|
mu_msg_get_header (msg, "In-Reply-To"));
|
||||||
|
|
||||||
append_sexp_attr (gstr, "body-txt",
|
append_sexp_attr (gstr, "body-txt",
|
||||||
mu_msg_get_body_text(msg));
|
mu_msg_get_body_text(msg));
|
||||||
append_sexp_attr (gstr, "body-html",
|
append_sexp_attr (gstr, "body-html",
|
||||||
mu_msg_get_body_html(msg));
|
mu_msg_get_body_html(msg));
|
||||||
}
|
}
|
||||||
|
@ -260,25 +262,29 @@ append_sexp_thread_info (GString *gstr, const MuMsgIterThreadInfo *ti)
|
||||||
|
|
||||||
|
|
||||||
char*
|
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;
|
GString *gstr;
|
||||||
time_t t;
|
time_t t;
|
||||||
|
|
||||||
gstr = g_string_sized_new (dbonly ? 1024 : 8192);
|
gstr = g_string_sized_new (headers ? 1024 : 8192);
|
||||||
g_string_append (gstr, "(\n");
|
g_string_append (gstr, "(\n");
|
||||||
|
|
||||||
|
if (docid != 0)
|
||||||
|
g_string_append_printf (gstr, "\t:docid %u\n", docid);
|
||||||
|
|
||||||
append_sexp_contacts (gstr, msg);
|
append_sexp_contacts (gstr, msg);
|
||||||
|
|
||||||
if (ti)
|
if (ti)
|
||||||
append_sexp_thread_info (gstr, ti);
|
append_sexp_thread_info (gstr, ti);
|
||||||
|
|
||||||
append_sexp_attr (gstr,
|
append_sexp_attr (gstr,
|
||||||
"subject", mu_msg_get_subject (msg));
|
"subject", mu_msg_get_subject (msg));
|
||||||
|
|
||||||
t = mu_msg_get_date (msg);
|
t = mu_msg_get_date (msg);
|
||||||
/* weird time format for emacs 29-bit ints...*/
|
/* 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),
|
"\t:date (%u %u 0)\n", (unsigned)(t >> 16),
|
||||||
(unsigned)(t & 0xffff));
|
(unsigned)(t & 0xffff));
|
||||||
g_string_append_printf (gstr, "\t:size %u\n",
|
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, "message-id", mu_msg_get_msgid (msg));
|
||||||
append_sexp_attr (gstr, "path", mu_msg_get_path (msg));
|
append_sexp_attr (gstr, "path", mu_msg_get_path (msg));
|
||||||
append_sexp_attr (gstr, "maildir", mu_msg_get_maildir (msg));
|
append_sexp_attr (gstr, "maildir", mu_msg_get_maildir (msg));
|
||||||
|
|
||||||
g_string_append_printf (gstr, "\t:priority %s\n",
|
g_string_append_printf (gstr, "\t:priority %s\n",
|
||||||
mu_msg_prio_name(mu_msg_get_prio(msg)));
|
mu_msg_prio_name(mu_msg_get_prio(msg)));
|
||||||
|
|
||||||
append_sexp_flags (gstr, msg);
|
append_sexp_flags (gstr, msg);
|
||||||
|
|
||||||
/* file attr things can only be gotten from the file (ie., mu
|
/* headers are retrieved from the database, views from the message file
|
||||||
* view), not from the database (mu find) */
|
*
|
||||||
if (!dbonly)
|
* 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);
|
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);
|
return g_string_free (gstr, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue