aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--camel/ChangeLog14
-rw-r--r--camel/providers/nntp/Makefile.am4
-rw-r--r--camel/providers/nntp/camel-nntp-folder.c213
-rw-r--r--camel/providers/nntp/camel-nntp-folder.h2
-rw-r--r--camel/providers/nntp/camel-nntp-provider.c8
-rw-r--r--camel/providers/nntp/camel-nntp-store.c37
-rw-r--r--camel/providers/nntp/camel-nntp-summary.c396
-rw-r--r--camel/providers/nntp/camel-nntp-summary.h81
-rw-r--r--camel/providers/nntp/camel-nntp-utils.c78
-rw-r--r--camel/providers/nntp/camel-nntp-utils.h2
10 files changed, 156 insertions, 679 deletions
diff --git a/camel/ChangeLog b/camel/ChangeLog
index 4198e4a9b0..7eddc455a8 100644
--- a/camel/ChangeLog
+++ b/camel/ChangeLog
@@ -1,3 +1,17 @@
+2000-05-16 Chris Toshok <toshok@helixcode.com>
+
+ * providers/nntp/camel-nntp-folder.c:
+ * providers/nntp/camel-nntp-folder.h:
+ * providers/nntp/camel-nntp-provider.c:
+ * providers/nntp/camel-nntp-store.c:
+ * providers/nntp/camel-nntp-utils.c:
+ * providers/nntp/camel-nntp-utils.h:
+ get things working with new camel summary stuff.
+
+ * providers/nntp/camel-nntp-summary.c:
+ * providers/nntp/camel-nntp-summary.h:
+ removed files since camel-folder-summary does all we need.
+
2000-05-15 Jeffrey Stedfast <fejj@stampede.org>
* providers/smtp/camel-smtp-transport.c: Added some preliminary
diff --git a/camel/providers/nntp/Makefile.am b/camel/providers/nntp/Makefile.am
index 200011c4dc..6c37e2112f 100644
--- a/camel/providers/nntp/Makefile.am
+++ b/camel/providers/nntp/Makefile.am
@@ -19,13 +19,11 @@ libcamelnntp_la_SOURCES = \
camel-nntp-folder.c \
camel-nntp-provider.c \
camel-nntp-store.c \
- camel-nntp-summary.c \
camel-nntp-utils.c
libcamelnntpinclude_HEADERS = \
camel-nntp-folder.h \
- camel-nntp-store.h \
- camel-nntp-summary.h
+ camel-nntp-store.h
libcamelnntp_la_LDFLAGS = -version-info 0:0:0 -rpath $(libdir)
diff --git a/camel/providers/nntp/camel-nntp-folder.c b/camel/providers/nntp/camel-nntp-folder.c
index 6fee4d2aac..067849712c 100644
--- a/camel/providers/nntp/camel-nntp-folder.c
+++ b/camel/providers/nntp/camel-nntp-folder.c
@@ -34,18 +34,18 @@
#include <string.h>
#include <fcntl.h>
+#include "camel-folder-summary.h"
#include "camel-nntp-store.h"
#include "camel-nntp-folder.h"
#include "camel-nntp-store.h"
#include "camel-nntp-utils.h"
-#include "camel-nntp-summary.h"
#include "string-utils.h"
#include "camel-stream-mem.h"
#include "camel-stream-buffer.h"
-#include "gmime-utils.h"
#include "camel-data-wrapper.h"
#include "camel-mime-message.h"
+#include "camel-folder-summary.h"
#include "camel-exception.h"
@@ -60,8 +60,6 @@ static CamelFolderClass *parent_class=NULL;
static void _init (CamelFolder *folder, CamelStore *parent_store,
CamelFolder *parent_folder, const gchar *name,
gchar separator, CamelException *ex);
-static void _set_name(CamelFolder *folder, const gchar *name, CamelException *ex);
-
static void _open (CamelFolder *folder, CamelFolderOpenMode mode, CamelException *ex);
static void _close (CamelFolder *folder, gboolean expunge, CamelException *ex);
@@ -95,7 +93,6 @@ camel_nntp_folder_class_init (CamelNNTPFolderClass *camel_nntp_folder_class)
/* virtual method overload */
camel_folder_class->init = _init;
- camel_folder_class->set_name = _set_name;
camel_folder_class->open = _open;
camel_folder_class->close = _close;
camel_folder_class->exists = _exists;
@@ -103,7 +100,6 @@ camel_nntp_folder_class_init (CamelNNTPFolderClass *camel_nntp_folder_class)
camel_folder_class->delete = _delete;
camel_folder_class->delete_messages = _delete_messages;
camel_folder_class->list_subfolders = _list_subfolders;
- camel_folder_class->get_message_by_number = _get_message_by_number;
camel_folder_class->get_message_count = _get_message_count;
camel_folder_class->get_uid_list = _get_uid_list;
camel_folder_class->get_message_by_uid = _get_message_by_uid;
@@ -118,8 +114,6 @@ camel_nntp_folder_class_init (CamelNNTPFolderClass *camel_nntp_folder_class)
}
-
-
static void
_finalize (GtkObject *object)
{
@@ -130,10 +124,6 @@ _finalize (GtkObject *object)
GTK_OBJECT_CLASS (parent_class)->finalize (object);
}
-
-
-
-
GtkType
camel_nntp_folder_get_type (void)
{
@@ -158,11 +148,6 @@ camel_nntp_folder_get_type (void)
return camel_nntp_folder_type;
}
-
-
-
-
-
static void
_init (CamelFolder *folder, CamelStore *parent_store,
CamelFolder *parent_folder, const gchar *name, gchar separator,
@@ -191,11 +176,8 @@ _init (CamelFolder *folder, CamelStore *parent_store,
folder->has_uid_capability = TRUE;
folder->has_search_capability = FALSE;
- folder->summary = NULL;
}
-
-
/* internal method used to :
- test for the existence of a summary file
- test the sync between the summary and the newsgroup
@@ -206,44 +188,18 @@ _check_get_or_maybe_generate_summary_file (CamelNNTPFolder *nntp_folder,
CamelException *ex)
{
CamelFolder *folder = CAMEL_FOLDER (nntp_folder);
- CamelNNTPSummary *summ = NULL;
- GArray *message_info_array;
- folder->summary = NULL;
-
- /* Test for the existence and up-to-dateness of the summary file. */
- if (access (nntp_folder->summary_file_path, F_OK) == 0) {
- summ = camel_nntp_summary_load (CAMEL_FOLDER(nntp_folder)->name,
- nntp_folder->summary_file_path, ex);
- if (summ) {
- folder->summary = CAMEL_FOLDER_SUMMARY (summ);
- } else {
- /* Bad summary file */
- if (camel_exception_get_id (ex) !=
- CAMEL_EXCEPTION_FOLDER_SUMMARY_INVALID)
- return;
- camel_exception_clear (ex);
- }
- }
+ nntp_folder->summary = camel_folder_summary_new ();
+ camel_folder_summary_set_filename (nntp_folder->summary, nntp_folder->summary_file_path);
- /* In the case where the summary does not exist (or was the
- * wrong version), or is not in sync with the nntp file,
- * regenerate it.
- */
- if (folder->summary == NULL) {
- message_info_array =
- camel_nntp_get_headers (CAMEL_FOLDER( folder )->parent_store, nntp_folder, ex);
+ if (-1 == camel_folder_summary_load (nntp_folder->summary)) {
+ /* Bad or nonexistant summary file */
+ camel_nntp_get_headers (CAMEL_FOLDER( folder )->parent_store, nntp_folder, ex);
if (camel_exception_get_id (ex))
return;
- summ = CAMEL_NNTP_SUMMARY (gtk_object_new (camel_nntp_summary_get_type (), NULL));
- summ->message_info = message_info_array;
- summ->nb_message = summ->message_info->len;
-
- folder->summary = CAMEL_FOLDER_SUMMARY (summ);
-
- camel_nntp_summary_save (summ,
- nntp_folder->summary_file_path, ex);
+ /* XXX check return value */
+ camel_folder_summary_save (nntp_folder->summary);
}
}
@@ -252,6 +208,7 @@ static void
_open (CamelFolder *folder, CamelFolderOpenMode mode, CamelException *ex)
{
CamelNNTPFolder *nntp_folder = CAMEL_NNTP_FOLDER (folder);
+ const gchar *root_dir_path;
/* call parent class */
parent_class->open (folder, mode, ex);
@@ -263,7 +220,11 @@ _open (CamelFolder *folder, CamelFolderOpenMode mode, CamelException *ex)
if (!(nntp_load_uid_list (nntp_folder) > 0))
nntp_generate_uid_list (nntp_folder);
#endif
-
+
+ root_dir_path = camel_nntp_store_get_toplevel_dir (CAMEL_NNTP_STORE(folder->parent_store));
+
+ nntp_folder->summary_file_path = g_strdup_printf ("%s/%s-ev-summary", root_dir_path, folder->name);
+
_check_get_or_maybe_generate_summary_file (nntp_folder, ex);
}
@@ -272,38 +233,15 @@ static void
_close (CamelFolder *folder, gboolean expunge, CamelException *ex)
{
CamelNNTPFolder *nntp_folder = CAMEL_NNTP_FOLDER (folder);
- CamelNNTPSummary *nntp_summary = CAMEL_NNTP_SUMMARY (folder->summary);
+ CamelFolderSummary *summary = nntp_folder->summary;
/* call parent implementation */
parent_class->close (folder, expunge, ex);
- camel_nntp_summary_save (nntp_summary,
- nntp_folder->summary_file_path, ex);
+ /* XXX only if dirty? */
+ camel_folder_summary_save (summary);
}
-
-
-
-static void
-_set_name (CamelFolder *folder, const gchar *name, CamelException *ex)
-{
- CamelNNTPFolder *nntp_folder = CAMEL_NNTP_FOLDER (folder);
- const gchar *root_dir_path;
-
- /* call default implementation */
- parent_class->set_name (folder, name, ex);
- if (camel_exception_get_id (ex)) return;
-
- root_dir_path = camel_nntp_store_get_toplevel_dir (CAMEL_NNTP_STORE(folder->parent_store));
-
- nntp_folder->summary_file_path = g_strdup_printf ("%s/%s-ev-summary", root_dir_path, folder->name);
-}
-
-
-
-
-
-
static gboolean
_exists (CamelFolder *folder, CamelException *ex)
{
@@ -338,13 +276,6 @@ _exists (CamelFolder *folder, CamelException *ex)
return TRUE;
}
-
-
-
-
-
-
-
static gboolean
_create (CamelFolder *folder, CamelException *ex)
{
@@ -362,12 +293,10 @@ _create (CamelFolder *folder, CamelException *ex)
summary->nntp_file_size = 0;
summary->message_info = g_array_new (FALSE, FALSE, sizeof (CamelNNTPSummaryInformation));
#endif
-
+
return TRUE;
}
-
-
static gboolean
_delete (CamelFolder *folder, gboolean recurse, CamelException *ex)
{
@@ -396,9 +325,6 @@ _delete (CamelFolder *folder, gboolean recurse, CamelException *ex)
return TRUE;
}
-
-
-
gboolean
_delete_messages (CamelFolder *folder, CamelException *ex)
{
@@ -417,7 +343,6 @@ _delete_messages (CamelFolder *folder, CamelException *ex)
return TRUE;
}
-
static GList *
_list_subfolders (CamelFolder *folder, CamelException *ex)
{
@@ -425,23 +350,17 @@ _list_subfolders (CamelFolder *folder, CamelException *ex)
return NULL;
}
-
-
-
static gint
_get_message_count (CamelFolder *folder, CamelException *ex)
{
- gint message_count = 0;
+ CamelNNTPFolder *nntp_folder = CAMEL_NNTP_FOLDER(folder);
g_assert (folder);
- g_assert (folder->summary);
-
- message_count = CAMEL_NNTP_SUMMARY (folder->summary)->nb_message;
+ g_assert (nntp_folder->summary);
- return message_count;
+ return camel_folder_summary_count(nntp_folder->summary);
}
-
#if 0
static void
_append_message (CamelFolder *folder, CamelMimeMessage *message, CamelException *ex)
@@ -571,48 +490,22 @@ _append_message (CamelFolder *folder, CamelMimeMessage *message, CamelException
static GList *
_get_uid_list (CamelFolder *folder, CamelException *ex)
{
- GArray *message_info_array;
- CamelNNTPSummaryInformation *message_info;
+ CamelNNTPFolder *nntp_folder = CAMEL_NNTP_FOLDER (folder);
+ GPtrArray *message_info_array;
+ CamelMessageInfo *message_info;
GList *uid_list = NULL;
int i;
- message_info_array =
- CAMEL_NNTP_SUMMARY (folder->summary)->message_info;
+ message_info_array = nntp_folder->summary->messages;
for (i=0; i<message_info_array->len; i++) {
- message_info = (CamelNNTPSummaryInformation *)(message_info_array->data) + i;
- uid_list = g_list_prepend (uid_list, g_strdup (message_info->headers.uid));
+ message_info = (CamelMessageInfo *)(message_info_array->pdata) + i;
+ uid_list = g_list_prepend (uid_list, g_strdup (message_info->uid));
}
return uid_list;
}
-
-
-static CamelMimeMessage *
-_get_message_by_number (CamelFolder *folder, gint number, CamelException *ex)
-{
- GArray *message_info_array;
- CamelNNTPSummaryInformation *message_info;
-
- message_info_array =
- CAMEL_NNTP_SUMMARY (folder->summary)->message_info;
-
- if (number > message_info_array->len) {
- camel_exception_setv (ex, CAMEL_EXCEPTION_FOLDER_INVALID,
- "No such message %d in folder `%s'.",
- number, folder->name);
- return NULL;
- }
-
- message_info =
- (CamelNNTPSummaryInformation *)(message_info_array->data) +
- (number - 1);
-
- return _get_message_by_uid (folder, message_info->headers.uid, ex);
-}
-
-
static CamelMimeMessage *
_get_message_by_uid (CamelFolder *folder, const gchar *uid, CamelException *ex)
{
@@ -655,8 +548,12 @@ _get_message_by_uid (CamelFolder *folder, const gchar *uid, CamelException *ex)
buf[0] = 0;
while (!done) {
- char *line = camel_stream_buffer_read_line ( CAMEL_STREAM_BUFFER ( nntp_istream ));
- int line_length = strlen ( line );
+ char *line = camel_stream_buffer_read_line ( CAMEL_STREAM_BUFFER ( nntp_istream ), ex);
+ int line_length;
+
+ /* XXX check exception */
+
+ line_length = strlen ( line );
if (!strcmp(line, ".")) {
done = TRUE;
@@ -675,12 +572,44 @@ _get_message_by_uid (CamelFolder *folder, const gchar *uid, CamelException *ex)
}
/* create a stream bound to the message */
- message_stream = camel_stream_mem_new_with_buffer(buf,
- buf_len,
- CAMEL_STREAM_MEM_READ);
+ message_stream = camel_stream_mem_new_with_buffer(buf, buf_len);
message = camel_mime_message_new ();
- camel_data_wrapper_set_input_stream (CAMEL_DATA_WRAPPER (message), message_stream);
-
+ if (camel_data_wrapper_construct_from_stream ((CamelDataWrapper *)message, message_stream) == -1) {
+ gtk_object_unref ((GtkObject *)message);
+ gtk_object_unref ((GtkObject *)message_stream);
+ camel_exception_setv (ex,
+ CAMEL_EXCEPTION_FOLDER_INVALID_UID, /* XXX */
+ "Could not create message for uid %s.", uid);
+
+ return NULL;
+ }
+ gtk_object_unref ((GtkObject *)message_stream);
+
+ /* init other fields? */
+ message->folder = folder;
+ gtk_object_ref((GtkObject *)folder);
+ message->message_uid = g_strdup(uid);
+
+#if 0
+ gtk_signal_connect((GtkObject *)message, "message_changed", message_changed, folder);
+#endif
+
return message;
}
+
+/* get message info for a range of messages */
+static GPtrArray *
+summary_get_message_info (CamelFolder *folder, int first, int count)
+{
+ GPtrArray *array = g_ptr_array_new();
+ int i, maxcount;
+ CamelNNTPFolder *nntp_folder = (CamelNNTPFolder *)folder;
+
+ maxcount = camel_folder_summary_count(nntp_folder->summary);
+ maxcount = MIN(first + count, maxcount);
+ for (i=first;i<maxcount;i++)
+ g_ptr_array_add(array, g_ptr_array_index(nntp_folder->summary->messages, i));
+
+ return array;
+}
diff --git a/camel/providers/nntp/camel-nntp-folder.h b/camel/providers/nntp/camel-nntp-folder.h
index 7029023a62..7a445d697f 100644
--- a/camel/providers/nntp/camel-nntp-folder.h
+++ b/camel/providers/nntp/camel-nntp-folder.h
@@ -35,7 +35,6 @@ extern "C" {
#include <gtk/gtk.h>
#include "camel-folder.h"
-#include "camel-nntp-summary.h"
/* #include "camel-store.h" */
@@ -49,6 +48,7 @@ typedef struct {
CamelFolder parent_object;
gchar *summary_file_path; /* contains the messages summary */
+ CamelFolderSummary *summary;
} CamelNNTPFolder;
diff --git a/camel/providers/nntp/camel-nntp-provider.c b/camel/providers/nntp/camel-nntp-provider.c
index 449de945e6..fe50a1f952 100644
--- a/camel/providers/nntp/camel-nntp-provider.c
+++ b/camel/providers/nntp/camel-nntp-provider.c
@@ -3,7 +3,7 @@
/*
* Authors :
- * Dan Winship <danw@helixcode.com>
+ * Chris Toshok <toshok@helixcode.com>
*
* Copyright (C) 2000 Helix Code, Inc. (www.helixcode.com)
*
@@ -56,15 +56,13 @@ camel_provider_module_init (CamelSession *session)
{
news_provider.object_types[CAMEL_PROVIDER_STORE] =
camel_nntp_store_get_type();
- nntp_provider.object_types[CAMEL_PROVIDER_STORE] =
- camel_nntp_store_get_type();
#ifdef NOTYET
nntp_provider.object_types[CAMEL_PROVIDER_TRANSPORT] =
camel_nntp_transport_get_type();
#endif
- camel_session_register_provider (session", &news_provider);
- camel_session_register_provider (session", &nntp_provider);
+ camel_session_register_provider (session, &news_provider);
+ camel_session_register_provider (session, &nntp_provider);
}
diff --git a/camel/providers/nntp/camel-nntp-store.c b/camel/providers/nntp/camel-nntp-store.c
index 639e8fa9e0..2a0084eee2 100644
--- a/camel/providers/nntp/camel-nntp-store.c
+++ b/camel/providers/nntp/camel-nntp-store.c
@@ -37,6 +37,7 @@
#include "libgnome/libgnome.h"
+#include "camel-folder-summary.h"
#include "camel-nntp-store.h"
#include "camel-nntp-folder.h"
#include "camel-stream-buffer.h"
@@ -113,9 +114,6 @@ _get_folder (CamelStore *store, const gchar *folder_name, CamelException *ex)
CamelNNTPFolder *new_nntp_folder;
CamelFolder *new_folder;
- /* XXX */
- folder_name = "netscape.public.mozilla.announce";
-
/* check if folder has already been created */
/* call the standard routine for that when */
/* it is done ... */
@@ -152,7 +150,6 @@ void
camel_nntp_store_open (CamelNNTPStore *store, CamelException *ex)
{
CamelService *service = CAMEL_SERVICE (store);
-
if (!camel_service_is_connected (service))
nntp_connect (service, ex);
}
@@ -177,8 +174,8 @@ nntp_connect (CamelService *service, CamelException *ex)
{
struct hostent *h;
struct sockaddr_in sin;
- int fd, status, apoplen;
- char *buf, *apoptime, *pass;
+ int fd;
+ char *buf;
CamelNNTPStore *store = CAMEL_NNTP_STORE (service);
if (!service_class->connect (service, ex))
@@ -209,7 +206,7 @@ nntp_connect (CamelService *service, CamelException *ex)
CAMEL_STREAM_BUFFER_READ);
/* Read the greeting */
- buf = camel_stream_buffer_read_line (CAMEL_STREAM_BUFFER (store->istream));
+ buf = camel_stream_buffer_read_line (CAMEL_STREAM_BUFFER (store->istream), ex /* XX check this */);
if (!buf) {
return -1;
}
@@ -217,6 +214,11 @@ nntp_connect (CamelService *service, CamelException *ex)
g_free (buf);
/* get a list of extensions that the server supports */
+ if (CAMEL_NNTP_OK == camel_nntp_command (store, NULL, "LIST EXTENSIONS")) {
+ char *ext_response = camel_nntp_command_get_additional_data(store);
+
+ g_free (ext_response);
+ }
return TRUE;
}
@@ -284,12 +286,12 @@ camel_nntp_command (CamelNNTPStore *store, char **ret, char *fmt, ...)
}
/* Send the command */
- camel_stream_write (store->ostream, cmdbuf, strlen (cmdbuf));
+ camel_stream_write (store->ostream, cmdbuf, strlen (cmdbuf), ex /* XXX */);
g_free (cmdbuf);
- camel_stream_write (store->ostream, "\r\n", 2);
+ camel_stream_write (store->ostream, "\r\n", 2, ex /* XXX */);
/* Read the response */
- respbuf = camel_stream_buffer_read_line (CAMEL_STREAM_BUFFER (store->istream));
+ respbuf = camel_stream_buffer_read_line (CAMEL_STREAM_BUFFER (store->istream), ex /* XXX */);
resp_code = atoi (respbuf);
if (resp_code < 400)
@@ -314,6 +316,7 @@ camel_nntp_command (CamelNNTPStore *store, char **ret, char *fmt, ...)
* a NNTP command.
* @store: the NNTP store
*
+ * This command gets the additional data returned by
* This command gets the additional data returned by "multi-line" POP
* commands, such as LIST, RETR, TOP, and UIDL. This command _must_
* be called after a successful (CAMEL_NNTP_OK) call to
@@ -330,10 +333,11 @@ camel_nntp_command_get_additional_data (CamelNNTPStore *store)
GPtrArray *data;
char *buf;
int i, status = CAMEL_NNTP_OK;
+ CamelException *ex = camel_exception_new();
data = g_ptr_array_new ();
while (1) {
- buf = camel_stream_buffer_read_line (stream);
+ buf = camel_stream_buffer_read_line (stream, ex /* XXX */);
if (!buf) {
status = CAMEL_NNTP_FAIL;
break;
@@ -382,8 +386,16 @@ camel_nntp_store_subscribe_group (CamelStore *store,
if (CAMEL_NNTP_OK == camel_nntp_command ( CAMEL_NNTP_STORE (store),
&ret, "GROUP %s", group_name)) {
+ /* we create an empty summary file here, so that when
+ the group is opened we'll know we need to build it. */
gchar *summary_file;
+ int fd;
summary_file = g_strdup_printf ("%s/%s-ev-summary", root_dir, group_name);
+
+ fd = open (summary_file, O_CREAT | O_RDWR, 0666);
+ close (fd);
+
+ g_free (summary_file);
}
if (ret) g_free (ret);
@@ -420,7 +432,8 @@ camel_nntp_store_list_subscribed_groups(CamelStore *store)
gchar *root_dir = camel_nntp_store_get_toplevel_dir(CAMEL_NNTP_STORE(store));
dir_handle = opendir (root_dir);
-
+ g_return_val_if_fail (dir_handle, NULL);
+
/* read the first entry in the directory */
dir_entry = readdir (dir_handle);
while ((stat_error != -1) && (dir_entry != NULL)) {
diff --git a/camel/providers/nntp/camel-nntp-summary.c b/camel/providers/nntp/camel-nntp-summary.c
deleted file mode 100644
index dad88b6ca4..0000000000
--- a/camel/providers/nntp/camel-nntp-summary.c
+++ /dev/null
@@ -1,396 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-/* camel-nntp-utils.c : summary support for nntp groups. */
-
-/*
- * Author : Chris Toshok <toshok@helixcode.com>
- *
- * Copyright (C) 2000 Helix Code .
-
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- * USA
- */
-
-
-#include <config.h>
-
-#include "camel-exception.h"
-#include "camel-nntp-folder.h"
-#include "camel-nntp-summary.h"
-#include "md5-utils.h"
-
-
-#include <sys/stat.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <fcntl.h>
-#include <dirent.h>
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
-#include <netinet/in.h>
-
-static CamelFolderSummaryClass *parent_class = NULL;
-
-static int count_messages (CamelFolderSummary *summary);
-static int count_subfolders (CamelFolderSummary *summary);
-static GPtrArray *get_subfolder_info (CamelFolderSummary *summary,
- int first, int count);
-static GPtrArray *get_message_info (CamelFolderSummary *summary,
- int first, int count);
-static void finalize (GtkObject *object);
-
-static void
-camel_nntp_summary_class_init (CamelNNTPSummaryClass *camel_nntp_summary_class)
-{
- GtkObjectClass *gtk_object_class =
- GTK_OBJECT_CLASS (camel_nntp_summary_class);
- CamelFolderSummaryClass *camel_folder_summary_class =
- CAMEL_FOLDER_SUMMARY_CLASS (camel_nntp_summary_class);
-
- parent_class = gtk_type_class (camel_folder_summary_get_type ());
-
- /* virtual method override */
- camel_folder_summary_class->count_messages = count_messages;
- camel_folder_summary_class->count_subfolders = count_subfolders;
- camel_folder_summary_class->get_subfolder_info = get_subfolder_info;
- camel_folder_summary_class->get_message_info = get_message_info;
-
- gtk_object_class->finalize = finalize;
-}
-
-
-GtkType
-camel_nntp_summary_get_type (void)
-{
- static GtkType camel_nntp_summary_type = 0;
-
- if (!camel_nntp_summary_type) {
- GtkTypeInfo camel_nntp_summary_info =
- {
- "CamelNNTPSummary",
- sizeof (CamelNNTPSummary),
- sizeof (CamelNNTPSummaryClass),
- (GtkClassInitFunc) camel_nntp_summary_class_init,
- (GtkObjectInitFunc) NULL,
- /* reserved_1 */ NULL,
- /* reserved_2 */ NULL,
- (GtkClassInitFunc) NULL,
- };
-
- camel_nntp_summary_type = gtk_type_unique (camel_folder_summary_get_type (), &camel_nntp_summary_info);
- }
-
- return camel_nntp_summary_type;
-}
-
-static void
-finalize (GtkObject *object)
-{
- CamelNNTPSummary *summary = CAMEL_NNTP_SUMMARY (object);
- CamelNNTPSummaryInformation *info;
- int i;
-
- for (i = 0; i < summary->message_info->len; i++) {
- info = &(((CamelNNTPSummaryInformation *)summary->message_info->data)[i]);
- g_free (info->headers.subject);
- g_free (info->headers.sender);
- g_free (info->headers.to);
- g_free (info->headers.sent_date);
- g_free (info->headers.received_date);
- g_free (info->headers.uid);
- }
- g_array_free (summary->message_info, TRUE);
-
- GTK_OBJECT_CLASS (parent_class)->finalize (object);
-}
-
-static int
-count_messages (CamelFolderSummary *summary)
-{
- return CAMEL_NNTP_SUMMARY (summary)->nb_message;
-}
-
-static int
-count_subfolders (CamelFolderSummary *summary)
-{
- return 0;
-}
-
-static GPtrArray *
-get_subfolder_info (CamelFolderSummary *summary, int first, int count)
-{
- return NULL;
-}
-
-static GPtrArray *
-get_message_info (CamelFolderSummary *summary, int first, int count)
-{
- CamelNNTPSummary *nntp_summary = CAMEL_NNTP_SUMMARY (summary);
- CamelNNTPSummaryInformation *info;
- GPtrArray *arr;
-
- /* XXX bounds check */
-
- arr = g_ptr_array_new ();
- for (; count; count--) {
- info = &((CamelNNTPSummaryInformation *)nntp_summary->message_info->data)[first++];
- g_ptr_array_add (arr, info);
- }
-
- return arr;
-}
-
-/**
- * camel_nntp_summary_save:
- * @summary:
- * @filename:
- * @ex:
- *
- * save the summary into a file
- **/
-void
-camel_nntp_summary_save (CamelNNTPSummary *summary, const gchar *filename,
- CamelException *ex)
-{
- CamelNNTPSummaryInformation *msg_info;
- guint cur_msg;
- guint field_length;
- gint fd;
- gint write_result; /* XXX use this */
- guint32 data;
-
- fd = open (filename, O_WRONLY | O_CREAT | O_TRUNC,
- S_IRUSR | S_IWUSR);
- if (fd == -1) {
- camel_exception_setv (ex, CAMEL_EXCEPTION_FOLDER_INSUFFICIENT_PERMISSION,
- "could not create the nntp summary "
- "file\n\t%s\nFull error is : %s\n",
- filename,
- strerror (errno));
- return;
- }
-
- /* We write the file out in network byte order, not because
- * that makes sense, but because it's easy.
- */
-
- data = htonl (CAMEL_NNTP_SUMMARY_VERSION);
- write (fd, &data, sizeof (data));
-
- data = htonl (summary->nb_message);
- write (fd, &data, sizeof (data));
-
- for (cur_msg = 0; cur_msg < summary->nb_message; cur_msg++) {
- msg_info = (CamelNNTPSummaryInformation *)
- (summary->message_info->data) + cur_msg;
-
- /* Write meta-info. */
- data = htonl (msg_info->size);
- write (fd, &data, sizeof (data));
- write (fd, &msg_info->status, 1);
-
- /* Write subject. */
- if (msg_info->headers.subject)
- field_length = strlen (msg_info->headers.subject);
- else
- field_length = 0;
- data = htonl (field_length);
- write (fd, &data, sizeof (data));
- if (msg_info->headers.subject)
- write (fd, msg_info->headers.subject, field_length);
-
- /* Write sender. */
- if (msg_info->headers.sender)
- field_length = strlen (msg_info->headers.sender);
- else
- field_length = 0;
- data = htonl (field_length);
- write (fd, &data, sizeof (data));
- if (msg_info->headers.sender)
- write (fd, msg_info->headers.sender, field_length);
-
- /* Write sent date. */
- if (msg_info->headers.sent_date)
- field_length = strlen (msg_info->headers.sent_date);
- else
- field_length = 0;
- data = htonl (field_length);
- write (fd, &data, sizeof (data));
- if (msg_info->headers.sent_date)
- write (fd, msg_info->headers.sent_date, field_length);
-
- /* Write received date. */
- if (msg_info->headers.received_date)
- field_length = strlen (msg_info->headers.received_date);
- else
- field_length = 0;
- data = htonl (field_length);
- write (fd, &data, sizeof (data));
- if (msg_info->headers.received_date)
- write (fd, msg_info->headers.received_date, field_length);
-
- /* Write uid date. */
- if (msg_info->headers.uid)
- field_length = strlen (msg_info->headers.uid);
- else
- field_length = 0;
- data = htonl (field_length);
- write (fd, &data, sizeof (data));
- if (msg_info->headers.uid)
- write (fd, msg_info->headers.uid, field_length);
-
- }
-
- close (fd);
-}
-
-
-
-/**
- * camel_nntp_summary_load:
- * @filename:
- * @ex:
- *
- * load the summary from a file
- *
- * Return value:
- **/
-CamelNNTPSummary *
-camel_nntp_summary_load (const gchar *newsgroup, const gchar *filename, CamelException *ex)
-{
- CamelNNTPSummaryInformation *msg_info;
- guint cur_msg;
- guint field_length;
- gint fd;
- CamelNNTPSummary *summary;
- gint read_result;
- guint32 data;
-
- fd = open (filename, O_RDONLY);
- if (fd == -1) {
- camel_exception_setv (ex, CAMEL_EXCEPTION_FOLDER_INSUFFICIENT_PERMISSION,
- "could not open the nntp summary file\n"
- "\t%s\nFull error is : %s\n",
- filename, strerror (errno));
- return NULL;
- }
-
- /* Verify version number. */
- read (fd, &data, sizeof(data));
- data = ntohl (data);
-
- if (data != CAMEL_NNTP_SUMMARY_VERSION) {
- camel_exception_setv (ex, CAMEL_EXCEPTION_FOLDER_SUMMARY_INVALID,
- "This folder summary was written by "
- "%s version of this software.",
- data < CAMEL_NNTP_SUMMARY_VERSION ?
- "an older" : "a newer");
- return NULL;
- }
-
- summary = CAMEL_NNTP_SUMMARY (gtk_object_new (camel_nntp_summary_get_type (), NULL));
-
- read (fd, &data, sizeof(data));
- summary->nb_message = ntohl (data);
-
- summary->message_info =
- g_array_new (FALSE, FALSE,
- sizeof (CamelNNTPSummaryInformation));
- g_array_set_size (summary->message_info, summary->nb_message);
-
- for (cur_msg = 0; cur_msg < summary->nb_message; cur_msg++) {
- msg_info = (CamelNNTPSummaryInformation *)
- (summary->message_info->data) + cur_msg;
-
- /* Read the meta-info. */
- read (fd, &data, sizeof(data));
- msg_info->size = ntohl (data);
- read (fd, &msg_info->status, 1);
-
- /* Read the subject. */
- read (fd, &field_length, sizeof (field_length));
- field_length = ntohl (field_length);
- if (field_length > 0) {
- msg_info->headers.subject =
- g_new0 (gchar, field_length + 1);
- read (fd, msg_info->headers.subject, field_length);
- } else
- msg_info->headers.subject = NULL;
-
- /* Read the sender. */
- read (fd, &field_length, sizeof (field_length));
- field_length = ntohl (field_length);
- if (field_length > 0) {
- msg_info->headers.sender =
- g_new0 (gchar, field_length + 1);
- read (fd, msg_info->headers.sender, field_length);
- } else
- msg_info->headers.sender = NULL;
-
- msg_info->headers.to = g_strdup (newsgroup);
-
- /* Read the sent date field. */
- read (fd, &field_length, sizeof (field_length));
- field_length = ntohl (field_length);
- if (field_length > 0) {
- msg_info->headers.sent_date =
- g_new0 (gchar, field_length + 1);
- read (fd, msg_info->headers.sent_date, field_length);
- } else
- msg_info->headers.sent_date = NULL;
-
- /* Read the received date field. */
- read (fd, &field_length, sizeof (field_length));
- field_length = ntohl (field_length);
- if (field_length > 0) {
- msg_info->headers.received_date =
- g_new0 (gchar, field_length + 1);
- read (fd, msg_info->headers.received_date,
- field_length);
- } else
- msg_info->headers.received_date = NULL;
-
- /* Read the uid field. */
- read (fd, &field_length, sizeof (field_length));
- field_length = ntohl (field_length);
- if (field_length > 0) {
- msg_info->headers.uid =
- g_new0 (gchar, field_length + 1);
- read (fd, msg_info->headers.uid,
- field_length);
- } else
- msg_info->headers.uid = NULL;
- }
-
- close (fd);
- return summary;
-}
-
-
-/**
- * camel_nntp_summary_append_entries:
- * @summary:
- * @entries:
- *
- * append an entry to a summary
- **/
-void
-camel_nntp_summary_append_entries (CamelNNTPSummary *summary, GArray *entries)
-{
-
- summary->message_info = g_array_append_vals (summary->message_info,
- entries->data,
- entries->len);
-}
diff --git a/camel/providers/nntp/camel-nntp-summary.h b/camel/providers/nntp/camel-nntp-summary.h
deleted file mode 100644
index 6c54f6cb33..0000000000
--- a/camel/providers/nntp/camel-nntp-summary.h
+++ /dev/null
@@ -1,81 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-/* camel-nntp-utils.c : summary support for nntp groups. */
-
-/*
- *
- * Author : Chris Toshok <toshok@helixcode.com>
- *
- * Copyright (C) 2000 Helix Code (http://www.helixcode.com).
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- * USA
- */
-
-#ifndef NNTP_SUMMARY_H
-#define NNTP_SUMMARY_H 1
-
-#include <camel-folder-summary.h>
-
-#define CAMEL_NNTP_SUMMARY_TYPE (camel_nntp_summary_get_type ())
-#define CAMEL_NNTP_SUMMARY(obj) (GTK_CHECK_CAST((obj), CAMEL_NNTP_SUMMARY_TYPE, CamelNNTPSummary))
-#define CAMEL_NNTP_SUMMARY_CLASS(k) (GTK_CHECK_CLASS_CAST ((k), CAMEL_NNTP_SUMMARY_TYPE, CamelNNTPSummaryClass))
-#define CAMEL_IS_NNTP_SUMMARY(o) (GTK_CHECK_TYPE((o), CAMEL_NNTP_SUMMARY_TYPE))
-
-
-#define CAMEL_NNTP_SUMMARY_VERSION 1
-
-
-typedef struct {
- CamelMessageInfo headers;
-
- guint size;
- guchar status;
-
-} CamelNNTPSummaryInformation;
-
-
-/* this contains informations about the whole nntp file */
-typedef struct {
- CamelFolderSummary parent_object;
-
- guint first_message; /* the first message number in the summary */
- guint nb_message; /* number of messages in the summary */
-
- GArray *message_info; /* array of CamelNNTPSummaryInformation */
-
-} CamelNNTPSummary;
-
-typedef struct {
- CamelFolderSummaryClass parent_class;
-
-} CamelNNTPSummaryClass;
-
-
-GtkType camel_nntp_summary_get_type (void);
-
-void camel_nntp_summary_save (CamelNNTPSummary *summary,
- const gchar *filename, CamelException *ex);
-CamelNNTPSummary *
-camel_nntp_summary_load (const gchar *newsgroup, const gchar *filename, CamelException *ex);
-
-gboolean camel_nntp_summary_check_sync (gchar *summary_filename,
- gchar *nntp_filename,
- CamelException *ex);
-
-void camel_nntp_summary_append_entries (CamelNNTPSummary *summary,
- GArray *entries);
-
-
-#endif /* NNTP_SUMMARY_H */
diff --git a/camel/providers/nntp/camel-nntp-utils.c b/camel/providers/nntp/camel-nntp-utils.c
index b89ae120da..7100be0aed 100644
--- a/camel/providers/nntp/camel-nntp-utils.c
+++ b/camel/providers/nntp/camel-nntp-utils.c
@@ -22,22 +22,22 @@
* USA
*/
+#include "camel-folder-summary.h"
#include "camel-nntp-folder.h"
#include "camel-nntp-store.h"
-#include "camel-nntp-summary.h"
#include "camel-nntp-utils.h"
#include "camel-stream-buffer.h"
#include "camel-stream-mem.h"
-#include "gmime-utils.h"
#include <stdlib.h>
#include <string.h>
-static GArray*
+static void
get_XOVER_headers(CamelNNTPStore *nntp_store, CamelFolder *folder,
- int first_message, int last_message)
+ int first_message, int last_message, CamelException *ex)
{
int status;
+ CamelNNTPFolder *nntp_folder = CAMEL_NNTP_FOLDER (folder);
status = camel_nntp_command (nntp_store, NULL,
"XOVER %d-%d",
@@ -46,57 +46,51 @@ get_XOVER_headers(CamelNNTPStore *nntp_store, CamelFolder *folder,
if (status == CAMEL_NNTP_OK) {
CamelStream *nntp_istream = nntp_store->istream;
- GArray *array;
gboolean done = FALSE;
- array = g_array_new(FALSE, FALSE, sizeof(CamelNNTPSummaryInformation));
-
while (!done) {
char *line;
line = camel_stream_buffer_read_line (
- CAMEL_STREAM_BUFFER ( nntp_istream ));
+ CAMEL_STREAM_BUFFER ( nntp_istream ), ex /* XXX */);
if (*line == '.') {
done = TRUE;
}
else {
- CamelNNTPSummaryInformation new_info;
+ CamelMessageInfo *new_info = g_new0(CamelMessageInfo, 1);
char **split_line = g_strsplit (line, "\t", 7);
- memset (&new_info, 0, sizeof(new_info));
-
- new_info.headers.subject = g_strdup(split_line[1]);
- new_info.headers.sender = g_strdup(split_line[2]);
- new_info.headers.to = g_strdup(folder->name);
- new_info.headers.sent_date = g_strdup(split_line[3]);
+ new_info->subject = g_strdup(split_line[1]);
+ new_info->from = g_strdup(split_line[2]);
+ new_info->to = g_strdup(folder->name);
+#if 0
+ new_info->date_sent = g_strdup(split_line[3]);
/* XXX do we need to fill in both dates? */
- new_info.headers.received_date = g_strdup(split_line[3]);
- new_info.headers.size = atoi(split_line[5]);
- new_info.headers.uid = g_strdup(split_line[4]);
+ new_info->headers.date_received = g_strdup(split_line[3]);
+#endif
+ new_info->size = atoi(split_line[5]);
+ new_info->uid = g_strdup(split_line[4]);
g_strfreev (split_line);
- g_array_append_val(array, new_info);
+ camel_folder_summary_add (nntp_folder->summary, new_info);
}
g_free (line);
}
-
- return array;
}
-
- return NULL;
}
+#if 0
static GArray*
get_HEAD_headers(CamelNNTPStore *nntp_store, CamelFolder *folder,
- int first_message, int last_message)
+ int first_message, int last_message, CamelException *ex)
{
int i;
int status;
GArray *array;
- CamelNNTPSummaryInformation info;
+ CamelMessageInfo info;
- array = g_array_new(FALSE, FALSE, sizeof(CamelNNTPSummaryInformation));
+ array = g_array_new(FALSE, FALSE, sizeof(CamelMessageInfo));
for (i = first_message; i < last_message; i ++) {
status = camel_nntp_command (nntp_store, NULL,
@@ -156,16 +150,18 @@ get_HEAD_headers(CamelNNTPStore *nntp_store, CamelFolder *folder,
for (h = 0; h < header_array->len; h ++) {
Rfc822Header *header = &((Rfc822Header*)header_array->data)[h];
if (!g_strcasecmp(header->name, "From"))
- info.headers.sender = g_strdup(header->value);
+ info.from = g_strdup(header->value);
else if (!g_strcasecmp(header->name, "To"))
- info.headers.to = g_strdup(header->value);
+ info.to = g_strdup(header->value);
else if (!g_strcasecmp(header->name, "Subject"))
- info.headers.subject = g_strdup(header->value);
+ info.subject = g_strdup(header->value);
else if (!g_strcasecmp(header->name, "Message-ID"))
- info.headers.uid = g_strdup(header->value);
+ info.uid = g_strdup(header->value);
else if (!g_strcasecmp(header->name, "Date")) {
- info.headers.sent_date = g_strdup(header->value);
- info.headers.received_date = g_strdup(header->value);
+#if 0
+ info.date_sent = g_strdup(header->value);
+ info.date_received = g_strdup(header->value);
+#endif
}
}
g_array_append_val(array, info);
@@ -178,8 +174,9 @@ get_HEAD_headers(CamelNNTPStore *nntp_store, CamelFolder *folder,
}
return array;
}
+#endif
-GArray *
+void
camel_nntp_get_headers (CamelStore *store,
CamelNNTPFolder *nntp_folder,
CamelException *ex)
@@ -196,14 +193,19 @@ camel_nntp_get_headers (CamelStore *store,
sscanf (ret, "%d %d %d", &nb_message, &first_message, &last_message);
g_free (ret);
- if (status != CAMEL_NNTP_OK)
- return NULL;
+ if (status != CAMEL_NNTP_OK) {
+ /* XXX throw invalid group exception */
+ printf ("invalid group\n");
+ return;
+ }
- if (TRUE /* nntp_store->extensions & CAMEL_NNTP_EXT_XOVER */) {
- return get_XOVER_headers (nntp_store, folder, first_message, last_message);
+ if (nntp_store->extensions & CAMEL_NNTP_EXT_XOVER) {
+ get_XOVER_headers (nntp_store, folder, first_message, last_message, ex);
}
else {
- return get_HEAD_headers (nntp_store, folder, first_message, last_message);
+#if 0
+ get_HEAD_headers (nntp_store, folder, first_message, last_message, ex);
+#endif
}
}
diff --git a/camel/providers/nntp/camel-nntp-utils.h b/camel/providers/nntp/camel-nntp-utils.h
index 52617fa0ce..f28697c744 100644
--- a/camel/providers/nntp/camel-nntp-utils.h
+++ b/camel/providers/nntp/camel-nntp-utils.h
@@ -33,7 +33,7 @@ extern "C" {
#pragma }
#endif /* __cplusplus }*/
-GArray *camel_nntp_get_headers (CamelStore *store, CamelNNTPFolder *nntp_folder, CamelException *ex);
+void camel_nntp_get_headers (CamelStore *store, CamelNNTPFolder *nntp_folder, CamelException *ex);
#ifdef __cplusplus
}