[evolution-patches] NNTP one-liners



Hello,

Some minor changes to NNTP-related code, basically just what Not Zed and Jeffrey suggested, and a small bugfix for a problem I found myself.

Soms remarks still:

Not Zed wrote:

@@ -285,14 +484,26 @@
static void
nntp_folder_class_init (CamelNNTPFolderClass *camel_nntp_folder_class) { + CamelDiscoFolderClass *camel_disco_folder_class = CAMEL_DISCO_FOLDER_CLASS (camel_nntp_folder_class); CamelFolderClass *camel_folder_class = CAMEL_FOLDER_CLASS (camel_nntp_folder_class); - parent_class = CAMEL_FOLDER_CLASS (camel_type_get_global_classfuncs (camel_folder_get_type ())); + parent_class = CAMEL_DISCO_FOLDER_CLASS (camel_type_get_global_classfuncs (camel_disco_folder_get_type ())); + folder_class = CAMEL_FOLDER_CLASS (camel_type_get_global_classfuncs (camel_folder_get_type ()));

This is a hangover from older code, you only need to call

folder_class = (CamelFolderClass *)camel_folder_get_type();

Actually you only need to get the parent class anyway,
CameDiscoFolderClass.  You shouldn't access CamelFolderClass that way.

So I do

disco_folder_class = (CamelDiscoFolderClass *)camel_disco_folder_get_type();

as well? And how should I override CamelFolderClass functions then?

Still need an answer to that...

+static CamelFolderInfo *
+nntp_store_get_subscribed_folder_info(CamelNNTPStore *store, const char *top, guint flags, CamelException *ex)

+{
+    CamelURL *url = CAMEL_SERVICE (store)->url;
+    int i;
+    CamelStoreInfo *si;
+    CamelFolderInfo *first = NULL, *last = NULL, *fi = NULL;
+
+ /* since we do not do a tree, any request that is not for root is sure to give no results */

+    if (top != NULL && top[0] != 0) return NULL;

You should actually be able to do get_folder_info("news.group") and get
back 'news.group' (if it exists).

Well, I used IMAP's "totally on crack" (quoting from em-folder-tree.c) method of only returning children wich seemed to work okay... So, when you do a (recursive) get_folder_info for NULL you would also need to add the top item? Em-folder-tree doesn't seem to do this, so I patched it. The folder tree also still missed support for resursive, non-subscribed folder info (not that anyone with a sane mind would want that...).

+    /* compile the name */
+    char *caption, *tmp, *tmp2;
+    gboolean post_custom;
+
+    if (hdrs->priv->post_to.entry == NULL) return;
+
+    caption = g_strdup("");
+
+    while (urls) {
+        tmp = folder_name_to_string(hdrs, (char *)urls->data);

How does this work with imap/other store's folder names?

+{

In the Post-to header view, relative names just have the part of the path URL that's the same as the store's URL cut off, and when they're converted back to absolute, it's appended again. So I guess when you have a provider that puts the path in the '#bla' portion of the URL, the field will show '#bla' rather than just bla.

From what I understand of it, the right thing to do would be to look up the store->provider, and find out its url_flags, and if its CAMEL_URL_FRAGMENT_IS_PATH use the fragment, and otherwise use the path for the string representation. And looking at some implementations of camelstore->url_equals(), that function checks whether a given folder belongs to the store (couldn't find it documented anywhere)?

+get_reply_sender (CamelMimeMessage *message, CamelInternetAddress **to, const char **postto)

{
    const CamelInternetAddress *reply_to;
-    const char *name, *addr;
+    const char *name, *addr, *posthdr;
    int i;
+ /* check whether there is a 'Newsgroups: ' header in there */ + posthdr = camel_medium_get_header (CAMEL_MEDIUM(message), "Newsgroups");
+    if (posthdr && postto) {
+        *postto = posthdr;
+        while (**postto == ' ') (*postto)++;

Should postto be a list of addresses?  I presume at the moment it is
taken as a space-separated string list of addresses?

A comma-separated list actually; this code removes spaces in front of the header (shouldn't be nessecary anymore though...) The composer_hdrs_set_post_to_base splits it up.

+    if (posthdr && postto) {
+        *postto = posthdr;
+        while (**postto == ' ') (*postto)++;

This looks familiar.  Any way to reuse the code?  Should probably have
a camel-mime-utils function to parse the newgroups header into a list
of newsgroups.

We have a CamelNewsAddress class which cam be used like the
CamelInternetAddress 'to' and 'cc' addresses, to store a list of
addresses (newgroups).  Perhaps that should be finished/used
everwhere, rather than strings (but it might need a lot of work yet).

Last time I looked at it, it was pretty much empty :)

I'm not sure this will really help; this header-retrieval code is pretty much the only code that is really NNTP-specific, the rest of it is generic posting code (that is, it is used for non-news purposes as well). Maybe a CamelPostAddress is a good idea though.

Btw the "while (**postto == ' ') (*postto)++;" portion was not actually nessecary anymore...


Jeffrey Stedfast wrote:

(... stylistic fixes...)

Fixed those

+	if (camel_store_summary_load((CamelStoreSummary *)nntp_store->summary) == 0);
what's up with that if-statement?

Think I wanted to put some kind of check in it, but don't think that's nessecary anymore.

+	/* check whether there is a 'Newsgroups: ' header in there */
+	posthdr = camel_medium_get_header (CAMEL_MEDIUM(message),
"Newsgroups");
+	if (posthdr && postto) {
+		*postto = posthdr;
+		while (**postto == ' ') (*postto)++;
+		return;
+ } +

that seems like a waste? is that return supposed to really be there?

Yes, this is from the get_reply_sender function, and if there are newsgroups, we should reply to them rather than to the e-mail address of the sender.


Meilof
-- meilof wanadoo nl

--- /home/meilof/tmp/evolution//camel/ChangeLog	2004-01-14 00:41:49.000000000 +0100
+++ camel/ChangeLog	2004-01-14 14:14:46.000000000 +0100
@@ -1,3 +1,18 @@
+2004-01-14  Meilof Veeningen  <meilof wanadoo nl>
+
+	* providers/nntp/camel-nntp-folder.c: support for working without a
+	cache, object state files
+
+	* providers/nntp/camel-nntp-store.c: support for working without a
+	cache, support for looking up non-root subscribed folders, support for
+	recursive unsubscribed folder listings
+
+	* providers/nntp/camel-nntp-store-summary.[ch]: removed some
+	imap-specific code
+
+	* providers/nntp/camel-nntp-summary.c: work without cache
+
+
 2004-01-12  Meilof Veeningen  <meilof wanadoo nl>
 
 	* providers/nntp/camel-nntp-folder.[ch]: now based on discofolder,
--- /home/meilof/tmp/evolution//mail/ChangeLog	2004-01-14 00:39:54.000000000 +0100
+++ mail/ChangeLog	2004-01-14 14:21:43.000000000 +0100
@@ -1,3 +1,12 @@
+2004-01-14  Meilof Veeningen  <meilof wanadoo nl>
+
+	* em-folder-selection-button.c
+	(em_folder_selection_button_set_selection_mult): use gstring rather
+	than char*
+
+	* em-folder-tree.c (em_folder_tree_set_selected): use "" rather than
+	NULL for get_folder_info top (needed for check in folder_info__got)
+
 2004-01-12  Meilof Veeningen  <meilof wanadoo nl>
 
 	* em-composer-utils.c: support for posting both to mail and to
--- /home/meilof/tmp/evolution//composer/ChangeLog	2004-01-14 00:40:05.000000000 +0100
+++ composer/ChangeLog	2004-01-14 14:24:33.000000000 +0100
@@ -1,3 +1,9 @@
+2004-01-14  Meilof Veeningen  <meilof wanadoo nl>
+
+	* e-msg-composer-hdrs.c: fix to make relative folder names work
+	if the store url does not end with a slash, use gstring rather
+	than char* in some places.
+
 2004-01-12  JP Rosevear  <jpr ximian com>
 
 	* e-msg-composer-hdrs.c (e_msg_composer_hdrs_set_post_to): fix
--- /home/meilof/tmp/evolution//camel/providers/nntp/camel-nntp-folder.c	2004-01-14 00:39:27.000000000 +0100
+++ camel/providers/nntp/camel-nntp-folder.c	2004-01-14 14:08:17.000000000 +0100
@@ -79,7 +79,9 @@
 	
 	if (camel_nntp_summary_check ((CamelNNTPSummary *) folder->summary, nntp_folder->changes, ex) != -1)
 		camel_folder_summary_save (folder->summary);
-	
+
+	camel_object_state_write (folder);
+
 	if (camel_folder_change_info_changed(nntp_folder->changes)) {
 		changes = nntp_folder->changes;
 		nntp_folder->changes = camel_folder_change_info_new();
@@ -96,6 +98,7 @@
 static void
 nntp_folder_sync_offline (CamelFolder *folder, CamelException *ex)
 {
+	camel_object_state_write (folder);
 	camel_folder_summary_save (folder->summary);
 }
 
@@ -112,17 +115,18 @@
 	CamelStream *stream = NULL;
 	int ret;
 	char *line;
-	
+
 	if (camel_nntp_store_set_folder (nntp_store, (CamelFolder *) nntp_folder, nntp_folder->changes, ex) == -1)
 		return NULL;
-	
+
 	ret = camel_nntp_command (nntp_store, &line, "article %s", msgid);
 	if (ret == -1)
 		goto fail;
-	
+
 	if (ret == 220) {
-		stream = camel_data_cache_add (nntp_store->cache, "cache", msgid, NULL);
-		if (stream) {
+
+		if (nntp_store->cache &&
+		    (stream = camel_data_cache_add (nntp_store->cache, "cache", msgid, NULL)) != NULL) {
 			if (camel_stream_write_to_stream ((CamelStream *) nntp_store->stream, stream) == -1)
 				goto fail;
 			if (camel_stream_reset (stream) == -1)
@@ -132,15 +136,15 @@
 			camel_object_ref (stream);
 		}
 	}
-	
+
 	return stream;
-	
+
  fail:
 	if (errno == EINTR)
 		camel_exception_setv (ex, CAMEL_EXCEPTION_USER_CANCEL, _("User cancelled"));
 	else
 		camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, _("Cannot get message %s: %s"), msgid, g_strerror (errno));
-	
+
 	return NULL;
 }
 
@@ -151,16 +155,16 @@
 	CamelNNTPStore *nntp_store = (CamelNNTPStore *)((CamelFolder *) disco_folder)->parent_store;
 	CamelStream *stream;
 	const char *msgid;
-	
+
 	if (!(msgid = strchr (uid, ','))) {
 		camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
 				      _("Internal error: uid in invalid format: %s"), uid);
 		return;
 	}
 	msgid++;
-	
+
 	CAMEL_NNTP_STORE_LOCK(nntp_store, command_lock);
-	
+
 	stream = nntp_folder_download_message ((CamelNNTPFolder *) disco_folder, msgid, ex);
 	if (stream) {
 		camel_object_unref (stream);
@@ -169,7 +173,7 @@
 		camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE,
 				      _("Could not get article %s from NNTP server"), uid);
 	}
-	
+
 	CAMEL_NNTP_STORE_UNLOCK(nntp_store, command_lock);
 }
 
@@ -198,19 +202,19 @@
 	msgid++;
 	
 	/* Lookup in cache, NEWS is global messageid's so use a global cache path */
-	stream = camel_data_cache_get (nntp_store->cache, "cache", msgid, NULL);
-	if (stream == NULL) {
+	if (nntp_store->cache == NULL ||
+	    (stream = camel_data_cache_get (nntp_store->cache, "cache", msgid, NULL)) == NULL) {
 		if (camel_disco_store_status ((CamelDiscoStore *) nntp_store) == CAMEL_DISCO_STORE_OFFLINE) {
 			camel_exception_set (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE,
 					     _("This message is not currently available"));
 			goto fail;
 		}
-		
+
 		stream = nntp_folder_download_message (nntp_folder, msgid, ex);
 		if (stream == NULL)
 			goto fail;
 	}
-	
+
 	if (stream) {
 		message = camel_mime_message_new ();
 		if (camel_data_wrapper_construct_from_stream ((CamelDataWrapper *) message, stream) == -1)
@@ -292,7 +296,7 @@
 	summary = g_ptr_array_new ();
 	for (i = 0; i < uids->len; i++) {
 		CamelMessageInfo *info;
-		
+
 		if ((info = camel_folder_get_message_info (folder, uids->pdata[i])))
 			g_ptr_array_add (summary, info);
 	}
@@ -577,7 +581,7 @@
 {
 	CamelFolder *folder;
 	CamelNNTPFolder *nntp_folder;
-	char *root;
+	char *filename;
 	CamelService *service;
 #ifdef ASYNC_SUMMARY
 	struct _folder_check_msg *m;
@@ -586,22 +590,27 @@
 	gboolean subscribed = TRUE;
 	
 	service = (CamelService *) parent;
-	root = camel_session_get_storage_path (service->session, service, ex);
-	if (root == NULL)
+	filename = camel_session_get_storage_path (service->session, service, ex);
+	if (filename == NULL)
 		return NULL;
-	
+
 	/* If this doesn't work, stuff wont save, but let it continue anyway */
-	camel_mkdir (root, 0777);
-	
+	camel_mkdir (filename, 0777);
+
 	folder = (CamelFolder *) camel_object_new (CAMEL_NNTP_FOLDER_TYPE);
 	nntp_folder = (CamelNNTPFolder *)folder;
-	
+
 	camel_folder_construct (folder, parent, folder_name, folder_name);
 	folder->folder_flags |= CAMEL_FOLDER_HAS_SUMMARY_CAPABILITY|CAMEL_FOLDER_HAS_SEARCH_CAPABILITY;
 	
-	nntp_folder->storage_path = g_build_filename (root, folder->full_name, NULL);
-	g_free (root);
-	
+	nntp_folder->storage_path = g_build_filename (filename, folder->full_name, NULL);
+	g_free (filename);
+
+	filename = g_strdup_printf ("%s.cmeta", nntp_folder->storage_path);
+	camel_object_set (folder, NULL, CAMEL_OBJECT_STATE_FILE, filename, NULL);
+	camel_object_state_read (folder);
+	g_free (filename);
+
 	folder->summary = (CamelFolderSummary *) camel_nntp_summary_new (nntp_folder);
 	camel_folder_summary_load (folder->summary);
 	
--- /home/meilof/tmp/evolution//camel/providers/nntp/camel-nntp-store.c	2004-01-14 00:39:28.000000000 +0100
+++ camel/providers/nntp/camel-nntp-store.c	2004-01-14 14:10:14.000000000 +0100
@@ -102,22 +102,23 @@
 	/* setup store-wide cache */
 	if (store->cache == NULL) {
 		if (store->storage_path == NULL)
-			goto fail;
-		
+			goto cache_done;
+
 		store->cache = camel_data_cache_new (store->storage_path, 0, ex);
 		if (store->cache == NULL)
-			goto fail;
-		
+			goto cache_done;
+
 		/* Default cache expiry - 2 weeks old, or not visited in 5 days */
 		camel_data_cache_set_expire_age (store->cache, 60*60*24*14);
 		camel_data_cache_set_expire_access (store->cache, 60*60*24*5);
 	}
-	
+
+ cache_done:
 	if (!(h = camel_service_gethost (service, ex)))
 		goto fail;
-	
+
 	port = service->url->port ? service->url->port : NNTP_PORT;
-	
+
 #ifdef HAVE_SSL
 	if (ssl_mode != USE_SSL_NEVER) {
 		port = service->url->port ? service->url->port : NNTPS_PORT;
@@ -128,7 +129,7 @@
 #else
 	tcp_stream = camel_tcp_stream_raw_new ();
 #endif /* HAVE_SSL */
-	
+
 	ret = camel_tcp_stream_connect (CAMEL_TCP_STREAM (tcp_stream), h, port);
 	camel_free_host (h);
 	if (ret == -1) {
@@ -139,15 +140,15 @@
 			camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE,
 					      _("Could not connect to %s (port %d): %s"),
 					      service->url->host, port, g_strerror (errno));
-		
+
 		camel_object_unref (tcp_stream);
-		
+
 		goto fail;
 	}
-	
+
 	store->stream = (CamelNNTPStream *) camel_nntp_stream_new (tcp_stream);
 	camel_object_unref (tcp_stream);
-	
+
 	/* Read the greeting, if any. */
 	if (camel_nntp_stream_line (store->stream, &buf, &len) == -1) {
 		if (errno == EINTR)
@@ -172,14 +173,14 @@
 		
 		camel_object_unref (store->stream);
 		store->stream = NULL;
-		
+
 		goto fail;
 	}
 	
 	/* set 'reader' mode & ignore return code */
 	if (camel_nntp_command (store, (char **) &buf, "mode reader") < 0 ||
 	/* hack: inn seems to close connections if nothing is done within
-	   the first ten seconds. a non-existent command is enough though */
+	   the first ten seconds, so we do some pseudo-useful command */
 	    camel_nntp_command (store, (char **) &buf, "date") < 0)
 	    goto fail;
 	
@@ -259,18 +260,18 @@
 	/* setup store-wide cache */
 	if (nntp_store->cache == NULL) {
 		nntp_store->cache = camel_data_cache_new (nntp_store->storage_path, 0, ex);
-		if (nntp_store->cache == NULL)
-			return FALSE;
-		
-		/* Default cache expiry - 2 weeks old, or not visited in 5 days */
-		camel_data_cache_set_expire_age (nntp_store->cache, 60*60*24*14);
-		camel_data_cache_set_expire_access (nntp_store->cache, 60*60*24*5);
-	}	
-	
+
+		if (nntp_store->cache != NULL) {
+			/* Default cache expiry - 2 weeks old, or not visited in 5 days */
+			camel_data_cache_set_expire_age (nntp_store->cache, 60*60*24*14);
+			camel_data_cache_set_expire_access (nntp_store->cache, 60*60*24*5);
+		}
+	}
+
 	path = g_build_filename (nntp_store->storage_path, ".ev-journal", NULL);
 	disco_store->diary = camel_disco_diary_new (disco_store, path, ex);
 	g_free (path);
-	
+
 	if (!disco_store->diary)
 		return FALSE;
 	
@@ -308,7 +309,7 @@
 	
 	if (!service_class->disconnect (service, clean, ex))
 		return FALSE;
-	
+
 	if (disco->diary) {
 		camel_object_unref (disco->diary);
 		disco->diary = NULL;
@@ -466,12 +467,31 @@
 {
 	int i;
 	CamelStoreInfo *si;
-	CamelFolderInfo *first = NULL, *last = NULL, *fi = NULL;
-	
-	/* since we do not do a tree, any request that is not for root is sure to give no results */
-	if (top != NULL && top[0] != 0)
+	CamelFolderInfo *root, *first = NULL, *last = NULL, *fi = NULL;
+
+	if (flags & CAMEL_STORE_FOLDER_INFO_RECURSIVE) {
+		/* for recursive queries, the item itself should be added */
+		if (top && top[0] != 0) {
+			si = (CamelStoreInfo *) camel_nntp_store_summary_full_name (store->summary, top);
+			if (si) {
+				if (si->flags & CAMEL_STORE_INFO_FOLDER_SUBSCRIBED)
+					root = nntp_folder_info_from_store_info (store, store->do_short_folder_notation, si);
+				camel_store_summary_info_free ((CamelStoreSummary *) store->summary, si);
+			}
+		}
+
+		if (!root) {
+			root = nntp_folder_info_from_name (store, store->do_short_folder_notation, top ? top : "");
+			root->flags |= CAMEL_FOLDER_NOSELECT;
+		}
+	}
+
+	if (top != NULL && top[0] != 0) {
+		/* no subitems for sure */
 		return NULL;
-	
+	}
+
+
 	for (i=0;(si = camel_store_summary_index ((CamelStoreSummary *) store->summary, i));i++) {
 		if (si->flags & CAMEL_STORE_INFO_FOLDER_SUBSCRIBED) {
 			fi = nntp_folder_info_from_store_info (store, store->do_short_folder_notation, si);
@@ -486,8 +506,42 @@
 		}
 		camel_store_summary_info_free ((CamelStoreSummary *) store->summary, si);
 	}
-	
-	return first;
+
+	if (!(flags & CAMEL_STORE_FOLDER_INFO_RECURSIVE))
+		return first;
+
+	root->child = first;
+	return root;
+}
+
+static CamelFolderInfo *
+nntp_folder_list_hierarchical (CamelNNTPStore *store, CamelFolderInfo *first, char *top)
+{
+	GPtrArray *arr = g_ptr_array_new();
+	CamelFolderInfo *cur;
+	CamelStoreInfo *si;
+
+	if (top != NULL) {
+		/* check to see whether top exists */
+		cur = nntp_folder_info_from_name (store, FALSE,
+		         (store->folder_hierarchy_relative || top == NULL) ? "" : top);
+		si = (CamelStoreInfo *) camel_nntp_store_summary_full_name (store->summary, top);
+		if (si)
+			camel_store_summary_info_free ((CamelStoreSummary *) store->summary, si);
+		else
+			cur->flags |= CAMEL_FOLDER_NOSELECT;
+		g_ptr_array_add (arr, cur);
+	}
+
+	while (first) {
+		g_ptr_array_add (arr, first);
+		first = first->sibling;
+	}
+
+	cur = camel_folder_info_build (arr, NULL, '.', store->folder_hierarchy_relative);
+	g_ptr_array_free (arr, FALSE);
+
+	return cur;
 }
 
 /*
@@ -553,7 +607,11 @@
 	}
 	
 	g_free(top);
-	return first;
+
+	if (recursive_flag)
+		return nntp_folder_list_hierarchical (store, first, top);
+	else
+		return first;
 }
 
 /* retrieves the date from the NNTP server */
@@ -1057,8 +1115,11 @@
 			;
 	}
 	camel_nntp_stream_set_mode(store->stream, CAMEL_NNTP_STREAM_LINE);
-	
- command_begin_send:
+
+	camel_stream_reset ((CamelStream *) store->mem);
+	/* FIXME: hack */
+	g_byte_array_set_size (store->mem->buffer, 0);
+
 	va_start(ap, fmt);
 	ps = p = fmt;
 	while ((c = *p++)) {
@@ -1098,47 +1159,46 @@
 			}
 		}
 	}
-	
+
 	camel_stream_write ((CamelStream *) store->mem, ps, p-ps-1);
 	dd(printf("NNTP_COMMAND: '%.*s'\n", (int)store->mem->buffer->len, store->mem->buffer->data));
 	camel_stream_write ((CamelStream *) store->mem, "\r\n", 2);
-	
-	if (camel_stream_write ((CamelStream *) store->stream, store->mem->buffer->data, store->mem->buffer->len) == -1 && errno != EINTR) {
-		camel_stream_reset ((CamelStream *) store->mem);
-		/* FIXME: hack */
-		g_byte_array_set_size (store->mem->buffer, 0);
-		
-	reconnect:
-		/* some error, re-connect */
-		camel_service_disconnect (CAMEL_SERVICE (store), FALSE, NULL);
-		
-		if (!nntp_connected (store, NULL))
+
+	while (1) {
+		dd(printf("NNTP_COMMAND: '%.*s'\n", (int)store->mem->buffer->len, store->mem->buffer->data));
+		if (camel_stream_write ((CamelStream *) store->stream, store->mem->buffer->data, store->mem->buffer->len) == -1
+		    && errno != EINTR) {
+reconnect:
+			/* some error, re-connect */
+			camel_service_disconnect (CAMEL_SERVICE (store), FALSE, NULL);
+
+			if (!nntp_connected (store, NULL))
+				return -1;
+
+			continue;
+		}
+
+		if (camel_nntp_stream_line (store->stream, (unsigned char **) line, &u) == -1)
 			return -1;
-		
-		goto command_begin_send;
+
+		u = strtoul (*line, NULL, 10);
+
+		/* Check for 'authentication required' codes */
+		if (u == NNTP_AUTH_REQUIRED &&
+		    camel_nntp_try_authenticate (store))
+			continue;
+
+		/* the server doesn't like us anymore, but we still like her! */
+		if (u == 401 || u == 503)
+			goto reconnect;
+
+		/* success */
+		break;
 	}
-	
-	camel_stream_reset ((CamelStream *) store->mem);
-	/* FIXME: hack */
-	g_byte_array_set_size (store->mem->buffer, 0);
-	
-	if (camel_nntp_stream_line (store->stream, (unsigned char **) line, &u) == -1)
-		return -1;
-	
-	u = strtoul (*line, NULL, 10);
-	
-	/* Check for 'authentication required' codes */
-	if (u == NNTP_AUTH_REQUIRED &&
-	    camel_nntp_try_authenticate(store))
-		goto command_begin_send;
-	
-	/* the server doesn't like us anymore, but we still like her! */
-	if (u == 401 || u == 503)
-		goto reconnect;
-	
+
 	/* Handle all switching to data mode here, to make callers job easier */
 	if (u == 215 || (u >= 220 && u <=224) || (u >= 230 && u <= 231))
 		camel_nntp_stream_set_mode(store->stream, CAMEL_NNTP_STREAM_DATA);
-	
+
 	return u;
 }
--- /home/meilof/tmp/evolution//camel/providers/nntp/camel-nntp-store-summary.c	2004-01-12 23:20:40.000000000 +0100
+++ camel/providers/nntp/camel-nntp-store-summary.c	2004-01-14 13:42:07.000000000 +0100
@@ -87,10 +87,6 @@
 static void
 camel_nntp_store_summary_init (CamelNNTPStoreSummary *s)
 {
-	/*struct _CamelNNTPStoreSummaryPrivate *p;
-
-	  p = _PRIVATE(s) = g_malloc0(sizeof(*p));*/
-
 	((CamelStoreSummary *) s)->store_info_size = sizeof (CamelNNTPStoreInfo);
 	s->version = CAMEL_NNTP_STORE_SUMMARY_VERSION;
 	memset (&s->last_newslist, 0, sizeof (s->last_newslist));
@@ -99,11 +95,6 @@
 static void
 camel_nntp_store_summary_finalise (CamelObject *obj)
 {
-	/*struct _CamelNNTPStoreSummaryPrivate *p;*/
-	/*CamelNNTPStoreSummary *s = (CamelNNTPStoreSummary *)obj;*/
-
-	/*p = _PRIVATE(obj);
-	  g_free(p);*/
 }
 
 CamelType
@@ -121,7 +112,7 @@
 					   (CamelObjectInitFunc) camel_nntp_store_summary_init,
 					   (CamelObjectFinalizeFunc) camel_nntp_store_summary_finalise);
 	}
-	
+
 	return type;
 }
 
@@ -157,7 +148,7 @@
 {
 	int count, i;
 	CamelNNTPStoreInfo *info;
-	
+
 	count = camel_store_summary_count ((CamelStoreSummary *) s);
 	for (i = 0; i < count; i++) {
 		info = (CamelNNTPStoreInfo *)camel_store_summary_index ((CamelStoreSummary *) s, i);
@@ -167,150 +158,8 @@
 			camel_store_summary_info_free ((CamelStoreSummary *) s, (CamelStoreInfo *)info);
 		}
 	}
-	
-	return NULL;
-}
 
-char *
-camel_nntp_store_summary_full_to_path (CamelNNTPStoreSummary *s, const char *full_name, char dir_sep)
-{
-	char *path, *p;
-	int c;
-	const char *f;
-
-	if (dir_sep != '/') {
-		p = path = g_alloca (strlen (full_name) * 3 + 1);
-		f = full_name;
-		while ((c = *f++ & 0xff)) {
-			if (c == dir_sep)
-				*p++ = '/';
-			else if (c == '/' || c == '%')
-				p += sprintf (p, "%%%02X", c);
-			else
-				*p++ = c;
-		}
-		*p = 0;
-	} else
-		path = (char *) full_name;
-	
-	return camel_utf7_utf8 (path);
-}
-
-static guint32
-hexnib (guint32 c)
-{
-	if (c >= '0' && c <= '9')
-		return c-'0';
-	else if (c >= 'A' && c <= 'Z')
-		return c - 'A' + 10;
-	else
-		return 0;
-}
-
-char *
-camel_nntp_store_summary_path_to_full (CamelNNTPStoreSummary *s, const char *path, char dir_sep)
-{
-	unsigned char *full, *f;
-	guint32 c, v = 0;
-	const char *p;
-	int state=0;
-	char *subpath, *last = NULL;
-	CamelStoreInfo *si;
-	
-	/* check to see if we have a subpath of path already defined */
-	subpath = g_alloca (strlen (path) + 1);
-	strcpy (subpath, path);
-	do {
-		si = camel_store_summary_path ((CamelStoreSummary *) s, subpath);
-		if (si == NULL) {
-			last = strrchr (subpath, '/');
-			if (last)
-				*last = 0;
-		}
-	} while (si == NULL && last);
-	
-	/* path is already present, use the raw version we have */
-	if (si && strlen (subpath) == strlen (path)) {
-		f = g_strdup (camel_nntp_store_info_full_name (s, si));
-		camel_store_summary_info_free ((CamelStoreSummary *) s, si);
-		return f;
-	}
-	
-	f = full = g_alloca (strlen (path)*2+1);
-	if (si)
-		p = path + strlen (subpath);
-	else
-		p = path;
-	
-	while ((c = camel_utf8_getc ((const unsigned char **) &p))) {
-		switch (state) {
-		case 0:
-			if (c == '%') {
-				state = 1;
-			} else {
-				if (c == '/')
-					c = dir_sep;
-				camel_utf8_putc(&f, c);
-			}
-			break;
-		case 1:
-			state = 2;
-			v = hexnib (c) << 4;
-			break;
-		case 2:
-			state = 0;
-			v |= hexnib (c);
-			camel_utf8_putc (&f, v);
-			break;
-		}
-	}
-	camel_utf8_putc (&f, c);
-	
-	/* merge old path part if required */
-	f = camel_utf8_utf7 (full);
-	if (si) {
-		full = g_strdup_printf ("%s%s", camel_nntp_store_info_full_name (s, si), f);
-		g_free (f);
-		camel_store_summary_info_free ((CamelStoreSummary *) s, si);
-		f = full;
-	}
-	
-	return f;
-}
-
-CamelNNTPStoreInfo *
-camel_nntp_store_summary_add_from_full (CamelNNTPStoreSummary *s, const char *full, char dir_sep)
-{
-	CamelNNTPStoreInfo *info;
-	char *pathu8;
-	int len;
-	char *full_name;
-	
-	d(printf("adding full name '%s' '%c'\n", full, dir_sep));
-	
-	len = strlen (full);
-	full_name = g_alloca (len+1);
-	strcpy(full_name, full);
-	if (full_name[len-1] == dir_sep)
-		full_name[len-1] = 0;
-	
-	info = camel_nntp_store_summary_full_name (s, full_name);
-	if (info) {
-		camel_store_summary_info_free ((CamelStoreSummary *) s, (CamelStoreInfo *) info);
-		d(printf("  already there\n"));
-		return info;
-	}
-	
-	pathu8 = camel_nntp_store_summary_full_to_path (s, full_name, dir_sep);
-	
-	info = (CamelNNTPStoreInfo *) camel_store_summary_add_from_path ((CamelStoreSummary *) s, pathu8);
-	if (info) {
-		d(printf("  '%s' -> '%s'\n", pathu8, full_name));
-		camel_store_info_set_string((CamelStoreSummary *)s, (CamelStoreInfo *)info, CAMEL_NNTP_STORE_INFO_FULL_NAME, full_name);
-	} else
-		d(printf("  failed\n"));
-	
-	return info;
+	return NULL;
 }
 
 static int
--- /home/meilof/tmp/evolution//camel/providers/nntp/camel-nntp-summary.c	2004-01-14 00:39:28.000000000 +0100
+++ camel/providers/nntp/camel-nntp-summary.c	2004-01-14 13:37:16.000000000 +0100
@@ -276,7 +276,7 @@
 					   a cached message that might be in another folder - not that important as
 					   it is a true cache */
 					msgid = strchr(uid, ',');
-					if (msgid)
+					if (msgid && store->cache)
 						camel_data_cache_remove(store->cache, "cache", msgid+1, NULL);
 					camel_folder_change_info_remove_uid(changes, uid);
 					camel_folder_summary_remove(s, mi);
--- /home/meilof/tmp/evolution//camel/providers/nntp/camel-nntp-store-summary.h	2004-01-12 23:20:40.000000000 +0100
+++ camel/providers/nntp/camel-nntp-store-summary.h	2004-01-14 13:41:01.000000000 +0100
@@ -71,27 +71,8 @@
 CamelType			 camel_nntp_store_summary_get_type	(void);
 CamelNNTPStoreSummary      *camel_nntp_store_summary_new	(void);
 
-/* TODO: this api needs some more work, needs to support lists */
-/*CamelNNTPStoreNamespace *camel_nntp_store_summary_namespace_new(CamelNNTPStoreSummary *s, const char *full_name, char dir_sep);*/
-/*void camel_nntp_store_summary_namespace_set(CamelNNTPStoreSummary *s, CamelNNTPStoreNamespace *ns);*/
-/*CamelNNTPStoreNamespace *camel_nntp_store_summary_namespace_find_path(CamelNNTPStoreSummary *s, const char *path);*/
-/*CamelNNTPStoreNamespace *camel_nntp_store_summary_namespace_find_full(CamelNNTPStoreSummary *s, const char *full_name);*/
-
-/* helper macro's */
-#define camel_nntp_store_info_full_name(s, i) (camel_store_info_string((CamelStoreSummary *)s, (const CamelStoreInfo *)i, CAMEL_NNTP_STORE_INFO_FULL_NAME))
-
-/* converts to/from utf8 canonical nasmes */
-char *camel_nntp_store_summary_full_to_path(CamelNNTPStoreSummary *s, const char *full_name, char dir_sep);
-
-char *camel_nntp_store_summary_path_to_full(CamelNNTPStoreSummary *s, const char *path, char dir_sep);
-char *camel_nntp_store_summary_dotted_to_full(CamelNNTPStoreSummary *s, const char *dotted, char dir_sep);
 
 CamelNNTPStoreInfo *camel_nntp_store_summary_full_name(CamelNNTPStoreSummary *s, const char *full_name);
-CamelNNTPStoreInfo *camel_nntp_store_summary_add_from_full(CamelNNTPStoreSummary *s, const char *full_name, char dir_sep);
-
-/* a convenience lookup function. always use this if path known */
-char *camel_nntp_store_summary_full_from_path(CamelNNTPStoreSummary *s, const char *path);
-
 
 #ifdef __cplusplus
 }
--- /home/meilof/tmp/evolution//composer/e-msg-composer-hdrs.c	2004-01-14 00:40:05.000000000 +0100
+++ composer/e-msg-composer-hdrs.c	2004-01-14 14:07:54.000000000 +0100
@@ -650,7 +650,7 @@
 static void
 set_pair_visibility (EMsgComposerHdrs *h, EMsgComposerHdrPair *pair, int visible)
 {
-	if (visible /*& h->visible_mask*/) {
+	if (visible) {
 		gtk_widget_show (pair->label);
 		gtk_widget_show (pair->entry);
 	} else {
@@ -1023,14 +1023,6 @@
 		eab_destination_freev (cc_destv);
 		eab_destination_freev (bcc_destv);
 	}
-	
-#if 0
-	if (hdrs->visible_mask & E_MSG_COMPOSER_VISIBLE_POSTTO) {
-		header = e_msg_composer_hdrs_get_post_to (hdrs);
-		camel_medium_set_header (CAMEL_MEDIUM (msg), "X-Evolution-PostTo", header);
-		g_free (header);
-	}
-#endif
 }
 
 
@@ -1165,12 +1157,12 @@
 				 const char *post_to)
 {
 	GList *list;
-	
+
 	g_return_if_fail (E_IS_MSG_COMPOSER_HDRS (hdrs));
 	g_return_if_fail (post_to != NULL);
-	
+
 	list = g_list_append (NULL, g_strdup (post_to));
-	
+
 	e_msg_composer_hdrs_set_post_to_list (hdrs, list);
 	
 	g_free (list->data);
@@ -1191,7 +1183,7 @@
 		
 		if (tmp[0])
 			lst = g_list_append (lst, g_strdup (tmp));
-		
+
 		cur_ptr++;
 	}
 	
@@ -1205,15 +1197,16 @@
 {
 	CamelURL *url;
 	char *ret = NULL;
-	
+
 	if (hdrs->account->source && hdrs->account->source->url) {
 		url = camel_url_new (hdrs->account->source->url, NULL);
+		camel_url_set_path (url, "/");
 		ret = camel_url_to_string (url, CAMEL_URL_HIDE_ALL);
 		camel_url_free (url);
 	}
-	
+
 	return ret;
-}                                            
+}
 
 static char *
 folder_name_to_string (EMsgComposerHdrs *hdrs, const char *uri)
