* mu-msg: add support for GSList* fields
This commit is contained in:
52
src/mu-msg.c
52
src/mu-msg.c
@ -189,6 +189,42 @@ get_msg_file (MuMsg *self)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static const GSList*
|
||||||
|
get_str_list_field (MuMsg *self, MuMsgFieldId mfid)
|
||||||
|
{
|
||||||
|
gboolean do_free;
|
||||||
|
GSList *val;
|
||||||
|
|
||||||
|
/* first we try the cache */
|
||||||
|
if (mu_msg_cache_cached (self->_cache, mfid))
|
||||||
|
return mu_msg_cache_str_list (self->_cache, mfid);
|
||||||
|
|
||||||
|
/* if it's not in the cache but it is a value retrievable from
|
||||||
|
* the doc backend, use that */
|
||||||
|
val = NULL;
|
||||||
|
if (self->_doc && mu_msg_field_xapian_value (mfid))
|
||||||
|
val = mu_msg_doc_get_str_list_field (self->_doc,
|
||||||
|
mfid, &do_free);
|
||||||
|
else {
|
||||||
|
/* if we don't have a file object yet, we need to
|
||||||
|
* create it from the file on disk */
|
||||||
|
if (!self->_file)
|
||||||
|
self->_file = get_msg_file (self);
|
||||||
|
if (!self->_file && !(self->_file = get_msg_file (self)))
|
||||||
|
return NULL;
|
||||||
|
val = mu_msg_file_get_str_list_field (self->_file, mfid,
|
||||||
|
&do_free);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* if we get a string that needs freeing, we tell the cache to
|
||||||
|
* mark the string as such, so it will be freed when the cache
|
||||||
|
* is freed (or when the value is overwritten) */
|
||||||
|
return mu_msg_cache_set_str_list (self->_cache, mfid, val,
|
||||||
|
do_free);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static const char*
|
static const char*
|
||||||
get_str_field (MuMsg *self, MuMsgFieldId mfid)
|
get_str_field (MuMsg *self, MuMsgFieldId mfid)
|
||||||
@ -382,11 +418,11 @@ mu_msg_get_body_text (MuMsg *self)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const char*
|
const GSList*
|
||||||
mu_msg_get_references_str (MuMsg *self)
|
mu_msg_get_references (MuMsg *self)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail (self, NULL);
|
g_return_val_if_fail (self, NULL);
|
||||||
return get_str_field (self, MU_MSG_FIELD_ID_REFS);
|
return get_str_list_field (self, MU_MSG_FIELD_ID_REFS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -397,6 +433,16 @@ mu_msg_get_field_string (MuMsg *self, MuMsgFieldId mfid)
|
|||||||
return get_str_field (self, mfid);
|
return get_str_field (self, mfid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const GSList*
|
||||||
|
mu_msg_get_field_string_list (MuMsg *self, MuMsgFieldId mfid)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail (self, NULL);
|
||||||
|
return get_str_list_field (self, mfid);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
gint64
|
gint64
|
||||||
mu_msg_get_field_numeric (MuMsg *self, MuMsgFieldId mfid)
|
mu_msg_get_field_numeric (MuMsg *self, MuMsgFieldId mfid)
|
||||||
{
|
{
|
||||||
|
|||||||
10
src/mu-msg.h
10
src/mu-msg.h
@ -264,6 +264,16 @@ size_t mu_msg_get_size (MuMsg *msg);
|
|||||||
const char* mu_msg_get_field_string (MuMsg *msg, MuMsgFieldId mfid);
|
const char* mu_msg_get_field_string (MuMsg *msg, MuMsgFieldId mfid);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get some field value as string-list
|
||||||
|
*
|
||||||
|
* @param msg a valid MuMsg instance
|
||||||
|
* @param field the field to retrieve; it must be a string-list-typed field
|
||||||
|
*
|
||||||
|
* @return a list that should not be freed
|
||||||
|
*/
|
||||||
|
const GSList* mu_msg_get_field_string_list (MuMsg *self, MuMsgFieldId mfid);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get some field value as string
|
* get some field value as string
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user