mirror of https://github.com/djcb/mu.git
* <many>: make gmime initialization/de-initialization implicit (remove mu_msg_init/mu_msg_uninit)
This commit is contained in:
parent
55981b27df
commit
57fc2441a8
|
@ -211,16 +211,12 @@ mu_cmd_extract (MuConfigOptions *opts)
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
mu_msg_init();
|
||||
|
||||
if (!opts->parts &&
|
||||
!opts->save_attachments &&
|
||||
!opts->save_all) /* show, don't save */
|
||||
rv = show_parts (opts->params[1], opts);
|
||||
else
|
||||
rv = save_parts (opts->params[1], opts); /* save */
|
||||
|
||||
mu_msg_uninit();
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
|
|
@ -343,20 +343,16 @@ mu_cmd_find (MuConfigOptions *opts)
|
|||
|
||||
/* first param is 'query', search params are after that */
|
||||
params = (const gchar**)&opts->params[1];
|
||||
|
||||
mu_msg_init();
|
||||
|
||||
xapian = mu_query_new (opts->xpath);
|
||||
if (!xapian) {
|
||||
g_printerr ("Failed to create a Xapian query\n");
|
||||
mu_msg_uninit ();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
rv = do_output (xapian, opts, params);
|
||||
|
||||
mu_query_destroy (xapian);
|
||||
mu_msg_uninit();
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
|
|
@ -208,14 +208,9 @@ run_index (MuIndex *midx, const char* maildir, MuIndexStats *stats,
|
|||
MuResult rv;
|
||||
|
||||
mu_index_stats_clear (stats);
|
||||
mu_msg_init ();
|
||||
|
||||
rv = mu_index_run (midx, maildir, reindex, stats,
|
||||
quiet ? index_msg_silent_cb :index_msg_cb,
|
||||
NULL, NULL);
|
||||
|
||||
mu_msg_init ();
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
|
|
@ -87,14 +87,10 @@ mu_cmd_view (MuConfigOptions *opts)
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
mu_msg_init();
|
||||
|
||||
rv = TRUE;
|
||||
for (i = 1; opts->params[i] && rv; ++i)
|
||||
rv = view_file (opts->params[i], NULL,
|
||||
opts->summary_len);
|
||||
|
||||
mu_msg_uninit();
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
|
53
src/mu-msg.c
53
src/mu-msg.c
|
@ -32,6 +32,28 @@
|
|||
#include "mu-msg.h"
|
||||
|
||||
|
||||
static guint _refcount = 0;
|
||||
|
||||
static void
|
||||
ref_gmime (void)
|
||||
{
|
||||
if (G_UNLIKELY(_refcount == 0)) {
|
||||
srandom (getpid()*time(NULL));
|
||||
g_mime_init(0);
|
||||
}
|
||||
++_refcount;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
unref_gmime (void)
|
||||
{
|
||||
g_return_if_fail (_refcount > 0);
|
||||
|
||||
--_refcount;
|
||||
if (G_UNLIKELY(_refcount == 0))
|
||||
g_mime_shutdown();
|
||||
}
|
||||
|
||||
void
|
||||
mu_msg_destroy (MuMsg *msg)
|
||||
|
@ -50,6 +72,7 @@ mu_msg_destroy (MuMsg *msg)
|
|||
g_free (msg->_fields[i]);
|
||||
|
||||
g_slice_free (MuMsg, msg);
|
||||
unref_gmime ();
|
||||
}
|
||||
|
||||
|
||||
|
@ -135,9 +158,9 @@ mu_msg_new (const char* filepath, const gchar* mdir)
|
|||
|
||||
g_return_val_if_fail (filepath, NULL);
|
||||
|
||||
ref_gmime ();
|
||||
|
||||
msg = g_slice_new0 (MuMsg);
|
||||
if (!msg)
|
||||
return NULL;
|
||||
|
||||
if (!init_file_metadata(msg, filepath, mdir)) {
|
||||
mu_msg_destroy (msg);
|
||||
|
@ -794,29 +817,3 @@ mu_msg_get_field_numeric (MuMsg *msg, const MuMsgField* field)
|
|||
|
||||
|
||||
|
||||
static gboolean _initialized = FALSE;
|
||||
|
||||
void
|
||||
mu_msg_init (void)
|
||||
{
|
||||
if (!_initialized) {
|
||||
|
||||
srandom (getpid()*time(NULL));
|
||||
|
||||
g_mime_init(0);
|
||||
_initialized = TRUE;
|
||||
g_debug ("%s", __FUNCTION__);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
mu_msg_uninit (void)
|
||||
{
|
||||
if (_initialized) {
|
||||
g_mime_shutdown();
|
||||
_initialized = FALSE;
|
||||
g_debug ("%s", __FUNCTION__);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
19
src/mu-msg.h
19
src/mu-msg.h
|
@ -30,25 +30,6 @@ G_BEGIN_DECLS
|
|||
struct _MuMsg;
|
||||
typedef struct _MuMsg MuMsg;
|
||||
|
||||
/**
|
||||
* initialize the message parsing system; this function must be called
|
||||
* before doing any message parsing (ie., any of the other
|
||||
* mu_msg functions). when done with the message parsing system,
|
||||
* call mu_msg_uninit. Note: calling this function on an already
|
||||
* initialized system has no effect
|
||||
*/
|
||||
void mu_msg_init (void);
|
||||
|
||||
/**
|
||||
* uninitialize the messge parsing system that has previously been
|
||||
* initialized with mu_msg_init. not calling mu_msg_uninit after
|
||||
* mu_msg_init has been called will lead to memory leakage. Note:
|
||||
* calling mu_msg_uninit on an uninitialized system has no
|
||||
* effect
|
||||
*/
|
||||
void mu_msg_uninit (void);
|
||||
|
||||
|
||||
/**
|
||||
* create a new MuMsg* instance which parses a message and provides
|
||||
* read access to its properties; call mu_msg_destroy when done with it.
|
||||
|
|
|
@ -84,7 +84,6 @@ test_mu_msg_01 (void)
|
|||
MuMsg *msg;
|
||||
gint i;
|
||||
|
||||
mu_msg_init ();
|
||||
mfile = get_mailpath (1);
|
||||
|
||||
msg = mu_msg_new (mfile, NULL);
|
||||
|
@ -113,7 +112,6 @@ test_mu_msg_01 (void)
|
|||
mu_msg_destroy (msg);
|
||||
|
||||
g_free (mfile);
|
||||
mu_msg_uninit ();
|
||||
}
|
||||
|
||||
|
||||
|
@ -150,8 +148,7 @@ test_mu_msg_02 (void)
|
|||
char *mfile;
|
||||
MuMsg *msg;
|
||||
int i;
|
||||
|
||||
mu_msg_init ();
|
||||
|
||||
mfile = get_mailpath (2);
|
||||
|
||||
msg = mu_msg_new (mfile, NULL);
|
||||
|
@ -179,7 +176,6 @@ test_mu_msg_02 (void)
|
|||
mu_msg_destroy (msg);
|
||||
|
||||
g_free (mfile);
|
||||
mu_msg_uninit ();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -159,8 +159,6 @@ test_mu_query_04 (void)
|
|||
|
||||
query = mu_query_new (xpath);
|
||||
iter = mu_query_run (query, "fünkÿ", NULL, FALSE, 1);
|
||||
|
||||
mu_msg_init ();
|
||||
msg = mu_msg_iter_get_msg (iter);
|
||||
|
||||
g_assert_cmpstr (mu_msg_get_subject(msg),==,
|
||||
|
@ -169,8 +167,6 @@ test_mu_query_04 (void)
|
|||
" Let's write some fünkÿ text using umlauts. ");
|
||||
|
||||
mu_msg_destroy (msg);
|
||||
mu_msg_uninit ();
|
||||
|
||||
mu_msg_iter_destroy (iter);
|
||||
mu_query_destroy (query);
|
||||
g_free (xpath);
|
||||
|
|
Loading…
Reference in New Issue