@@ -1239,30 +1232,30 @@
 e_msg_composer_hdrs_set_post_to_list (EMsgComposerHdrs *hdrs, GList *urls)
 {
 	/* compile the name */
-	char *caption, *tmp, *tmp2;
+	GString *caption;
+	char *tmp;
 	gboolean post_custom;
-	
+
 	if (hdrs->priv->post_to.entry == NULL)
 		return;
-	
-	caption = g_strdup ("");
-	
+
+	caption = g_string_new("");
+
 	while (urls) {
-		tmp = folder_name_to_string (hdrs, (char *)urls->data);
+		tmp = folder_name_to_string (hdrs, (char *) urls->data);
 		if (tmp) {
-			tmp2 = g_strconcat (caption, ", ", tmp, NULL);
-			g_free (caption);
-			caption = tmp2;
+			g_string_append (caption, ", ");
+			g_string_append (caption, tmp);
 			g_free (tmp);
 		}
-		
 		urls = g_list_next (urls);
 	}
-	
+
 	post_custom = hdrs->priv->post_custom;
-	gtk_entry_set_text (GTK_ENTRY (hdrs->priv->post_to.entry), caption[0] ? caption + 2 : "");
+	gtk_entry_set_text (GTK_ENTRY (hdrs->priv->post_to.entry), caption->str[0] ? caption->str + 2 : "");
 	hdrs->priv->post_custom = post_custom;
-	g_free (caption);
+	g_string_free (caption, TRUE);
+
 }
 
 void
