* lib: cleanup header fields a bit more; fixes #209
This commit is contained in:
@ -592,28 +592,34 @@ get_tags (MuMsgFile *self)
|
||||
}
|
||||
|
||||
|
||||
/* wrongly encoded messages may cause GMime to return invalid
|
||||
* UTF8... we double check, and ensure our output is always correct
|
||||
* utf8 */
|
||||
gchar *
|
||||
maybe_cleanup (const char* str, const char *path, gboolean *do_free)
|
||||
static char*
|
||||
cleanup_maybe (const char *str, gboolean *do_free)
|
||||
{
|
||||
if (!str || G_LIKELY(g_utf8_validate(str, -1, NULL)))
|
||||
return (char*)str;
|
||||
char *cur, *s;
|
||||
|
||||
g_debug ("invalid utf8 in %s", path);
|
||||
if (!str)
|
||||
return NULL;
|
||||
|
||||
if (!g_utf8_validate(str, -1, NULL)) {
|
||||
if (*do_free)
|
||||
return mu_str_asciify_in_place ((char*)str);
|
||||
s = mu_str_asciify_in_place ((char*)str);
|
||||
else {
|
||||
gchar *ascii;
|
||||
ascii = mu_str_asciify_in_place(g_strdup (str));
|
||||
*do_free = TRUE;
|
||||
return ascii;
|
||||
s = mu_str_asciify_in_place(g_strdup (str));
|
||||
}
|
||||
} else
|
||||
s = (char*)str;
|
||||
|
||||
/* strip control chars */
|
||||
for (cur = s; *cur; ++cur)
|
||||
if (iscntrl(*cur))
|
||||
*cur = ' ';
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
|
||||
G_GNUC_CONST static GMimeRecipientType
|
||||
recipient_type (MuMsgFieldId mfid)
|
||||
{
|
||||
@ -659,9 +665,8 @@ mu_msg_file_get_str_field (MuMsgFile *self, MuMsgFieldId mfid,
|
||||
return get_recipient (self, recipient_type(mfid));
|
||||
|
||||
case MU_MSG_FIELD_ID_FROM:
|
||||
return (char*)maybe_cleanup
|
||||
(g_mime_message_get_sender (self->_mime_msg),
|
||||
self->_path, do_free);
|
||||
return (char*)cleanup_maybe
|
||||
(g_mime_message_get_sender (self->_mime_msg), do_free);
|
||||
|
||||
case MU_MSG_FIELD_ID_PATH: return self->_path;
|
||||
|
||||
@ -670,9 +675,8 @@ mu_msg_file_get_str_field (MuMsgFile *self, MuMsgFieldId mfid,
|
||||
return (char*)get_mailing_list (self);
|
||||
|
||||
case MU_MSG_FIELD_ID_SUBJECT:
|
||||
return (char*)maybe_cleanup
|
||||
(g_mime_message_get_subject (self->_mime_msg),
|
||||
self->_path, do_free);
|
||||
return (char*)cleanup_maybe
|
||||
(g_mime_message_get_subject (self->_mime_msg), do_free);
|
||||
|
||||
case MU_MSG_FIELD_ID_MSGID:
|
||||
return get_msgid (self, do_free);
|
||||
|
||||
@ -17,6 +17,7 @@
|
||||
**
|
||||
*/
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "mu-str.h"
|
||||
#include "mu-msg.h"
|
||||
@ -49,12 +50,18 @@ append_sexp_attr_list (GString *gstr, const char* elm, const GSList *lst)
|
||||
static void
|
||||
append_sexp_attr (GString *gstr, const char* elm, const char *str)
|
||||
{
|
||||
gchar *esc;
|
||||
gchar *esc, *utf8, *cur;
|
||||
|
||||
if (!str || strlen(str) == 0)
|
||||
return; /* empty: don't include */
|
||||
|
||||
esc = mu_str_escape_c_literal (str, TRUE);
|
||||
utf8 = mu_str_utf8ify (str);
|
||||
for (cur = utf8; *cur; ++cur)
|
||||
if (iscntrl(*cur))
|
||||
*cur = ' ';
|
||||
|
||||
esc = mu_str_escape_c_literal (utf8, TRUE);
|
||||
g_free (utf8);
|
||||
|
||||
g_string_append_printf (gstr, "\t:%s %s\n", elm, esc);
|
||||
g_free (esc);
|
||||
|
||||
Reference in New Issue
Block a user