Combine duplicate IMAP INBOX nodes
- From: Peter Bloomfield <bloomfld eos ncsu edu>
- To: balsa-list gnome org
- Subject: Combine duplicate IMAP INBOX nodes
- Date: Wed, 20 Jun 2001 18:56:35 -0400
Balsa-1.1.6 puts two INBOX nodes in the IMAP tree (at least for my Cyrus
server). This results from the way libmutt's imap_browse() handles
namespaces. The attached patch (against version 1.1.6) eliminates the
duplication.
Add_imap_folder() is changed only in checking whether a node with the given
name already exists. Add_imap_mailbox() has changed more substantially. It
first uses add_imap_folder() to get a node with the right name, which might
be new or old. It then creates and attaches a mailbox, if the node didn't
already have one. This should work regardless of whether the two INBOXes
are both mailboxes (as in Brian Stafford's case) or one is a folder and one
a mailbox (my case). Add_imap_entry() is now never called with a non-null
mailbox argument, so the argument is removed.
All comments and suggestions welcome, as always.
diff -Nur balsa-uninit/src/mailbox-node.c balsa-work/src/mailbox-node.c
--- balsa-uninit/src/mailbox-node.c Wed Jun 20 15:12:05 2001
+++ balsa-work/src/mailbox-node.c Wed Jun 20 18:20:12 2001
@@ -744,27 +744,23 @@
return d[1] ? d[1] : root;
}
-static GNode* add_imap_entry(GNode*root, const char* fn,
- LibBalsaMailboxImap* mailbox, char delim)
+static GNode* add_imap_entry(GNode*root, const char* fn, char delim)
{
GNode* parent;
BalsaMailboxNode* mbnode;
+ const gchar *basename;
gchar * parent_name = get_parent_folder_name(fn, delim);
parent = get_parent_by_name(root, parent_name);
g_free(parent_name);
g_return_val_if_fail(parent, NULL);
- if(mailbox)
- mbnode =
- balsa_mailbox_node_new_from_mailbox(LIBBALSA_MAILBOX(mailbox));
- else {
- const gchar *basename = strrchr(fn, delim);
- if(!basename) basename = fn;
- else basename++;
- mbnode = balsa_mailbox_node_new();
- mbnode->name = g_strdup(basename);
- }
+
+ basename = strrchr(fn, delim);
+ if(!basename) basename = fn;
+ else basename++;
+ mbnode = balsa_mailbox_node_new();
+ mbnode->name = g_strdup(basename);
mbnode->dir = g_strdup(fn);
return g_node_append(parent, g_node_new(mbnode));
}
@@ -782,6 +778,8 @@
{
LibBalsaMailboxImap* m;
const gchar *basename;
+ GNode *node;
+ BalsaMailboxNode* mbnode;
basename = strrchr(fn, delim);
if(!basename) basename = fn;
@@ -791,22 +789,47 @@
return NULL;
}
+ node = add_imap_folder(root, fn, delim);
+ if (!node)
+ /* add_imap_entry failed */
+ return NULL;
+
+ mbnode = BALSA_MAILBOX_NODE(node->data);
+ g_return_val_if_fail(mbnode, NULL);
+ if (mbnode->mailbox)
+ /* a mailbox of this name already exists */
+ return node;
+
m = LIBBALSA_MAILBOX_IMAP(libbalsa_mailbox_imap_new());
libbalsa_mailbox_remote_set_server(
LIBBALSA_MAILBOX_REMOTE(m), BALSA_MAILBOX_NODE(root->data)->server);
- m->path = g_strdup(fn);
+ m->path = g_strdup(fn); /* FIXME: this is the same as mbnode->dir! */
if(balsa_app.debug)
printf("add_imap_mailbox: Adding mailbox of name %s (full path %s)\n",
basename, fn);
- LIBBALSA_MAILBOX(m)->name = g_strdup(basename);
- return add_imap_entry(root, fn, m, delim);
+ LIBBALSA_MAILBOX(m)->name = mbnode->name;
+ mbnode->name = NULL; /* Avoids another g_strdup */
+ mbnode->mailbox = LIBBALSA_MAILBOX(m);
+ gtk_signal_connect(GTK_OBJECT(mbnode), "show-prop-dialog",
+ mailbox_conf_edit, NULL);
+
+ return node;
}
static GNode*
add_imap_folder(GNode*root, const char* fn, char delim)
{
+ GNode *node;
+
if(balsa_app.debug)
printf("add_imap_folder: Adding folder of path %s\n", fn);
- return add_imap_entry(root, fn, NULL, delim);
+
+ /* `get_parent_by_name' should be `get_node_by_name'! */
+ node = get_parent_by_name(root, fn);
+ if (node != root)
+ /* a folder of this name already exists */
+ return node;
+
+ return add_imap_entry(root, fn, delim);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]