aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNotZed <NotZed@HelixCode.com>2000-05-20 03:58:41 +0800
committerMichael Zucci <zucchi@src.gnome.org>2000-05-20 03:58:41 +0800
commit2ce4eb74b65f3e9d07a921aad3899a7141b0000f (patch)
tree50439e412a6f12dc0b7db68274de8a8f16b74e08
parentb5ae6150b2a72683b7311af3252230069300d9e2 (diff)
downloadgsoc2013-evolution-2ce4eb74b65f3e9d07a921aad3899a7141b0000f.tar
gsoc2013-evolution-2ce4eb74b65f3e9d07a921aad3899a7141b0000f.tar.gz
gsoc2013-evolution-2ce4eb74b65f3e9d07a921aad3899a7141b0000f.tar.bz2
gsoc2013-evolution-2ce4eb74b65f3e9d07a921aad3899a7141b0000f.tar.lz
gsoc2013-evolution-2ce4eb74b65f3e9d07a921aad3899a7141b0000f.tar.xz
gsoc2013-evolution-2ce4eb74b65f3e9d07a921aad3899a7141b0000f.tar.zst
gsoc2013-evolution-2ce4eb74b65f3e9d07a921aad3899a7141b0000f.zip
> searchpart = strchr(namepart, '?');
2000-05-19 NotZed <NotZed@HelixCode.com> * camel-simple-data-wrapper.c (construct_from_stream): If we already have been constructed, unref our content. (write_to_stream): Check we've been constructued, and change for stream api changes. * camel-mime-parser.c: Removed exception stuff. * md5-utils.c (md5_get_digest_from_stream): repaired. * camel-mime-message.c: Remove exception from write_to_stream, and fix, and fix formatting. * providers/sendmail/camel-sendmail-transport.c (_send_internal): Fix for stream changes. * providers/pop3/camel-pop3-store.c (camel_pop3_command): Fixes for stream changes. * providers/mbox/camel-mbox-folder.c, and elsewhere, fix all stream api changes. (mbox_append_message): Use stream_close() now its back. (mbox_append_message): unref the from filter. * camel-stream-mem.c: And here. * camel-stream-fs.[ch]: Here too. * camel-stream-filter.c: Likewise. This is getting tedious. * camel-stream-buffer.c (stream_write): Fix a few little problems. (stream_close): Reimplmeent. (camel_stream_buffer_read_line): Slightly more efficient version, that also only allocates the right amount of memory for strings. * camel-seekable-substream.c: Likewise. * camel-seekable-stream.[ch]: Remove exceptions, fix formatting, changes for stream (re)fixes. set_bounds returns an error. * camel-stream.[ch]: Remove exceptions. Make flush and reset return an error code, repair all the screwed up formatting, and put back close. * camel-mime-part-utils.c (camel_mime_part_construct_content_from_parser): And here. * camel-mime-part.c (camel_mime_part_set_content): And this too. (write_to_stream): Fixed for stream changes. * camel.h: Fixed. * providers/vee/camel-vee-folder.c (vee_search_by_expression): Implement. Performs an intersection of the two searches. (camel_vee_folder_finalise): Unref search folders. (vee_append_message): Implement append. svn path=/trunk/; revision=3142
-rw-r--r--camel/ChangeLog58
-rw-r--r--camel/camel-data-wrapper.c45
-rw-r--r--camel/camel-data-wrapper.h14
-rw-r--r--camel/camel-folder-search.c2
-rw-r--r--camel/camel-folder.c2
-rw-r--r--camel/camel-mime-message.c10
-rw-r--r--camel/camel-mime-parser.c23
-rw-r--r--camel/camel-mime-part.c28
-rw-r--r--camel/camel-multipart.c35
-rw-r--r--camel/camel-seekable-stream.c49
-rw-r--r--camel/camel-seekable-stream.h17
-rw-r--r--camel/camel-seekable-substream.c76
-rw-r--r--camel/camel-simple-data-wrapper.c18
-rw-r--r--camel/camel-stream-buffer.c136
-rw-r--r--camel/camel-stream-buffer.h9
-rw-r--r--camel/camel-stream-filter.c53
-rw-r--r--camel/camel-stream-fs.c109
-rw-r--r--camel/camel-stream-fs.h17
-rw-r--r--camel/camel-stream-mem.c23
-rw-r--r--camel/camel-stream-mem.h3
-rw-r--r--camel/camel-stream.c107
-rw-r--r--camel/camel-stream.h37
-rw-r--r--camel/camel.h1
-rw-r--r--camel/gmime-content-field.c3
-rw-r--r--camel/md5-utils.c5
-rw-r--r--camel/providers/mbox/camel-mbox-folder.c32
-rw-r--r--camel/providers/pop3/camel-pop3-store.c22
-rw-r--r--camel/providers/sendmail/camel-sendmail-transport.c13
-rw-r--r--camel/providers/vee/camel-vee-folder.c98
-rw-r--r--camel/providers/vee/camel-vee-folder.h2
30 files changed, 562 insertions, 485 deletions
diff --git a/camel/ChangeLog b/camel/ChangeLog
index a2a09c9e05..504b95bf7a 100644
--- a/camel/ChangeLog
+++ b/camel/ChangeLog
@@ -1,3 +1,61 @@
+2000-05-19 NotZed <NotZed@HelixCode.com>
+
+ * camel-simple-data-wrapper.c (construct_from_stream): If we
+ already have been constructed, unref our content.
+ (write_to_stream): Check we've been constructued, and change for
+ stream api changes.
+
+ * camel-mime-parser.c: Removed exception stuff.
+
+ * md5-utils.c (md5_get_digest_from_stream): repaired.
+
+ * camel-mime-message.c: Remove exception from write_to_stream, and
+ fix, and fix formatting.
+
+ * providers/sendmail/camel-sendmail-transport.c (_send_internal):
+ Fix for stream changes.
+
+ * providers/pop3/camel-pop3-store.c (camel_pop3_command): Fixes
+ for stream changes.
+
+ * providers/mbox/camel-mbox-folder.c, and elsewhere, fix all
+ stream api changes.
+ (mbox_append_message): Use stream_close() now its back.
+ (mbox_append_message): unref the from filter.
+
+ * camel-stream-mem.c: And here.
+
+ * camel-stream-fs.[ch]: Here too.
+
+ * camel-stream-filter.c: Likewise. This is getting tedious.
+
+ * camel-stream-buffer.c (stream_write): Fix a few little problems.
+ (stream_close): Reimplmeent.
+ (camel_stream_buffer_read_line): Slightly more efficient version,
+ that also only allocates the right amount of memory for strings.
+
+ * camel-seekable-substream.c: Likewise.
+
+ * camel-seekable-stream.[ch]: Remove exceptions, fix formatting,
+ changes for stream (re)fixes. set_bounds returns an error.
+
+ * camel-stream.[ch]: Remove exceptions. Make flush and reset return
+ an error code, repair all the screwed up formatting, and put back
+ close.
+
+ * camel-mime-part-utils.c
+ (camel_mime_part_construct_content_from_parser): And here.
+
+ * camel-mime-part.c (camel_mime_part_set_content): And this too.
+ (write_to_stream): Fixed for stream changes.
+
+ * camel.h: Fixed.
+
+ * providers/vee/camel-vee-folder.c (vee_search_by_expression):
+ Implement. Performs an intersection of the two searches.
+ (camel_vee_folder_finalise): Unref search folders.
+ (vee_append_message): Implement append.
+
2000-05-18 Dan Winship <danw@helixcode.com>
* camel-folder.c: remove message_number_capability and require uid
diff --git a/camel/camel-data-wrapper.c b/camel/camel-data-wrapper.c
index 61cee59a51..fe9f8bf78b 100644
--- a/camel/camel-data-wrapper.c
+++ b/camel/camel-data-wrapper.c
@@ -1,4 +1,4 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; fill-column: 160 -*- */
/* camel-data-wrapper.c : Abstract class for a data_wrapper */
/*
@@ -37,14 +37,11 @@ static CamelObjectClass *parent_class = NULL;
static int construct_from_stream(CamelDataWrapper *, CamelStream *);
-static int write_to_stream (CamelDataWrapper *data_wrapper,
- CamelStream *stream, CamelException *ex);
-static void set_mime_type (CamelDataWrapper *data_wrapper,
- const gchar *mime_type);
+static int write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream);
+static void set_mime_type (CamelDataWrapper *data_wrapper, const gchar *mime_type);
static gchar *get_mime_type (CamelDataWrapper *data_wrapper);
static GMimeContentField *get_mime_type_field (CamelDataWrapper *data_wrapper);
-static void set_mime_type_field (CamelDataWrapper *data_wrapper,
- GMimeContentField *mime_type);
+static void set_mime_type_field (CamelDataWrapper *data_wrapper, GMimeContentField *mime_type);
static void finalize (GtkObject *object);
static void
@@ -115,12 +112,22 @@ finalize (GtkObject *object)
}
static int
-write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream,
- CamelException *ex)
+write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
{
- g_warning ("CamelDataWrapper::write_to_stream not implemented for "
- "`%s'", gtk_type_name (GTK_OBJECT_TYPE (data_wrapper)));
- return -1;
+ if (data_wrapper->stream == NULL) {
+ return -1;
+ }
+
+ if (camel_stream_reset (data_wrapper->stream) == -1)
+ return -1;
+
+ return camel_stream_write_to_stream (data_wrapper->stream, stream);
+}
+
+CamelDataWrapper *
+camel_data_wrapper_new(void)
+{
+ return (CamelDataWrapper *)gtk_type_new(camel_data_wrapper_get_type());
}
/**
@@ -138,20 +145,17 @@ write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream,
**/
int
camel_data_wrapper_write_to_stream (CamelDataWrapper *data_wrapper,
- CamelStream *stream, CamelException *ex)
+ CamelStream *stream)
{
g_return_val_if_fail (CAMEL_IS_DATA_WRAPPER (data_wrapper), -1);
g_return_val_if_fail (CAMEL_IS_STREAM (stream), -1);
- return CDW_CLASS (data_wrapper)->write_to_stream (data_wrapper,
- stream, ex);
+ return CDW_CLASS (data_wrapper)->write_to_stream (data_wrapper, stream);
}
static int
construct_from_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
{
- g_warning ("CamelDataWrapper::construct_from_stream not implemented "
- "for `%s'", gtk_type_name (GTK_OBJECT_TYPE (data_wrapper)));
return -1;
}
@@ -163,9 +167,7 @@ construct_from_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
* Constructs the content of the data wrapper from the
* supplied @stream.
*
- * This could fail, but you can't know if it did.
- *
- * Return value: Who knows. FIXME
+ * Return value: -1 on error.
**/
int
camel_data_wrapper_construct_from_stream (CamelDataWrapper *data_wrapper,
@@ -274,6 +276,5 @@ void
camel_data_wrapper_set_mime_type_field (CamelDataWrapper *data_wrapper,
GMimeContentField *mime_type)
{
- CDW_CLASS (data_wrapper)->set_mime_type_field (data_wrapper,
- mime_type);
+ CDW_CLASS (data_wrapper)->set_mime_type_field (data_wrapper, mime_type);
}
diff --git a/camel/camel-data-wrapper.h b/camel/camel-data-wrapper.h
index d6e9e754cf..8df09fa848 100644
--- a/camel/camel-data-wrapper.h
+++ b/camel/camel-data-wrapper.h
@@ -42,16 +42,14 @@ extern "C" {
#define CAMEL_DATA_WRAPPER_CLASS(k) (GTK_CHECK_CLASS_CAST ((k), CAMEL_DATA_WRAPPER_TYPE, CamelDataWrapperClass))
#define CAMEL_IS_DATA_WRAPPER(o) (GTK_CHECK_TYPE((o), CAMEL_DATA_WRAPPER_TYPE))
-
struct _CamelDataWrapper
{
CamelObject parent_object;
GMimeContentField *mime_type;
+ CamelStream *stream;
};
-
-
typedef struct {
CamelObjectClass parent_class;
@@ -68,23 +66,19 @@ typedef struct {
GMimeContentField *mime_type_field);
int (*write_to_stream) (CamelDataWrapper *data_wrapper,
- CamelStream *stream,
- CamelException *ex);
+ CamelStream *stream);
int (*construct_from_stream) (CamelDataWrapper *data_wrapper,
CamelStream *);
} CamelDataWrapperClass;
-
-
/* Standard Gtk function */
GtkType camel_data_wrapper_get_type (void);
-
/* public methods */
+CamelDataWrapper * camel_data_wrapper_new(void);
int camel_data_wrapper_write_to_stream (CamelDataWrapper *data_wrapper,
- CamelStream *stream,
- CamelException *ex);
+ CamelStream *stream);
void camel_data_wrapper_set_mime_type (CamelDataWrapper *data_wrapper,
const gchar *mime_type);
gchar * camel_data_wrapper_get_mime_type (CamelDataWrapper *data_wrapper);
diff --git a/camel/camel-folder-search.c b/camel/camel-folder-search.c
index b6332c5656..fa07fc819f 100644
--- a/camel/camel-folder-search.c
+++ b/camel/camel-folder-search.c
@@ -472,7 +472,7 @@ static ESExpResult *search_user_flag(struct _ESExp *f, int argc, struct _ESExpRe
ESExpResult *r;
int i;
- r(printf("executing header-contains\n"));
+ r(printf("executing user-flag\n"));
/* are we inside a match-all? */
if (search->current) {
diff --git a/camel/camel-folder.c b/camel/camel-folder.c
index 2c6e04d73b..34b830f564 100644
--- a/camel/camel-folder.c
+++ b/camel/camel-folder.c
@@ -1,4 +1,4 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; fill-column: 160 -*- */
/* camel-folder.c: Abstract class for an email folder */
/*
diff --git a/camel/camel-mime-message.c b/camel/camel-mime-message.c
index f65691909f..8fca516fd0 100644
--- a/camel/camel-mime-message.c
+++ b/camel/camel-mime-message.c
@@ -1,4 +1,4 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; fill-column: 160 -*- */
/* camelMimeMessage.c : class for a mime_message */
/*
@@ -66,8 +66,7 @@ static guint signals[LAST_SIGNAL] = { 0 };
static void set_message_number (CamelMimeMessage *mime_message, guint number);
static guint get_message_number (CamelMimeMessage *mime_message);
-static int write_to_stream (CamelDataWrapper *data_wrapper,
- CamelStream *stream, CamelException *ex);
+static int write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream);
static void finalize (GtkObject *object);
static void add_header (CamelMedium *medium, const char *header_name, const void *header_value);
static void set_header (CamelMedium *medium, const char *header_name, const void *header_value);
@@ -592,8 +591,7 @@ construct_from_parser(CamelMimePart *dw, CamelMimeParser *mp)
}
static int
-write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream,
- CamelException *ex)
+write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
{
CamelMimeMessage *mm = CAMEL_MIME_MESSAGE (data_wrapper);
@@ -615,7 +613,7 @@ write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream,
camel_medium_set_header((CamelMedium *)mm, "Mime-Version", "1.0");
- return CAMEL_DATA_WRAPPER_CLASS (parent_class)->write_to_stream (data_wrapper, stream, ex);
+ return CAMEL_DATA_WRAPPER_CLASS (parent_class)->write_to_stream (data_wrapper, stream);
}
static char *
diff --git a/camel/camel-mime-parser.c b/camel/camel-mime-parser.c
index 3db6adfe83..74c7653df3 100644
--- a/camel/camel-mime-parser.c
+++ b/camel/camel-mime-parser.c
@@ -41,7 +41,6 @@
#include "camel-mime-filter.h"
#include "camel-stream.h"
#include "camel-seekable-stream.h"
-#include "camel-exception.h"
#define r(x)
#define h(x)
@@ -209,7 +208,6 @@ struct _header_scan_state {
int fd; /* input for a fd input */
CamelStream *stream; /* or for a stream */
- CamelException *ex; /* exception for the stream */
/* for scanning input buffers */
char *realbuf; /* the real buffer, SCAN_HEAD*2 + SCAN_BUF bytes */
@@ -826,8 +824,7 @@ folder_read(struct _header_scan_state *s)
memcpy(s->inbuf, s->inptr, inoffset);
}
if (s->stream) {
- len = camel_stream_read(s->stream, s->inbuf+inoffset,
- SCAN_BUF-inoffset, s->ex);
+ len = camel_stream_read(s->stream, s->inbuf+inoffset, SCAN_BUF-inoffset);
} else {
len = read(s->fd, s->inbuf+inoffset, SCAN_BUF-inoffset);
}
@@ -872,7 +869,7 @@ folder_seek(struct _header_scan_state *s, off_t offset, int whence)
if (CAMEL_IS_SEEKABLE_STREAM(s->stream)) {
/* NOTE: assumes whence seekable stream == whence libc, which is probably
the case (or bloody well should've been) */
- newoffset = camel_seekable_stream_seek((CamelSeekableStream *)s->stream, offset, whence, s->ex);
+ newoffset = camel_seekable_stream_seek((CamelSeekableStream *)s->stream, offset, whence);
} else {
newoffset = -1;
errno = EINVAL;
@@ -889,7 +886,7 @@ folder_seek(struct _header_scan_state *s, off_t offset, int whence)
s->inptr = s->inbuf;
s->inend = s->inbuf;
if (s->stream)
- len = camel_stream_read(s->stream, s->inbuf, SCAN_BUF, s->ex);
+ len = camel_stream_read(s->stream, s->inbuf, SCAN_BUF);
else
len = read(s->fd, s->inbuf, SCAN_BUF);
if (len>=0) {
@@ -1358,7 +1355,6 @@ folder_scan_close(struct _header_scan_state *s)
close(s->fd);
if (s->stream) {
gtk_object_unref((GtkObject *)s->stream);
- camel_exception_free(s->ex);
}
g_free(s);
}
@@ -1373,7 +1369,6 @@ folder_scan_init(void)
s->fd = -1;
s->stream = NULL;
- s->ex = NULL;
s->outbuf = g_malloc(1024);
s->outptr = s->outbuf;
@@ -1421,8 +1416,6 @@ folder_scan_init_with_fd(struct _header_scan_state *s, int fd)
if (s->stream) {
gtk_object_unref((GtkObject *)s->stream);
s->stream = NULL;
- camel_exception_free(s->ex);
- s->ex = NULL;
}
return 0;
} else {
@@ -1434,11 +1427,9 @@ static int
folder_scan_init_with_stream(struct _header_scan_state *s, CamelStream *stream)
{
int len;
- CamelException *ex;
- ex = camel_exception_new();
- len = camel_stream_read(stream, s->inbuf, SCAN_BUF, ex);
- if (!camel_exception_is_set (ex)) {
+ len = camel_stream_read(stream, s->inbuf, SCAN_BUF);
+ if (len >= 0) {
s->inend = s->inbuf+len;
s->inptr = s->inbuf;
s->inend[0] = '\n';
@@ -1446,16 +1437,12 @@ folder_scan_init_with_stream(struct _header_scan_state *s, CamelStream *stream)
gtk_object_unref((GtkObject *)s->stream);
s->stream = stream;
gtk_object_ref((GtkObject *)stream);
- if (s->ex)
- camel_exception_free(s->ex);
- s->ex = ex;
if (s->fd != -1) {
close(s->fd);
s->fd = -1;
}
return 0;
} else {
- camel_exception_free (ex);
return -1;
}
}
diff --git a/camel/camel-mime-part.c b/camel/camel-mime-part.c
index e79edaa3dd..d727c98811 100644
--- a/camel/camel-mime-part.c
+++ b/camel/camel-mime-part.c
@@ -66,9 +66,7 @@ static CamelMediumClass *parent_class=NULL;
static void finalize (GtkObject *object);
/* from CamelDataWrapper */
-static int write_to_stream (CamelDataWrapper *data_wrapper,
- CamelStream *stream,
- CamelException *ex);
+static int write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream);
static int construct_from_stream (CamelDataWrapper *dw, CamelStream *s);
/* from CamelMedia */
@@ -480,13 +478,13 @@ set_content_object (CamelMedium *medium, CamelDataWrapper *content)
/**********************************************************************/
static int
-write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream,
- CamelException *ex)
+write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
{
CamelMimePart *mp = CAMEL_MIME_PART (data_wrapper);
CamelMedium *medium = CAMEL_MEDIUM (data_wrapper);
CamelDataWrapper *content;
int total = 0;
+ int count;
d(printf("mime_part::write_to_stream\n"));
@@ -497,19 +495,18 @@ write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream,
if (mp->headers) {
struct _header_raw *h = mp->headers;
while (h) {
- total += camel_stream_printf (stream, ex, "%s%s%s\n",
- h->name,
- isspace(h->value[0]) ? ":" : ": ",
- h->value);
- if (camel_exception_is_set (ex))
+ count = camel_stream_printf(stream, "%s%s%s\n", h->name, isspace(h->value[0]) ? ":" : ": ", h->value);
+ if (count == -1)
return -1;
+ total += count;
h = h->next;
}
}
- total += camel_stream_write (stream, "\n", 1, ex);
- if (camel_exception_is_set (ex))
+ count = camel_stream_write (stream, "\n", 1);
+ if (count == -1)
return -1;
+ total += count;
content = camel_medium_get_content_object (medium);
if (content) {
@@ -537,11 +534,12 @@ write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream,
}
#endif
- total += camel_data_wrapper_write_to_stream (content, stream, ex);
+ count = camel_data_wrapper_write_to_stream (content, stream);
if (filter_stream)
gtk_object_unref((GtkObject *)filter_stream);
- if (camel_exception_is_set (ex))
+ if (count == -1)
return -1;
+ total += count;
} else {
g_warning("No content for medium, nothing to write");
}
@@ -692,7 +690,7 @@ camel_mime_part_set_content (CamelMimePart *camel_mime_part,
CamelDataWrapper *dw;
CamelStream *stream;
- dw = camel_simple_data_wrapper_new ();
+ dw = camel_data_wrapper_new ();
camel_data_wrapper_set_mime_type (dw, type);
stream = camel_stream_mem_new_with_buffer (data, length);
camel_data_wrapper_construct_from_stream (dw, stream);
diff --git a/camel/camel-multipart.c b/camel/camel-multipart.c
index 8155ce1229..ea1f7d356f 100644
--- a/camel/camel-multipart.c
+++ b/camel/camel-multipart.c
@@ -51,8 +51,7 @@ static void set_boundary (CamelMultipart *multipart,
gchar *boundary);
static const gchar * get_boundary (CamelMultipart *multipart);
static int write_to_stream (CamelDataWrapper *data_wrapper,
- CamelStream *stream,
- CamelException *ex);
+ CamelStream *stream);
static void finalize (GtkObject *object);
static CamelDataWrapperClass *parent_class = NULL;
@@ -406,12 +405,12 @@ camel_multipart_get_boundary (CamelMultipart *multipart)
/* this is MIME specific, doesn't belong here really */
static int
-write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream,
- CamelException *ex)
+write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
{
CamelMultipart *multipart = CAMEL_MULTIPART (data_wrapper);
const gchar *boundary;
int total = 0;
+ int count;
GList *node;
/* get the bundary text */
@@ -426,10 +425,10 @@ write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream,
* your mail client probably doesn't support ...."
*/
if (multipart->preface) {
- total += camel_stream_write_string (stream,
- multipart->preface, ex);
- if (camel_exception_is_set (ex))
+ count = camel_stream_write_string (stream, multipart->preface);
+ if (count == -1)
return -1;
+ total += count;
}
/*
@@ -438,28 +437,30 @@ write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream,
*/
node = multipart->parts;
while (node) {
- total += camel_stream_printf (stream, ex, "\n--%s\n",
- boundary);
- if (camel_exception_is_set (ex))
+ count = camel_stream_printf (stream, "\n--%s\n", boundary);
+ if (count == -1)
return -1;
+ total += count;
- total += camel_data_wrapper_write_to_stream (CAMEL_DATA_WRAPPER (node->data), stream, ex);
- if (camel_exception_is_set (ex))
+ count = camel_data_wrapper_write_to_stream (CAMEL_DATA_WRAPPER (node->data), stream);
+ if (count == -1)
return -1;
+ total += count;
node = node->next;
}
/* write the terminating boudary delimiter */
- total += camel_stream_printf (stream, ex, "\n--%s--\n", boundary);
- if (camel_exception_is_set (ex))
+ count = camel_stream_printf (stream, "\n--%s--\n", boundary);
+ if (count == -1)
return -1;
+ total += count;
/* and finally the postface */
if (multipart->postface) {
- total += camel_stream_write_string (stream,
- multipart->postface, ex);
- if (camel_exception_is_set (ex))
+ count = camel_stream_write_string (stream, multipart->postface);
+ if (count == -1)
return -1;
+ total += count;
}
return total;
diff --git a/camel/camel-seekable-stream.c b/camel/camel-seekable-stream.c
index a62ae9544f..507c69dd48 100644
--- a/camel/camel-seekable-stream.c
+++ b/camel/camel-seekable-stream.c
@@ -32,13 +32,10 @@ static CamelStreamClass *parent_class = NULL;
#define CSS_CLASS(so) CAMEL_SEEKABLE_STREAM_CLASS (GTK_OBJECT(so)->klass)
static off_t seek (CamelSeekableStream *stream, off_t offset,
- CamelStreamSeekPolicy policy,
- CamelException *ex);
+ CamelStreamSeekPolicy policy);
static off_t stream_tell (CamelSeekableStream *stream);
-static void reset (CamelStream *stream, CamelException *ex);
-static void set_bounds (CamelSeekableStream *stream, off_t start, off_t end,
- CamelException *ex);
-
+static int reset (CamelStream *stream);
+static int set_bounds (CamelSeekableStream *stream, off_t start, off_t end);
static void
camel_seekable_stream_class_init (CamelSeekableStreamClass *camel_seekable_stream_class)
@@ -93,7 +90,7 @@ camel_seekable_stream_get_type (void)
static off_t
seek (CamelSeekableStream *stream, off_t offset,
- CamelStreamSeekPolicy policy, CamelException *ex)
+ CamelStreamSeekPolicy policy)
{
g_warning ("CamelSeekableStream::seek called on default "
"implementation\n");
@@ -105,7 +102,6 @@ seek (CamelSeekableStream *stream, off_t offset,
* @stream: a CamelStream object.
* @offset: offset value
* @policy: what to do with the offset
- * @ex: a CamelException
*
* Seek to the specified position in @stream.
*
@@ -125,12 +121,11 @@ seek (CamelSeekableStream *stream, off_t offset,
**/
off_t
camel_seekable_stream_seek (CamelSeekableStream *stream, off_t offset,
- CamelStreamSeekPolicy policy,
- CamelException *ex)
+ CamelStreamSeekPolicy policy)
{
g_return_val_if_fail (CAMEL_IS_SEEKABLE_STREAM (stream), -1);
- return CSS_CLASS (stream)->seek (stream, offset, policy, ex);
+ return CSS_CLASS (stream)->seek (stream, offset, policy);
}
@@ -156,17 +151,17 @@ camel_seekable_stream_tell (CamelSeekableStream *stream)
return CSS_CLASS (stream)->tell (stream);
}
-
-static void
-set_bounds (CamelSeekableStream *stream, off_t start, off_t end,
- CamelException *ex)
+static int
+set_bounds (CamelSeekableStream *stream, off_t start, off_t end)
{
/* store the bounds */
stream->bound_start = start;
stream->bound_end = end;
if (start > stream->position)
- camel_seekable_stream_seek (stream, start, CAMEL_STREAM_SET, ex);
+ return camel_seekable_stream_seek (stream, start, CAMEL_STREAM_SET);
+
+ return 0;
}
/**
@@ -178,28 +173,30 @@ set_bounds (CamelSeekableStream *stream, off_t start, off_t end,
* Set the range of valid data this stream is allowed to cover. If
* there is to be no @end value, then @end should be set to
* #CAMEL_STREAM_UNBOUND.
+ *
+ * Return value: -1 on error.
**/
-void
+int
camel_seekable_stream_set_bounds (CamelSeekableStream *stream,
- off_t start, off_t end, CamelException *ex)
+ off_t start, off_t end)
{
- g_return_if_fail (CAMEL_IS_SEEKABLE_STREAM (stream));
- g_return_if_fail (end == CAMEL_STREAM_UNBOUND || end >= start);
+ g_return_val_if_fail (CAMEL_IS_SEEKABLE_STREAM (stream), -1);
+ g_return_val_if_fail (end == CAMEL_STREAM_UNBOUND || end >= start, -1);
- CSS_CLASS (stream)->set_bounds (stream, start, end, ex);
+ return CSS_CLASS (stream)->set_bounds (stream, start, end);
}
/* a default implementation of reset for seekable streams */
-static void
-reset (CamelStream *stream, CamelException *ex)
+static int
+reset (CamelStream *stream)
{
CamelSeekableStream *seekable_stream;
seekable_stream = CAMEL_SEEKABLE_STREAM (stream);
- camel_seekable_stream_seek (seekable_stream,
- seekable_stream->bound_start,
- CAMEL_STREAM_SET, ex);
+ return camel_seekable_stream_seek (seekable_stream,
+ seekable_stream->bound_start,
+ CAMEL_STREAM_SET);
}
diff --git a/camel/camel-seekable-stream.h b/camel/camel-seekable-stream.h
index 24333bcfa0..f1cd5cdbca 100644
--- a/camel/camel-seekable-stream.h
+++ b/camel/camel-seekable-stream.h
@@ -66,25 +66,20 @@ typedef struct {
/* Virtual methods */
off_t (*seek) (CamelSeekableStream *stream, off_t offset,
- CamelStreamSeekPolicy policy,
- CamelException *ex);
+ CamelStreamSeekPolicy policy);
off_t (*tell) (CamelSeekableStream *stream);
- void (*set_bounds) (CamelSeekableStream *stream,
- off_t start, off_t end, CamelException *ex);
+ int (*set_bounds) (CamelSeekableStream *stream,
+ off_t start, off_t end);
} CamelSeekableStreamClass;
/* Standard Gtk function */
GtkType camel_seekable_stream_get_type (void);
/* public methods */
-off_t camel_seekable_stream_seek (CamelSeekableStream *stream,
- off_t offset,
- CamelStreamSeekPolicy policy,
- CamelException *ex);
+off_t camel_seekable_stream_seek (CamelSeekableStream *stream, off_t offset,
+ CamelStreamSeekPolicy policy);
off_t camel_seekable_stream_tell (CamelSeekableStream *stream);
-void camel_seekable_stream_set_bounds (CamelSeekableStream *,
- off_t, off_t,
- CamelException *);
+int camel_seekable_stream_set_bounds (CamelSeekableStream *, off_t start, off_t end);
#ifdef __cplusplus
}
diff --git a/camel/camel-seekable-substream.c b/camel/camel-seekable-substream.c
index 5c9ea6ebe7..4fc5b5d853 100644
--- a/camel/camel-seekable-substream.c
+++ b/camel/camel-seekable-substream.c
@@ -23,28 +23,20 @@
*/
#include <config.h>
#include "camel-seekable-substream.h"
-#include "camel-exception.h"
static CamelSeekableStreamClass *parent_class = NULL;
/* Returns the class for a CamelSeekableSubStream */
#define CSS_CLASS(so) CAMEL_SEEKABLE_SUBSTREAM_CLASS (GTK_OBJECT(so)->klass)
-static int stream_read (CamelStream *stream,
- char *buffer, unsigned int n,
- CamelException *ex);
-static int stream_write (CamelStream *stream,
- const char *buffer,
- unsigned int n,
- CamelException *ex);
-static void stream_flush (CamelStream *stream,
- CamelException *ex);
-static gboolean eos (CamelStream *stream);
-static off_t stream_seek (CamelSeekableStream *stream,
- off_t offset,
- CamelStreamSeekPolicy policy,
- CamelException *ex);
-static void finalize (GtkObject *object);
+static int stream_read (CamelStream *stream, char *buffer, unsigned int n);
+static int stream_write (CamelStream *stream, const char *buffer, unsigned int n);
+static int stream_flush (CamelStream *stream);
+static int stream_close (CamelStream *stream);
+static gboolean eos (CamelStream *stream);
+static off_t stream_seek (CamelSeekableStream *stream, off_t offset,
+ CamelStreamSeekPolicy policy);
+static void finalize (GtkObject *object);
static void
@@ -65,6 +57,7 @@ camel_seekable_substream_class_init (CamelSeekableSubstreamClass *camel_seekable
camel_stream_class->read = stream_read;
camel_stream_class->write = stream_write;
camel_stream_class->flush = stream_flush;
+ camel_stream_class->close = stream_close;
camel_stream_class->eos = eos;
camel_seekable_stream_class->seek = stream_seek;
@@ -131,7 +124,6 @@ camel_seekable_substream_new_with_seekable_stream_and_bounds (CamelSeekableStrea
off_t start, off_t end)
{
CamelSeekableSubstream *seekable_substream;
- CamelException ex;
g_return_val_if_fail (CAMEL_IS_SEEKABLE_STREAM (parent_stream), NULL);
@@ -145,16 +137,13 @@ camel_seekable_substream_new_with_seekable_stream_and_bounds (CamelSeekableStrea
/* Set the bound of the substream. We can ignore any possible error
* here, because if we fail to seek now, it will try again later.
*/
- camel_exception_init (&ex);
- camel_seekable_stream_set_bounds ((CamelSeekableStream *)seekable_substream, start, end, &ex);
- camel_exception_clear (&ex);
+ camel_seekable_stream_set_bounds ((CamelSeekableStream *)seekable_substream, start, end);
return CAMEL_STREAM (seekable_substream);
}
static gboolean
-parent_reset (CamelSeekableSubstream *seekable_substream,
- CamelSeekableStream *parent, CamelException *ex)
+parent_reset (CamelSeekableSubstream *seekable_substream, CamelSeekableStream *parent)
{
CamelSeekableStream *seekable_stream =
CAMEL_SEEKABLE_STREAM (seekable_substream);
@@ -162,14 +151,12 @@ parent_reset (CamelSeekableSubstream *seekable_substream,
if (camel_seekable_stream_tell (parent) == seekable_stream->position)
return TRUE;
- camel_seekable_stream_seek (parent, seekable_stream->position,
- CAMEL_STREAM_SET, ex);
- return !camel_exception_is_set (ex);
+ return camel_seekable_stream_seek (parent, seekable_stream->position, CAMEL_STREAM_SET)
+ == seekable_stream->position;
}
static int
-stream_read (CamelStream *stream, char *buffer, unsigned int n,
- CamelException *ex)
+stream_read (CamelStream *stream, char *buffer, unsigned int n)
{
CamelSeekableStream *parent;
CamelSeekableStream *seekable_stream = CAMEL_SEEKABLE_STREAM (stream);
@@ -183,7 +170,7 @@ stream_read (CamelStream *stream, char *buffer, unsigned int n,
parent = seekable_substream->parent_stream;
/* Go to our position in the parent stream. */
- if (!parent_reset (seekable_substream, parent, ex)) {
+ if (!parent_reset (seekable_substream, parent)) {
stream->eos = TRUE;
return 0;
}
@@ -197,7 +184,7 @@ stream_read (CamelStream *stream, char *buffer, unsigned int n,
return 0;
}
- v = camel_stream_read (CAMEL_STREAM (parent), buffer, n, ex);
+ v = camel_stream_read (CAMEL_STREAM (parent), buffer, n);
/* ignore <0 - its an error, let the caller deal */
if (v > 0)
@@ -207,22 +194,29 @@ stream_read (CamelStream *stream, char *buffer, unsigned int n,
}
static int
-stream_write (CamelStream *stream, const char *buffer, unsigned int n,
- CamelException *ex)
+stream_write (CamelStream *stream, const char *buffer, unsigned int n)
{
/* NOT VALID ON SEEKABLE SUBSTREAM */
/* Well, its entirely valid, just not implemented */
g_warning ("CamelSeekableSubstream:: seekable substream doesn't "
- "have a write method\n");
+ "have a write method yet?\n");
return -1;
}
-static void
-stream_flush (CamelStream *stream, CamelException *ex)
+static int
+stream_flush (CamelStream *stream)
{
/* NOT VALID ON SEEKABLE SUBSTREAM */
g_warning ("CamelSeekableSubstream:: seekable substream doesn't "
"have a flush method\n");
+ return -1;
+}
+
+static int
+stream_close (CamelStream *stream)
+{
+ /* we dont really want to close the substream ... */
+ return 0;
}
static gboolean
@@ -232,19 +226,14 @@ eos (CamelStream *stream)
CAMEL_SEEKABLE_SUBSTREAM (stream);
CamelSeekableStream *seekable_stream = CAMEL_SEEKABLE_STREAM (stream);
CamelSeekableStream *parent;
- CamelException ex;
gboolean eos;
if (stream->eos)
eos = TRUE;
else {
parent = seekable_substream->parent_stream;
- camel_exception_init (&ex);
- parent_reset (seekable_substream, parent, &ex);
- if (camel_exception_is_set (&ex)) {
- camel_exception_clear (&ex);
+ if (!parent_reset (seekable_substream, parent))
return TRUE;
- }
eos = camel_stream_eos (CAMEL_STREAM (parent));
if (!eos && (seekable_stream->bound_end != CAMEL_STREAM_UNBOUND)) {
@@ -257,7 +246,7 @@ eos (CamelStream *stream)
static off_t
stream_seek (CamelSeekableStream *seekable_stream, off_t offset,
- CamelStreamSeekPolicy policy, CamelException *ex)
+ CamelStreamSeekPolicy policy)
{
CamelSeekableSubstream *seekable_substream =
CAMEL_SEEKABLE_SUBSTREAM (seekable_stream);
@@ -278,9 +267,8 @@ stream_seek (CamelSeekableStream *seekable_stream, off_t offset,
case CAMEL_STREAM_END:
real_offset = camel_seekable_stream_seek (seekable_substream->parent_stream,
offset,
- CAMEL_STREAM_END,
- ex);
- if (camel_exception_is_set (ex))
+ CAMEL_STREAM_END);
+ if (real_offset == -1)
return -1;
break;
}
diff --git a/camel/camel-simple-data-wrapper.c b/camel/camel-simple-data-wrapper.c
index cc6bbc6771..f091211e3c 100644
--- a/camel/camel-simple-data-wrapper.c
+++ b/camel/camel-simple-data-wrapper.c
@@ -37,7 +37,7 @@ static CamelDataWrapperClass *parent_class = NULL;
static int construct_from_stream (CamelDataWrapper *, CamelStream *);
static int write_to_stream (CamelDataWrapper *data_wrapper,
- CamelStream *stream, CamelException *ex);
+ CamelStream *stream);
static void finalize (GtkObject *object);
@@ -116,6 +116,9 @@ construct_from_stream (CamelDataWrapper *wrapper, CamelStream *stream)
CamelSimpleDataWrapper *simple_data_wrapper =
CAMEL_SIMPLE_DATA_WRAPPER (wrapper);
+ if (simple_data_wrapper->content)
+ gtk_object_unref((GtkObject *)simple_data_wrapper->content);
+
simple_data_wrapper->content = stream;
gtk_object_ref (GTK_OBJECT (stream));
return 0;
@@ -123,15 +126,16 @@ construct_from_stream (CamelDataWrapper *wrapper, CamelStream *stream)
static int
-write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream,
- CamelException *ex)
+write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
{
CamelSimpleDataWrapper *simple_data_wrapper =
CAMEL_SIMPLE_DATA_WRAPPER (data_wrapper);
- camel_stream_reset (simple_data_wrapper->content, ex);
- if (camel_exception_is_set (ex))
+ if (simple_data_wrapper->content == NULL)
return -1;
- return camel_stream_write_to_stream (simple_data_wrapper->content,
- stream, ex);
+
+ if (camel_stream_reset (simple_data_wrapper->content) == -1)
+ return -1;
+
+ return camel_stream_write_to_stream (simple_data_wrapper->content, stream);
}
diff --git a/camel/camel-stream-buffer.c b/camel/camel-stream-buffer.c
index 8475cab2c0..68dcc7ad21 100644
--- a/camel/camel-stream-buffer.c
+++ b/camel/camel-stream-buffer.c
@@ -1,4 +1,4 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; fill-column: 160 -*- */
/* camel-stream-buffer.c : Buffer any other other stream
*
@@ -25,7 +25,6 @@
#include <config.h>
#include "camel-stream-buffer.h"
-#include "camel-exception.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
@@ -39,11 +38,10 @@ enum {
#define BUF_SIZE 1024
-static int stream_read (CamelStream *stream, char *buffer,
- unsigned int n, CamelException *ex);
-static int stream_write (CamelStream *stream, const char *buffer,
- unsigned int n, CamelException *ex);
-static void stream_flush (CamelStream *stream, CamelException *ex);
+static int stream_read (CamelStream *stream, char *buffer, unsigned int n);
+static int stream_write (CamelStream *stream, const char *buffer, unsigned int n);
+static int stream_flush (CamelStream *stream);
+static int stream_close (CamelStream *stream);
static gboolean stream_eos (CamelStream *stream);
static void finalize (GtkObject *object);
@@ -68,6 +66,7 @@ camel_stream_buffer_class_init (CamelStreamBufferClass *camel_stream_buffer_clas
camel_stream_class->read = stream_read;
camel_stream_class->write = stream_write;
camel_stream_class->flush = stream_flush;
+ camel_stream_class->close = stream_close;
camel_stream_class->eos = stream_eos;
gtk_object_class->finalize = finalize;
@@ -87,6 +86,8 @@ camel_stream_buffer_init (gpointer object, gpointer klass)
sbf->end = sbf->buf;
sbf->mode = CAMEL_STREAM_BUFFER_READ | CAMEL_STREAM_BUFFER_BUFFER;
sbf->stream = 0;
+ sbf->linesize = 80;
+ sbf->linebuf = g_malloc(sbf->linesize);
}
GtkType
@@ -138,6 +139,8 @@ finalize (GtkObject *object)
if (sbf->stream)
gtk_object_unref(GTK_OBJECT(sbf->stream));
+ g_free(sbf->linebuf);
+
GTK_OBJECT_CLASS (parent_class)->finalize (object);
}
@@ -244,8 +247,7 @@ CamelStream *camel_stream_buffer_new_with_vbuf (CamelStream *stream, CamelStream
}
static int
-stream_read (CamelStream *stream, char *buffer, unsigned int n,
- CamelException *ex)
+stream_read (CamelStream *stream, char *buffer, unsigned int n)
{
CamelStreamBuffer *sbf = CAMEL_STREAM_BUFFER (stream);
int bytes_read = 1;
@@ -265,13 +267,13 @@ stream_read (CamelStream *stream, char *buffer, unsigned int n,
}
/* if we are reading a lot, then read directly to the destination buffer */
if (n >= sbf->size/3) {
- bytes_read = camel_stream_read(sbf->stream, bptr, n, ex);
+ bytes_read = camel_stream_read(sbf->stream, bptr, n);
if (bytes_read>0) {
n -= bytes_read;
bptr += bytes_read;
}
} else {
- bytes_read = camel_stream_read(sbf->stream, sbf->buf, sbf->size, ex);
+ bytes_read = camel_stream_read(sbf->stream, sbf->buf, sbf->size);
if (bytes_read>0) {
sbf->ptr = sbf->buf;
sbf->end = sbf->buf+bytes_read;
@@ -281,8 +283,6 @@ stream_read (CamelStream *stream, char *buffer, unsigned int n,
n -= bytes_read;
}
}
- if (camel_exception_is_set (ex))
- return -1;
} else {
memcpy(bptr, sbf->ptr, bytes_left);
sbf->ptr += n;
@@ -294,15 +294,14 @@ stream_read (CamelStream *stream, char *buffer, unsigned int n,
return bptr-buffer;
}
-
static int
-stream_write (CamelStream *stream, const char *buffer,
- unsigned int n, CamelException *ex)
+stream_write (CamelStream *stream, const char *buffer, unsigned int n)
{
CamelStreamBuffer *sbf = CAMEL_STREAM_BUFFER (stream);
const char *bptr = buffer;
int bytes_written = 1;
int bytes_left;
+ int total = n;
g_return_val_if_fail( (sbf->mode & CAMEL_STREAM_BUFFER_MODE) == CAMEL_STREAM_BUFFER_WRITE, 0);
@@ -312,22 +311,22 @@ stream_write (CamelStream *stream, const char *buffer,
memcpy(sbf->ptr, bptr, bytes_left);
n -= bytes_left;
bptr += bytes_left;
- bytes_written = camel_stream_write(sbf->stream, sbf->buf, sbf->size, ex);
+ bytes_written = camel_stream_write(sbf->stream, sbf->buf, sbf->size);
sbf->ptr = sbf->buf;
/* if we are writing a lot, write directly to the stream */
if (n >= sbf->size/3) {
- bytes_written = camel_stream_write(sbf->stream, bptr, n, ex);
- bytes_written = n;
- n -= bytes_written;
- bptr += bytes_written;
+ bytes_written = camel_stream_write(sbf->stream, bptr, n);
+ if (bytes_written >0) {
+ bytes_written = n;
+ n -= bytes_written;
+ bptr += bytes_written;
+ }
} else {
memcpy(sbf->ptr, bptr, n);
sbf->ptr += n;
bptr += n;
n = 0;
}
- if (camel_exception_is_set (ex))
- return -1;
} else {
memcpy(sbf->ptr, bptr, n);
sbf->ptr += n;
@@ -335,27 +334,38 @@ stream_write (CamelStream *stream, const char *buffer,
n = 0;
}
}
- return 0;
+ if (bytes_written == -1)
+ return -1;
+ return total;
}
-
-
-static void
-stream_flush (CamelStream *stream, CamelException *ex)
+static int
+stream_flush (CamelStream *stream)
{
CamelStreamBuffer *sbf = CAMEL_STREAM_BUFFER (stream);
if ((sbf->mode & CAMEL_STREAM_BUFFER_MODE) == CAMEL_STREAM_BUFFER_WRITE) {
- int written = camel_stream_write(sbf->stream, sbf->buf, sbf->ptr-sbf->buf, ex);
- if (written > 0) {
+ int len = sbf->ptr-sbf->buf;
+ int written = camel_stream_write(sbf->stream, sbf->buf, len);
+ if (written > 0)
sbf->ptr += written;
- }
+ if (written != len)
+ return -1;
} else {
/* nothing to do for read mode 'flush' */
}
- if (!camel_exception_is_set (ex))
- camel_stream_flush(sbf->stream, ex);
+ return camel_stream_flush(sbf->stream);
+}
+
+static int
+stream_close (CamelStream *stream)
+{
+ CamelStreamBuffer *sbf = CAMEL_STREAM_BUFFER (stream);
+
+ if (stream_flush(stream) == -1)
+ return -1;
+ return camel_stream_close(sbf->stream);
}
static gboolean
@@ -371,7 +381,6 @@ stream_eos (CamelStream *stream)
* @sbf: A CamelStreamBuffer.
* @buf: Memory to write the string to.
* @max: Maxmimum number of characters to store.
- * @ex: a CamelException
*
* Read a line of characters up to the next newline character or
* @max characters.
@@ -379,11 +388,10 @@ stream_eos (CamelStream *stream)
* If the newline character is encountered, then it will be
* included in the buffer @buf. The buffer will be #NUL terminated.
*
- * Return value: The number of characters read, or 0 for end of file.
- * If an error occurs, @ex will be set.
+ * Return value: The number of characters read, or 0 for end of file,
+ * and -1 on error.
**/
-int camel_stream_buffer_gets(CamelStreamBuffer *sbf, char *buf,
- unsigned int max, CamelException *ex)
+int camel_stream_buffer_gets(CamelStreamBuffer *sbf, char *buf, unsigned int max)
{
register char *outptr, *inptr, *inend, c, *outend;
int bytes_read;
@@ -406,13 +414,12 @@ int camel_stream_buffer_gets(CamelStreamBuffer *sbf, char *buf,
if (outptr == outend)
break;
- bytes_read = camel_stream_read(sbf->stream, sbf->buf,
- sbf->size, ex);
- if (bytes_read>0) {
- inptr = sbf->ptr = sbf->buf;
- inend = sbf->end = sbf->buf + bytes_read;
- }
- } while (bytes_read>0 && !camel_exception_is_set (ex));
+ bytes_read = camel_stream_read(sbf->stream, sbf->buf, sbf->size);
+ if (bytes_read == -1)
+ return -1;
+ inptr = sbf->ptr = sbf->buf;
+ inend = sbf->end = sbf->buf + bytes_read;
+ } while (bytes_read>0);
sbf->ptr = inptr;
if (outptr<=outend)
@@ -424,7 +431,6 @@ int camel_stream_buffer_gets(CamelStreamBuffer *sbf, char *buf,
/**
* camel_stream_buffer_read_line: read a complete line from the stream
* @sbf: A CamelStreamBuffer
- * @ex: a CamelException
*
* This function reads a complete newline-terminated line from the stream
* and returns it in allocated memory. The trailing newline (and carriage
@@ -434,34 +440,36 @@ int camel_stream_buffer_gets(CamelStreamBuffer *sbf, char *buf,
* or NULL on eof. If an error occurs, @ex will be set.
**/
char *
-camel_stream_buffer_read_line (CamelStreamBuffer *sbf, CamelException *ex)
+camel_stream_buffer_read_line (CamelStreamBuffer *sbf)
{
- char *buf, *p;
- int bufsiz, nread;
+ unsigned char *p;
+ int nread;
- bufsiz = 80;
- p = buf = g_malloc (bufsiz);
+ p = sbf->linebuf;
while (1) {
- nread = camel_stream_buffer_gets (sbf, p,
- bufsiz - (p - buf), ex);
- if (nread == 0 || camel_exception_is_set (ex)) {
- g_free (buf);
+ nread = camel_stream_buffer_gets (sbf, p, sbf->linesize - (p - sbf->linebuf));
+ if (nread <=0) {
+ if (p > sbf->linebuf)
+ break;
return NULL;
}
p += nread;
- if (*(p - 1) == '\n')
+ if (p[-1] == '\n')
break;
- nread = p - buf;
- bufsiz *= 2;
- buf = g_realloc (buf, bufsiz);
- p = buf + nread;
+ nread = p - sbf->linebuf;
+ sbf->linesize *= 2;
+ sbf->linebuf = g_realloc (sbf->linebuf, sbf->linesize);
+ p = sbf->linebuf + nread;
}
- *--p = '\0';
- if (*(p - 1) == '\r')
- *--p = '\0';
- return buf;
+ p--;
+ if (p[-1] == '\r')
+ p--;
+ p[0] = 0;
+
+ return g_strdup(sbf->linebuf);
}
+
diff --git a/camel/camel-stream-buffer.h b/camel/camel-stream-buffer.h
index 33132e39a4..367735e4e1 100644
--- a/camel/camel-stream-buffer.h
+++ b/camel/camel-stream-buffer.h
@@ -62,6 +62,9 @@ struct _CamelStreamBuffer
unsigned char *buf, *ptr, *end;
int size;
+ unsigned char *linebuf; /* for reading lines at a time */
+ int linesize;
+
CamelStreamBufferMode mode;
unsigned int flags; /* internal flags */
};
@@ -95,11 +98,9 @@ CamelStream *camel_stream_buffer_new_with_vbuf (CamelStream *s,
CamelStream *camel_stream_buffer_set_vbuf (CamelStreamBuffer *b, CamelStreamBufferMode mode, char *buf, guint32 size); */
/* read a line of characters */
-int camel_stream_buffer_gets (CamelStreamBuffer *b, char *buf,
- unsigned int max, CamelException *ex);
+int camel_stream_buffer_gets (CamelStreamBuffer *b, char *buf, unsigned int max);
-char *camel_stream_buffer_read_line (CamelStreamBuffer *sbf,
- CamelException *ex);
+char *camel_stream_buffer_read_line (CamelStreamBuffer *sbf);
#ifdef __cplusplus
}
diff --git a/camel/camel-stream-filter.c b/camel/camel-stream-filter.c
index 389390caaf..3aaa1a20ed 100644
--- a/camel/camel-stream-filter.c
+++ b/camel/camel-stream-filter.c
@@ -1,3 +1,4 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; fill-column: 160 -*- */
/*
* Copyright (C) 2000 Helix Code Inc.
*
@@ -19,7 +20,6 @@
*/
#include "camel-stream-filter.h"
-#include "camel-exception.h"
struct _filter {
struct _filter *next;
@@ -48,13 +48,12 @@ struct _CamelStreamFilterPrivate {
static void camel_stream_filter_class_init (CamelStreamFilterClass *klass);
static void camel_stream_filter_init (CamelStreamFilter *obj);
-static int do_read (CamelStream *stream, char *buffer,
- unsigned int n, CamelException *ex);
-static int do_write (CamelStream *stream, const char *buffer,
- unsigned int n, CamelException *ex);
-static void do_flush (CamelStream *stream, CamelException *ex);
+static int do_read (CamelStream *stream, char *buffer, unsigned int n);
+static int do_write (CamelStream *stream, const char *buffer, unsigned int n);
+static int do_flush (CamelStream *stream);
+static int do_close (CamelStream *stream);
static gboolean do_eos (CamelStream *stream);
-static void do_reset (CamelStream *stream, CamelException *ex);
+static int do_reset (CamelStream *stream);
static CamelStreamClass *camel_stream_filter_parent;
@@ -121,6 +120,7 @@ camel_stream_filter_class_init (CamelStreamFilterClass *klass)
camel_stream_class->read = do_read;
camel_stream_class->write = do_write;
camel_stream_class->flush = do_flush;
+ camel_stream_class->flush = do_close;
camel_stream_class->eos = do_eos;
camel_stream_class->reset = do_reset;
@@ -216,7 +216,7 @@ camel_stream_filter_remove(CamelStreamFilter *filter, int id)
}
static int
-do_read (CamelStream *stream, char *buffer, unsigned int n, CamelException *ex)
+do_read (CamelStream *stream, char *buffer, unsigned int n)
{
CamelStreamFilter *filter = (CamelStreamFilter *)stream;
struct _CamelStreamFilterPrivate *p = _PRIVATE(filter);
@@ -228,7 +228,7 @@ do_read (CamelStream *stream, char *buffer, unsigned int n, CamelException *ex)
if (p->filteredlen<=0) {
int presize = READ_SIZE;
- size = camel_stream_read(filter->source, p->buffer, READ_SIZE, ex);
+ size = camel_stream_read(filter->source, p->buffer, READ_SIZE);
if (size<=0) {
/* this is somewhat untested */
if (camel_stream_eos(filter->source)) {
@@ -263,7 +263,7 @@ do_read (CamelStream *stream, char *buffer, unsigned int n, CamelException *ex)
}
static int
-do_write (CamelStream *stream, const char *buf, unsigned int n, CamelException *ex)
+do_write (CamelStream *stream, const char *buf, unsigned int n)
{
CamelStreamFilter *filter = (CamelStreamFilter *)stream;
struct _CamelStreamFilterPrivate *p = _PRIVATE(filter);
@@ -280,11 +280,11 @@ do_write (CamelStream *stream, const char *buf, unsigned int n, CamelException *
f = f->next;
}
- return camel_stream_write(filter->source, buffer, n, ex);
+ return camel_stream_write(filter->source, buffer, n);
}
-static void
-do_flush (CamelStream *stream, CamelException *ex)
+static int
+do_flush (CamelStream *stream)
{
CamelStreamFilter *filter = (CamelStreamFilter *)stream;
struct _CamelStreamFilterPrivate *p = _PRIVATE(filter);
@@ -294,7 +294,7 @@ do_flush (CamelStream *stream, CamelException *ex)
if (p->last_was_read) {
g_warning("Flushing a filter stream without writing to it");
- return;
+ return 0;
}
buffer = "";
@@ -305,9 +305,21 @@ do_flush (CamelStream *stream, CamelException *ex)
camel_mime_filter_complete(f->filter, buffer, len, presize, &buffer, &len, &presize);
f = f->next;
}
- camel_stream_write(filter->source, buffer, len, ex);
- if (!camel_exception_is_set(ex))
- camel_stream_flush(filter->source, ex);
+ if (len>0 && camel_stream_write(filter->source, buffer, len) == -1)
+ return -1;
+ return camel_stream_flush(filter->source);
+}
+
+static int
+do_close (CamelStream *stream)
+{
+ CamelStreamFilter *filter = (CamelStreamFilter *)stream;
+ struct _CamelStreamFilterPrivate *p = _PRIVATE(filter);
+
+ if (!p->last_was_read) {
+ do_flush(stream);
+ }
+ return camel_stream_close(filter->source);
}
static gboolean
@@ -322,15 +334,14 @@ do_eos (CamelStream *stream)
return camel_stream_eos(filter->source);
}
-static void
-do_reset (CamelStream *stream, CamelException *ex)
+static int
+do_reset (CamelStream *stream)
{
CamelStreamFilter *filter = (CamelStreamFilter *)stream;
struct _CamelStreamFilterPrivate *p = _PRIVATE(filter);
struct _filter *f;
p->filteredlen = 0;
- camel_stream_reset(filter->source, ex);
/* and reset filters */
f = p->filters;
@@ -338,5 +349,7 @@ do_reset (CamelStream *stream, CamelException *ex)
camel_mime_filter_reset(f->filter);
f = f->next;
}
+
+ return camel_stream_reset(filter->source);
}
diff --git a/camel/camel-stream-fs.c b/camel/camel-stream-fs.c
index 3f53b5907a..4b5a6015a4 100644
--- a/camel/camel-stream-fs.c
+++ b/camel/camel-stream-fs.c
@@ -1,4 +1,4 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; fill-column: 160 -*- */
/* camel-stream-fs.c : file system based stream */
/*
@@ -25,7 +25,6 @@
#include <config.h>
#include "camel-stream-fs.h"
-#include "camel-exception.h"
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
@@ -38,15 +37,12 @@ static CamelSeekableStreamClass *parent_class = NULL;
/* Returns the class for a CamelStreamFS */
#define CSFS_CLASS(so) CAMEL_STREAM_FS_CLASS (GTK_OBJECT(so)->klass)
-static int stream_read (CamelStream *stream, char *buffer, unsigned int n,
- CamelException *ex);
-static int stream_write (CamelStream *stream, const char *buffer,
- unsigned int n, CamelException *ex);
-static void stream_flush (CamelStream *stream, CamelException *ex);
+static int stream_read (CamelStream *stream, char *buffer, unsigned int n);
+static int stream_write (CamelStream *stream, const char *buffer, unsigned int n);
+static int stream_flush (CamelStream *stream);
+static int stream_close (CamelStream *stream);
static off_t stream_seek (CamelSeekableStream *stream, off_t offset,
- CamelStreamSeekPolicy policy,
- CamelException *ex);
-
+ CamelStreamSeekPolicy policy);
static void finalize (GtkObject *object);
static void
@@ -65,6 +61,7 @@ camel_stream_fs_class_init (CamelStreamFsClass *camel_stream_fs_class)
camel_stream_class->read = stream_read;
camel_stream_class->write = stream_write;
camel_stream_class->flush = stream_flush;
+ camel_stream_class->close = stream_close;
camel_seekable_stream_class->seek = stream_seek;
@@ -151,14 +148,12 @@ camel_stream_fs_new_with_fd (int fd)
* Return value: the stream
**/
CamelStream *
-camel_stream_fs_new_with_fd_and_bounds (int fd, off_t start, off_t end,
- CamelException *ex)
+camel_stream_fs_new_with_fd_and_bounds (int fd, off_t start, off_t end)
{
CamelStream *stream;
stream = camel_stream_fs_new_with_fd (fd);
- camel_seekable_stream_set_bounds (CAMEL_SEEKABLE_STREAM (stream),
- start, end, ex);
+ camel_seekable_stream_set_bounds (CAMEL_SEEKABLE_STREAM (stream), start, end);
return stream;
}
@@ -168,31 +163,23 @@ camel_stream_fs_new_with_fd_and_bounds (int fd, off_t start, off_t end,
* @name: a local filename
* @flags: flags as in open(2)
* @mode: a file mode
- * @ex: a CamelException.
*
* Creates a new CamelStream corresponding to the named file, flags,
- * and mode. If an error occurs, @ex will be set.
+ * and mode.
*
- * Return value: the stream
+ * Return value: the stream, or #NULL on error.
**/
CamelStream *
-camel_stream_fs_new_with_name (const char *name, int flags, mode_t mode,
- CamelException *ex)
+camel_stream_fs_new_with_name (const char *name, int flags, mode_t mode)
{
- CamelStream *stream;
int fd;
fd = open (name, flags, mode);
if (fd == -1) {
- camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
- "Could not open file %s: %s.",
- name, g_strerror (errno));
return NULL;
}
- stream = camel_stream_fs_new_with_fd (fd);
-
- return stream;
+ return camel_stream_fs_new_with_fd (fd);
}
/**
@@ -202,38 +189,30 @@ camel_stream_fs_new_with_name (const char *name, int flags, mode_t mode,
* @mode: a file mode
* @start: the first valid position in the file
* @end: the first invalid position in the file, or CAMEL_STREAM_UNBOUND
- * @ex: a CamelException.
*
- * Creates a new CamelStream corresponding to the given arguments. If
- * an error occurs, @ex will be set.
+ * Creates a new CamelStream corresponding to the given arguments.
*
- * Return value: the stream
+ * Return value: the stream, or NULL on error.
**/
CamelStream *
camel_stream_fs_new_with_name_and_bounds (const char *name, int flags,
- mode_t mode, off_t start, off_t end,
- CamelException *ex)
+ mode_t mode, off_t start, off_t end)
{
CamelStream *stream;
- stream = camel_stream_fs_new_with_name (name, flags, mode, ex);
- if (camel_exception_is_set (ex))
+ stream = camel_stream_fs_new_with_name (name, flags, mode);
+ if (stream == NULL)
return NULL;
camel_seekable_stream_set_bounds (CAMEL_SEEKABLE_STREAM (stream),
- start, end, ex);
- if (camel_exception_is_set (ex)) {
- gtk_object_unref (GTK_OBJECT (stream));
- return NULL;
- }
+ start, end);
return stream;
}
static int
-stream_read (CamelStream *stream, char *buffer, unsigned int n,
- CamelException *ex)
+stream_read (CamelStream *stream, char *buffer, unsigned int n)
{
CamelStreamFs *stream_fs = CAMEL_STREAM_FS (stream);
CamelSeekableStream *seekable = CAMEL_SEEKABLE_STREAM (stream);
@@ -250,18 +229,12 @@ stream_read (CamelStream *stream, char *buffer, unsigned int n,
seekable->position += nread;
else if (nread == 0)
stream->eos = TRUE;
- else {
- camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
- "Could not read from stream: %s",
- g_strerror (errno));
- }
return nread;
}
static int
-stream_write (CamelStream *stream, const char *buffer, unsigned int n,
- CamelException *ex)
+stream_write (CamelStream *stream, const char *buffer, unsigned int n)
{
CamelStreamFs *stream_fs = CAMEL_STREAM_FS (stream);
CamelSeekableStream *seekable = CAMEL_SEEKABLE_STREAM (stream);
@@ -278,33 +251,31 @@ stream_write (CamelStream *stream, const char *buffer, unsigned int n,
if (written > 0)
seekable->position += written;
- else if (v == -1) {
- camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
- "Could not write to stream: %s",
- g_strerror (errno));
- }
+ else if (v == -1)
+ return -1;
return written;
}
-static void
-stream_flush (CamelStream *stream, CamelException *ex)
+static int
+stream_flush (CamelStream *stream)
{
- if (fsync (CAMEL_STREAM_FS (stream)->fd) == -1) {
- camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
- "Could not flush stream data: %s",
- g_strerror (errno));
- }
+ return fsync(((CamelStreamFs *)stream)->fd);
+}
+
+static int
+stream_close (CamelStream *stream)
+{
+ return close(((CamelStreamFs *)stream)->fd);
}
static off_t
-stream_seek (CamelSeekableStream *stream, off_t offset,
- CamelStreamSeekPolicy policy, CamelException *ex)
+stream_seek (CamelSeekableStream *stream, off_t offset, CamelStreamSeekPolicy policy)
{
CamelStreamFs *stream_fs = CAMEL_STREAM_FS (stream);
off_t real = 0;
- switch (policy) {
+ switch (policy) {
case CAMEL_STREAM_SET:
real = offset;
break;
@@ -316,12 +287,6 @@ stream_seek (CamelSeekableStream *stream, off_t offset,
real = lseek(stream_fs->fd, offset, SEEK_END);
if (real != -1)
stream->position = real;
- else {
- camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
- "Could not seek to "
- "given offset: %s",
- g_strerror (errno));
- }
return real;
}
real = stream->bound_end + offset;
@@ -333,12 +298,8 @@ stream_seek (CamelSeekableStream *stream, off_t offset,
real = MAX (real, stream->bound_start);
real = lseek(stream_fs->fd, real, SEEK_SET);
- if (real == -1) {
- camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
- "Could not seek to given offset: %s",
- g_strerror (errno));
+ if (real == -1)
return -1;
- }
if (real != stream->position && ((CamelStream *)stream)->eos)
((CamelStream *)stream)->eos = FALSE;
diff --git a/camel/camel-stream-fs.h b/camel/camel-stream-fs.h
index 1c40855143..08ae49bddf 100644
--- a/camel/camel-stream-fs.h
+++ b/camel/camel-stream-fs.h
@@ -60,22 +60,13 @@ typedef struct {
/* Standard Gtk function */
GtkType camel_stream_fs_get_type (void);
-
/* public methods */
-CamelStream * camel_stream_fs_new_with_name (const char *name,
- int flags,
- mode_t mode,
- CamelException *ex);
-CamelStream * camel_stream_fs_new_with_name_and_bounds (const char *name,
- int flags, mode_t mode,
- off_t start,
- off_t end,
- CamelException *ex);
+CamelStream * camel_stream_fs_new_with_name (const char *name, int flags, mode_t mode);
+CamelStream * camel_stream_fs_new_with_name_and_bounds (const char *name, int flags, mode_t mode,
+ off_t start, off_t end);
CamelStream * camel_stream_fs_new_with_fd (int fd);
-CamelStream * camel_stream_fs_new_with_fd_and_bounds (int fd, off_t start,
- off_t end,
- CamelException *ex);
+CamelStream * camel_stream_fs_new_with_fd_and_bounds (int fd, off_t start, off_t end);
#ifdef __cplusplus
}
diff --git a/camel/camel-stream-mem.c b/camel/camel-stream-mem.c
index 2c6357b12b..ca384485b6 100644
--- a/camel/camel-stream-mem.c
+++ b/camel/camel-stream-mem.c
@@ -35,14 +35,11 @@ static CamelStreamClass *parent_class = NULL;
/* Returns the class for a CamelStreamMem */
#define CSM_CLASS(so) CAMEL_STREAM_MEM_CLASS (GTK_OBJECT(so)->klass)
-static int stream_read (CamelStream *stream, char *buffer, unsigned int n,
- CamelException *ex);
-static int stream_write (CamelStream *stream, const char *buffer,
- unsigned int n, CamelException *ex);
+static int stream_read (CamelStream *stream, char *buffer, unsigned int n);
+static int stream_write (CamelStream *stream, const char *buffer, unsigned int n);
static gboolean stream_eos (CamelStream *stream);
static off_t stream_seek (CamelSeekableStream *stream, off_t offset,
- CamelStreamSeekPolicy policy,
- CamelException *ex);
+ CamelStreamSeekPolicy policy);
static void finalize (GtkObject *object);
@@ -161,8 +158,7 @@ finalize (GtkObject *object)
}
static int
-stream_read (CamelStream *stream, char *buffer, unsigned int n,
- CamelException *ex)
+stream_read (CamelStream *stream, char *buffer, unsigned int n)
{
CamelStreamMem *camel_stream_mem = CAMEL_STREAM_MEM (stream);
CamelSeekableStream *seekable = CAMEL_SEEKABLE_STREAM (stream);
@@ -182,8 +178,7 @@ stream_read (CamelStream *stream, char *buffer, unsigned int n,
}
static int
-stream_write (CamelStream *stream, const char *buffer, unsigned int n,
- CamelException *ex)
+stream_write (CamelStream *stream, const char *buffer, unsigned int n)
{
CamelStreamMem *stream_mem = CAMEL_STREAM_MEM (stream);
CamelSeekableStream *seekable = CAMEL_SEEKABLE_STREAM (stream);
@@ -194,13 +189,11 @@ stream_write (CamelStream *stream, const char *buffer, unsigned int n,
#warning "g_byte_arrays use g_malloc and so are totally unsuitable for this object"
if (seekable->position == stream_mem->buffer->len) {
stream_mem->buffer =
- g_byte_array_append (stream_mem->buffer,
- (const guint8 *)buffer, n);
+ g_byte_array_append (stream_mem->buffer, (const guint8 *)buffer, n);
} else {
g_byte_array_set_size (stream_mem->buffer,
n+stream_mem->buffer->len);
- memcpy (stream_mem->buffer->data + seekable->position,
- buffer, n);
+ memcpy (stream_mem->buffer->data + seekable->position, buffer, n);
}
seekable->position += n;
@@ -218,7 +211,7 @@ stream_eos (CamelStream *stream)
static off_t
stream_seek (CamelSeekableStream *stream, off_t offset,
- CamelStreamSeekPolicy policy, CamelException *ex)
+ CamelStreamSeekPolicy policy)
{
off_t position;
CamelStreamMem *stream_mem = CAMEL_STREAM_MEM (stream);
diff --git a/camel/camel-stream-mem.h b/camel/camel-stream-mem.h
index 21f9a62e29..e508644e6b 100644
--- a/camel/camel-stream-mem.h
+++ b/camel/camel-stream-mem.h
@@ -65,8 +65,7 @@ CamelStream *camel_stream_mem_new_with_buffer (const char *buffer, size_t len);
/* these are really only here for implementing classes */
void camel_stream_mem_set_byte_array (CamelStreamMem *, GByteArray *buffer);
-void camel_stream_mem_set_buffer (CamelStreamMem *, const char *buffer,
- size_t len);
+void camel_stream_mem_set_buffer (CamelStreamMem *, const char *buffer, size_t len);
#ifdef __cplusplus
}
diff --git a/camel/camel-stream.c b/camel/camel-stream.c
index 07578a7848..244b6cf9d8 100644
--- a/camel/camel-stream.c
+++ b/camel/camel-stream.c
@@ -1,4 +1,4 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; fill-column: 160 -*- */
/* camel-stream.c : abstract class for a stream */
/*
@@ -31,7 +31,8 @@ static CamelObjectClass *parent_class = NULL;
/* Returns the class for a CamelStream */
#define CS_CLASS(so) CAMEL_STREAM_CLASS (GTK_OBJECT(so)->klass)
-static void stream_flush (CamelStream *stream, CamelException *ex);
+static int stream_flush (CamelStream *stream);
+static int stream_close (CamelStream *stream);
static gboolean stream_eos (CamelStream *stream);
@@ -42,6 +43,7 @@ camel_stream_class_init (CamelStreamClass *camel_stream_class)
/* virtual method definition */
camel_stream_class->flush = stream_flush;
+ camel_stream_class->close = stream_close;
camel_stream_class->eos = stream_eos;
}
@@ -75,22 +77,20 @@ camel_stream_get_type (void)
* @stream: a CamelStream.
* @buffer: buffer where bytes pulled from the stream are stored.
* @n: max number of bytes to read.
- * @ex: a CamelException
*
* Read at most @n bytes from the @stream object and stores them
* in the buffer pointed at by @buffer.
*
- * Return value: number of bytes actually read. If an error occurs,
- * @ex will contain a description of the error.
+ * Return value: number of bytes actually read, or -1 on error and
+ * set errno.
**/
int
-camel_stream_read (CamelStream *stream, char *buffer, unsigned int n,
- CamelException *ex)
+camel_stream_read (CamelStream *stream, char *buffer, unsigned int n)
{
g_return_val_if_fail (CAMEL_IS_STREAM (stream), -1);
g_return_val_if_fail (n == 0 || buffer, -1);
- return CS_CLASS (stream)->read (stream, buffer, n, ex);
+ return CS_CLASS (stream)->read (stream, buffer, n);
}
/**
@@ -98,44 +98,68 @@ camel_stream_read (CamelStream *stream, char *buffer, unsigned int n,
* @stream: a CamelStream object.
* @buffer: buffer to write.
* @n: number of bytes to write
- * @ex: a CamelException
*
* Write @n bytes from the buffer pointed at by @buffer into @stream.
*
- * Return value: the number of bytes actually written to the stream. If
- * an error occurs, @ex will contain a description of the error.
+ * Return value: the number of bytes actually written to the stream,
+ * or -1 on error.
**/
int
-camel_stream_write (CamelStream *stream, const char *buffer, unsigned int n,
- CamelException *ex)
+camel_stream_write (CamelStream *stream, const char *buffer, unsigned int n)
{
g_return_val_if_fail (CAMEL_IS_STREAM (stream), -1);
g_return_val_if_fail (n == 0 || buffer, -1);
- return CS_CLASS (stream)->write (stream, buffer, n, ex);
+ return CS_CLASS (stream)->write (stream, buffer, n);
}
-static void
-stream_flush (CamelStream *stream, CamelException *ex)
+static int
+stream_flush (CamelStream *stream)
{
/* nothing */
+ return 0;
}
/**
* camel_stream_flush:
* @stream: a CamelStream object
- * @ex: a CamelException
*
* Flushes the contents of the stream to its backing store. Only meaningful
- * on writable streams. If an error occurs, @ex will be set.
+ * on writable streams.
+ *
+ * Return value: -1 on error.
+ **/
+int
+camel_stream_flush (CamelStream *stream)
+{
+ g_return_val_if_fail (CAMEL_IS_STREAM (stream), -1);
+
+ return CS_CLASS (stream)->flush (stream);
+}
+
+
+static int
+stream_close (CamelStream *stream)
+{
+ /* nothing */
+ return 0;
+}
+
+/**
+ * camel_stream_close:
+ * @stream:
+ *
+ * Close a stream.
+ *
+ * Return value: -1 on error.
**/
-void
-camel_stream_flush (CamelStream *stream, CamelException *ex)
+int
+camel_stream_close (CamelStream *stream)
{
- g_return_if_fail (CAMEL_IS_STREAM (stream));
+ g_return_val_if_fail (CAMEL_IS_STREAM (stream), -1);
- CS_CLASS (stream)->flush (stream, ex);
+ return CS_CLASS (stream)->close (stream);
}
@@ -166,18 +190,19 @@ camel_stream_eos (CamelStream *stream)
/**
* camel_stream_reset: reset a stream
* @stream: the stream object
- * @ex: a CamelException
*
* Reset a stream. That is, put it in a state where it can be read
* from the beginning again. Not all streams in Camel are seekable,
* but they must all be resettable.
+ *
+ * Return value: -1 on error.
**/
-void
-camel_stream_reset (CamelStream *stream, CamelException *ex)
+int
+camel_stream_reset (CamelStream *stream)
{
- g_return_if_fail (CAMEL_IS_STREAM (stream));
+ g_return_val_if_fail (CAMEL_IS_STREAM (stream), -1);
- CS_CLASS (stream)->reset (stream, ex);
+ return CS_CLASS (stream)->reset (stream);
}
/***************** Utility functions ********************/
@@ -186,33 +211,28 @@ camel_stream_reset (CamelStream *stream, CamelException *ex)
* camel_stream_write_string:
* @stream: a stream object
* @string: a string
- * @ex: a CamelException
*
* Writes the string to the stream.
*
- * Return value: the number of characters output.
+ * Return value: the number of characters output, -1 on error.
**/
int
-camel_stream_write_string (CamelStream *stream, const char *string,
- CamelException *ex)
+camel_stream_write_string (CamelStream *stream, const char *string)
{
- return camel_stream_write (stream, string, strlen (string), ex);
+ return camel_stream_write (stream, string, strlen (string));
}
/**
* camel_stream_printf:
* @stream: a stream object
- * @ex: a CamelException
* @fmt: a printf-style format string
*
- * This printfs the given data to @stream. If an error occurs, @ex
- * will be set.
+ * This printfs the given data to @stream.
*
- * Return value: the number of characters output.
+ * Return value: the number of characters output, -1 on error.
**/
int
-camel_stream_printf (CamelStream *stream, CamelException *ex,
- const char *fmt, ... )
+camel_stream_printf (CamelStream *stream, const char *fmt, ... )
{
va_list args;
char *string;
@@ -227,7 +247,7 @@ camel_stream_printf (CamelStream *stream, CamelException *ex,
if (!string)
return -1;
- ret = camel_stream_write (stream, string, strlen (string), ex);
+ ret = camel_stream_write (stream, string, strlen (string));
g_free (string);
return ret;
}
@@ -236,7 +256,6 @@ camel_stream_printf (CamelStream *stream, CamelException *ex,
* camel_stream_write_to_stream:
* @stream: Source CamelStream.
* @output_stream: Destination CamelStream.
- * @ex: a CamelException.
*
* Write all of a stream (until eos) into another stream, in a blocking
* fashion.
@@ -245,8 +264,7 @@ camel_stream_printf (CamelStream *stream, CamelException *ex,
* copied across streams.
**/
int
-camel_stream_write_to_stream (CamelStream *stream, CamelStream *output_stream,
- CamelException *ex)
+camel_stream_write_to_stream (CamelStream *stream, CamelStream *output_stream)
{
char tmp_buf[4096];
int total = 0;
@@ -257,15 +275,14 @@ camel_stream_write_to_stream (CamelStream *stream, CamelStream *output_stream,
g_return_val_if_fail (CAMEL_IS_STREAM (output_stream), -1);
while (!camel_stream_eos (stream)) {
- nb_read = camel_stream_read (stream, tmp_buf,
- sizeof (tmp_buf), ex);
+ nb_read = camel_stream_read (stream, tmp_buf, sizeof (tmp_buf));
if (nb_read < 0)
return -1;
else if (nb_read > 0) {
nb_written = 0;
while (nb_written < nb_read) {
- int len = camel_stream_write (output_stream, tmp_buf + nb_written, nb_read - nb_written, ex);
+ int len = camel_stream_write (output_stream, tmp_buf + nb_written, nb_read - nb_written);
if (len < 0)
return -1;
nb_written += len;
diff --git a/camel/camel-stream.h b/camel/camel-stream.h
index c1a044e68f..44562b3321 100644
--- a/camel/camel-stream.h
+++ b/camel/camel-stream.h
@@ -1,4 +1,4 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; fill-column: 160 -*- */
/* camel-stream.h : class for an abstract stream */
/*
@@ -53,13 +53,12 @@ typedef struct {
/* Virtual methods */
- int (*read) (CamelStream *stream, char *buffer,
- unsigned int n, CamelException *ex);
- int (*write) (CamelStream *stream, const char *buffer,
- unsigned int n, CamelException *ex);
- void (*flush) (CamelStream *stream, CamelException *ex);
+ int (*read) (CamelStream *stream, char *buffer, unsigned int n);
+ int (*write) (CamelStream *stream, const char *buffer, unsigned int n);
+ int (*close) (CamelStream *stream);
+ int (*flush) (CamelStream *stream);
gboolean (*eos) (CamelStream *stream);
- void (*reset) (CamelStream *stream, CamelException *ex);
+ int (*reset) (CamelStream *stream);
} CamelStreamClass;
@@ -67,28 +66,22 @@ typedef struct {
GtkType camel_stream_get_type (void);
/* public methods */
-int camel_stream_read (CamelStream *stream, char *buffer,
- unsigned int n, CamelException *ex);
-int camel_stream_write (CamelStream *stream, const char *buffer,
- unsigned int n, CamelException *ex);
-void camel_stream_flush (CamelStream *stream, CamelException *ex);
+int camel_stream_read (CamelStream *stream, char *buffer, unsigned int n);
+int camel_stream_write (CamelStream *stream, const char *buffer, unsigned int n);
+int camel_stream_flush (CamelStream *stream);
+int camel_stream_close (CamelStream *stream);
gboolean camel_stream_eos (CamelStream *stream);
-void camel_stream_reset (CamelStream *stream, CamelException *ex);
+int camel_stream_reset (CamelStream *stream);
/* utility macros and funcs */
-int camel_stream_write_string (CamelStream *stream, const char *string,
- CamelException *ex);
-int camel_stream_printf (CamelStream *stream, CamelException *ex,
- const char *fmt, ... ) G_GNUC_PRINTF (3, 4);
-int camel_stream_vprintf (CamelStream *stream, CamelException *ex,
- const char *fmt, va_list ap);
+int camel_stream_write_string (CamelStream *stream, const char *string);
+int camel_stream_printf (CamelStream *stream, const char *fmt, ... ) G_GNUC_PRINTF (2, 3);
+int camel_stream_vprintf (CamelStream *stream, const char *fmt, va_list ap);
/* Write a whole stream to another stream, until eof or error on
* either stream.
*/
-int camel_stream_write_to_stream (CamelStream *stream,
- CamelStream *output_stream,
- CamelException *ex);
+int camel_stream_write_to_stream (CamelStream *stream, CamelStream *output_stream);
#ifdef __cplusplus
}
diff --git a/camel/camel.h b/camel/camel.h
index ac314ac656..d3a65b1312 100644
--- a/camel/camel.h
+++ b/camel/camel.h
@@ -54,7 +54,6 @@ extern "C" {
#include <camel/camel-seekable-substream.h>
#include <camel/camel-service.h>
#include <camel/camel-session.h>
-#include <camel/camel-simple-data-wrapper.h>
#include <camel/camel-store.h>
#include <camel/camel-stream-buffer.h>
#include <camel/camel-stream-filter.h>
diff --git a/camel/gmime-content-field.c b/camel/gmime-content-field.c
index ce61cf2a84..4d38314873 100644
--- a/camel/gmime-content-field.c
+++ b/camel/gmime-content-field.c
@@ -130,8 +130,7 @@ gmime_content_field_write_to_stream (GMimeContentField *content_field, CamelStre
txt = header_content_type_format(content_field->content_type);
if (txt) {
- /* FIXME. Shouldn't pass NULL for CamelException. */
- camel_stream_printf (stream, NULL, "Content-Type: %s\n", txt);
+ camel_stream_printf (stream, "Content-Type: %s\n", txt);
g_free(txt);
}
}
diff --git a/camel/md5-utils.c b/camel/md5-utils.c
index 382aadffec..7363eaec40 100644
--- a/camel/md5-utils.c
+++ b/camel/md5-utils.c
@@ -335,11 +335,10 @@ md5_get_digest_from_stream (CamelStream *stream, guchar digest[16])
md5_init (&ctx);
- /* FIXME (the NULL) */
- nb_bytes_read = camel_stream_read (stream, tmp_buf, 1024, NULL);
+ nb_bytes_read = camel_stream_read (stream, tmp_buf, 1024);
while (nb_bytes_read) {
md5_update (&ctx, tmp_buf, nb_bytes_read);
- nb_bytes_read = camel_stream_read (stream, tmp_buf, 1024, NULL);
+ nb_bytes_read = camel_stream_read (stream, tmp_buf, 1024);
}
md5_final (&ctx, digest);
diff --git a/camel/providers/mbox/camel-mbox-folder.c b/camel/providers/mbox/camel-mbox-folder.c
index 707fea1206..ccf57f02b7 100644
--- a/camel/providers/mbox/camel-mbox-folder.c
+++ b/camel/providers/mbox/camel-mbox-folder.c
@@ -602,11 +602,11 @@ mbox_append_message (CamelFolder *folder, CamelMimeMessage *message, CamelExcept
if (stat(mbox_folder->folder_file_path, &st) != 0)
goto fail;
- output_stream = camel_stream_fs_new_with_name (mbox_folder->folder_file_path, O_RDWR, 0600, ex);
+ output_stream = camel_stream_fs_new_with_name (mbox_folder->folder_file_path, O_RDWR, 0600);
if (output_stream == NULL)
goto fail;
- seek = camel_seekable_stream_seek((CamelSeekableStream *)output_stream, st.st_size, SEEK_SET, ex);
+ seek = camel_seekable_stream_seek((CamelSeekableStream *)output_stream, st.st_size, SEEK_SET);
if (seek != st.st_size)
goto fail;
@@ -618,19 +618,17 @@ mbox_append_message (CamelFolder *folder, CamelMimeMessage *message, CamelExcept
g_free(xev);
/* we must write this to the non-filtered stream ... */
- if (camel_stream_write_string (output_stream, "From - \n", ex) == -1)
+ if (camel_stream_write_string (output_stream, "From - \n") == -1)
goto fail;
/* and write the content to the filtering stream, that translated '\nFrom' into '\n>From' */
filter_stream = (CamelStream *)camel_stream_filter_new_with_stream(output_stream);
filter_from = (CamelMimeFilter *)camel_mime_filter_from_new();
camel_stream_filter_add((CamelStreamFilter *)filter_stream, filter_from);
- camel_data_wrapper_write_to_stream (CAMEL_DATA_WRAPPER (message), filter_stream, ex);
-#warning "we still need stream_close() for this"
- if (!camel_exception_is_set (ex))
- camel_stream_flush (filter_stream, ex);
+ if (camel_data_wrapper_write_to_stream (CAMEL_DATA_WRAPPER (message), filter_stream) == -1)
+ goto fail;
- if (camel_exception_is_set (ex))
+ if (camel_stream_close (filter_stream) == -1)
goto fail;
/* filter stream ref's the output stream itself, so we need to unref it too */
@@ -659,6 +657,9 @@ fail:
if (output_stream)
gtk_object_unref ((GtkObject *)output_stream);
+ if (filter_from)
+ gtk_object_unref ((GtkObject *)filter_from);
+
/* make sure the file isn't munged by us */
if (seek != -1) {
int fd = open(mbox_folder->folder_file_path, O_WRONLY, 0600);
@@ -760,7 +761,7 @@ mbox_get_message_by_uid (CamelFolder *folder, const gchar *uid, CamelException *
g_assert(info->frompos != -1);
/* where we read from */
- message_stream = camel_stream_fs_new_with_name (mbox_folder->folder_file_path, O_RDONLY, 0, ex);
+ message_stream = camel_stream_fs_new_with_name (mbox_folder->folder_file_path, O_RDONLY, 0);
if (message_stream == NULL)
goto fail;
@@ -800,15 +801,10 @@ mbox_get_message_by_uid (CamelFolder *folder, const gchar *uid, CamelException *
return message;
fail:
- if (camel_exception_is_set (ex)) {
- camel_exception_setv (ex, camel_exception_get_id (ex),
- "Cannot get message: %s",
- camel_exception_get_description (ex));
- } else {
- camel_exception_setv (ex, CAMEL_EXCEPTION_FOLDER_INVALID_UID,
- "Cannot get message: %s",
- g_strerror(errno));
- }
+ camel_exception_setv (ex, CAMEL_EXCEPTION_FOLDER_INVALID_UID,
+ "Cannot get message: %s",
+ g_strerror(errno));
+
if (parser)
gtk_object_unref((GtkObject *)parser);
if (message)
diff --git a/camel/providers/pop3/camel-pop3-store.c b/camel/providers/pop3/camel-pop3-store.c
index ddddf9f59f..bc39d4ab2b 100644
--- a/camel/providers/pop3/camel-pop3-store.c
+++ b/camel/providers/pop3/camel-pop3-store.c
@@ -33,6 +33,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <errno.h>
#include "camel-pop3-store.h"
#include "camel-pop3-folder.h"
@@ -376,7 +377,7 @@ pop3_connect (CamelService *service, CamelException *ex)
CAMEL_STREAM_BUFFER_READ);
/* Read the greeting, note APOP timestamp, if any. */
- buf = camel_stream_buffer_read_line (CAMEL_STREAM_BUFFER (store->istream), ex);
+ buf = camel_stream_buffer_read_line (CAMEL_STREAM_BUFFER (store->istream));
if (!buf) {
camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE,
"Could not read greeting from POP "
@@ -513,28 +514,25 @@ camel_pop3_command (CamelPop3Store *store, char **ret, char *fmt, ...)
char *cmdbuf, *respbuf;
va_list ap;
int status;
- CamelException *ex = camel_exception_new ();
va_start (ap, fmt);
cmdbuf = g_strdup_vprintf (fmt, ap);
va_end (ap);
/* Send the command */
- camel_stream_printf (store->ostream, ex, "%s\r\n", cmdbuf);
- g_free (cmdbuf);
- if (camel_exception_is_set (ex)) {
+ if (camel_stream_printf (store->ostream, "%s\r\n", cmdbuf) == -1) {
+ g_free (cmdbuf);
if (*ret)
- *ret = g_strdup (camel_exception_get_description (ex));
- camel_exception_free (ex);
+ *ret = g_strdup(strerror(errno));
return CAMEL_POP3_FAIL;
}
+ g_free (cmdbuf);
/* Read the response */
- respbuf = camel_stream_buffer_read_line (CAMEL_STREAM_BUFFER (store->istream), ex);
- if (camel_exception_is_set (ex)) {
+ respbuf = camel_stream_buffer_read_line (CAMEL_STREAM_BUFFER (store->istream));
+ if (respbuf == NULL) {
if (*ret)
- *ret = g_strdup (camel_exception_get_description (ex));
- camel_exception_free (ex);
+ *ret = g_strdup(strerror(errno));
return CAMEL_POP3_FAIL;
}
if (!strncmp (respbuf, "+OK", 3))
@@ -582,7 +580,7 @@ camel_pop3_command_get_additional_data (CamelPop3Store *store,
data = g_ptr_array_new ();
while (1) {
- buf = camel_stream_buffer_read_line (stream, ex);
+ buf = camel_stream_buffer_read_line (stream);
if (!buf) {
status = CAMEL_POP3_FAIL;
break;
diff --git a/camel/providers/sendmail/camel-sendmail-transport.c b/camel/providers/sendmail/camel-sendmail-transport.c
index a5eeff1a25..3b84d5cb90 100644
--- a/camel/providers/sendmail/camel-sendmail-transport.c
+++ b/camel/providers/sendmail/camel-sendmail-transport.c
@@ -31,6 +31,7 @@
#include <signal.h>
#include <sys/wait.h>
#include <unistd.h>
+#include <string.h>
#include "camel-sendmail-transport.h"
#include "camel-mime-message.h"
@@ -139,15 +140,15 @@ _send_internal (CamelMedium *message, char **argv, CamelException *ex)
/* Parent process. Write the message out. */
close (fd[0]);
out = camel_stream_fs_new_with_fd (fd[1]);
- camel_data_wrapper_write_to_stream (CAMEL_DATA_WRAPPER (message),
- out, ex);
- gtk_object_unref (GTK_OBJECT (out));
- if (camel_exception_is_set (ex)) {
- camel_exception_setv (ex, camel_exception_get_id (ex),
+ if (camel_data_wrapper_write_to_stream (CAMEL_DATA_WRAPPER (message), out) == -1
+ || camel_stream_close(out) == -1) {
+ gtk_object_unref (GTK_OBJECT (out));
+ camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
"Could not send message: %s",
- camel_exception_get_description (ex));
+ strerror(errno));
return FALSE;
}
+ gtk_object_unref (GTK_OBJECT (out));
/* Wait for sendmail to exit. */
while (waitpid (pid, &wstat, 0) == -1 && errno == EINTR)
diff --git a/camel/providers/vee/camel-vee-folder.c b/camel/providers/vee/camel-vee-folder.c
index 88e48134a3..3d4050cf19 100644
--- a/camel/providers/vee/camel-vee-folder.c
+++ b/camel/providers/vee/camel-vee-folder.c
@@ -53,7 +53,10 @@ void vee_free_summary (CamelFolder *folder, GPtrArray *array);
static gint vee_get_message_count (CamelFolder *folder, CamelException *ex);
static CamelMimeMessage *vee_get_message_by_uid (CamelFolder *folder, const gchar *uid, CamelException *ex);
+static void vee_append_message (CamelFolder *folder, CamelMimeMessage *message, CamelException *ex);
+
static const CamelMessageInfo *vee_summary_get_by_uid(CamelFolder *f, const char *uid);
+static GList *vee_search_by_expression(CamelFolder *folder, const char *expression, CamelException *ex);
static void camel_vee_folder_class_init (CamelVeeFolderClass *klass);
@@ -111,10 +114,12 @@ camel_vee_folder_class_init (CamelVeeFolderClass *klass)
folder_class->get_summary = vee_get_summary;
folder_class->free_summary = vee_free_summary;
folder_class->get_message_by_uid = vee_get_message_by_uid;
+ folder_class->append_message = vee_append_message;
folder_class->summary_get_by_uid = vee_summary_get_by_uid;
folder_class->get_message_count = vee_get_message_count;
+ folder_class->search_by_expression = vee_search_by_expression;
object_class->finalize = camel_vee_folder_finalise;
@@ -134,6 +139,17 @@ camel_vee_folder_init (CamelVeeFolder *obj)
static void
camel_vee_folder_finalise (GtkObject *obj)
{
+ CamelVeeFolder *vf = (CamelVeeFolder *)obj;
+ struct _CamelVeeFolderPrivate *p = _PRIVATE(vf);
+ GList *node;
+
+ node = p->folders;
+ while (node) {
+ CamelFolder *f = node->data;
+ gtk_object_unref((GtkObject *)f);
+ node = g_list_next(node);
+ }
+
((GtkObjectClass *)(camel_vee_folder_parent))->finalize((GtkObject *)obj);
}
@@ -152,11 +168,31 @@ camel_vee_folder_new (void)
}
+void
+camel_vee_folder_add_folder(CamelVeeFolder *vf, CamelFolder *sub)
+{
+ struct _CamelVeeFolderPrivate *p = _PRIVATE(vf);
+
+ gtk_object_ref((GtkObject *)sub);
+ p->folders = g_list_append(p->folders, sub);
+}
+
+
static void vee_init (CamelFolder *folder, CamelStore *parent_store,
CamelFolder *parent_folder, const gchar *name,
gchar separator, CamelException *ex)
{
CamelVeeFolder *vf = (CamelVeeFolder *)folder;
+ char *namepart, *searchpart;
+
+ namepart = g_strdup(name);
+ searchpart = strchr(namepart, '?');
+ if (searchpart == NULL) {
+ /* no search, no result! */
+ searchpart = "(body-contains \"=some-invalid_string-sequence=xx\")";
+ } else {
+ *searchpart++ = 0;
+ }
camel_vee_folder_parent->init (folder, parent_store, parent_folder, name, separator, ex);
if (camel_exception_get_id (ex))
@@ -177,7 +213,13 @@ static void vee_init (CamelFolder *folder, CamelStore *parent_store,
vf->messages = g_ptr_array_new();
vf->messages_uid = g_hash_table_new(g_str_hash, g_str_equal);
- vf->expression = g_strdup(folder->name);
+ vf->expression = g_strdup_printf("(or\n (match-all (user-flag \"%s\"))\n %s\n)", namepart, searchpart);
+ vf->vname = g_strdup(namepart);
+
+ printf("VFolder expression is %s\n", vf->expression);
+ printf("VFolder full name = %s\n", camel_folder_get_full_name(folder));
+
+ g_free(namepart);
}
static void vee_open (CamelFolder *folder, CamelFolderOpenMode mode, CamelException *ex)
@@ -205,6 +247,19 @@ static gboolean vee_exists (CamelFolder *folder, CamelException *ex)
return TRUE;
}
+static void vee_append_message (CamelFolder *folder, CamelMimeMessage *message, CamelException *ex)
+{
+ CamelVeeFolder *vf = (CamelVeeFolder *)folder;
+
+ if (message->folder && message->folder->permanent_flags & CAMEL_MESSAGE_USER) {
+ /* set the flag on the message ... */
+ camel_mime_message_set_user_flag(message, vf->vname, TRUE);
+ } else {
+ /* FIXME: error code */
+ camel_exception_setv(ex, 1, "Cannot append this message to virtual folder");
+ }
+}
+
static gint vee_get_message_count (CamelFolder *folder, CamelException *ex)
{
CamelVeeFolder *vf = (CamelVeeFolder *)folder;
@@ -259,13 +314,30 @@ static GPtrArray *vee_get_uids (CamelFolder *folder, CamelException *ex)
return result;
}
-void
-camel_vee_folder_add_folder(CamelVeeFolder *vf, CamelFolder *sub)
+static GList *
+vee_search_by_expression(CamelFolder *folder, const char *expression, CamelException *ex)
{
+ GList *result = NULL, *node;
+ char *expr;
+ CamelVeeFolder *vf = (CamelVeeFolder *)folder;
struct _CamelVeeFolderPrivate *p = _PRIVATE(vf);
- gtk_object_ref((GtkObject *)sub);
- p->folders = g_list_append(p->folders, sub);
+ expr = g_strdup_printf("(and %s %s)", vf->expression, expression);
+ node = p->folders;
+ while (node) {
+ CamelFolder *f = node->data;
+ GList *matches, *match;
+ matches = camel_folder_search_by_expression(f, vf->expression, ex);
+ match = matches;
+ while (match) {
+ char *uid = match->data;
+ result = g_list_prepend(result, g_strdup_printf("%p:%s", f, uid));
+ match = g_list_next(match);
+ }
+ g_list_free(matches);
+ node = g_list_next(node);
+ }
+ return result;
}
/*
@@ -283,6 +355,19 @@ vee_folder_build(CamelVeeFolder *vf, CamelException *ex)
GPtrArray *messages;
GHashTable *messages_uid;
+ {
+ int i;
+
+ for (i=0;i<vf->messages->len;i++) {
+ CamelVeeMessageInfo *mi = g_ptr_array_index(vf->messages, i);
+ g_free(mi->info.subject);
+ g_free(mi->info.to);
+ g_free(mi->info.from);
+ g_free(mi->info.uid);
+ camel_flag_list_free(&mi->info.user_flags);
+ }
+ }
+
messages = g_ptr_array_new();
messages_uid = g_hash_table_new(g_str_hash, g_str_equal);
@@ -324,8 +409,9 @@ vee_folder_build(CamelVeeFolder *vf, CamelException *ex)
node = g_list_next(node);
}
-#warning "free messages on query update"
+ g_ptr_array_free(vf->messages, TRUE);
vf->messages = messages;
+ g_hash_table_destroy(vf->messages_uid);
vf->messages_uid = messages_uid;
}
diff --git a/camel/providers/vee/camel-vee-folder.h b/camel/providers/vee/camel-vee-folder.h
index 4d82c842ea..ea2a82a25b 100644
--- a/camel/providers/vee/camel-vee-folder.h
+++ b/camel/providers/vee/camel-vee-folder.h
@@ -38,6 +38,8 @@ struct _CamelVeeFolder {
struct _CamelVeeFolderPrivate *priv;
char *expression; /* query expression */
+ char *vname; /* local name */
+ CamelFolder *local; /* local storage for folder */
/* FIXME: Move this to a summary object??? */
GPtrArray *messages; /* message info's */