[balsa/gtk3] Simplify add-messages code for local mailboxes
- From: Peter Bloomfield <PeterB src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [balsa/gtk3] Simplify add-messages code for local mailboxes
- Date: Mon, 20 May 2013 02:04:47 +0000 (UTC)
commit 0674e21214a8d7fd63b08a18aa53fea3f17786d1
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date: Sun May 19 22:02:59 2013 -0400
Simplify add-messages code for local mailboxes
Implement add-messages at LibBalsaMailboxLocal level, and use a
new add-message method for the backends.
* libbalsa/mailbox_local.c (libbalsa_mailbox_local_class_init):
new add-messages method.
* libbalsa/mailbox_local.h: new member
LibBalsaMailboxLocalClass::add_message.
* libbalsa/mailbox_maildir.c (libbalsa_mailbox_maildir_class_init),
(lbm_maildir_add_message): implement
LibBalsaMailboxLocalClass::add_message.
* libbalsa/mailbox_mbox.c (libbalsa_mailbox_mbox_class_init),
(lbm_mbox_add_message): ditto.
* libbalsa/mailbox_mh.c (libbalsa_mailbox_mh_class_init),
(lbm_mh_add_message): ditto.
ChangeLog | 17 +++++++++++++++++
libbalsa/mailbox_local.c | 36 ++++++++++++++++++++++++++++++++++++
libbalsa/mailbox_local.h | 7 +++++++
libbalsa/mailbox_maildir.c | 40 ++++++++--------------------------------
libbalsa/mailbox_mbox.c | 39 ++++++++-------------------------------
libbalsa/mailbox_mh.c | 40 ++++++++--------------------------------
6 files changed, 84 insertions(+), 95 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 2b5c9ba..537dbcd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2013-05-19 Peter Bloomfield
+
+ Implement add-messages at LibBalsaMailboxLocal level, and use a
+ new add-message method for the backends.
+
+ * libbalsa/mailbox_local.c (libbalsa_mailbox_local_class_init):
+ new add-messages method.
+ * libbalsa/mailbox_local.h: new member
+ LibBalsaMailboxLocalClass::add_message.
+ * libbalsa/mailbox_maildir.c (libbalsa_mailbox_maildir_class_init),
+ (lbm_maildir_add_message): implement
+ LibBalsaMailboxLocalClass::add_message.
+ * libbalsa/mailbox_mbox.c (libbalsa_mailbox_mbox_class_init),
+ (lbm_mbox_add_message): ditto.
+ * libbalsa/mailbox_mh.c (libbalsa_mailbox_mh_class_init),
+ (lbm_mh_add_message): ditto.
+
2013-05-18 Peter Bloomfield
* libbalsa/mailbox_local.c: avoid zero-divide.
diff --git a/libbalsa/mailbox_local.c b/libbalsa/mailbox_local.c
index 292bb52..7f4858a 100644
--- a/libbalsa/mailbox_local.c
+++ b/libbalsa/mailbox_local.c
@@ -85,6 +85,12 @@ static gboolean libbalsa_mailbox_local_get_msg_part(LibBalsaMessage *msg,
GError **err);
static void lbm_local_sort(LibBalsaMailbox * mailbox, GArray *sort_array);
+static guint
+libbalsa_mailbox_local_add_messages(LibBalsaMailbox * mailbox,
+ LibBalsaAddMessageIterator msg_iterator,
+ gpointer iter_data,
+ GError ** err);
+
static GArray *libbalsa_mailbox_local_duplicate_msgnos(LibBalsaMailbox *
mailbox);
static gboolean
@@ -169,6 +175,8 @@ libbalsa_mailbox_local_class_init(LibBalsaMailboxLocalClass * klass)
libbalsa_mailbox_class->get_message_part =
libbalsa_mailbox_local_get_msg_part;
libbalsa_mailbox_class->sort = lbm_local_sort;
+ libbalsa_mailbox_class->add_messages =
+ libbalsa_mailbox_local_add_messages;
libbalsa_mailbox_class->messages_change_flags =
libbalsa_mailbox_local_messages_change_flags;
libbalsa_mailbox_class->msgno_has_flags =
@@ -2211,6 +2219,34 @@ lbm_local_sort(LibBalsaMailbox * mailbox, GArray *sort_array)
lbm_local_queue_save_tree(LIBBALSA_MAILBOX_LOCAL(mailbox));
}
+static guint
+libbalsa_mailbox_local_add_messages(LibBalsaMailbox * mailbox,
+ LibBalsaAddMessageIterator msg_iterator,
+ gpointer iter_data,
+ GError ** err)
+{
+ LibBalsaMessageFlag flag;
+ GMimeStream *stream;
+ LibBalsaMailboxLocal *local;
+ guint cnt;
+ LibBalsaMailboxLocalAddMessageFunc *add_message;
+
+ local = LIBBALSA_MAILBOX_LOCAL(mailbox);
+ cnt = 0;
+ add_message = LIBBALSA_MAILBOX_LOCAL_GET_CLASS(local)->add_message;
+ while (msg_iterator(&flag, &stream, iter_data)) {
+ gboolean success;
+
+ success = (*add_message)(local, stream, flag, err);
+ g_object_unref(stream);
+ if (!success)
+ break;
+ cnt++;
+ }
+
+ return cnt;
+}
+
#define FLAGS_REALLY_DIFFER(flags0, flags1) \
(((flags0 ^ flags1) & LIBBALSA_MESSAGE_FLAGS_REAL) != 0)
diff --git a/libbalsa/mailbox_local.h b/libbalsa/mailbox_local.h
index 8a6721f..054896c 100644
--- a/libbalsa/mailbox_local.h
+++ b/libbalsa/mailbox_local.h
@@ -78,6 +78,12 @@ struct _LibBalsaMailboxLocal {
guint pool_seqno;
};
+typedef gboolean LibBalsaMailboxLocalAddMessageFunc(LibBalsaMailboxLocal *
+ local,
+ GMimeStream * stream,
+ LibBalsaMessageFlag
+ flags, GError ** err);
+
struct _LibBalsaMailboxLocalClass {
LibBalsaMailboxClass klass;
@@ -87,6 +93,7 @@ struct _LibBalsaMailboxLocalClass {
guint (*fileno)(LibBalsaMailboxLocal * local, guint msgno);
LibBalsaMailboxLocalMessageInfo *(*get_info)(LibBalsaMailboxLocal * local,
guint msgno);
+ LibBalsaMailboxLocalAddMessageFunc *add_message;
};
GObject *libbalsa_mailbox_local_new(const gchar * path, gboolean create);
diff --git a/libbalsa/mailbox_maildir.c b/libbalsa/mailbox_maildir.c
index 23628d3..28f7902 100644
--- a/libbalsa/mailbox_maildir.c
+++ b/libbalsa/mailbox_maildir.c
@@ -87,10 +87,6 @@ static gboolean
libbalsa_mailbox_maildir_fetch_message_structure(LibBalsaMailbox * mailbox,
LibBalsaMessage * message,
LibBalsaFetchFlag flags);
-static guint libbalsa_mailbox_maildir_add_messages(LibBalsaMailbox *
- mailbox,
- LibBalsaAddMessageIterator m,
- void *m_arg, GError ** err);
static guint
libbalsa_mailbox_maildir_total_messages(LibBalsaMailbox * mailbox);
@@ -102,6 +98,7 @@ static void lbm_maildir_remove_files(LibBalsaMailboxLocal * local);
static guint lbm_maildir_fileno(LibBalsaMailboxLocal * local, guint msgno);
static LibBalsaMailboxLocalMessageInfo
*lbm_maildir_get_info(LibBalsaMailboxLocal * local, guint msgno);
+static LibBalsaMailboxLocalAddMessageFunc lbm_maildir_add_message;
/* util functions */
static struct message_info *message_info_from_msgno(LibBalsaMailboxMaildir
@@ -167,8 +164,6 @@ libbalsa_mailbox_maildir_class_init(LibBalsaMailboxMaildirClass * klass)
libbalsa_mailbox_maildir_close_mailbox;
libbalsa_mailbox_class->fetch_message_structure =
libbalsa_mailbox_maildir_fetch_message_structure;
- libbalsa_mailbox_class->add_messages =
- libbalsa_mailbox_maildir_add_messages;
libbalsa_mailbox_class->total_messages =
libbalsa_mailbox_maildir_total_messages;
@@ -177,6 +172,7 @@ libbalsa_mailbox_maildir_class_init(LibBalsaMailboxMaildirClass * klass)
libbalsa_mailbox_local_class->remove_files = lbm_maildir_remove_files;
libbalsa_mailbox_local_class->fileno = lbm_maildir_fileno;
libbalsa_mailbox_local_class->get_info = lbm_maildir_get_info;
+ libbalsa_mailbox_local_class->add_message = lbm_maildir_add_message;
}
static void
@@ -885,11 +881,12 @@ lbm_maildir_get_info(LibBalsaMailboxLocal * local, guint msgno)
/* Called with mailbox locked. */
static gboolean
-libbalsa_mailbox_maildir_add_message(LibBalsaMailbox * mailbox,
- GMimeStream * stream,
- LibBalsaMessageFlag flags,
- GError **err)
+lbm_maildir_add_message(LibBalsaMailboxLocal * local,
+ GMimeStream * stream,
+ LibBalsaMessageFlag flags,
+ GError ** err)
{
+ LibBalsaMailbox *mailbox = (LibBalsaMailbox *) local;
const char *path;
char *tmp;
int fd;
@@ -902,7 +899,7 @@ libbalsa_mailbox_maildir_add_message(LibBalsaMailbox * mailbox,
time_t mtime;
/* open tempfile */
- path = libbalsa_mailbox_local_get_path(mailbox);
+ path = libbalsa_mailbox_local_get_path(local);
fd = libbalsa_mailbox_maildir_open_temp(path, &tmp);
if (fd == -1)
return FALSE;
@@ -954,27 +951,6 @@ libbalsa_mailbox_maildir_add_message(LibBalsaMailbox * mailbox,
}
static guint
-libbalsa_mailbox_maildir_add_messages(LibBalsaMailbox * mailbox,
- LibBalsaAddMessageIterator msg_iterator,
- void *arg,
- GError **err)
-{
- LibBalsaMessageFlag flag;
- GMimeStream *stream;
-
- guint cnt = 0;
- while( msg_iterator(&flag, &stream, arg) ) {
- gboolean success =
- libbalsa_mailbox_maildir_add_message(mailbox, stream, flag, err);
- g_object_unref(stream);
- if(!success)
- break;
- cnt++;
- }
- return cnt;
-}
-
-static guint
libbalsa_mailbox_maildir_total_messages(LibBalsaMailbox * mailbox)
{
LibBalsaMailboxMaildir *mdir = (LibBalsaMailboxMaildir *) mailbox;
diff --git a/libbalsa/mailbox_mbox.c b/libbalsa/mailbox_mbox.c
index 98e0d8d..090e69c 100644
--- a/libbalsa/mailbox_mbox.c
+++ b/libbalsa/mailbox_mbox.c
@@ -90,15 +90,12 @@ static gboolean libbalsa_mailbox_mbox_sync(LibBalsaMailbox * mailbox,
/* LibBalsaMailboxLocal class methods */
static LibBalsaMailboxLocalMessageInfo
*lbm_mbox_get_info(LibBalsaMailboxLocal * local, guint msgno);
+static LibBalsaMailboxLocalAddMessageFunc lbm_mbox_add_message;
static gboolean
libbalsa_mailbox_mbox_fetch_message_structure(LibBalsaMailbox * mailbox,
LibBalsaMessage * message,
LibBalsaFetchFlag flags);
-static guint libbalsa_mailbox_mbox_add_messages(LibBalsaMailbox *mailbox,
- LibBalsaAddMessageIterator m,
- void *m_arg,
- GError ** err);
static guint
libbalsa_mailbox_mbox_total_messages(LibBalsaMailbox * mailbox);
#if BALSA_USE_THREADS
@@ -169,7 +166,6 @@ libbalsa_mailbox_mbox_class_init(LibBalsaMailboxMboxClass * klass)
libbalsa_mailbox_mbox_close_mailbox;
libbalsa_mailbox_class->fetch_message_structure =
libbalsa_mailbox_mbox_fetch_message_structure;
- libbalsa_mailbox_class->add_messages = libbalsa_mailbox_mbox_add_messages;
libbalsa_mailbox_class->total_messages =
libbalsa_mailbox_mbox_total_messages;
#if BALSA_USE_THREADS
@@ -181,6 +177,7 @@ libbalsa_mailbox_mbox_class_init(LibBalsaMailboxMboxClass * klass)
libbalsa_mailbox_mbox_remove_files;
libbalsa_mailbox_local_class->get_info = lbm_mbox_get_info;
+ libbalsa_mailbox_local_class->add_message = lbm_mbox_add_message;
object_class->dispose = libbalsa_mailbox_mbox_dispose;
}
@@ -1935,11 +1932,12 @@ lbm_mbox_armored_stream(GMimeStream * stream)
/* Called with mailbox locked. */
static gboolean
-libbalsa_mailbox_mbox_add_message(LibBalsaMailbox * mailbox,
- GMimeStream * stream,
- LibBalsaMessageFlag flags,
- GError ** err)
+lbm_mbox_add_message(LibBalsaMailboxLocal * local,
+ GMimeStream * stream,
+ LibBalsaMessageFlag flags,
+ GError ** err)
{
+ LibBalsaMailbox *mailbox = (LibBalsaMailbox *) local;
LibBalsaMessage *message;
gchar date_string[27];
gchar *sender;
@@ -1978,7 +1976,7 @@ libbalsa_mailbox_mbox_add_message(LibBalsaMailbox * mailbox,
from = g_strdup_printf ("From %s %s", address, date_string );
g_free(address);
- path = libbalsa_mailbox_local_get_path(mailbox);
+ path = libbalsa_mailbox_local_get_path(local);
/* open in read-write mode */
fd = open(path, O_RDWR);
if (fd < 0) {
@@ -2045,27 +2043,6 @@ libbalsa_mailbox_mbox_add_message(LibBalsaMailbox * mailbox,
}
static guint
-libbalsa_mailbox_mbox_add_messages(LibBalsaMailbox * mailbox,
- LibBalsaAddMessageIterator msg_iterator,
- void *arg,
- GError **err)
-{
- LibBalsaMessageFlag flag;
- GMimeStream *stream;
-
- guint cnt = 0;
- while( msg_iterator(&flag, &stream, arg) ) {
- gboolean success =
- libbalsa_mailbox_mbox_add_message(mailbox, stream, flag, err);
- g_object_unref(stream);
- if(!success)
- break;
- cnt++;
- }
- return cnt;
-}
-
-static guint
libbalsa_mailbox_mbox_total_messages(LibBalsaMailbox * mailbox)
{
LibBalsaMailboxMbox *mbox = (LibBalsaMailboxMbox *) mailbox;
diff --git a/libbalsa/mailbox_mh.c b/libbalsa/mailbox_mh.c
index f9c7541..0c1c468 100644
--- a/libbalsa/mailbox_mh.c
+++ b/libbalsa/mailbox_mh.c
@@ -68,6 +68,7 @@ static void lbm_mh_set_path(LibBalsaMailboxLocal * mailbox,
static void lbm_mh_remove_files(LibBalsaMailboxLocal *mailbox);
static LibBalsaMailboxLocalMessageInfo
*lbm_mh_get_info(LibBalsaMailboxLocal * local, guint msgno);
+static LibBalsaMailboxLocalAddMessageFunc lbm_mh_add_message;
static gboolean libbalsa_mailbox_mh_open(LibBalsaMailbox * mailbox,
GError **err);
@@ -85,10 +86,6 @@ static gboolean libbalsa_mailbox_mh_fetch_message_structure(LibBalsaMailbox
* message,
LibBalsaFetchFlag
flags);
-static guint libbalsa_mailbox_mh_add_messages(LibBalsaMailbox * mailbox,
- LibBalsaAddMessageIterator m,
- void *m_arg,
- GError ** err);
static guint libbalsa_mailbox_mh_total_messages(LibBalsaMailbox * mailbox);
@@ -146,7 +143,6 @@ libbalsa_mailbox_mh_class_init(LibBalsaMailboxMhClass * klass)
libbalsa_mailbox_mh_close_mailbox;
libbalsa_mailbox_class->fetch_message_structure =
libbalsa_mailbox_mh_fetch_message_structure;
- libbalsa_mailbox_class->add_messages = libbalsa_mailbox_mh_add_messages;
libbalsa_mailbox_class->total_messages =
libbalsa_mailbox_mh_total_messages;
@@ -154,6 +150,7 @@ libbalsa_mailbox_mh_class_init(LibBalsaMailboxMhClass * klass)
libbalsa_mailbox_local_class->set_path = lbm_mh_set_path;
libbalsa_mailbox_local_class->remove_files = lbm_mh_remove_files;
libbalsa_mailbox_local_class->get_info = lbm_mh_get_info;
+ libbalsa_mailbox_local_class->add_message = lbm_mh_add_message;
}
static void
@@ -1060,10 +1057,10 @@ lbm_mh_update_sequences(LibBalsaMailboxMh * mh, gint fileno,
/* Called with mailbox locked. */
static gboolean
-libbalsa_mailbox_mh_add_message(LibBalsaMailbox * mailbox,
- GMimeStream * stream,
- LibBalsaMessageFlag flags,
- GError ** err)
+lbm_mh_add_message(LibBalsaMailboxLocal * local,
+ GMimeStream * stream,
+ LibBalsaMessageFlag flags,
+ GError ** err)
{
LibBalsaMailboxMh *mh;
const char *path;
@@ -1075,13 +1072,13 @@ libbalsa_mailbox_mh_add_message(LibBalsaMailbox * mailbox,
int retries;
GMimeStream *in_stream;
- mh = LIBBALSA_MAILBOX_MH(mailbox);
+ mh = LIBBALSA_MAILBOX_MH(local);
/* Make sure we know the highest message number: */
lbm_mh_parse_mailbox(mh, FALSE);
/* open tempfile */
- path = libbalsa_mailbox_local_get_path(mailbox);
+ path = libbalsa_mailbox_local_get_path(local);
fd = libbalsa_mailbox_mh_open_temp(path, &tmp);
if (fd == -1) {
g_set_error(err, LIBBALSA_MAILBOX_ERROR,
@@ -1153,27 +1150,6 @@ libbalsa_mailbox_mh_add_message(LibBalsaMailbox * mailbox,
}
static guint
-libbalsa_mailbox_mh_add_messages(LibBalsaMailbox * mailbox,
- LibBalsaAddMessageIterator msg_iterator,
- void *arg,
- GError **err)
-{
- LibBalsaMessageFlag flag;
- GMimeStream *stream;
-
- guint cnt = 0;
- while( msg_iterator(&flag, &stream, arg) ) {
- gboolean success =
- libbalsa_mailbox_mh_add_message(mailbox, stream, flag, err);
- g_object_unref(stream);
- if(!success)
- break;
- cnt++;
- }
- return cnt;
-}
-
-static guint
libbalsa_mailbox_mh_total_messages(LibBalsaMailbox * mailbox)
{
LibBalsaMailboxMh *mh = (LibBalsaMailboxMh *) mailbox;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]