* mu-msg, mu-msg-file: also initialize gmime for doc-backed messages

This commit is contained in:
Dirk-Jan C. Binnema 2011-08-20 13:06:39 +03:00
parent dc9f120b55
commit 8a8e35add8
2 changed files with 41 additions and 34 deletions

View File

@ -49,33 +49,6 @@ static gboolean init_file_metadata (MuMsgFile *self, const char* path,
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*
@ -84,12 +57,7 @@ mu_msg_file_new (const char* filepath, const char *mdir, GError **err)
MuMsgFile *self;
g_return_val_if_fail (filepath, NULL);
if (G_UNLIKELY(!_gmime_initialized)) {
gmime_init ();
g_atexit (gmime_uninit);
}
self = g_slice_new0 (MuMsgFile);
if (!init_file_metadata (self, filepath, mdir, err)) {

View File

@ -35,6 +35,35 @@
#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*
msg_new (void)
@ -56,6 +85,11 @@ mu_msg_new_from_file (const char *path, const char *mdir, GError **err)
MuMsgFile *msgfile;
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);
if (!msgfile)
@ -75,7 +109,12 @@ mu_msg_new_from_doc (XapianDocument *doc, GError **err)
MuMsgDoc *msgdoc;
g_return_val_if_fail (doc, NULL);
if (G_UNLIKELY(!_gmime_initialized)) {
gmime_init ();
g_atexit (gmime_uninit);
}
msgdoc = mu_msg_doc_new (doc, err);
if (!msgdoc)
return NULL;