mirror of https://github.com/djcb/mu.git
* mu-msg, mu-msg-file: move gmime-init to mu-msg-file, fix get_num_field
This commit is contained in:
parent
6fc029a6d3
commit
0c783567cf
|
@ -47,13 +47,48 @@ static gboolean init_file_metadata (MuMsgFile *self, const char* path,
|
||||||
const char *mdir, GError **err);
|
const char *mdir, GError **err);
|
||||||
static gboolean init_mime_msg (MuMsgFile *msg, const char *path, GError **err);
|
static gboolean init_mime_msg (MuMsgFile *msg, const char *path, GError **err);
|
||||||
|
|
||||||
|
|
||||||
|
/* note, we do the gmime initialization here rather than in
|
||||||
|
* mu-runtime, because this way we don't need mu-runtime for simple
|
||||||
|
* cases -- such as our unit tests */
|
||||||
|
static gboolean _gmime_initialized = FALSE;
|
||||||
|
|
||||||
|
static void
|
||||||
|
gmime_init (void)
|
||||||
|
{
|
||||||
|
g_return_if_fail (!_gmime_initialized);
|
||||||
|
|
||||||
|
#ifdef GMIME_ENABLE_RFC2047_WORKAROUNDS
|
||||||
|
g_mime_init(GMIME_ENABLE_RFC2047_WORKAROUNDS);
|
||||||
|
#else
|
||||||
|
g_mime_init(0);
|
||||||
|
#endif /* GMIME_ENABLE_RFC2047_WORKAROUNDS */
|
||||||
|
|
||||||
|
_gmime_initialized = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gmime_uninit (void)
|
||||||
|
{
|
||||||
|
g_return_if_fail (_gmime_initialized);
|
||||||
|
|
||||||
|
g_mime_shutdown();
|
||||||
|
_gmime_initialized = FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
MuMsgFile*
|
MuMsgFile*
|
||||||
mu_msg_file_new (const char* filepath, const char *mdir, GError **err)
|
mu_msg_file_new (const char* filepath, const char *mdir, GError **err)
|
||||||
{
|
{
|
||||||
MuMsgFile *self;
|
MuMsgFile *self;
|
||||||
|
|
||||||
g_return_val_if_fail (filepath, NULL);
|
g_return_val_if_fail (filepath, NULL);
|
||||||
|
|
||||||
|
if (G_UNLIKELY(!_gmime_initialized)) {
|
||||||
|
gmime_init ();
|
||||||
|
g_atexit (gmime_uninit);
|
||||||
|
}
|
||||||
|
|
||||||
self = g_slice_new0 (MuMsgFile);
|
self = g_slice_new0 (MuMsgFile);
|
||||||
|
|
||||||
if (!init_file_metadata (self, filepath, mdir, err)) {
|
if (!init_file_metadata (self, filepath, mdir, err)) {
|
||||||
|
|
54
src/mu-msg.c
54
src/mu-msg.c
|
@ -33,33 +33,6 @@
|
||||||
#include "mu-util.h"
|
#include "mu-util.h"
|
||||||
#include "mu-str.h"
|
#include "mu-str.h"
|
||||||
|
|
||||||
/* note, we do the gmime initialization here rather than in
|
|
||||||
* mu-runtime, because this way we don't need mu-runtime for simple
|
|
||||||
* cases -- such as our unit tests */
|
|
||||||
static gboolean _gmime_initialized = FALSE;
|
|
||||||
|
|
||||||
static void
|
|
||||||
gmime_init (void)
|
|
||||||
{
|
|
||||||
g_return_if_fail (!_gmime_initialized);
|
|
||||||
|
|
||||||
#ifdef GMIME_ENABLE_RFC2047_WORKAROUNDS
|
|
||||||
g_mime_init(GMIME_ENABLE_RFC2047_WORKAROUNDS);
|
|
||||||
#else
|
|
||||||
g_mime_init(0);
|
|
||||||
#endif /* GMIME_ENABLE_RFC2047_WORKAROUNDS */
|
|
||||||
|
|
||||||
_gmime_initialized = TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
gmime_uninit (void)
|
|
||||||
{
|
|
||||||
g_return_if_fail (_gmime_initialized);
|
|
||||||
|
|
||||||
g_mime_shutdown();
|
|
||||||
_gmime_initialized = FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static MuMsg*
|
static MuMsg*
|
||||||
|
@ -82,11 +55,6 @@ mu_msg_new_from_file (const char *path, const char *mdir, GError **err)
|
||||||
MuMsgFile *msgfile;
|
MuMsgFile *msgfile;
|
||||||
|
|
||||||
g_return_val_if_fail (path, NULL);
|
g_return_val_if_fail (path, NULL);
|
||||||
|
|
||||||
if (G_UNLIKELY(!_gmime_initialized)) {
|
|
||||||
gmime_init ();
|
|
||||||
g_atexit (gmime_uninit);
|
|
||||||
}
|
|
||||||
|
|
||||||
msgfile = mu_msg_file_new (path, mdir, err);
|
msgfile = mu_msg_file_new (path, mdir, err);
|
||||||
if (!msgfile)
|
if (!msgfile)
|
||||||
|
@ -260,18 +228,22 @@ get_num_field (MuMsg *self, MuMsgFieldId mfid)
|
||||||
|
|
||||||
if (mu_msg_cache_cached (self->_cache, mfid))
|
if (mu_msg_cache_cached (self->_cache, mfid))
|
||||||
return mu_msg_cache_num (self->_cache, mfid);
|
return mu_msg_cache_num (self->_cache, mfid);
|
||||||
|
|
||||||
/* if we don't have a file object yet, we need to create from
|
/* if it's not in the cache but it is a value retrievable from
|
||||||
* the file on disk */
|
* the doc backend, use that */
|
||||||
if (!self->_file) {
|
val = -1;
|
||||||
self->_file = get_msg_file (self);
|
if (self->_doc && mu_msg_field_xapian_value (mfid))
|
||||||
if (!self->_file) {
|
val = mu_msg_doc_get_num_field (self->_doc, mfid);
|
||||||
g_warning ("failed to open message file");
|
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 -1;
|
return -1;
|
||||||
}
|
val = mu_msg_file_get_num_field (self->_file, mfid);
|
||||||
}
|
}
|
||||||
|
|
||||||
val = mu_msg_file_get_num_field (self->_file, mfid);
|
|
||||||
return mu_msg_cache_set_num (self->_cache, mfid, val);
|
return mu_msg_cache_set_num (self->_cache, mfid, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -60,8 +60,8 @@ MuMsg *mu_msg_new_from_file (const char* filepath, const char *maildir,
|
||||||
* @return a new MuMsg instance or NULL in case of error; call
|
* @return a new MuMsg instance or NULL in case of error; call
|
||||||
* mu_msg_unref when done with this message
|
* mu_msg_unref when done with this message
|
||||||
*/
|
*/
|
||||||
MuMsg *mu_msg_new_from_db (const XapianDocument* doc, GError **err)
|
MuMsg *mu_msg_new_from_doc (const XapianDocument* doc, GError **err)
|
||||||
G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
|
G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue