aboutsummaryrefslogtreecommitdiffstats
path: root/camel/providers/nntp
diff options
context:
space:
mode:
Diffstat (limited to 'camel/providers/nntp')
-rw-r--r--camel/providers/nntp/camel-nntp-folder.c13
-rw-r--r--camel/providers/nntp/camel-nntp-utils.c192
2 files changed, 157 insertions, 48 deletions
diff --git a/camel/providers/nntp/camel-nntp-folder.c b/camel/providers/nntp/camel-nntp-folder.c
index 7c3e2063b1..00d0bcc902 100644
--- a/camel/providers/nntp/camel-nntp-folder.c
+++ b/camel/providers/nntp/camel-nntp-folder.c
@@ -252,6 +252,9 @@ _check_get_or_maybe_generate_summary_file (CamelNNTPFolder *nntp_folder,
summ->nb_message = summ->message_info->len;
folder->summary = CAMEL_FOLDER_SUMMARY (summ);
+
+ camel_nntp_summary_save (summ,
+ nntp_folder->summary_file_path, ex);
}
}
@@ -322,6 +325,7 @@ _set_name (CamelFolder *folder, const gchar *name, CamelException *ex)
static gboolean
_exists (CamelFolder *folder, CamelException *ex)
{
+#if 0
CamelNNTPFolder *nntp_folder;
struct stat stat_buf;
gint stat_error;
@@ -351,6 +355,8 @@ _exists (CamelFolder *folder, CamelException *ex)
CAMEL_LOG_FULL_DEBUG ("Leaving CamelNNTPFolder::exists\n");
return exists;
+#endif
+ return TRUE;
}
@@ -386,6 +392,7 @@ _create (CamelFolder *folder, CamelException *ex)
static gboolean
_delete (CamelFolder *folder, gboolean recurse, CamelException *ex)
{
+#if 0
gboolean folder_already_exists;
g_assert(folder != NULL);
@@ -406,7 +413,7 @@ _delete (CamelFolder *folder, gboolean recurse, CamelException *ex)
It should delete the messages in the folder
and recurse the operation to subfolders */
parent_class->delete (folder, recurse, ex);
-
+#endif
return TRUE;
}
@@ -683,7 +690,7 @@ _get_message_by_uid (CamelFolder *folder, const gchar *uid, CamelException *ex)
char *line = camel_stream_buffer_read_line ( CAMEL_STREAM_BUFFER ( nntp_istream ));
int line_length = strlen ( line );
- if (*line == '.') {
+ if (!strcmp(line, ".")) {
done = TRUE;
g_free (line);
}
@@ -694,7 +701,7 @@ _get_message_by_uid (CamelFolder *folder, const gchar *uid, CamelException *ex)
}
strcat(buf, line);
strcat(buf, "\n");
- buf_len += strlen(line);
+ buf_len += strlen(line) + 1;
g_free (line);
}
}
diff --git a/camel/providers/nntp/camel-nntp-utils.c b/camel/providers/nntp/camel-nntp-utils.c
index def5cecd23..4ee93fc572 100644
--- a/camel/providers/nntp/camel-nntp-utils.c
+++ b/camel/providers/nntp/camel-nntp-utils.c
@@ -27,81 +27,183 @@
#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>
-GArray *
-camel_nntp_get_headers (CamelStore *store,
- CamelNNTPFolder *nntp_folder,
- CamelException *ex)
+static GArray*
+get_XOVER_headers(CamelNNTPStore *nntp_store, CamelFolder *folder,
+ int first_message, int last_message)
{
- CamelNNTPStore *nntp_store = CAMEL_NNTP_STORE (store);
- CamelFolder *folder = CAMEL_FOLDER (nntp_folder);
+ int status;
- if (TRUE /* nntp_store->extensions & CAMEL_NNTP_EXT_XOVER */) {
- int status;
- char *ret;
- int first_message, nb_message, last_message;
+ status = camel_nntp_command (nntp_store, NULL,
+ "XOVER %d-%d",
+ first_message,
+ last_message);
+
+ 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 ));
+
+ if (*line == '.') {
+ done = TRUE;
+ }
+ else {
+ CamelNNTPSummaryInformation new_info;
+ 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]);
+ /* 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]);
+ g_strfreev (split_line);
+
+ g_array_append_val(array, new_info);
+ }
+ g_free (line);
+ }
+
+ return array;
+ }
- status = camel_nntp_command (nntp_store, &ret,
- "GROUP %s", folder->name);
+ return NULL;
+}
- if (status != CAMEL_NNTP_OK)
- return NULL;
+static GArray*
+get_HEAD_headers(CamelNNTPStore *nntp_store, CamelFolder *folder,
+ int first_message, int last_message)
+{
+ int i;
+ int status;
+ GArray *array;
+ CamelNNTPSummaryInformation info;
- sscanf (ret, "%d %d %d", &nb_message, &first_message, &last_message);
- g_free (ret);
+ array = g_array_new(FALSE, FALSE, sizeof(CamelNNTPSummaryInformation));
+ for (i = first_message; i < last_message; i ++) {
status = camel_nntp_command (nntp_store, NULL,
- "XOVER %d-%d",
- first_message,
- last_message);
-
+ "HEAD %d", i);
+
if (status == CAMEL_NNTP_OK) {
- CamelStream *nntp_istream = nntp_store->istream;
- GArray *array;
gboolean done = FALSE;
+ char *buf;
+ int buf_len;
+ int buf_alloc;
+ int h;
+ CamelStream *header_stream;
+ GArray *header_array;
+ CamelStream *nntp_istream;
- array = g_array_new(FALSE, FALSE, sizeof(CamelNNTPSummaryInformation));
+ buf_alloc = 2048;
+ buf_len = 0;
+ buf = malloc(buf_alloc);
+ done = FALSE;
+
+ buf[0] = 0;
+
+ nntp_istream = nntp_store->istream;
while (!done) {
char *line;
+ int line_length;
line = camel_stream_buffer_read_line (
CAMEL_STREAM_BUFFER ( nntp_istream ));
+ line_length = strlen ( line );
if (*line == '.') {
done = TRUE;
}
else {
- CamelNNTPSummaryInformation new_info;
- char **split_line = g_strsplit (line, "\t", 7);
-
- 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]);
- /* 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]);
- g_strfreev (split_line);
-
- printf ("%s\t%s\t%s\n", new_info.headers.subject,
- new_info.headers.sender,
- new_info.headers.uid);
- g_array_append_val(array, new_info);
+ if (buf_len + line_length > buf_alloc) {
+ buf_alloc *= 2;
+ buf = realloc (buf, buf_alloc);
+ }
+ strcat(buf, line);
+ strcat(buf, "\n");
+ buf_len += strlen(line);
+ g_free (line);
}
- g_free (line);
}
- return array;
+ /* create a stream from which to parse the headers */
+ header_stream = camel_stream_mem_new_with_buffer(buf,
+ buf_len,
+ CAMEL_STREAM_MEM_READ);
+
+ header_array = get_header_array_from_stream (header_stream);
+
+ memset (&info, 0, sizeof(info));
+
+ for (h = 0; h < header_array->len; h ++) {
+ Rfc822Header *header = &((Rfc822Header*)header_array->data)[h];
+ if (!strcasecmp(header->name, "From"))
+ info.headers.sender = g_strdup(header->value);
+ else if (!strcasecmp(header->name, "To"))
+ info.headers.to = g_strdup(header->value);
+ else if (!strcasecmp(header->name, "Subject"))
+ info.headers.subject = g_strdup(header->value);
+ else if (!strcasecmp(header->name, "Message-ID"))
+ info.headers.uid = g_strdup(header->value);
+ else if (!strcasecmp(header->name, "Date")) {
+ info.headers.sent_date = g_strdup(header->value);
+ info.headers.received_date = g_strdup(header->value);
+ }
+ }
+ g_array_append_val(array, info);
+ }
+ else if (status == CAMEL_NNTP_FAIL) {
+ /* nasty things are afoot */
+ g_warning ("failure doing HEAD\n");
+ break;
}
}
+ return array;
+}
+
+GArray *
+camel_nntp_get_headers (CamelStore *store,
+ CamelNNTPFolder *nntp_folder,
+ CamelException *ex)
+{
+ CamelNNTPStore *nntp_store = CAMEL_NNTP_STORE (store);
+ CamelFolder *folder = CAMEL_FOLDER (nntp_folder);
+ char *ret;
+ int first_message, nb_message, last_message;
+ int status;
+
+ status = camel_nntp_command (nntp_store, &ret,
+ "GROUP %s", folder->name);
+
+ sscanf (ret, "%d %d %d", &nb_message, &first_message, &last_message);
+ g_free (ret);
+
+ if (status != CAMEL_NNTP_OK)
+ return NULL;
+
+ if (TRUE /* nntp_store->extensions & CAMEL_NNTP_EXT_XOVER */) {
+ return get_XOVER_headers (nntp_store, folder, first_message, last_message);
+ }
else {
- /* do HEAD stuff for the range of articles */
+ return get_HEAD_headers (nntp_store, folder, first_message, last_message);
}
-
- return NULL;
}