* mu-contacts, mu-msg-file: better deal with contacts with control chars

This commit is contained in:
djcb
2013-06-24 22:42:18 +03:00
parent 6783e448aa
commit 97909566df
2 changed files with 21 additions and 23 deletions

View File

@ -270,6 +270,17 @@ downcase_domain_maybe (const char *addr)
return addr_conv; return addr_conv;
} }
static void
clear_str (char* str)
{
if (str) {
mu_str_remove_ctrl_in_place (str);
g_strstrip (str);
}
}
gboolean gboolean
mu_contacts_add (MuContacts *self, const char *addr, const char *name, mu_contacts_add (MuContacts *self, const char *addr, const char *name,
@ -299,6 +310,8 @@ mu_contacts_add (MuContacts *self, const char *addr, const char *name,
* empty*/ * empty*/
g_free (cinfo->_name); g_free (cinfo->_name);
cinfo->_name = g_strdup (name); cinfo->_name = g_strdup (name);
if (cinfo->_name)
mu_str_remove_ctrl_in_place (cinfo->_name);
} }
cinfo->_tstamp = tstamp; cinfo->_tstamp = tstamp;
} }
@ -454,21 +467,6 @@ mu_contacts_destroy (MuContacts *self)
} }
static void
clear_str (char* str)
{
/* replace ctrl chars with '_' */
while (str && *str) {
if (iscntrl (*str))
*str = '_';
++str;
}
if (str)
g_strstrip (str);
}
/* note, we will *own* the name, email we get, and we'll free them in /* note, we will *own* the name, email we get, and we'll free them in
* the end... */ * the end... */
static ContactInfo * static ContactInfo *

View File

@ -173,12 +173,11 @@ init_mime_msg (MuMsgFile *self, const char* path, GError **err)
return TRUE; return TRUE;
} }
static char* static char*
get_recipient (MuMsgFile *self, GMimeRecipientType rtype) get_recipient (MuMsgFile *self, GMimeRecipientType rtype)
{ {
char *recip; char *recip;
InternetAddressList *recips; InternetAddressList *recips;
recips = g_mime_message_get_recipients (self->_mime_msg, rtype); recips = g_mime_message_get_recipients (self->_mime_msg, rtype);
@ -195,6 +194,9 @@ get_recipient (MuMsgFile *self, GMimeRecipientType rtype)
return NULL; return NULL;
} }
if (recip)
mu_str_remove_ctrl_in_place (recip);
return recip; return recip;
} }
@ -592,10 +594,11 @@ get_tags (MuMsgFile *self)
} }
static char* static char*
cleanup_maybe (const char *str, gboolean *do_free) cleanup_maybe (const char *str, gboolean *do_free)
{ {
char *cur, *s; char *s;
if (!str) if (!str)
return NULL; return NULL;
@ -610,10 +613,7 @@ cleanup_maybe (const char *str, gboolean *do_free)
} else } else
s = (char*)str; s = (char*)str;
/* strip control chars */ mu_str_remove_ctrl_in_place (s);
for (cur = s; *cur; ++cur)
if (iscntrl(*cur))
*cur = ' ';
return s; return s;
} }