* mu-msg-file: ensure that mu_msg_file_get_header always returns proper utf8

This commit is contained in:
djcb
2012-01-12 00:21:33 +02:00
parent 1a45c45e79
commit 5fb5347bc8
2 changed files with 32 additions and 11 deletions

View File

@ -80,9 +80,18 @@ mu_msg_file_destroy (MuMsgFile *self)
if (self->_mime_msg) if (self->_mime_msg)
g_object_unref (self->_mime_msg); g_object_unref (self->_mime_msg);
mu_str_free_list (self->_free_later);
g_slice_free (MuMsgFile, self); g_slice_free (MuMsgFile, self);
} }
static const gchar*
free_string_later (MuMsgFile *self, gchar *str)
{
self->_free_later = g_slist_prepend (self->_free_later, str);
return str;
}
static gboolean static gboolean
init_file_metadata (MuMsgFile *self, const char* path, const gchar* mdir, init_file_metadata (MuMsgFile *self, const char* path, const gchar* mdir,
@ -631,8 +640,7 @@ get_references (MuMsgFile *self)
const GMimeReferences *cur; const GMimeReferences *cur;
GMimeReferences *mime_refs; GMimeReferences *mime_refs;
str = g_mime_object_get_header (GMIME_OBJECT(self->_mime_msg), str = mu_msg_file_get_header (self, headers[u]);
headers[u]);
if (!str) if (!str)
continue; continue;
@ -642,9 +650,10 @@ get_references (MuMsgFile *self)
msgid = g_mime_references_get_message_id (cur); msgid = g_mime_references_get_message_id (cur);
/* don't include duplicates */ /* don't include duplicates */
if (msgid && !contains (msgids, msgid)) if (msgid && !contains (msgids, msgid))
msgids = g_slist_prepend (msgids, g_strdup (msgid)); /* explicitly ensure it's utf8-safe, as GMime
* does not ensure that */
msgids = g_slist_prepend (msgids, g_strdup((msgid)));
} }
g_mime_references_free (mime_refs); g_mime_references_free (mime_refs);
} }
@ -655,12 +664,13 @@ get_references (MuMsgFile *self)
static GSList* static GSList*
get_tags (MuMsgFile *self) get_tags (MuMsgFile *self)
{ {
GMimeObject *obj; const char *hdr;
obj = GMIME_OBJECT(self->_mime_msg); hdr = mu_msg_file_get_header (self, "X-Label");
if (!hdr)
return NULL;
return mu_str_to_list (g_mime_object_get_header return mu_str_to_list (hdr, ',', TRUE);
(obj, "X-Label"), ',', TRUE);
} }
@ -797,9 +807,16 @@ mu_msg_file_get_num_field (MuMsgFile *self, const MuMsgFieldId mfid)
const char* const char*
mu_msg_file_get_header (MuMsgFile *self, const char *header) mu_msg_file_get_header (MuMsgFile *self, const char *header)
{ {
const gchar *hdr;
g_return_val_if_fail (self, NULL); g_return_val_if_fail (self, NULL);
g_return_val_if_fail (header, NULL); g_return_val_if_fail (header, NULL);
return g_mime_object_get_header /* sadly, g_mime_object_get_header may return non-ascii;
(GMIME_OBJECT(self->_mime_msg), header); * so, we need to ensure that
*/
hdr = g_mime_object_get_header (GMIME_OBJECT(self->_mime_msg),
header);
return hdr ? free_string_later (self, mu_str_utf8ify(hdr)) : NULL;
} }

View File

@ -32,13 +32,17 @@
G_BEGIN_DECLS G_BEGIN_DECLS
struct _MuMsgFile { struct _MuMsgFile {
GMimeMessage *_mime_msg; GMimeMessage *_mime_msg;
time_t _timestamp; time_t _timestamp;
size_t _size; size_t _size;
char _path [PATH_MAX + 1]; char _path [PATH_MAX + 1];
char _maildir [PATH_MAX + 1]; char _maildir [PATH_MAX + 1];
/* list where we push allocated strings so we can
* free them when the struct gets destroyed
*/
GSList *_free_later;
}; };