* mu-msg / mu-msg-file: move gmime init to mu_msg

we need gmime even for the MuMsgDoc backend, as there we are using gmime for
  parsing address lists. using the function without 'init' caused crashes...
This commit is contained in:
Dirk-Jan C. Binnema
2011-08-20 11:55:27 +03:00
parent 9b0a9320f5
commit 56c6863c09
3 changed files with 44 additions and 37 deletions

View File

@ -49,46 +49,12 @@ 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*
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);

View File

@ -36,11 +36,47 @@
#include "mu-maildir.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. Also note that we need gmime init
* even for the doc backend, as we use the address parsing functions
* also there. */
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)
{
MuMsg *self;
if (G_UNLIKELY(!_gmime_initialized)) {
gmime_init ();
g_atexit (gmime_uninit);
}
self = g_slice_new0 (MuMsg);
self->_refcount = 1;
@ -546,7 +582,7 @@ addresses_foreach (const char* addrs, MuMsgContactType ctype,
MuMsgContactForeachFunc func, gpointer user_data)
{
InternetAddressList *addrlist;
if (!addrs)
return;

View File

@ -368,18 +368,23 @@ int mu_msg_cmp (MuMsg *m1, MuMsg *m2, MuMsgFieldId mfid);
gboolean mu_msg_is_readable (MuMsg *self);
struct _MuMsgIterThreadInfo;
/**
* convert the msg to a Lisp symbolic expression (for further processing in
* e.g. emacs)
*
* @param msg a valid message
* @param ti thread info for the current message, or NULL
* @param dbonly if TRUE, only include message fields which can be
* obtained from the database (this is much faster if the MuMsg is
* database-backed, so no file needs to be opened)
*
* @return a string with the sexp (free with g_free) or NULL in case of error
*/
char* mu_msg_to_sexp (MuMsg *msg, gboolean dbonly);
char* mu_msg_to_sexp (MuMsg *msg, const struct _MuMsgIterThreadInfo *ti,
gboolean dbonly);
/**
* move a message to another maildir