@@ -1270,34 +1263,35 @@
                                       const char *base, const char *post_to)
 {
 	GList *lst, *curlist;
-	char *hdr_copy = g_strdup (post_to), *caption, *tmp, *tmp2;
+	char *hdr_copy = g_strdup (post_to), *tmp, *tmp2;
 	gboolean post_custom;
-	
+	GString *caption;
+
 	/* split to newsgroup names */
 	lst = newsgroups_list_split (hdr_copy);
 	curlist = lst;
-	
+
 	/* compile the name */
-	caption = g_strdup ("");
-	
+	caption = g_string_new("");
+
 	while (curlist) {
-		tmp2 = g_strdup_printf ("%s/%s", base, (char *)curlist->data);
+		tmp2 = g_strdup_printf ("%s/%s", base, (char *) curlist->data);
 		tmp = folder_name_to_string (hdrs, tmp2);
 		g_free (tmp2);
+
 		if (tmp) {
-			tmp2 = g_strconcat (caption, ", ", tmp, NULL);
-			g_free (caption);
-			caption = tmp2;
+			g_string_append (caption, ", ");
+			g_string_append (caption, tmp);
 			g_free (tmp);
 		}
 		curlist = g_list_next (curlist);
 	}
-	
+
 	post_custom = hdrs->priv->post_custom;
-	gtk_entry_set_text (GTK_ENTRY (hdrs->priv->post_to.entry), caption[0] ? caption + 2 : "");
+	gtk_entry_set_text (GTK_ENTRY (hdrs->priv->post_to.entry), caption->str[0] ? caption->str + 2 : "");
 	hdrs->priv->post_custom = post_custom;
-	g_free (caption);
-	
+	g_string_free (caption, TRUE);
+
         g_list_foreach (lst, (GFunc) g_free, NULL);
 	g_list_free (lst);
 	g_free (hdr_copy);
--- /home/meilof/tmp/evolution//mail/em-folder-selection-button.c	2004-01-14 00:39:54.000000000 +0100
+++ mail/em-folder-selection-button.c	2004-01-14 13:53:49.000000000 +0100
@@ -268,43 +268,46 @@
 em_folder_selection_button_set_selection_mult (EMFolderSelectionButton *button, GList *uris)
 {
 	struct _EMFolderSelectionButtonPrivate *priv = button->priv;
-	char *caption, *tmp, *tmp2;
-	
+	char *tmp;
+	GList *uri_next;
+	GString *caption = NULL;
+
+
 	g_return_if_fail (EM_IS_FOLDER_SELECTION_BUTTON (button));
-	
+
 	if (priv->uris) {
 		g_list_foreach (priv->uris, (GFunc) g_free, NULL);
 		g_list_free (priv->uris);
 		priv->uris = NULL;
 	}
-	
+
 	priv->uris = uris;
-	
+
 	/* compile the name */
-	caption = g_strdup ("");
-	
+	caption = g_string_new ("");
+
 	while (uris) {
 		tmp = em_utils_folder_name_from_uri (uris->data);
 		if (tmp) {
-			tmp2 = g_strconcat (caption, ", ", tmp, NULL);
-			g_free (caption);
-			caption = tmp2;
+			g_string_append (caption, ", ");
+			g_string_append (caption, tmp);
 			g_free (tmp);
-			uris = uris->next;
+			uris = g_list_next (uris);
 		} else {
 			/* apparently, we do not know this folder, so we'll just skip it */
 			g_free (uris->data);
-			uris = g_list_next (uris);
-			priv->uris = g_list_remove (priv->uris, uris->data);
+			uri_next = g_list_next (uris);
+			priv->uris = g_list_remove_link (priv->uris, uris);
+			uris = uri_next;
 		}
 	}
-	
-	if (caption[0])
-		gtk_label_set_text (GTK_LABEL (priv->label), caption + 2);
+
+	if (caption->str[0])
+		gtk_label_set_text (GTK_LABEL (priv->label), caption->str + 2);
 	else
 		set_contents_unselected (button);
-	
-	g_free (caption);
+
+	g_string_free (caption, TRUE);
 }
 
 GList *
--- /home/meilof/tmp/evolution//mail/em-folder-tree.c	2004-01-14 00:39:54.000000000 +0100
+++ mail/em-folder-tree.c	2004-01-14 13:59:10.000000000 +0100
@@ -77,7 +77,7 @@
 	GList *lost_folders;
 	
 	guint save_state_id;
-	
+
 	guint loading_row_id;
 };
 
@@ -148,7 +148,7 @@
 em_folder_tree_get_type (void)
 {
 	static GType type = 0;
-	
+
 	if (!type) {
 		static const GTypeInfo info = {
 			sizeof (EMFolderTreeClass),
@@ -161,10 +161,10 @@
 			0,    /* n_preallocs */
 			(GInstanceInitFunc) em_folder_tree_init,
 		};
-		
+
 		type = g_type_register_static (GTK_TYPE_VBOX, "EMFolderTree", &info, 0);
 	}
-	
+
 	return type;
 }
 
@@ -173,12 +173,12 @@
 {
 	GObjectClass *object_class = G_OBJECT_CLASS (klass);
 	GtkObjectClass *gtk_object_class = GTK_OBJECT_CLASS (klass);
-	
+
 	parent_class = g_type_class_ref (GTK_TYPE_VBOX);
-	
+
 	object_class->finalize = em_folder_tree_finalize;
 	gtk_object_class->destroy = em_folder_tree_destroy;
-	
+
 	signals[FOLDER_SELECTED] =
 		g_signal_new ("folder-selected",
 			      G_OBJECT_CLASS_TYPE (object_class),
@@ -197,20 +197,20 @@
 {
 	unsigned int unread;
 	GtkTreeIter iter;
-	
+
 	if (!gtk_tree_model_iter_children (model, &iter, root))
 		return FALSE;
-	
+
 	do {
 		gtk_tree_model_get (model, &iter, COL_UINT_UNREAD, &unread, -1);
 		if (unread)
 			return TRUE;
-		
+
 		if (gtk_tree_model_iter_has_child (model, &iter))
 			if (subdirs_contain_unread (model, &iter))
 				return TRUE;
 	} while (gtk_tree_model_iter_next (model, &iter));
-	
+
 	return FALSE;
 }
 
@@ -285,7 +285,7 @@
 		display = g_strdup_printf ("%s (%u)", name, unread);
 	else
 		display = g_strdup (name);
-	
+
 	g_object_set (renderer, "text", display,
 		      "weight", bold ? PANGO_WEIGHT_BOLD : PANGO_WEIGHT_NORMAL,
 		      NULL);
@@ -372,7 +372,7 @@
 	
 	selection = gtk_tree_view_get_selection ((GtkTreeView *) tree);
 	gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
-	
+
 	gtk_tree_view_set_headers_visible ((GtkTreeView *) tree, FALSE);
 	
 	return (GtkTreeView *) tree;
@@ -659,7 +659,7 @@
 	
 	/* output data */
 	CamelFolderInfo *fi;
-	
+
 	/* uri to select if any after the op is done */
 	char *select_uri;
 };
@@ -1269,7 +1269,7 @@
 emft_selection_get_selected (GtkTreeSelection *selection, GtkTreeModel **model, GtkTreeIter *iter)
 {
 	struct _emft_selection_data dat = { NULL, iter, FALSE };
-	
+
 	if (gtk_tree_selection_get_mode (selection) == GTK_SELECTION_MULTIPLE) {
 		gtk_tree_selection_selected_foreach (selection, selfunc, &dat);
 		if (model)
@@ -1469,7 +1469,7 @@
 		if ((prop_data->argv->argv[i].tag & CAMEL_ARG_TYPE) == CAMEL_ARG_STR)
 			g_free (prop_data->argv->argv[i].ca_str);
 	}
-	
+
 	camel_object_unref (prop_data->object);
 	g_free (prop_data->argv);
 	g_free (prop_data);
@@ -1503,7 +1503,7 @@
 	w = gtk_frame_new (_("Properties"));
 	gtk_widget_show (w);
 	gtk_box_pack_start ((GtkBox *) ((GtkDialog *) dialog)->vbox, w, TRUE, TRUE, 6);
-	
+
 	table = gtk_table_new (g_slist_length (list) + 3, 2, FALSE);
 	gtk_widget_show (table);
 	gtk_container_add ((GtkContainer *) w, table);
@@ -1605,7 +1605,7 @@
 			g_assert_not_reached ();
 			break;
 		}
-		
+
 		row++;
 		l = l->next;
 	}
@@ -1707,7 +1707,7 @@
 	
 	gtk_tree_model_get (model, &iter, COL_STRING_FOLDER_PATH, &path,
 			    COL_STRING_URI, &uri, -1);
-	
+
 	g_free (priv->selected_uri);
 	priv->selected_uri = g_strdup (uri);
 	
@@ -1802,7 +1802,7 @@
 	m->root = gtk_tree_row_reference_copy (row);
 	m->store = store;
 	m->emft = emft;
-	m->top = top ? g_strdup (top) : NULL;
+	m->top = top ? g_strdup (top) : "";
 	m->flags = CAMEL_STORE_FOLDER_INFO_FAST | CAMEL_STORE_FOLDER_INFO_RECURSIVE;
 	m->select_uri = g_strdup (uri);
 	


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]