static const char* get_str_field (MuMsg *self, MuMsgFieldId mfid) { gboolean do_free; char *val; /* first we try the cache */ if (mu_msg_cache_cached (self->_cache, mfid)) return mu_msg_cache_str (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_field (self->_doc, mfid, &do_free); else if (mu_msg_field_gmime (mfid)) { /* 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_field (self->_file, mfid, &do_free); } else { g_warning ("%s: cannot retrieve field", __FUNCTION__); return NULL; } /* 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 (self->_cache, mfid, val, do_free); }
/* use this instead of mu_msg_get_path so we don't get into infinite * regress...*/ static const char* get_path (MuMsg *self) { char *val; gboolean do_free; do_free = TRUE; val = NULL; if (self->_doc) val = mu_msg_doc_get_str_field (self->_doc, MU_MSG_FIELD_ID_PATH); /* not in the cache yet? try to get it from the file backend, * in case we are using that */ if (!val && self->_file) val = mu_msg_file_get_str_field (self->_file, MU_MSG_FIELD_ID_PATH, &do_free); /* shouldn't happen */ if (!val) g_warning ("%s: cannot find path", __func__); return free_later_str (self, val); }
static const char* get_str_field (MuMsg *self, MuMsgFieldId mfid) { char *val; gboolean do_free; do_free = TRUE; val = NULL; if (self->_doc && mu_msg_field_xapian_value (mfid)) val = mu_msg_doc_get_str_field (self->_doc, mfid); else if (mu_msg_field_gmime (mfid)) { /* if we don't have a file object yet, we need to * create it from the file on disk */ if (!mu_msg_load_msg_file (self, NULL)) return NULL; val = mu_msg_file_get_str_field (self->_file, mfid, &do_free); } else { g_warning ("%s: cannot retrieve field", __FUNCTION__); val = NULL; } return do_free ? free_later_str (self, val) : val; }
/* use this instead of mu_msg_get_path so we don't get into infinite * regress...*/ static const char* get_path (MuMsg *self) { const char *path; char *val; gboolean do_free; /* try to get the path from the cache */ path = mu_msg_cache_str (self->_cache, MU_MSG_FIELD_ID_PATH); if (path) return path; /* nothing found yet? try the doc in case we are using that * backend */ val = NULL; if (self->_doc) val = mu_msg_doc_get_str_field (self->_doc, MU_MSG_FIELD_ID_PATH, &do_free); /* not in the cache yet? try to get it from the file backend, * in case we are using that */ if (!val && self->_file) val = mu_msg_file_get_str_field (self->_file, MU_MSG_FIELD_ID_PATH, &do_free); /* this cannot happen unless there are bugs in mu */ if (!val) { g_warning ("%s: cannot find path", __FUNCTION__); return NULL; } /* we found something */ return mu_msg_cache_set_str (self->_cache, MU_MSG_FIELD_ID_PATH, val, do_free); }