* mu-msg-sexp.c: fix each_contact for cc10, line33 checks

This commit is contained in:
Dirk-Jan C. Binnema 2011-08-11 08:21:41 +03:00
parent 250aa91f5c
commit 8f7ef5d748
1 changed files with 29 additions and 15 deletions

View File

@ -63,6 +63,7 @@ append_sexp_attr (GString *gstr, const char* elm, const char *str)
struct _ContactData { struct _ContactData {
gboolean from, to, cc, bcc; gboolean from, to, cc, bcc;
GString *gstr; GString *gstr;
MuMsgContactType prev_ctype;
}; };
typedef struct _ContactData ContactData; typedef struct _ContactData ContactData;
@ -87,38 +88,50 @@ get_name_addr_pair (MuMsgContact *c)
} }
static gboolean static gboolean
each_contact (MuMsgContact *c, ContactData *cdata) each_contact (MuMsgContact *c, ContactData *cdata)
{ {
char *pair; char *pair;
MuMsgContactType ctype;
if (mu_msg_contact_type (c) == MU_MSG_CONTACT_TYPE_FROM) { ctype = mu_msg_contact_type (c);
if (cdata->prev_ctype != ctype && cdata->prev_ctype != (unsigned)-1)
g_string_append (cdata->gstr, ")\n");
switch (ctype) {
case MU_MSG_CONTACT_TYPE_FROM:
if (!cdata->from) if (!cdata->from)
g_string_append (cdata->gstr, "\t:from ("); g_string_append (cdata->gstr, "\t:from (");
cdata->from = TRUE; cdata->from = TRUE;
break;
} else if (mu_msg_contact_type (c) == MU_MSG_CONTACT_TYPE_TO) { case MU_MSG_CONTACT_TYPE_TO:
if (!cdata->to) if (!cdata->to)
g_string_append_printf (cdata->gstr,"%s\t:to (", g_string_append_printf (cdata->gstr,"\t:to (");
cdata->from ? ")\n" : "");
cdata->to = TRUE; cdata->to = TRUE;
break;
} else if (mu_msg_contact_type (c) == MU_MSG_CONTACT_TYPE_CC) { case MU_MSG_CONTACT_TYPE_CC:
if (!cdata->cc) if (!cdata->cc)
g_string_append_printf (cdata->gstr,"%s\t:cc (", g_string_append_printf (cdata->gstr,"\t:cc (");
cdata->from||cdata->to ?
")\n" : "");
cdata->cc = TRUE; cdata->cc = TRUE;
break;
} else if (mu_msg_contact_type (c) == MU_MSG_CONTACT_TYPE_BCC) { case MU_MSG_CONTACT_TYPE_BCC:
if (!cdata->bcc) if (!cdata->bcc)
g_string_append_printf g_string_append_printf (cdata->gstr, "\t:bcc (");
(cdata->gstr, "%s\t:bcc (",
cdata->from||cdata->to||cdata->cc ? ")\n":"");
cdata->bcc = TRUE; cdata->bcc = TRUE;
} else break;
g_return_val_if_reached (FALSE);
default: g_return_val_if_reached (FALSE);
}
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);
@ -130,7 +143,8 @@ 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 = { FALSE, FALSE, FALSE, FALSE, gstr,
(unsigned)-1};
mu_msg_contact_foreach (msg, (MuMsgContactForeachFunc)each_contact, mu_msg_contact_foreach (msg, (MuMsgContactForeachFunc)each_contact,
&cdata); &cdata);