diff --git a/src/mu-msg-cache.c b/src/mu-msg-cache.c index b8ae8ede..a16d838b 100644 --- a/src/mu-msg-cache.c +++ b/src/mu-msg-cache.c @@ -17,15 +17,17 @@ ** */ -#include -#include - +#include "mu-msg-flags.h" +#include "mu-msg-prio.h" #include "mu-msg-cache.h" +#include "mu-str.h" struct _MuMsgCache { /* all string properties */ char *_str[MU_MSG_STRING_FIELD_ID_NUM]; + + GSList *_refs; time_t _timestamp, _date; size_t _size; @@ -123,6 +125,49 @@ mu_msg_cache_str (MuMsgCache *cache, MuMsgFieldId mfid) +const GSList* +mu_msg_cache_set_str_list (MuMsgCache *self, MuMsgFieldId mfid, + GSList *lst, gboolean do_free) +{ + g_return_val_if_fail(self, NULL); + g_return_val_if_fail(mu_msg_field_is_string_list(mfid), NULL); + + switch (mfid) { + case MU_MSG_FIELD_ID_REFS: + if (is_allocated(self, mfid)) + mu_str_free_list (self->_refs); + self->_refs = lst; + break; + default: + g_return_val_if_reached(NULL); + return NULL; + } + + set_cached (self, mfid); + + if (do_free) + set_allocated (self, mfid); + else + reset_allocated (self, mfid); + + return lst; +} + + +const GSList* +mu_msg_cache_str_list (MuMsgCache *self, MuMsgFieldId mfid) +{ + g_return_val_if_fail (mu_msg_field_is_string_list(mfid), NULL); + + switch (mfid) { + case MU_MSG_FIELD_ID_REFS: + return self->_refs; + default: + g_return_val_if_reached(NULL); + return NULL; + } +} + gint64 mu_msg_cache_set_num (MuMsgCache *self, MuMsgFieldId mfid, gint64 val) diff --git a/src/mu-msg-cache.h b/src/mu-msg-cache.h index ce90b038..ea0ecbb3 100644 --- a/src/mu-msg-cache.h +++ b/src/mu-msg-cache.h @@ -84,6 +84,30 @@ const char* mu_msg_cache_str (MuMsgCache *cache, MuMsgFieldId mfid); +/** + * cache a string-list value + * + * @param self a mumsgcache + * @param mfid the MessageFieldId for a string-list value + * @param lst the list + * @param do_free whether the cache should free this value (i.e, take ownership) + * + * @return + */ +const GSList* mu_msg_cache_set_str_list (MuMsgCache *self, MuMsgFieldId mfid, + GSList *lst, gboolean do_free); + +/** + * get a string-list value from the cache + * + * @param cache a MuMsgCache + * @param mfid the MessageFieldId for string-list value + * + * @return a list, which should not be modified + */ +const GSList* mu_msg_cache_str_list (MuMsgCache *cache, MuMsgFieldId mfid); + + /** * add a numeric value to the cache *