mirror of https://github.com/djcb/mu.git
* mu-msg.c: refactor to make functions respect 33-lines limit and use GMIME_ENABLE_RFC2047_WORKAROUNDS
This commit is contained in:
parent
c5c51f3798
commit
5341e8d4a8
34
src/mu-msg.c
34
src/mu-msg.c
|
@ -35,17 +35,24 @@
|
||||||
|
|
||||||
static guint _refcount = 0;
|
static guint _refcount = 0;
|
||||||
|
|
||||||
|
/* 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 void
|
static void
|
||||||
ref_gmime (void)
|
ref_gmime (void)
|
||||||
{
|
{
|
||||||
if (G_UNLIKELY(_refcount == 0)) {
|
if (G_UNLIKELY(_refcount == 0)) {
|
||||||
srandom ((unsigned)(getpid()*time(NULL)));
|
srandom ((unsigned)(getpid()*time(NULL)));
|
||||||
g_mime_init(0);
|
#ifdef GMIME_ENABLE_RFC2047_WORKAROUNDS
|
||||||
|
g_mime_init(GMIME_ENABLE_RFC2047_WORKAROUNDS);
|
||||||
|
#else
|
||||||
|
g_mime_init(0);
|
||||||
|
#endif /* GMIME_ENABLE_RFC2047_WORKAROUNDS */
|
||||||
}
|
}
|
||||||
++_refcount;
|
++_refcount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
unref_gmime (void)
|
unref_gmime (void)
|
||||||
{
|
{
|
||||||
|
@ -116,19 +123,19 @@ init_file_metadata (MuMsg* msg, const char* path, const gchar* mdir,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static gboolean
|
|
||||||
init_mime_msg (MuMsg *msg, GError **err)
|
static GMimeStream*
|
||||||
|
get_mime_stream (MuMsg *msg, GError **err)
|
||||||
{
|
{
|
||||||
FILE *file;
|
FILE *file;
|
||||||
GMimeStream *stream;
|
GMimeStream *stream;
|
||||||
GMimeParser *parser;
|
|
||||||
|
|
||||||
file = fopen (mu_msg_get_path(msg), "r");
|
file = fopen (mu_msg_get_path(msg), "r");
|
||||||
if (!file) {
|
if (!file) {
|
||||||
g_set_error (err, 0, MU_ERROR_FILE,
|
g_set_error (err, 0, MU_ERROR_FILE,
|
||||||
"cannot open %s: %s", mu_msg_get_path(msg),
|
"cannot open %s: %s", mu_msg_get_path(msg),
|
||||||
strerror (errno));
|
strerror (errno));
|
||||||
return FALSE;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
stream = g_mime_stream_file_new (file);
|
stream = g_mime_stream_file_new (file);
|
||||||
|
@ -137,8 +144,21 @@ init_mime_msg (MuMsg *msg, GError **err)
|
||||||
"cannot create mime stream for %s",
|
"cannot create mime stream for %s",
|
||||||
mu_msg_get_path(msg));
|
mu_msg_get_path(msg));
|
||||||
fclose (file);
|
fclose (file);
|
||||||
return FALSE;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return stream;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
init_mime_msg (MuMsg *msg, GError **err)
|
||||||
|
{
|
||||||
|
GMimeStream *stream;
|
||||||
|
GMimeParser *parser;
|
||||||
|
|
||||||
|
stream = get_mime_stream (msg, err);
|
||||||
|
if (!stream)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
parser = g_mime_parser_new_with_stream (stream);
|
parser = g_mime_parser_new_with_stream (stream);
|
||||||
g_object_unref (stream);
|
g_object_unref (stream);
|
||||||
|
|
Loading…
Reference in New Issue