mirror of https://github.com/djcb/mu.git
* mu-msg.[ch], mu-msg-file.[ch]: update indentation
This commit is contained in:
parent
51fb5fe8e9
commit
228af3edee
|
@ -1,4 +1,5 @@
|
||||||
/*
|
/* -*- mode: c; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
|
||||||
|
**
|
||||||
** Copyright (C) 2011 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
** Copyright (C) 2011 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||||
**
|
**
|
||||||
** This program is free software; you can redistribute it and/or modify it
|
** This program is free software; you can redistribute it and/or modify it
|
||||||
|
@ -56,15 +57,15 @@ static gboolean _gmime_initialized = FALSE;
|
||||||
static void
|
static void
|
||||||
gmime_init (void)
|
gmime_init (void)
|
||||||
{
|
{
|
||||||
g_return_if_fail (!_gmime_initialized);
|
g_return_if_fail (!_gmime_initialized);
|
||||||
|
|
||||||
#ifdef GMIME_ENABLE_RFC2047_WORKAROUNDS
|
#ifdef GMIME_ENABLE_RFC2047_WORKAROUNDS
|
||||||
g_mime_init(GMIME_ENABLE_RFC2047_WORKAROUNDS);
|
g_mime_init(GMIME_ENABLE_RFC2047_WORKAROUNDS);
|
||||||
#else
|
#else
|
||||||
g_mime_init(0);
|
g_mime_init(0);
|
||||||
#endif /* GMIME_ENABLE_RFC2047_WORKAROUNDS */
|
#endif /* GMIME_ENABLE_RFC2047_WORKAROUNDS */
|
||||||
|
|
||||||
_gmime_initialized = TRUE;
|
_gmime_initialized = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -113,7 +114,7 @@ mu_msg_file_destroy (MuMsgFile *self)
|
||||||
|
|
||||||
if (self->_mime_msg)
|
if (self->_mime_msg)
|
||||||
g_object_unref (self->_mime_msg);
|
g_object_unref (self->_mime_msg);
|
||||||
|
|
||||||
g_slice_free (MuMsgFile, self);
|
g_slice_free (MuMsgFile, self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -700,7 +701,6 @@ get_msgids_from_header (MuMsgFile *self, const char* header)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static GSList*
|
static GSList*
|
||||||
get_references (MuMsgFile *self)
|
get_references (MuMsgFile *self)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
/* -*-mode: c; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Copyright (C) 2010 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
** Copyright (C) 2010 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||||
**
|
**
|
||||||
|
@ -44,6 +46,7 @@ MuMsgFile *mu_msg_file_new (const char *path,
|
||||||
void mu_msg_file_destroy (MuMsgFile *self);
|
void mu_msg_file_destroy (MuMsgFile *self);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get a string value for this message
|
* get a string value for this message
|
||||||
*
|
*
|
||||||
|
|
475
src/mu-msg.c
475
src/mu-msg.c
|
@ -1,4 +1,5 @@
|
||||||
/*
|
/* -*- mode: c; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
|
||||||
|
**
|
||||||
** Copyright (C) 2008-2011 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
** Copyright (C) 2008-2011 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||||
**
|
**
|
||||||
** This program is free software; you can redistribute it and/or modify
|
** This program is free software; you can redistribute it and/or modify
|
||||||
|
@ -38,87 +39,87 @@
|
||||||
static MuMsg*
|
static MuMsg*
|
||||||
msg_new (void)
|
msg_new (void)
|
||||||
{
|
{
|
||||||
MuMsg *self;
|
MuMsg *self;
|
||||||
|
|
||||||
self = g_slice_new0 (MuMsg);
|
self = g_slice_new0 (MuMsg);
|
||||||
|
|
||||||
self->_refcount = 1;
|
self->_refcount = 1;
|
||||||
self->_cache = mu_msg_cache_new ();
|
self->_cache = mu_msg_cache_new ();
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
MuMsg*
|
MuMsg*
|
||||||
mu_msg_new_from_file (const char *path, const char *mdir, GError **err)
|
mu_msg_new_from_file (const char *path, const char *mdir, GError **err)
|
||||||
{
|
{
|
||||||
MuMsg *self;
|
MuMsg *self;
|
||||||
MuMsgFile *msgfile;
|
MuMsgFile *msgfile;
|
||||||
|
|
||||||
g_return_val_if_fail (path, NULL);
|
g_return_val_if_fail (path, NULL);
|
||||||
|
|
||||||
msgfile = mu_msg_file_new (path, mdir, err);
|
msgfile = mu_msg_file_new (path, mdir, err);
|
||||||
if (!msgfile)
|
if (!msgfile)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
self = msg_new ();
|
self = msg_new ();
|
||||||
self->_file = msgfile;
|
self->_file = msgfile;
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
MuMsg*
|
MuMsg*
|
||||||
mu_msg_new_from_doc (const XapianDocument* doc, GError **err)
|
mu_msg_new_from_doc (const XapianDocument* doc, GError **err)
|
||||||
{
|
{
|
||||||
MuMsg *self;
|
MuMsg *self;
|
||||||
MuMsgDoc *msgdoc;
|
MuMsgDoc *msgdoc;
|
||||||
|
|
||||||
g_return_val_if_fail (doc, NULL);
|
g_return_val_if_fail (doc, NULL);
|
||||||
|
|
||||||
msgdoc = mu_msg_doc_new (doc, err);
|
msgdoc = mu_msg_doc_new (doc, err);
|
||||||
if (!msgdoc)
|
if (!msgdoc)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
self = msg_new ();
|
self = msg_new ();
|
||||||
self->_doc = msgdoc;
|
self->_doc = msgdoc;
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
mu_msg_destroy (MuMsg *self)
|
mu_msg_destroy (MuMsg *self)
|
||||||
{
|
{
|
||||||
if (!self)
|
if (!self)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
mu_msg_file_destroy (self->_file);
|
mu_msg_file_destroy (self->_file);
|
||||||
mu_msg_doc_destroy (self->_doc);
|
mu_msg_doc_destroy (self->_doc);
|
||||||
|
|
||||||
mu_msg_cache_destroy (self->_cache);
|
mu_msg_cache_destroy (self->_cache);
|
||||||
|
|
||||||
g_slice_free (MuMsg, self);
|
g_slice_free (MuMsg, self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
MuMsg*
|
MuMsg*
|
||||||
mu_msg_ref (MuMsg *self)
|
mu_msg_ref (MuMsg *self)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail (self, NULL);
|
g_return_val_if_fail (self, NULL);
|
||||||
|
|
||||||
++self->_refcount;
|
++self->_refcount;
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
mu_msg_unref (MuMsg *self)
|
mu_msg_unref (MuMsg *self)
|
||||||
{
|
{
|
||||||
g_return_if_fail (self);
|
g_return_if_fail (self);
|
||||||
g_return_if_fail (self->_refcount >= 1);
|
g_return_if_fail (self->_refcount >= 1);
|
||||||
|
|
||||||
if (--self->_refcount == 0)
|
if (--self->_refcount == 0)
|
||||||
mu_msg_destroy (self);
|
mu_msg_destroy (self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -127,40 +128,40 @@ mu_msg_unref (MuMsg *self)
|
||||||
static const char*
|
static const char*
|
||||||
get_path (MuMsg *self)
|
get_path (MuMsg *self)
|
||||||
{
|
{
|
||||||
const char *path;
|
const char *path;
|
||||||
char *val;
|
char *val;
|
||||||
gboolean do_free;
|
gboolean do_free;
|
||||||
|
|
||||||
/* try to get the path from the cache */
|
/* try to get the path from the cache */
|
||||||
path = mu_msg_cache_str (self->_cache, MU_MSG_FIELD_ID_PATH);
|
path = mu_msg_cache_str (self->_cache, MU_MSG_FIELD_ID_PATH);
|
||||||
if (path)
|
if (path)
|
||||||
return path;
|
return path;
|
||||||
|
|
||||||
/* nothing found yet? try the doc in case we are using that
|
/* nothing found yet? try the doc in case we are using that
|
||||||
* backend */
|
* backend */
|
||||||
val = NULL;
|
val = NULL;
|
||||||
if (self->_doc)
|
if (self->_doc)
|
||||||
val = mu_msg_doc_get_str_field (self->_doc,
|
val = mu_msg_doc_get_str_field (self->_doc,
|
||||||
MU_MSG_FIELD_ID_PATH,
|
MU_MSG_FIELD_ID_PATH,
|
||||||
&do_free);
|
&do_free);
|
||||||
|
|
||||||
/* not in the cache yet? try to get it from the file backend,
|
/* not in the cache yet? try to get it from the file backend,
|
||||||
* in case we are using that */
|
* in case we are using that */
|
||||||
if (!val && self->_file)
|
if (!val && self->_file)
|
||||||
val = mu_msg_file_get_str_field (self->_file,
|
val = mu_msg_file_get_str_field (self->_file,
|
||||||
MU_MSG_FIELD_ID_PATH,
|
MU_MSG_FIELD_ID_PATH,
|
||||||
&do_free);
|
&do_free);
|
||||||
|
|
||||||
/* this cannot happen unless there are bugs in mu */
|
/* this cannot happen unless there are bugs in mu */
|
||||||
if (!val) {
|
if (!val) {
|
||||||
g_warning ("%s: cannot find path", __FUNCTION__);
|
g_warning ("%s: cannot find path", __FUNCTION__);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* we found something */
|
/* we found something */
|
||||||
return mu_msg_cache_set_str (self->_cache,
|
return mu_msg_cache_set_str (self->_cache,
|
||||||
MU_MSG_FIELD_ID_PATH, val,
|
MU_MSG_FIELD_ID_PATH, val,
|
||||||
do_free);
|
do_free);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -168,23 +169,23 @@ get_path (MuMsg *self)
|
||||||
static MuMsgFile*
|
static MuMsgFile*
|
||||||
get_msg_file (MuMsg *self)
|
get_msg_file (MuMsg *self)
|
||||||
{
|
{
|
||||||
MuMsgFile *mfile;
|
MuMsgFile *mfile;
|
||||||
const char *path;
|
const char *path;
|
||||||
GError *err;
|
GError *err;
|
||||||
|
|
||||||
if (!(path = get_path (self)))
|
if (!(path = get_path (self)))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
err = NULL;
|
err = NULL;
|
||||||
mfile = mu_msg_file_new (path, NULL, &err);
|
mfile = mu_msg_file_new (path, NULL, &err);
|
||||||
if (!mfile) {
|
if (!mfile) {
|
||||||
g_warning ("%s: failed to create MuMsgFile: %s",
|
g_warning ("%s: failed to create MuMsgFile: %s",
|
||||||
__FUNCTION__, err->message ? err->message : "?");
|
__FUNCTION__, err->message ? err->message : "?");
|
||||||
g_error_free (err);
|
g_error_free (err);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return mfile;
|
return mfile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -192,128 +193,128 @@ get_msg_file (MuMsg *self)
|
||||||
static const char*
|
static const char*
|
||||||
get_str_field (MuMsg *self, MuMsgFieldId mfid)
|
get_str_field (MuMsg *self, MuMsgFieldId mfid)
|
||||||
{
|
{
|
||||||
gboolean do_free;
|
gboolean do_free;
|
||||||
char *val;
|
char *val;
|
||||||
|
|
||||||
/* first we try the cache */
|
/* first we try the cache */
|
||||||
if (mu_msg_cache_cached (self->_cache, mfid))
|
if (mu_msg_cache_cached (self->_cache, mfid))
|
||||||
return mu_msg_cache_str (self->_cache, mfid);
|
return mu_msg_cache_str (self->_cache, mfid);
|
||||||
|
|
||||||
/* if it's not in the cache but it is a value retrievable from
|
/* if it's not in the cache but it is a value retrievable from
|
||||||
* the doc backend, use that */
|
* the doc backend, use that */
|
||||||
val = NULL;
|
val = NULL;
|
||||||
if (self->_doc && mu_msg_field_xapian_value (mfid))
|
if (self->_doc && mu_msg_field_xapian_value (mfid))
|
||||||
val = mu_msg_doc_get_str_field (self->_doc, mfid, &do_free);
|
val = mu_msg_doc_get_str_field (self->_doc, mfid, &do_free);
|
||||||
else {
|
else {
|
||||||
/* if we don't have a file object yet, we need to
|
/* if we don't have a file object yet, we need to
|
||||||
* create it from the file on disk */
|
* create it from the file on disk */
|
||||||
if (!self->_file)
|
if (!self->_file)
|
||||||
self->_file = get_msg_file (self);
|
self->_file = get_msg_file (self);
|
||||||
if (!self->_file && !(self->_file = get_msg_file (self)))
|
if (!self->_file && !(self->_file = get_msg_file (self)))
|
||||||
return NULL;
|
return NULL;
|
||||||
val = mu_msg_file_get_str_field (self->_file, mfid, &do_free);
|
val = mu_msg_file_get_str_field (self->_file, mfid, &do_free);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if we get a string that needs freeing, we tell the cache to
|
/* if we get a string that needs freeing, we tell the cache to
|
||||||
* mark the string as such, so it will be freed when the cache
|
* mark the string as such, so it will be freed when the cache
|
||||||
* is freed (or when the value is overwritten) */
|
* is freed (or when the value is overwritten) */
|
||||||
return mu_msg_cache_set_str (self->_cache, mfid, val, do_free);
|
return mu_msg_cache_set_str (self->_cache, mfid, val, do_free);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static gint64
|
static gint64
|
||||||
get_num_field (MuMsg *self, MuMsgFieldId mfid)
|
get_num_field (MuMsg *self, MuMsgFieldId mfid)
|
||||||
{
|
{
|
||||||
guint64 val;
|
guint64 val;
|
||||||
|
|
||||||
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 it's not in the cache but it is a value retrievable from
|
/* if it's not in the cache but it is a value retrievable from
|
||||||
* the doc backend, use that */
|
* the doc backend, use that */
|
||||||
val = -1;
|
val = -1;
|
||||||
if (self->_doc && mu_msg_field_xapian_value (mfid))
|
if (self->_doc && mu_msg_field_xapian_value (mfid))
|
||||||
val = mu_msg_doc_get_num_field (self->_doc, mfid);
|
val = mu_msg_doc_get_num_field (self->_doc, mfid);
|
||||||
else {
|
else {
|
||||||
/* if we don't have a file object yet, we need to
|
/* if we don't have a file object yet, we need to
|
||||||
* create it from the file on disk */
|
* create it from the file on disk */
|
||||||
if (!self->_file)
|
if (!self->_file)
|
||||||
self->_file = get_msg_file (self);
|
self->_file = get_msg_file (self);
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const char*
|
const char*
|
||||||
mu_msg_get_path (MuMsg *self)
|
mu_msg_get_path (MuMsg *self)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail (self, NULL);
|
g_return_val_if_fail (self, NULL);
|
||||||
return get_str_field (self, MU_MSG_FIELD_ID_PATH);
|
return get_str_field (self, MU_MSG_FIELD_ID_PATH);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const char*
|
const char*
|
||||||
mu_msg_get_subject (MuMsg *self)
|
mu_msg_get_subject (MuMsg *self)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail (self, NULL);
|
g_return_val_if_fail (self, NULL);
|
||||||
return get_str_field (self, MU_MSG_FIELD_ID_SUBJECT);
|
return get_str_field (self, MU_MSG_FIELD_ID_SUBJECT);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char*
|
const char*
|
||||||
mu_msg_get_msgid (MuMsg *self)
|
mu_msg_get_msgid (MuMsg *self)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail (self, NULL);
|
g_return_val_if_fail (self, NULL);
|
||||||
return get_str_field (self, MU_MSG_FIELD_ID_MSGID);
|
return get_str_field (self, MU_MSG_FIELD_ID_MSGID);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char*
|
const char*
|
||||||
mu_msg_get_maildir (MuMsg *self)
|
mu_msg_get_maildir (MuMsg *self)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail (self, NULL);
|
g_return_val_if_fail (self, NULL);
|
||||||
return get_str_field (self, MU_MSG_FIELD_ID_MAILDIR);
|
return get_str_field (self, MU_MSG_FIELD_ID_MAILDIR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const char*
|
const char*
|
||||||
mu_msg_get_from (MuMsg *self)
|
mu_msg_get_from (MuMsg *self)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail (self, NULL);
|
g_return_val_if_fail (self, NULL);
|
||||||
return get_str_field (self, MU_MSG_FIELD_ID_FROM);
|
return get_str_field (self, MU_MSG_FIELD_ID_FROM);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const char*
|
const char*
|
||||||
mu_msg_get_to (MuMsg *self)
|
mu_msg_get_to (MuMsg *self)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail (self, NULL);
|
g_return_val_if_fail (self, NULL);
|
||||||
return get_str_field (self, MU_MSG_FIELD_ID_TO);
|
return get_str_field (self, MU_MSG_FIELD_ID_TO);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char*
|
const char*
|
||||||
mu_msg_get_cc (MuMsg *self)
|
mu_msg_get_cc (MuMsg *self)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail (self, NULL);
|
g_return_val_if_fail (self, NULL);
|
||||||
return get_str_field (self, MU_MSG_FIELD_ID_CC);
|
return get_str_field (self, MU_MSG_FIELD_ID_CC);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const char*
|
const char*
|
||||||
mu_msg_get_bcc (MuMsg *self)
|
mu_msg_get_bcc (MuMsg *self)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail (self, NULL);
|
g_return_val_if_fail (self, NULL);
|
||||||
return get_str_field (self, MU_MSG_FIELD_ID_BCC);
|
return get_str_field (self, MU_MSG_FIELD_ID_BCC);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
time_t
|
time_t
|
||||||
mu_msg_get_date (MuMsg *self)
|
mu_msg_get_date (MuMsg *self)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail (self, (time_t)-1);
|
g_return_val_if_fail (self, (time_t)-1);
|
||||||
return (time_t)get_num_field (self, MU_MSG_FIELD_ID_DATE);
|
return (time_t)get_num_field (self, MU_MSG_FIELD_ID_DATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -321,23 +322,23 @@ mu_msg_get_date (MuMsg *self)
|
||||||
MuMsgFlags
|
MuMsgFlags
|
||||||
mu_msg_get_flags (MuMsg *self)
|
mu_msg_get_flags (MuMsg *self)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail (self, MU_MSG_FLAG_NONE);
|
g_return_val_if_fail (self, MU_MSG_FLAG_NONE);
|
||||||
return (MuMsgFlags)get_num_field (self, MU_MSG_FIELD_ID_FLAGS);
|
return (MuMsgFlags)get_num_field (self, MU_MSG_FIELD_ID_FLAGS);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t
|
size_t
|
||||||
mu_msg_get_size (MuMsg *self)
|
mu_msg_get_size (MuMsg *self)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail (self, (size_t)-1);
|
g_return_val_if_fail (self, (size_t)-1);
|
||||||
return (size_t)get_num_field (self, MU_MSG_FIELD_ID_SIZE);
|
return (size_t)get_num_field (self, MU_MSG_FIELD_ID_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
MuMsgPrio
|
MuMsgPrio
|
||||||
mu_msg_get_prio (MuMsg *self)
|
mu_msg_get_prio (MuMsg *self)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail (self, MU_MSG_PRIO_NORMAL);
|
g_return_val_if_fail (self, MU_MSG_PRIO_NORMAL);
|
||||||
return (MuMsgPrio)get_num_field (self, MU_MSG_FIELD_ID_PRIO);
|
return (MuMsgPrio)get_num_field (self, MU_MSG_FIELD_ID_PRIO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -355,8 +356,8 @@ mu_msg_get_prio (MuMsg *self)
|
||||||
time_t
|
time_t
|
||||||
mu_msg_get_timestamp (MuMsg *self)
|
mu_msg_get_timestamp (MuMsg *self)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail (self, (time_t)-1);
|
g_return_val_if_fail (self, (time_t)-1);
|
||||||
return (MuMsgPrio)get_num_field (self, MU_MSG_FIELD_ID_TIMESTAMP);
|
return (MuMsgPrio)get_num_field (self, MU_MSG_FIELD_ID_TIMESTAMP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -365,61 +366,61 @@ mu_msg_get_timestamp (MuMsg *self)
|
||||||
const char*
|
const char*
|
||||||
mu_msg_get_body_html (MuMsg *self)
|
mu_msg_get_body_html (MuMsg *self)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail (self, NULL);
|
g_return_val_if_fail (self, NULL);
|
||||||
return get_str_field (self, MU_MSG_FIELD_ID_BODY_HTML);
|
return get_str_field (self, MU_MSG_FIELD_ID_BODY_HTML);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const char*
|
const char*
|
||||||
mu_msg_get_body_text (MuMsg *self)
|
mu_msg_get_body_text (MuMsg *self)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail (self, NULL);
|
g_return_val_if_fail (self, NULL);
|
||||||
return get_str_field (self, MU_MSG_FIELD_ID_BODY_TEXT);
|
return get_str_field (self, MU_MSG_FIELD_ID_BODY_TEXT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const char*
|
const char*
|
||||||
mu_msg_get_references_str (MuMsg *self)
|
mu_msg_get_references_str (MuMsg *self)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail (self, NULL);
|
g_return_val_if_fail (self, NULL);
|
||||||
return get_str_field (self, MU_MSG_FIELD_ID_REFS);
|
return get_str_field (self, MU_MSG_FIELD_ID_REFS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const char*
|
const char*
|
||||||
mu_msg_get_field_string (MuMsg *self, MuMsgFieldId mfid)
|
mu_msg_get_field_string (MuMsg *self, MuMsgFieldId mfid)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail (self, NULL);
|
g_return_val_if_fail (self, NULL);
|
||||||
return get_str_field (self, mfid);
|
return get_str_field (self, mfid);
|
||||||
}
|
}
|
||||||
|
|
||||||
gint64
|
gint64
|
||||||
mu_msg_get_field_numeric (MuMsg *self, MuMsgFieldId mfid)
|
mu_msg_get_field_numeric (MuMsg *self, MuMsgFieldId mfid)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail (self, -1);
|
g_return_val_if_fail (self, -1);
|
||||||
return get_num_field (self, mfid);
|
return get_num_field (self, mfid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
MuMsgContact *
|
MuMsgContact *
|
||||||
mu_msg_contact_new (const char *name, const char *address,
|
mu_msg_contact_new (const char *name, const char *address,
|
||||||
MuMsgContactType type)
|
MuMsgContactType type)
|
||||||
{
|
{
|
||||||
MuMsgContact *self;
|
MuMsgContact *self;
|
||||||
|
|
||||||
g_return_val_if_fail (name, NULL);
|
g_return_val_if_fail (name, NULL);
|
||||||
g_return_val_if_fail (address, NULL);
|
g_return_val_if_fail (address, NULL);
|
||||||
g_return_val_if_fail (!mu_msg_contact_type_is_valid(type),
|
g_return_val_if_fail (!mu_msg_contact_type_is_valid(type),
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
self = g_slice_new (MuMsgContact);
|
self = g_slice_new (MuMsgContact);
|
||||||
|
|
||||||
self->name = g_strdup (name);
|
self->name = g_strdup (name);
|
||||||
self->address = g_strdup (address);
|
self->address = g_strdup (address);
|
||||||
self->type = type;
|
self->type = type;
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -427,112 +428,112 @@ void
|
||||||
mu_msg_contact_destroy (MuMsgContact *self)
|
mu_msg_contact_destroy (MuMsgContact *self)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (!self)
|
if (!self)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
g_free ((void*)self->name);
|
g_free ((void*)self->name);
|
||||||
g_free ((void*)self->address);
|
g_free ((void*)self->address);
|
||||||
g_slice_free (MuMsgContact, self);
|
g_slice_free (MuMsgContact, self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
fill_contact (MuMsgContact *self, InternetAddress *addr,
|
fill_contact (MuMsgContact *self, InternetAddress *addr,
|
||||||
MuMsgContactType ctype)
|
MuMsgContactType ctype)
|
||||||
{
|
{
|
||||||
if (!addr)
|
if (!addr)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
self->name = internet_address_get_name (addr);
|
self->name = internet_address_get_name (addr);
|
||||||
self->type = ctype;
|
self->type = ctype;
|
||||||
|
|
||||||
/* we only support internet mailbox addresses; if we don't
|
/* we only support internet mailbox addresses; if we don't
|
||||||
* check, g_mime hits an assert
|
* check, g_mime hits an assert
|
||||||
*/
|
*/
|
||||||
if (INTERNET_ADDRESS_IS_MAILBOX(addr))
|
if (INTERNET_ADDRESS_IS_MAILBOX(addr))
|
||||||
self->address = internet_address_mailbox_get_addr
|
self->address = internet_address_mailbox_get_addr
|
||||||
(INTERNET_ADDRESS_MAILBOX(addr));
|
(INTERNET_ADDRESS_MAILBOX(addr));
|
||||||
else
|
else
|
||||||
self->address = NULL;
|
self->address = NULL;
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
address_list_foreach (InternetAddressList *addrlist,
|
address_list_foreach (InternetAddressList *addrlist,
|
||||||
MuMsgContactType ctype,
|
MuMsgContactType ctype,
|
||||||
MuMsgContactForeachFunc func,
|
MuMsgContactForeachFunc func,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (!addrlist)
|
if (!addrlist)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (i = 0; i != internet_address_list_length(addrlist); ++i) {
|
for (i = 0; i != internet_address_list_length(addrlist); ++i) {
|
||||||
|
|
||||||
MuMsgContact contact;
|
MuMsgContact contact;
|
||||||
if (!fill_contact(&contact,
|
if (!fill_contact(&contact,
|
||||||
internet_address_list_get_address (addrlist, i),
|
internet_address_list_get_address (addrlist, i),
|
||||||
ctype)) {
|
ctype)) {
|
||||||
MU_WRITE_LOG ("ignoring contact");
|
MU_WRITE_LOG ("ignoring contact");
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
if (!(func)(&contact, user_data))
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!(func)(&contact, user_data))
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
get_contacts_from (MuMsg *msg, MuMsgContactForeachFunc func,
|
get_contacts_from (MuMsg *msg, MuMsgContactForeachFunc func,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
InternetAddressList *lst;
|
InternetAddressList *lst;
|
||||||
|
|
||||||
/* we go through this whole excercise of trying to get a *list*
|
/* we go through this whole excercise of trying to get a *list*
|
||||||
* of 'From:' address (usually there is only one...), because
|
* of 'From:' address (usually there is only one...), because
|
||||||
* internet_address_parse_string has the nice side-effect of
|
* internet_address_parse_string has the nice side-effect of
|
||||||
* splitting in names and addresses for us */
|
* splitting in names and addresses for us */
|
||||||
lst = internet_address_list_parse_string (
|
lst = internet_address_list_parse_string (
|
||||||
g_mime_message_get_sender (msg->_file->_mime_msg));
|
g_mime_message_get_sender (msg->_file->_mime_msg));
|
||||||
|
|
||||||
if (lst) {
|
if (lst) {
|
||||||
address_list_foreach (lst, MU_MSG_CONTACT_TYPE_FROM,
|
address_list_foreach (lst, MU_MSG_CONTACT_TYPE_FROM,
|
||||||
func, user_data);
|
func, user_data);
|
||||||
g_object_unref (G_OBJECT(lst));
|
g_object_unref (G_OBJECT(lst));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
mu_msg_contact_foreach (MuMsg *msg, MuMsgContactForeachFunc func,
|
mu_msg_contact_foreach (MuMsg *msg, MuMsgContactForeachFunc func,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
struct {
|
struct {
|
||||||
GMimeRecipientType _gmime_type;
|
GMimeRecipientType _gmime_type;
|
||||||
MuMsgContactType _type;
|
MuMsgContactType _type;
|
||||||
} ctypes[] = {
|
} ctypes[] = {
|
||||||
{GMIME_RECIPIENT_TYPE_TO, MU_MSG_CONTACT_TYPE_TO},
|
{GMIME_RECIPIENT_TYPE_TO, MU_MSG_CONTACT_TYPE_TO},
|
||||||
{GMIME_RECIPIENT_TYPE_CC, MU_MSG_CONTACT_TYPE_CC},
|
{GMIME_RECIPIENT_TYPE_CC, MU_MSG_CONTACT_TYPE_CC},
|
||||||
{GMIME_RECIPIENT_TYPE_BCC, MU_MSG_CONTACT_TYPE_BCC},
|
{GMIME_RECIPIENT_TYPE_BCC, MU_MSG_CONTACT_TYPE_BCC},
|
||||||
};
|
};
|
||||||
|
|
||||||
g_return_if_fail (func && msg);
|
g_return_if_fail (func && msg);
|
||||||
|
|
||||||
/* first, get the from address(es) */
|
/* first, get the from address(es) */
|
||||||
get_contacts_from (msg, func, user_data);
|
get_contacts_from (msg, func, user_data);
|
||||||
|
|
||||||
/* get to, cc, bcc */
|
/* get to, cc, bcc */
|
||||||
for (i = 0; i != G_N_ELEMENTS(ctypes); ++i) {
|
for (i = 0; i != G_N_ELEMENTS(ctypes); ++i) {
|
||||||
InternetAddressList *addrlist;
|
InternetAddressList *addrlist;
|
||||||
addrlist = g_mime_message_get_recipients (msg->_file->_mime_msg,
|
addrlist = g_mime_message_get_recipients (msg->_file->_mime_msg,
|
||||||
ctypes[i]._gmime_type);
|
ctypes[i]._gmime_type);
|
||||||
address_list_foreach (addrlist, ctypes[i]._type, func, user_data);
|
address_list_foreach (addrlist, ctypes[i]._type, func, user_data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
22
src/mu-msg.h
22
src/mu-msg.h
|
@ -1,4 +1,5 @@
|
||||||
/*
|
/* -*- mode: c; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
|
||||||
|
**
|
||||||
** Copyright (C) 2010 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
** Copyright (C) 2010 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||||
**
|
**
|
||||||
** This program is free software; you can redistribute it and/or modify
|
** This program is free software; you can redistribute it and/or modify
|
||||||
|
@ -39,14 +40,16 @@ typedef struct _MuMsg MuMsg;
|
||||||
* ~/Maildir/foo/bar/cur/msg, the maildir would be foo/bar; you can
|
* ~/Maildir/foo/bar/cur/msg, the maildir would be foo/bar; you can
|
||||||
* pass NULL for this parameter, in which case some maildir-specific
|
* pass NULL for this parameter, in which case some maildir-specific
|
||||||
* information is not available.
|
* information is not available.
|
||||||
* @param err receive error information (MU_ERROR_FILE or MU_ERROR_GMIME), or NULL. There
|
* @param err receive error information (MU_ERROR_FILE or
|
||||||
* will only be err info if the function returns NULL
|
* MU_ERROR_GMIME), or NULL. There will only be err info if the
|
||||||
|
* function returns NULL
|
||||||
*
|
*
|
||||||
* @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_file (const char* filepath, const char *maildir,
|
MuMsg *mu_msg_new_from_file (const char* filepath, const char *maildir,
|
||||||
GError **err) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
|
GError **err)
|
||||||
|
G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -294,17 +297,6 @@ MuMsgPrio mu_msg_get_prio (MuMsg *msg);
|
||||||
time_t mu_msg_get_timestamp (MuMsg *msg);
|
time_t mu_msg_get_timestamp (MuMsg *msg);
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get a list of message ids this message refers to -- this is based
|
|
||||||
* on the References: and In-reply-to: headers.
|
|
||||||
*
|
|
||||||
* @param msg a valid MuMsg instance
|
|
||||||
*
|
|
||||||
* @return a list of message id, with the most immediate parent as the
|
|
||||||
* last element. Don't modify/free this list.
|
|
||||||
*/
|
|
||||||
const GSList *mu_msg_get_references (MuMsg *msg);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get the list of references as a comma-separated string
|
* get the list of references as a comma-separated string
|
||||||
|
|
Loading…
Reference in New Issue