aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeffrey Stedfast <fejj@helixcode.com>2000-06-29 00:55:55 +0800
committerJeffrey Stedfast <fejj@src.gnome.org>2000-06-29 00:55:55 +0800
commit161fabb3552c44eb2e57563e40d5c80535c0a763 (patch)
tree869111fdb07289ccaf07d88ea9c06b1f27298dce
parent97bf430fbb1980da4b683dbe4b63128f69483c5b (diff)
downloadgsoc2013-evolution-161fabb3552c44eb2e57563e40d5c80535c0a763.tar
gsoc2013-evolution-161fabb3552c44eb2e57563e40d5c80535c0a763.tar.gz
gsoc2013-evolution-161fabb3552c44eb2e57563e40d5c80535c0a763.tar.bz2
gsoc2013-evolution-161fabb3552c44eb2e57563e40d5c80535c0a763.tar.lz
gsoc2013-evolution-161fabb3552c44eb2e57563e40d5c80535c0a763.tar.xz
gsoc2013-evolution-161fabb3552c44eb2e57563e40d5c80535c0a763.tar.zst
gsoc2013-evolution-161fabb3552c44eb2e57563e40d5c80535c0a763.zip
General cleanup (camel_mbox_summary_sync): Fixed a memory leak and added
2000-06-28 Jeffrey Stedfast <fejj@helixcode.com> * providers/mbox/camel-mbox-summary.c: General cleanup (camel_mbox_summary_sync): Fixed a memory leak and added CamelException handling. * providers/mbox/camel-mbox-store.c (delete_folder): Fixed a memory leak * providers/mbox/camel-mbox-folder.c (mbox_append_message): Default 'off_t seek' to -1 so as to make sure it's initialized before it's used in the case of a bad stat() call. (mbox_sync): Updated (mbox_expunge): Updated svn path=/trunk/; revision=3774
-rw-r--r--camel/ChangeLog15
-rw-r--r--camel/providers/mbox/camel-mbox-folder.c197
-rw-r--r--camel/providers/mbox/camel-mbox-store.c15
-rw-r--r--camel/providers/mbox/camel-mbox-summary.c499
-rw-r--r--camel/providers/mbox/camel-mbox-summary.h4
5 files changed, 403 insertions, 327 deletions
diff --git a/camel/ChangeLog b/camel/ChangeLog
index d6471af21b..dbf62f9751 100644
--- a/camel/ChangeLog
+++ b/camel/ChangeLog
@@ -1,3 +1,18 @@
+2000-06-28 Jeffrey Stedfast <fejj@helixcode.com>
+
+ * providers/mbox/camel-mbox-summary.c: General cleanup
+ (camel_mbox_summary_sync): Fixed a memory leak and added
+ CamelException handling.
+
+ * providers/mbox/camel-mbox-store.c (delete_folder): Fixed a
+ memory leak
+
+ * providers/mbox/camel-mbox-folder.c (mbox_append_message):
+ Default 'off_t seek' to -1 so as to make sure it's initialized
+ before it's used in the case of a bad stat() call.
+ (mbox_sync): Updated
+ (mbox_expunge): Updated
+
2000-06-27 Jeffrey Stedfast <fejj@helixcode.com>
* providers/imap/camel-imap-store.c (imap_connect): Move the
diff --git a/camel/providers/mbox/camel-mbox-folder.c b/camel/providers/mbox/camel-mbox-folder.c
index fb0434af41..dee06ed39d 100644
--- a/camel/providers/mbox/camel-mbox-folder.c
+++ b/camel/providers/mbox/camel-mbox-folder.c
@@ -226,7 +226,8 @@ mbox_init (CamelFolder *folder, CamelStore *parent_store,
/* no summary (disk or memory), and we're proverbially screwed */
printf("loading summary\n");
- mbox_folder->summary = camel_mbox_summary_new(mbox_folder->summary_file_path, mbox_folder->folder_file_path, mbox_folder->index);
+ mbox_folder->summary = camel_mbox_summary_new (mbox_folder->summary_file_path,
+ mbox_folder->folder_file_path, mbox_folder->index);
if (mbox_folder->summary == NULL
|| camel_mbox_summary_load(mbox_folder->summary, forceindex) == -1) {
camel_exception_set (ex,
@@ -243,9 +244,9 @@ mbox_sync (CamelFolder *folder, gboolean expunge, CamelException *ex)
CamelMboxFolder *mbox_folder = CAMEL_MBOX_FOLDER (folder);
if (expunge)
- mbox_expunge(folder, ex);
+ mbox_expunge (folder, ex);
else
- camel_mbox_summary_sync(mbox_folder->summary, FALSE);
+ camel_mbox_summary_sync (mbox_folder->summary, FALSE, ex);
/* save index */
if (mbox_folder->index) {
@@ -253,12 +254,12 @@ mbox_sync (CamelFolder *folder, gboolean expunge, CamelException *ex)
mbox_folder->index = NULL;
}
if (mbox_folder->summary) {
- camel_folder_summary_save ((CamelFolderSummary *)mbox_folder->summary);
- gtk_object_unref((GtkObject *)mbox_folder->summary);
+ camel_folder_summary_save (CAMEL_FOLDER_SUMMARY (mbox_folder->summary));
+ gtk_object_unref (GTK_OBJECT (mbox_folder->summary));
mbox_folder->summary = NULL;
}
if (mbox_folder->search) {
- gtk_object_unref((GtkObject *)mbox_folder->search);
+ gtk_object_unref (GTK_OBJECT (mbox_folder->search));
mbox_folder->search = NULL;
}
}
@@ -266,26 +267,23 @@ mbox_sync (CamelFolder *folder, gboolean expunge, CamelException *ex)
static void
mbox_expunge (CamelFolder *folder, CamelException *ex)
{
- CamelMboxFolder *mbox = (CamelMboxFolder *)folder;
+ CamelMboxFolder *mbox = CAMEL_MBOX_FOLDER (folder);
- if (camel_mbox_summary_sync(mbox->summary, TRUE) == -1) {
- camel_exception_setv (ex, CAMEL_EXCEPTION_FOLDER_INVALID, /* FIXME: right error code */
- "Could not expunge: %s", strerror(errno));
- }
+ camel_mbox_summary_sync (mbox->summary, TRUE, ex);
/* TODO: check it actually changed */
- gtk_signal_emit_by_name((GtkObject *)folder, "folder_changed", 0);
+ gtk_signal_emit_by_name (GTK_OBJECT (folder), "folder_changed", 0);
}
static gint
mbox_get_message_count (CamelFolder *folder, CamelException *ex)
{
- CamelMboxFolder *mbox_folder = (CamelMboxFolder *)folder;
+ CamelMboxFolder *mbox_folder = CAMEL_MBOX_FOLDER (folder);
g_assert (folder);
g_assert (mbox_folder->summary);
- return camel_folder_summary_count((CamelFolderSummary *)mbox_folder->summary);
+ return camel_folder_summary_count (CAMEL_FOLDER_SUMMARY (mbox_folder->summary));
}
/* FIXME: this may need some tweaking for performance? */
@@ -296,11 +294,11 @@ mbox_append_message (CamelFolder *folder, CamelMimeMessage *message, CamelExcept
CamelStream *output_stream = NULL, *filter_stream = NULL;
CamelMimeFilter *filter_from = NULL;
struct stat st;
- off_t seek;
+ off_t seek = -1;
char *xev, last;
guint32 uid;
- if (stat(mbox_folder->folder_file_path, &st) != 0)
+ 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);
@@ -308,7 +306,7 @@ mbox_append_message (CamelFolder *folder, CamelMimeMessage *message, CamelExcept
goto fail;
if (st.st_size) {
- seek = camel_seekable_stream_seek((CamelSeekableStream *)output_stream, st.st_size - 1, SEEK_SET);
+ seek = camel_seekable_stream_seek ((CamelSeekableStream *)output_stream, st.st_size - 1, SEEK_SET);
if (++seek != st.st_size)
goto fail;
@@ -321,20 +319,20 @@ mbox_append_message (CamelFolder *folder, CamelMimeMessage *message, CamelExcept
seek = 0;
/* assign a new x-evolution header/uid */
- camel_medium_remove_header((CamelMedium *)message, "X-Evolution");
- uid = camel_folder_summary_next_uid((CamelFolderSummary *)mbox_folder->summary);
- xev = g_strdup_printf("%08x-0000", uid);
- camel_medium_add_header((CamelMedium *)message, "X-Evolution", xev);
- g_free(xev);
+ camel_medium_remove_header (CAMEL_MEDIUM (message), "X-Evolution");
+ uid = camel_folder_summary_next_uid (CAMEL_FOLDER_SUMMARY (mbox_folder->summary));
+ xev = g_strdup_printf ("%08x-0000", uid);
+ camel_medium_add_header (CAMEL_MEDIUM (message), "X-Evolution", xev);
+ g_free (xev);
/* we must write this to the non-filtered stream ... */
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);
+ 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);
if (camel_data_wrapper_write_to_stream (CAMEL_DATA_WRAPPER (message), filter_stream) == -1)
goto fail;
@@ -347,7 +345,7 @@ mbox_append_message (CamelFolder *folder, CamelMimeMessage *message, CamelExcept
gtk_object_unref (GTK_OBJECT (output_stream));
/* force a summary update - will only update from the new position, if it can */
- camel_mbox_summary_update(mbox_folder->summary, seek);
+ camel_mbox_summary_update (mbox_folder->summary, seek);
return;
fail:
@@ -362,19 +360,20 @@ fail:
}
if (filter_stream) {
/*camel_stream_close (filter_stream);*/
- gtk_object_unref ((GtkObject *)filter_stream);
+ gtk_object_unref (GTK_OBJECT (filter_stream));
}
if (output_stream)
- gtk_object_unref ((GtkObject *)output_stream);
+ gtk_object_unref (GTK_OBJECT (output_stream));
if (filter_from)
- gtk_object_unref ((GtkObject *)filter_from);
+ gtk_object_unref (GTK_OBJECT (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);
+ int fd = open (mbox_folder->folder_file_path, O_WRONLY, 0600);
+
if (fd != -1) {
- ftruncate(fd, st.st_size);
+ ftruncate (fd, st.st_size);
close(fd);
}
}
@@ -384,15 +383,16 @@ static GPtrArray *
mbox_get_uids (CamelFolder *folder, CamelException *ex)
{
GPtrArray *array;
- CamelMboxFolder *mbox_folder = (CamelMboxFolder *)folder;
+ CamelMboxFolder *mbox_folder = CAMEL_MBOX_FOLDER (folder);
int i, count;
- count = camel_folder_summary_count((CamelFolderSummary *)mbox_folder->summary);
+ count = camel_folder_summary_count (CAMEL_FOLDER_SUMMARY (mbox_folder->summary));
array = g_ptr_array_new ();
g_ptr_array_set_size (array, count);
- for (i=0;i<count;i++) {
- CamelMboxMessageInfo *info = (CamelMboxMessageInfo *)camel_folder_summary_index((CamelFolderSummary *)mbox_folder->summary, i);
- array->pdata[i] = g_strdup(info->info.uid);
+ for (i = 0; i < count; i++) {
+ CamelMboxMessageInfo *info = (CamelMboxMessageInfo *) camel_folder_summary_index (
+ CAMEL_FOLDER_SUMMARY (mbox_folder->summary), i);
+ array->pdata[i] = g_strdup (info->info.uid);
}
return array;
@@ -406,15 +406,15 @@ mbox_get_subfolder_names (CamelFolder *folder, CamelException *ex)
}
static void
-mbox_delete_message_by_uid(CamelFolder *folder, const gchar *uid, CamelException *ex)
+mbox_delete_message_by_uid (CamelFolder *folder, const gchar *uid, CamelException *ex)
{
CamelMessageInfo *info;
- CamelMboxFolder *mf = (CamelMboxFolder *)folder;
+ CamelMboxFolder *mf = CAMEL_MBOX_FOLDER (folder);
- info = camel_folder_summary_uid((CamelFolderSummary *)mf->summary, uid);
+ info = camel_folder_summary_uid (CAMEL_FOLDER_SUMMARY (mf->summary), uid);
if (info) {
- info->flags |= CAMEL_MESSAGE_DELETED | CAMEL_MESSAGE_FOLDER_FLAGGED;
- camel_folder_summary_touch((CamelFolderSummary *)mf->summary);
+ info->flags |= CAMEL_MESSAGE_DELETED | CAMEL_MESSAGE_FOLDER_FLAGGED;
+ camel_folder_summary_touch (CAMEL_FOLDER_SUMMARY (mf->summary));
}
}
@@ -430,7 +430,7 @@ mbox_get_message_by_uid (CamelFolder *folder, const gchar *uid, CamelException *
int len;
/* get the message summary info */
- info = (CamelMboxMessageInfo *)camel_folder_summary_uid((CamelFolderSummary *)mbox_folder->summary, uid);
+ info = (CamelMboxMessageInfo *)camel_folder_summary_uid (CAMEL_FOLDER_SUMMARY (mbox_folder->summary), uid);
if (info == NULL) {
errno = ENOENT;
@@ -438,8 +438,8 @@ mbox_get_message_by_uid (CamelFolder *folder, const gchar *uid, CamelException *
}
/* if this has no content, its an error in the library */
- g_assert(info->info.content);
- g_assert(info->frompos != -1);
+ g_assert (info->info.content);
+ 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);
@@ -447,31 +447,31 @@ mbox_get_message_by_uid (CamelFolder *folder, const gchar *uid, CamelException *
goto fail;
/* we use a parser to verify the message is correct, and in the correct position */
- parser = camel_mime_parser_new();
- camel_mime_parser_init_with_stream(parser, message_stream);
- gtk_object_unref((GtkObject *)message_stream);
- camel_mime_parser_scan_from(parser, TRUE);
-
- camel_mime_parser_seek(parser, info->frompos, SEEK_SET);
- if (camel_mime_parser_step(parser, &buffer, &len) != HSCAN_FROM) {
- g_warning("File appears truncated");
+ parser = camel_mime_parser_new ();
+ camel_mime_parser_init_with_stream (parser, message_stream);
+ gtk_object_unref (GTK_OBJECT (message_stream));
+ camel_mime_parser_scan_from (parser, TRUE);
+
+ camel_mime_parser_seek (parser, info->frompos, SEEK_SET);
+ if (camel_mime_parser_step (parser, &buffer, &len) != HSCAN_FROM) {
+ g_warning ("File appears truncated");
goto fail;
}
- if (camel_mime_parser_tell_start_from(parser) != info->frompos) {
- g_warning("Summary doesn't match the folder contents! eek!\n"
- " expecting offset %ld got %ld", (long int)info->frompos,
- (long int)camel_mime_parser_tell_start_from(parser));
+ if (camel_mime_parser_tell_start_from (parser) != info->frompos) {
+ g_warning ("Summary doesn't match the folder contents! eek!\n"
+ " expecting offset %ld got %ld", (long int)info->frompos,
+ (long int)camel_mime_parser_tell_start_from (parser));
errno = EINVAL;
goto fail;
}
- message = camel_mime_message_new();
- if (camel_mime_part_construct_from_parser((CamelMimePart *)message, parser) == -1) {
- g_warning("Construction failed");
+ message = camel_mime_message_new ();
+ if (camel_mime_part_construct_from_parser (CAMEL_MIME_PART (message), parser) == -1) {
+ g_warning ("Construction failed");
goto fail;
}
- gtk_object_unref((GtkObject *)parser);
+ gtk_object_unref (GTK_OBJECT (parser));
return message;
@@ -481,9 +481,9 @@ fail:
g_strerror(errno));
if (parser)
- gtk_object_unref((GtkObject *)parser);
+ gtk_object_unref (GTK_OBJECT (parser));
if (message)
- gtk_object_unref((GtkObject *)message);
+ gtk_object_unref (GTK_OBJECT (message));
return NULL;
}
@@ -491,9 +491,9 @@ fail:
GPtrArray *
mbox_get_summary (CamelFolder *folder, CamelException *ex)
{
- CamelMboxFolder *mbox_folder = (CamelMboxFolder *)folder;
+ CamelMboxFolder *mbox_folder = CAMEL_MBOX_FOLDER (folder);
- return ((CamelFolderSummary *)mbox_folder->summary)->messages;
+ return CAMEL_FOLDER_SUMMARY (mbox_folder->summary)->messages;
}
void
@@ -504,42 +504,44 @@ mbox_free_summary (CamelFolder *folder, GPtrArray *array)
/* get a single message info, by uid */
static const CamelMessageInfo *
-mbox_summary_get_by_uid(CamelFolder *f, const char *uid)
+mbox_summary_get_by_uid (CamelFolder *folder, const char *uid)
{
- CamelMboxFolder *mbox_folder = (CamelMboxFolder *)f;
+ CamelMboxFolder *mbox_folder = CAMEL_MBOX_FOLDER (folder);
- return camel_folder_summary_uid((CamelFolderSummary *)mbox_folder->summary, uid);
+ return camel_folder_summary_uid (CAMEL_FOLDER_SUMMARY (mbox_folder->summary), uid);
}
static GList *
-mbox_search_by_expression(CamelFolder *folder, const char *expression, CamelException *ex)
+mbox_search_by_expression (CamelFolder *folder, const char *expression, CamelException *ex)
{
- CamelMboxFolder *mbox_folder = (CamelMboxFolder *)folder;
+ CamelMboxFolder *mbox_folder = CAMEL_MBOX_FOLDER (folder);
if (mbox_folder->search == NULL) {
- mbox_folder->search = camel_folder_search_new();
+ mbox_folder->search = camel_folder_search_new ();
}
- camel_folder_search_set_folder(mbox_folder->search, folder);
- if (mbox_folder->summary)
+ camel_folder_search_set_folder (mbox_folder->search, folder);
+ if (mbox_folder->summary) {
/* FIXME: dont access summary array directly? */
- camel_folder_search_set_summary(mbox_folder->search, ((CamelFolderSummary *)mbox_folder->summary)->messages);
- camel_folder_search_set_body_index(mbox_folder->search, mbox_folder->index);
+ camel_folder_search_set_summary (mbox_folder->search,
+ CAMEL_FOLDER_SUMMARY (mbox_folder->summary)->messages);
+ }
+
+ camel_folder_search_set_body_index (mbox_folder->search, mbox_folder->index);
- return camel_folder_search_execute_expression(mbox_folder->search, expression, ex);
+ return camel_folder_search_execute_expression (mbox_folder->search, expression, ex);
}
static guint32
-mbox_get_message_flags (CamelFolder *folder, const char *uid,
- CamelException *ex)
+mbox_get_message_flags (CamelFolder *folder, const char *uid, CamelException *ex)
{
CamelMessageInfo *info;
- CamelMboxFolder *mf = (CamelMboxFolder *)folder;
+ CamelMboxFolder *mf = CAMEL_MBOX_FOLDER (folder);
- info = camel_folder_summary_uid((CamelFolderSummary *)mf->summary, uid);
- if (info)
+ info = camel_folder_summary_uid (CAMEL_FOLDER_SUMMARY (mf->summary), uid);
+ if (info) {
return info->flags;
- else {
+ } else {
camel_exception_setv(ex, CAMEL_EXCEPTION_FOLDER_INVALID_UID,
"No such message %s in %s.", uid,
folder->name);
@@ -552,18 +554,19 @@ mbox_set_message_flags (CamelFolder *folder, const char *uid, guint32 flags,
guint32 set, CamelException *ex)
{
CamelMessageInfo *info;
- CamelMboxFolder *mf = (CamelMboxFolder *)folder;
+ CamelMboxFolder *mf = CAMEL_MBOX_FOLDER (folder);
- info = camel_folder_summary_uid((CamelFolderSummary *)mf->summary, uid);
+ info = camel_folder_summary_uid (CAMEL_FOLDER_SUMMARY (mf->summary), uid);
if (info) {
info->flags = (info->flags & ~flags) | (set & flags) |
CAMEL_MESSAGE_FOLDER_FLAGGED;
- camel_folder_summary_touch((CamelFolderSummary *)mf->summary);
- gtk_signal_emit_by_name((GtkObject *)folder, "message_changed", uid);
+ camel_folder_summary_touch (CAMEL_FOLDER_SUMMARY (mf->summary));
+
+ gtk_signal_emit_by_name (GTK_OBJECT (folder), "message_changed", uid);
} else {
- camel_exception_setv(ex, CAMEL_EXCEPTION_FOLDER_INVALID_UID,
- "No such message %s in %s.", uid,
- folder->name);
+ camel_exception_setv (ex, CAMEL_EXCEPTION_FOLDER_INVALID_UID,
+ "No such message %s in %s.", uid,
+ folder->name);
}
}
@@ -572,11 +575,11 @@ mbox_get_message_user_flag (CamelFolder *folder, const char *uid,
const char *name, CamelException *ex)
{
CamelMessageInfo *info;
- CamelMboxFolder *mf = (CamelMboxFolder *)folder;
+ CamelMboxFolder *mf = CAMEL_MBOX_FOLDER (folder);
- info = camel_folder_summary_uid((CamelFolderSummary *)mf->summary, uid);
+ info = camel_folder_summary_uid (CAMEL_FOLDER_SUMMARY (mf->summary), uid);
if (info)
- return camel_flag_get(&info->user_flags, name);
+ return camel_flag_get (&info->user_flags, name);
else {
camel_exception_setv(ex, CAMEL_EXCEPTION_FOLDER_INVALID_UID,
"No such message %s in %s.", uid,
@@ -590,16 +593,16 @@ static void mbox_set_message_user_flag (CamelFolder *folder, const char *uid,
CamelException *ex)
{
CamelMessageInfo *info;
- CamelMboxFolder *mf = (CamelMboxFolder *)folder;
+ CamelMboxFolder *mf = CAMEL_MBOX_FOLDER (folder);
- info = camel_folder_summary_uid((CamelFolderSummary *)mf->summary, uid);
+ info = camel_folder_summary_uid (CAMEL_FOLDER_SUMMARY (mf->summary), uid);
if (info) {
- camel_flag_set(&info->user_flags, name, value);
+ camel_flag_set (&info->user_flags, name, value);
info->flags |= CAMEL_MESSAGE_FOLDER_FLAGGED;
- camel_folder_summary_touch((CamelFolderSummary *)mf->summary);
- gtk_signal_emit_by_name((GtkObject *)folder, "message_changed", uid);
+ camel_folder_summary_touch (CAMEL_FOLDER_SUMMARY (mf->summary));
+ gtk_signal_emit_by_name (GTK_OBJECT (folder), "message_changed", uid);
} else {
- camel_exception_setv(ex, CAMEL_EXCEPTION_FOLDER_INVALID_UID,
+ camel_exception_setv (ex, CAMEL_EXCEPTION_FOLDER_INVALID_UID,
"No such message %s in %s.", uid,
folder->name);
}
diff --git a/camel/providers/mbox/camel-mbox-store.c b/camel/providers/mbox/camel-mbox-store.c
index c2d53f0072..42cb931927 100644
--- a/camel/providers/mbox/camel-mbox-store.c
+++ b/camel/providers/mbox/camel-mbox-store.c
@@ -98,7 +98,7 @@ camel_mbox_store_get_toplevel_dir (CamelMboxStore *store)
{
CamelURL *url = CAMEL_SERVICE (store)->url;
- g_assert(url != NULL);
+ g_assert (url != NULL);
return url->path;
}
@@ -132,8 +132,7 @@ get_folder (CamelStore *store, const char *folder_name, gboolean create,
return NULL;
}
- fd = open (name, O_WRONLY | O_CREAT | O_APPEND,
- S_IRUSR | S_IWUSR);
+ fd = open (name, O_WRONLY | O_CREAT | O_APPEND, S_IRUSR | S_IWUSR);
g_free (name);
if (fd == -1) {
camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
@@ -169,8 +168,11 @@ delete_folder (CamelStore *store, const char *folder_name, CamelException *ex)
name = g_strdup_printf ("%s%s", CAMEL_SERVICE (store)->url->path,
folder_name);
if (stat (name, &st) == -1) {
- if (errno == ENOENT)
+ if (errno == ENOENT) {
+ /* file doesn't exist - it's kinda like deleting it ;-) */
+ g_free (name);
return;
+ }
camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
"Could not delete folder `%s':\n%s",
@@ -178,12 +180,14 @@ delete_folder (CamelStore *store, const char *folder_name, CamelException *ex)
g_free (name);
return;
}
+
if (!S_ISREG (st.st_mode)) {
camel_exception_setv (ex, CAMEL_EXCEPTION_STORE_NO_FOLDER,
"`%s' is not a regular file.", name);
g_free (name);
return;
}
+
if (st.st_size != 0) {
camel_exception_setv (ex, CAMEL_EXCEPTION_FOLDER_NON_EMPTY,
"Folder `%s' is not empty. Not deleted.",
@@ -213,8 +217,7 @@ delete_folder (CamelStore *store, const char *folder_name, CamelException *ex)
}
static char *
-get_folder_name (CamelStore *store, const char *folder_name,
- CamelException *ex)
+get_folder_name (CamelStore *store, const char *folder_name, CamelException *ex)
{
/* For now, we don't allow hieararchy. FIXME. */
if (strchr (folder_name + 1, '/')) {
diff --git a/camel/providers/mbox/camel-mbox-summary.c b/camel/providers/mbox/camel-mbox-summary.c
index 12c1c38274..90f13a7ff2 100644
--- a/camel/providers/mbox/camel-mbox-summary.c
+++ b/camel/providers/mbox/camel-mbox-summary.c
@@ -40,14 +40,14 @@ struct _CamelMboxSummaryPrivate {
#define _PRIVATE(o) (((CamelMboxSummary *)(o))->priv)
-static int summary_header_load(CamelFolderSummary *, FILE *);
-static int summary_header_save(CamelFolderSummary *, FILE *);
+static int summary_header_load (CamelFolderSummary *, FILE *);
+static int summary_header_save (CamelFolderSummary *, FILE *);
-static CamelMessageInfo * message_info_new(CamelFolderSummary *, struct _header_raw *);
-static CamelMessageInfo * message_info_new_from_parser(CamelFolderSummary *, CamelMimeParser *);
-static CamelMessageInfo * message_info_load(CamelFolderSummary *, FILE *);
-static int message_info_save(CamelFolderSummary *, FILE *, CamelMessageInfo *);
-/*static void message_info_free(CamelFolderSummary *, CamelMessageInfo *);*/
+static CamelMessageInfo * message_info_new (CamelFolderSummary *, struct _header_raw *);
+static CamelMessageInfo * message_info_new_from_parser (CamelFolderSummary *, CamelMimeParser *);
+static CamelMessageInfo * message_info_load (CamelFolderSummary *, FILE *);
+static int message_info_save (CamelFolderSummary *, FILE *, CamelMessageInfo *);
+/*static void message_info_free (CamelFolderSummary *, CamelMessageInfo *);*/
static void camel_mbox_summary_class_init (CamelMboxSummaryClass *klass);
static void camel_mbox_summary_init (CamelMboxSummary *obj);
@@ -124,11 +124,11 @@ camel_mbox_summary_init (CamelMboxSummary *obj)
static void
camel_mbox_summary_finalise (GtkObject *obj)
{
- CamelMboxSummary *mbs = (CamelMboxSummary *)obj;
+ CamelMboxSummary *mbs = CAMEL_MBOX_SUMMARY (obj);
- g_free(mbs->folder_path);
+ g_free (mbs->folder_path);
- ((GtkObjectClass *)(camel_mbox_summary_parent))->finalize((GtkObject *)obj);
+ ((GtkObjectClass *)(camel_mbox_summary_parent))->finalize(GTK_OBJECT (obj));
}
/**
@@ -141,185 +141,200 @@ camel_mbox_summary_finalise (GtkObject *obj)
CamelMboxSummary *
camel_mbox_summary_new (const char *filename, const char *mbox_name, ibex *index)
{
- CamelMboxSummary *new = CAMEL_MBOX_SUMMARY ( gtk_type_new (camel_mbox_summary_get_type ()));
+ CamelMboxSummary *new = CAMEL_MBOX_SUMMARY (gtk_type_new (camel_mbox_summary_get_type ()));
+
if (new) {
/* ?? */
- camel_folder_summary_set_build_content((CamelFolderSummary *)new, TRUE);
- camel_folder_summary_set_filename((CamelFolderSummary *)new, filename);
- new->folder_path = g_strdup(mbox_name);
+ camel_folder_summary_set_build_content (CAMEL_FOLDER_SUMMARY (new), TRUE);
+ camel_folder_summary_set_filename (CAMEL_FOLDER_SUMMARY (new), filename);
+ new->folder_path = g_strdup (mbox_name);
new->index = index;
}
return new;
}
-
-static int summary_header_load(CamelFolderSummary *s, FILE *in)
+static int
+summary_header_load (CamelFolderSummary *s, FILE *in)
{
- CamelMboxSummary *mbs = (CamelMboxSummary *)s;
+ CamelMboxSummary *mbs = CAMEL_MBOX_SUMMARY (s);
- if (((CamelFolderSummaryClass *)camel_mbox_summary_parent)->summary_header_load(s, in) == -1)
+ if (((CamelFolderSummaryClass *)camel_mbox_summary_parent)->summary_header_load (s, in) == -1)
return -1;
- return camel_folder_summary_decode_uint32(in, &mbs->folder_size);
+ return camel_folder_summary_decode_uint32 (in, &mbs->folder_size);
}
-static int summary_header_save(CamelFolderSummary *s, FILE *out)
+static int
+summary_header_save (CamelFolderSummary *s, FILE *out)
{
- CamelMboxSummary *mbs = (CamelMboxSummary *)s;
+ CamelMboxSummary *mbs = CAMEL_MBOX_SUMMARY (s);
- if (((CamelFolderSummaryClass *)camel_mbox_summary_parent)->summary_header_save(s, out) == -1)
+ if (((CamelFolderSummaryClass *)camel_mbox_summary_parent)->summary_header_save (s, out) == -1)
return -1;
- return camel_folder_summary_encode_uint32(out, mbs->folder_size);
+ return camel_folder_summary_encode_uint32 (out, mbs->folder_size);
}
static int
-header_evolution_decode(const char *in, guint32 *uid, guint32 *flags)
+header_evolution_decode (const char *in, guint32 *uid, guint32 *flags)
{
char *header;
- if (in
- && (header = header_token_decode(in))) {
- if (strlen(header) == strlen("00000000-0000")
- && sscanf(header, "%08x-%04x", uid, flags) == 2) {
- g_free(header);
+
+ if (in && (header = header_token_decode(in))) {
+ if (strlen (header) == strlen ("00000000-0000")
+ && sscanf (header, "%08x-%04x", uid, flags) == 2) {
+ g_free (header);
return *uid;
}
- g_free(header);
+ g_free (header);
}
return -1;
}
static char *
-header_evolution_encode(guint32 uid, guint32 flags)
+header_evolution_encode (guint32 uid, guint32 flags)
{
- return g_strdup_printf("%08x-%04x", uid, flags & 0xffff);
+ return g_strdup_printf ("%08x-%04x", uid, flags & 0xffff);
}
-static CamelMessageInfo * message_info_new(CamelFolderSummary *s, struct _header_raw *h)
+static CamelMessageInfo *
+message_info_new (CamelFolderSummary *s, struct _header_raw *h)
{
CamelMessageInfo *mi;
- mi = ((CamelFolderSummaryClass *)camel_mbox_summary_parent)->message_info_new(s, h);
+ mi = ((CamelFolderSummaryClass *)camel_mbox_summary_parent)->message_info_new (s, h);
if (mi) {
const char *xev;
guint32 uid, flags;
CamelMboxMessageInfo *mbi = (CamelMboxMessageInfo *)mi;
- xev = header_raw_find(&h, "X-Evolution", NULL);
- if (xev
- && header_evolution_decode(xev, &uid, &flags) != -1) {
- g_free(mi->uid);
- mi->uid = g_strdup_printf("%u", uid);
+ xev = header_raw_find (&h, "X-Evolution", NULL);
+ if (xev && header_evolution_decode(xev, &uid, &flags) != -1) {
+ g_free (mi->uid);
+ mi->uid = g_strdup_printf ("%u", uid);
mi->flags = flags;
} else {
/* to indicate it has no xev header? */
- mi->flags |= CAMEL_MESSAGE_FOLDER_FLAGGED|CAMEL_MESSAGE_FOLDER_NOXEV;
- mi->uid = g_strdup_printf("%u", camel_folder_summary_next_uid(s));
+ mi->flags |= CAMEL_MESSAGE_FOLDER_FLAGGED | CAMEL_MESSAGE_FOLDER_NOXEV;
+ mi->uid = g_strdup_printf ("%u", camel_folder_summary_next_uid (s));
}
mbi->frompos = -1;
}
+
return mi;
}
-static CamelMessageInfo * message_info_new_from_parser(CamelFolderSummary *s, CamelMimeParser *mp)
+static CamelMessageInfo *
+message_info_new_from_parser (CamelFolderSummary *s, CamelMimeParser *mp)
{
CamelMessageInfo *mi;
- CamelMboxSummary *mbs = (CamelMboxSummary *)s;
+ CamelMboxSummary *mbs = CAMEL_MBOX_SUMMARY (s);
- mi = ((CamelFolderSummaryClass *)camel_mbox_summary_parent)->message_info_new_from_parser(s, mp);
+ mi = ((CamelFolderSummaryClass *)camel_mbox_summary_parent)->message_info_new_from_parser (s, mp);
if (mi) {
CamelMboxMessageInfo *mbi = (CamelMboxMessageInfo *)mi;
- mbi->frompos = camel_mime_parser_tell_start_from(mp);
+ mbi->frompos = camel_mime_parser_tell_start_from (mp);
/* do we want to index this message as we add it, as well? */
if (mbs->index_force
|| (mi->flags & CAMEL_MESSAGE_FOLDER_FLAGGED) != 0
|| !ibex_contains_name(mbs->index, mi->uid)) {
- camel_folder_summary_set_index(s, mbs->index);
+
+ camel_folder_summary_set_index (s, mbs->index);
} else {
- camel_folder_summary_set_index(s, NULL);
+ camel_folder_summary_set_index (s, NULL);
}
}
+
return mi;
}
-static CamelMessageInfo * message_info_load(CamelFolderSummary *s, FILE *in)
+static CamelMessageInfo *
+message_info_load (CamelFolderSummary *s, FILE *in)
{
CamelMessageInfo *mi;
- io(printf("loading mbox message info\n"));
+ io (printf ("loading mbox message info\n"));
- mi = ((CamelFolderSummaryClass *)camel_mbox_summary_parent)->message_info_load(s, in);
+ mi = ((CamelFolderSummaryClass *)camel_mbox_summary_parent)->message_info_load (s, in);
if (mi) {
CamelMboxMessageInfo *mbi = (CamelMboxMessageInfo *)mi;
- camel_folder_summary_decode_uint32(in, &mbi->frompos);
+ camel_folder_summary_decode_uint32 (in, &mbi->frompos);
}
+
return mi;
}
-static int message_info_save(CamelFolderSummary *s, FILE *out, CamelMessageInfo *mi)
+static int
+message_info_save (CamelFolderSummary *s, FILE *out, CamelMessageInfo *mi)
{
CamelMboxMessageInfo *mbi = (CamelMboxMessageInfo *)mi;
- io(printf("saving mbox message info\n"));
+ io (printf ("saving mbox message info\n"));
- ((CamelFolderSummaryClass *)camel_mbox_summary_parent)->message_info_save(s, out, mi);
+ ((CamelFolderSummaryClass *)camel_mbox_summary_parent)->message_info_save (s, out, mi);
- return camel_folder_summary_encode_uint32(out, mbi->frompos);
+ return camel_folder_summary_encode_uint32 (out, mbi->frompos);
}
static int
-summary_rebuild(CamelMboxSummary *mbs, off_t offset)
+summary_rebuild (CamelMboxSummary *mbs, off_t offset)
{
- CamelFolderSummary *s = (CamelFolderSummary *)mbs;
+ CamelFolderSummary *s = CAMEL_FOLDER_SUMMARY (mbs);
CamelMimeParser *mp;
int fd;
int ok = 0;
- printf("(re)Building summary from %d (%s)\n", (int)offset, mbs->folder_path);
+ printf ("(re)Building summary from %d (%s)\n", (int)offset, mbs->folder_path);
- fd = open(mbs->folder_path, O_RDONLY);
- mp = camel_mime_parser_new();
- camel_mime_parser_init_with_fd(mp, fd);
- camel_mime_parser_scan_from(mp, TRUE);
- camel_mime_parser_seek(mp, offset, SEEK_SET);
+ fd = open (mbs->folder_path, O_RDONLY);
+ if (fd == -1) {
+ printf ("%s failed to open: %s", mbs->folder_path, strerror (errno));
+ return -1;
+ }
+
+ mp = camel_mime_parser_new ();
+ camel_mime_parser_init_with_fd (mp, fd);
+ camel_mime_parser_scan_from (mp, TRUE);
+ camel_mime_parser_seek (mp, offset, SEEK_SET);
if (offset > 0) {
- if (camel_mime_parser_step(mp, NULL, NULL) == HSCAN_FROM) {
- if (camel_mime_parser_tell_start_from(mp) != offset) {
- g_warning("The next message didn't start where I expected\nbuilding summary from start");
- camel_mime_parser_drop_step(mp);
+ if (camel_mime_parser_step (mp, NULL, NULL) == HSCAN_FROM) {
+ if (camel_mime_parser_tell_start_from (mp) != offset) {
+ g_warning ("The next message didn't start where I expected\nbuilding summary from start");
+ camel_mime_parser_drop_step (mp);
offset = 0;
- camel_mime_parser_seek(mp, offset, SEEK_SET);
- camel_folder_summary_clear((CamelFolderSummary *)mbs);
+ camel_mime_parser_seek (mp, offset, SEEK_SET);
+ camel_folder_summary_clear (CAMEL_FOLDER_SUMMARY (mbs));
} else {
- camel_mime_parser_unstep(mp);
+ camel_mime_parser_unstep (mp);
}
} else {
- gtk_object_unref((GtkObject *)mp);
+ gtk_object_unref (GTK_OBJECT (mp));
/* end of file - no content? */
- printf("We radn out of file?\n");
+ printf("We ran out of file?\n");
return -1;
}
}
- while (camel_mime_parser_step(mp, NULL, NULL) == HSCAN_FROM) {
+ while (camel_mime_parser_step (mp, NULL, NULL) == HSCAN_FROM) {
CamelMessageInfo *info;
- info = camel_folder_summary_add_from_parser((CamelFolderSummary *)mbs, mp);
+ info = camel_folder_summary_add_from_parser (CAMEL_FOLDER_SUMMARY (mbs), mp);
if (info == NULL) {
- printf("Could not build info from file?\n");
+ printf ("Could not build info from file?\n");
ok = -1;
break;
}
- g_assert(camel_mime_parser_step(mp, NULL, NULL) == HSCAN_FROM_END);
+ g_assert (camel_mime_parser_step (mp, NULL, NULL) == HSCAN_FROM_END);
}
- gtk_object_unref((GtkObject *)mp);
+ gtk_object_unref (GTK_OBJECT (mp));
+
/* update the file size/mtime in the summary */
if (ok != -1) {
struct stat st;
@@ -334,12 +349,12 @@ summary_rebuild(CamelMboxSummary *mbs, off_t offset)
}
int
-camel_mbox_summary_update(CamelMboxSummary *mbs, off_t offset)
+camel_mbox_summary_update (CamelMboxSummary *mbs, off_t offset)
{
int ret;
mbs->index_force = FALSE;
- ret = summary_rebuild(mbs, offset);
+ ret = summary_rebuild (mbs, offset);
#if 0
#warning "Saving full summary and index after every summarisation is slow ..."
@@ -356,9 +371,9 @@ camel_mbox_summary_update(CamelMboxSummary *mbs, off_t offset)
}
int
-camel_mbox_summary_load(CamelMboxSummary *mbs, int forceindex)
+camel_mbox_summary_load (CamelMboxSummary *mbs, int forceindex)
{
- CamelFolderSummary *s = (CamelFolderSummary *)mbs;
+ CamelFolderSummary *s = CAMEL_FOLDER_SUMMARY (mbs);
struct stat st;
int ret = 0;
off_t minstart;
@@ -366,17 +381,17 @@ camel_mbox_summary_load(CamelMboxSummary *mbs, int forceindex)
mbs->index_force = forceindex;
/* is the summary out of date? */
- if (stat(mbs->folder_path, &st) == -1) {
- camel_folder_summary_clear(s);
- printf("Cannot summarise folder: '%s': %s\n", mbs->folder_path, strerror(errno));
+ if (stat (mbs->folder_path, &st) == -1) {
+ camel_folder_summary_clear (s);
+ printf ("Cannot summarise folder: '%s': %s\n", mbs->folder_path, strerror(errno));
return -1;
}
- if (forceindex || camel_folder_summary_load(s) == -1) {
+ if (forceindex || camel_folder_summary_load (s) == -1) {
printf ("REBUILDING SUMMARY: %s\n",
forceindex ? "Summary non-existent." : "Summary load failed.");
- camel_folder_summary_clear(s);
- ret = summary_rebuild(mbs, 0);
+ camel_folder_summary_clear (s);
+ ret = summary_rebuild (mbs, 0);
} else {
minstart = st.st_size;
#if 0
@@ -395,30 +410,30 @@ camel_mbox_summary_load(CamelMboxSummary *mbs, int forceindex)
#endif
/* is the summary uptodate? */
if (st.st_size == mbs->folder_size && st.st_mtime == s->time) {
- printf("Summary time and date match mbox\n");
+ printf ("Summary time and date match mbox\n");
if (minstart < st.st_size) {
/* FIXME: Only clear the messages and reindex from this point forward */
printf ("REBUILDING SUMMARY: Index file is incomplete.\n");
- camel_folder_summary_clear(s);
- ret = summary_rebuild(mbs, 0);
+ camel_folder_summary_clear (s);
+ ret = summary_rebuild (mbs, 0);
}
} else {
if (mbs->folder_size < st.st_size) {
- printf("REBUILDING SUMMARY: Summary is for a smaller mbox\n");
+ printf ("REBUILDING SUMMARY: Summary is for a smaller mbox\n");
if (minstart < mbs->folder_size) {
/* FIXME: only make it rebuild as necessary */
- camel_folder_summary_clear(s);
- ret = summary_rebuild(mbs, 0);
+ camel_folder_summary_clear (s);
+ ret = summary_rebuild (mbs, 0);
} else {
- ret = summary_rebuild(mbs, mbs->folder_size);
+ ret = summary_rebuild (mbs, mbs->folder_size);
}
} else {
if (mbs->folder_size > st.st_size)
- printf("REBUILDING_SUMMARY: Summary is for a bigger mbox\n");
+ printf ("REBUILDING_SUMMARY: Summary is for a bigger mbox\n");
else
- printf("REBUILDING SUMMARY: Summary is for an older mbox\n");
- camel_folder_summary_clear(s);
- ret = summary_rebuild(mbs, 0);
+ printf ("REBUILDING SUMMARY: Summary is for an older mbox\n");
+ camel_folder_summary_clear (s);
+ ret = summary_rebuild (mbs, 0);
}
}
}
@@ -426,20 +441,20 @@ camel_mbox_summary_load(CamelMboxSummary *mbs, int forceindex)
if (ret != -1) {
mbs->folder_size = st.st_size;
s->time = st.st_mtime;
- printf("saving summary\n");
- if (camel_folder_summary_save(s) == -1)
- g_warning("Could not save summary: %s", strerror(errno));
- printf("summary saved\n");
+ printf ("saving summary\n");
+ if (camel_folder_summary_save (s) == -1)
+ g_warning("Could not save summary: %s", strerror (errno));
+ printf ("summary saved\n");
if (mbs->index)
- ibex_save(mbs->index);
- printf("ibex saved\n");
+ ibex_save (mbs->index);
+ printf ("ibex saved\n");
}
return ret;
}
static int
-header_write(int fd, struct _header_raw *header, char *xevline)
+header_write (int fd, struct _header_raw *header, char *xevline)
{
struct iovec iv[4];
int outlen = 0, len;
@@ -450,7 +465,7 @@ header_write(int fd, struct _header_raw *header, char *xevline)
iv[3].iov_len = 1;
while (header) {
- if (strcasecmp(header->name, "X-Evolution")) {
+ if (strcasecmp (header->name, "X-Evolution")) {
iv[0].iov_base = header->name;
iv[0].iov_len = strlen(header->name);
iv[2].iov_base = header->value;
@@ -468,14 +483,14 @@ header_write(int fd, struct _header_raw *header, char *xevline)
}
iv[0].iov_base = "X-Evolution: ";
- iv[0].iov_len = strlen(iv[0].iov_base);
+ iv[0].iov_len = strlen (iv[0].iov_base);
iv[1].iov_base = xevline;
- iv[1].iov_len = strlen(xevline);
+ iv[1].iov_len = strlen (xevline);
iv[2].iov_base = "\n\n";
iv[2].iov_len = 2;
do {
- len = writev(fd, iv, 3);
+ len = writev (fd, iv, 3);
} while (len == -1 && errno == EINTR);
if (len == -1)
@@ -483,7 +498,7 @@ header_write(int fd, struct _header_raw *header, char *xevline)
outlen += 1;
- d(printf("Wrote %d bytes of headers\n", outlen));
+ d(printf ("Wrote %d bytes of headers\n", outlen));
return outlen;
}
@@ -494,21 +509,21 @@ copy_block(int fromfd, int tofd, off_t start, size_t bytes)
char buffer[4096];
int written = 0;
- d(printf("writing %d bytes ... ", bytes));
+ d(printf ("writing %d bytes ... ", bytes));
if (lseek(fromfd, start, SEEK_SET) != start)
return -1;
- while (bytes>0) {
+ while (bytes > 0) {
int toread, towrite;
toread = bytes;
- if (bytes>4096)
+ if (bytes > 4096)
toread = 4096;
else
toread = bytes;
do {
- towrite = read(fromfd, buffer, toread);
+ towrite = read (fromfd, buffer, toread);
} while (towrite == -1 && errno == EINTR);
if (towrite == -1)
@@ -516,12 +531,12 @@ copy_block(int fromfd, int tofd, off_t start, size_t bytes)
/* check for 'end of file' */
if (towrite == 0) {
- d(printf("end of file?\n"));
+ d(printf ("end of file?\n"));
break;
}
do {
- toread = write(tofd, buffer, towrite);
+ toread = write (tofd, buffer, towrite);
} while (toread == -1 && errno == EINTR);
if (toread == -1)
@@ -531,22 +546,21 @@ copy_block(int fromfd, int tofd, off_t start, size_t bytes)
bytes -= toread;
}
- d(printf("written %d bytes\n", written));
+ d(printf ("written %d bytes\n", written));
return written;
}
int
-camel_mbox_summary_sync(CamelMboxSummary *mbs, gboolean expunge)
+camel_mbox_summary_sync (CamelMboxSummary *mbs, gboolean expunge, CamelException *ex)
{
- CamelMimeParser *mp=NULL;
+ CamelMimeParser *mp = NULL;
int i, count;
CamelMboxMessageInfo *info;
- CamelFolderSummary *s = (CamelFolderSummary *)mbs;
-
- int fd=-1, fdout=-1;
+ CamelFolderSummary *s = CAMEL_FOLDER_SUMMARY (mbs);
+ int fd = -1, fdout = -1;
off_t offset = 0;
- char *tmpname=0;
+ char *tmpname = NULL;
char *buffer, *xevnew = NULL;
const char *xev;
int len;
@@ -555,18 +569,18 @@ camel_mbox_summary_sync(CamelMboxSummary *mbs, gboolean expunge)
struct stat st;
/* make sure we're in sync */
- count = camel_folder_summary_count(s);
- if (count>0) {
- CamelMessageInfo *mi = camel_folder_summary_index(s, count-1);
- camel_mbox_summary_update(mbs, mi->content->endpos);
+ count = camel_folder_summary_count (s);
+ if (count > 0) {
+ CamelMessageInfo *mi = camel_folder_summary_index (s, count - 1);
+ camel_mbox_summary_update (mbs, mi->content->endpos);
} else {
- camel_mbox_summary_update(mbs, 0);
+ camel_mbox_summary_update (mbs, 0);
}
/* check if we have any work to do */
- d(printf("Performing sync, %d messages in inbox\n", count));
- for (i=0;quick && i<count;i++) {
- info = (CamelMboxMessageInfo *)camel_folder_summary_index(s, i);
+ d(printf ("Performing sync, %d messages in inbox\n", count));
+ for (i = 0; quick && i < count; i++) {
+ info = (CamelMboxMessageInfo *)camel_folder_summary_index (s, i);
if ((expunge && (info->info.flags & CAMEL_MESSAGE_DELETED)) ||
(info->info.flags & CAMEL_MESSAGE_FOLDER_NOXEV))
quick = FALSE;
@@ -574,36 +588,43 @@ camel_mbox_summary_sync(CamelMboxSummary *mbs, gboolean expunge)
work |= (info->info.flags & CAMEL_MESSAGE_FOLDER_FLAGGED) != 0;
}
- d(printf("Options: %s %s %s\n", expunge?"expunge":"", quick?"quick":"", work?"Work":""));
+ d(printf ("Options: %s %s %s\n", expunge ? "expunge" : "", quick ? "quick" : "", work ? "Work" : ""));
if (quick && !work)
return 0;
- fd = open(mbs->folder_path, O_RDWR);
- if (fd == -1)
+ fd = open (mbs->folder_path, O_RDWR);
+ if (fd == -1) {
+ camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
+ "Could not open summary %s", mbs->folder_path);
return -1;
+ }
- mp = camel_mime_parser_new();
- camel_mime_parser_scan_from(mp, TRUE);
- camel_mime_parser_init_with_fd(mp, fd);
+ mp = camel_mime_parser_new ();
+ camel_mime_parser_scan_from (mp, TRUE);
+ camel_mime_parser_init_with_fd (mp, fd);
if (!quick) {
- tmpname = alloca(strlen(mbs->folder_path)+5);
- sprintf(tmpname, "%s.tmp", mbs->folder_path);
- d(printf("Writing tmp file to %s\n", tmpname));
+ tmpname = alloca (strlen (mbs->folder_path) + 5);
+ sprintf (tmpname, "%s.tmp", mbs->folder_path);
+ d(printf ("Writing tmp file to %s\n", tmpname));
retry_out:
- fdout = open(tmpname, O_WRONLY|O_CREAT|O_EXCL, 0600);
+ fdout = open (tmpname, O_WRONLY | O_CREAT | O_EXCL, 0600);
if (fdout == -1) {
if (errno == EEXIST)
if (unlink(tmpname) != -1)
goto retry_out;
- tmpname = 0;
- g_warning("Something failed (yo!)");
+
+ free (tmpname);
+ tmpname = NULL;
+ g_warning ("Something failed (yo!)");
+ camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
+ "Cannot open temporary mailbox: %s", strerror (errno));
goto error;
}
}
- for (i=0;i<count;i++) {
+ for (i = 0; i < count; i++) {
off_t frompos, bodypos, lastpos;
/* This has to be an int, not an off_t, because that's
* what camel_mime_parser_header returns... FIXME.
@@ -612,169 +633,201 @@ camel_mbox_summary_sync(CamelMboxSummary *mbs, gboolean expunge)
info = (CamelMboxMessageInfo *)camel_folder_summary_index(s, i);
- g_assert(info);
+ g_assert (info);
- d(printf("Looking at message %s\n", info->info.uid));
+ d(printf ("Looking at message %s\n", info->info.uid));
if (expunge && info->info.flags & CAMEL_MESSAGE_DELETED) {
- d(printf("Deleting %s\n", info->info.uid));
+ d(printf ("Deleting %s\n", info->info.uid));
- g_assert(!quick);
+ g_assert (!quick);
offset -= (info->info.content->endpos - info->frompos);
if (mbs->index)
- ibex_unindex(mbs->index, info->info.uid);
- camel_folder_summary_remove(s, (CamelMessageInfo *)info);
+ ibex_unindex (mbs->index, info->info.uid);
+ camel_folder_summary_remove (s, (CamelMessageInfo *)info);
count--;
i--;
info = NULL;
- } else if (info->info.flags & (CAMEL_MESSAGE_FOLDER_NOXEV|CAMEL_MESSAGE_FOLDER_FLAGGED)) {
+ } else if (info->info.flags & (CAMEL_MESSAGE_FOLDER_NOXEV | CAMEL_MESSAGE_FOLDER_FLAGGED)) {
int xevok = FALSE;
- d(printf("Updating header for %s flags = %08x\n", info->info.uid, info->info.flags));
+ d(printf ("Updating header for %s flags = %08x\n", info->info.uid, info->info.flags));
/* find the next message, header parts */
- camel_mime_parser_seek(mp, info->frompos, SEEK_SET);
- if (camel_mime_parser_step(mp, &buffer, &len) != HSCAN_FROM) {
- g_warning("camel_mime_parser_step failed (1)");
+ camel_mime_parser_seek (mp, info->frompos, SEEK_SET);
+ if (camel_mime_parser_step (mp, &buffer, &len) != HSCAN_FROM) {
+ g_warning ("camel_mime_parser_step failed (1)");
goto error;
}
- if (camel_mime_parser_tell_start_from(mp) != info->frompos) {
- g_warning("Summary/mbox mismatch, aborting sync");
+ if (camel_mime_parser_tell_start_from (mp) != info->frompos) {
+ g_warning ("Summary/mbox mismatch, aborting sync");
+ camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
+ "Summary mismatch, aborting sync");
goto error;
}
- if (camel_mime_parser_step(mp, &buffer, &len) == HSCAN_FROM_END) {
- g_warning("camel_mime_parser_step failed (2)");
+ if (camel_mime_parser_step (mp, &buffer, &len) == HSCAN_FROM_END) {
+ g_warning ("camel_mime_parser_step failed (2)");
goto error;
}
- xev = camel_mime_parser_header(mp, "X-Evolution", &xevoffset);
- if (xev && header_evolution_decode(xev, &uid, &flags) != -1) {
+ xev = camel_mime_parser_header (mp, "X-Evolution", &xevoffset);
+ if (xev && header_evolution_decode (xev, &uid, &flags) != -1) {
char name[64];
- sprintf(name, "%u", uid);
- if (strcmp(name, info->info.uid)) {
- d(printf("Summary mismatch, aborting leaving mailbox intact\n"));
+ sprintf (name, "%u", uid);
+ if (strcmp (name, info->info.uid)) {
+ d(printf ("Summary mismatch, aborting leaving mailbox intact\n"));
+ camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
+ "Summary mismatch, aborting leaving mailbox intact");
goto error;
}
xevok = TRUE;
}
- xevnew = header_evolution_encode(strtoul(info->info.uid, NULL, 10), info->info.flags & 0xffff);
+ xevnew = header_evolution_encode (strtoul (info->info.uid, NULL, 10), info->info.flags & 0xffff);
if (quick) {
if (!xevok) {
- g_warning("The summary told me I had an X-Evolution header, but i dont!");
+ g_warning ("The summary told me I had an X-Evolution header, but i dont!");
+ camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
+ "Summary mismatch, X-Evolution header missing");
goto error;
}
- buffer = g_strdup_printf("X-Evolution: %s", xevnew);
+ buffer = g_strdup_printf ("X-Evolution: %s", xevnew);
lastpos = lseek (fd, 0, SEEK_CUR);
lseek (fd, xevoffset, SEEK_SET);
do {
- len = write(fd, buffer, strlen(buffer));
+ len = write (fd, buffer, strlen (buffer));
} while (len == -1 && errno == EINTR);
lseek (fd, lastpos, SEEK_SET);
- g_free(buffer);
+ g_free (buffer);
if (len == -1) {
- g_warning("Yahoo! len == -1");
+ g_warning ("Yahoo! len == -1");
goto error;
}
} else {
- frompos = lseek(fdout, 0, SEEK_CUR);
- write(fdout, "From -\n", strlen("From -\n"));
- if (header_write(fdout, camel_mime_parser_headers_raw(mp), xevnew) == -1) {
- d(printf("Error writing to tmp mailbox\n"));
+ frompos = lseek (fdout, 0, SEEK_CUR);
+ write (fdout, "From -\n", strlen("From -\n"));
+ if (header_write (fdout, camel_mime_parser_headers_raw (mp), xevnew) == -1) {
+ d(printf ("Error writing to tmp mailbox\n"));
+ camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
+ "Error writing to temp mailbox: %s",
+ strerror (errno));
goto error;
}
- bodypos = lseek(fdout, 0, SEEK_CUR);
- d(printf("pos = %d, endpos = %d, bodypos = %d\n",
- info->info.content->pos,
- info->info.content->endpos,
- info->info.content->bodypos));
- if (copy_block(fd, fdout, info->info.content->bodypos,
- info->info.content->endpos - info->info.content->bodypos) == -1) {
- g_warning("Cannot copy data to output fd");
+ bodypos = lseek (fdout, 0, SEEK_CUR);
+ d(printf ("pos = %d, endpos = %d, bodypos = %d\n",
+ (int) info->info.content->pos,
+ (int) info->info.content->endpos,
+ (int) info->info.content->bodypos));
+ if (copy_block (fd, fdout, info->info.content->bodypos,
+ info->info.content->endpos - info->info.content->bodypos) == -1) {
+ g_warning ("Cannot copy data to output fd");
+ camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
+ "Cannot copy data to output fd: %s",
+ strerror (errno));
goto error;
}
info->frompos = frompos;
offset = bodypos - info->info.content->bodypos;
}
info->info.flags &= 0xffff;
- g_free(xevnew); xevnew = NULL;
- camel_mime_parser_drop_step(mp);
- camel_mime_parser_drop_step(mp);
+ g_free (xevnew);
+ xevnew = NULL;
+ camel_mime_parser_drop_step (mp);
+ camel_mime_parser_drop_step (mp);
} else {
if (!quick) {
- if (copy_block(fd, fdout, info->frompos,
- info->info.content->endpos - info->frompos) == -1) {
- g_warning("Cannot copy data to output fd");
+ if (copy_block (fd, fdout, info->frompos,
+ info->info.content->endpos - info->frompos) == -1) {
+ g_warning ("Cannot copy data to output fd");
+ camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
+ "Cannot copy data to output fd: %s",
+ strerror (errno));
goto error;
}
/* update from pos here? */
info->frompos += offset;
} else {
- d(printf("Nothing to do for this message\n"));
+ d(printf ("Nothing to do for this message\n"));
}
}
- if (!quick && info!=NULL && offset!=0) {
- d(printf("offsetting content: %d\n", offset));
- camel_folder_summary_offset_content(info->info.content, offset);
- d(printf("pos = %d, endpos = %d, bodypos = %d\n",
- info->info.content->pos,
- info->info.content->endpos,
- info->info.content->bodypos));
+ if (!quick && info != NULL && offset != 0) {
+ d(printf ("offsetting content: %d\n", (int) offset));
+ camel_folder_summary_offset_content (info->info.content, offset);
+ d(printf ("pos = %d, endpos = %d, bodypos = %d\n",
+ (int) info->info.content->pos,
+ (int) info->info.content->endpos,
+ (int) info->info.content->bodypos));
}
}
- d(printf("Closing folders\n"));
+ d(printf ("Closing folders\n"));
- if (close(fd) == -1) {
- g_warning("Cannot close source folder: %s", strerror(errno));
+ if (close (fd) == -1) {
+ g_warning ("Cannot close source folder: %s", strerror (errno));
+ camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
+ "Could not close source folder %s: %s",
+ mbs->folder_path, strerror (errno));
goto error;
}
if (!quick) {
- if (close(fdout) == -1) {
- g_warning("Cannot close tmp folder: %s", strerror(errno));
+ if (close (fdout) == -1) {
+ g_warning ("Cannot close tmp folder: %s", strerror (errno));
+ camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
+ "Could not close temp folder: %s",
+ strerror (errno));
goto error;
}
- if (rename(tmpname, mbs->folder_path) == -1) {
- g_warning("Cannot rename folder: %s", strerror(errno));
+ if (rename (tmpname, mbs->folder_path) == -1) {
+ g_warning ("Cannot rename folder: %s", strerror (errno));
+ camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
+ "Could not rename folder: %s",
+ strerror (errno));
goto error;
}
- tmpname = 0;
+ tmpname = NULL;
if (mbs->index)
- ibex_save(mbs->index);
+ ibex_save (mbs->index);
}
- if (stat(mbs->folder_path, &st) == -1) {
- g_warning("Hmm... stat(mbs->folder_path, &st) == -1");
+ if (stat (mbs->folder_path, &st) == -1) {
+ g_warning ("Hmm... stat(mbs->folder_path, &st) == -1");
+ camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
+ "Unknown error: %s",
+ strerror (errno));
goto error;
}
- camel_folder_summary_touch(s);
+ camel_folder_summary_touch (s);
s->time = st.st_mtime;
mbs->folder_size = st.st_size;
- camel_folder_summary_save(s);
-
- gtk_object_unref((GtkObject *)mp);
+ camel_folder_summary_save (s);
+ gtk_object_unref (GTK_OBJECT (mp));
+
return 0;
-error:
- d(printf("Error occured: %s\n", strerror(errno)));
- count = errno;
-
- close(fd);
- close(fdout);
-
- g_free(xevnew);
-
+ error:
+ if (fd != -1)
+ close (fd);
+
+ if (fdout != -1)
+ close (fdout);
+
+ g_free (xevnew);
+
if (tmpname)
- unlink(tmpname);
+ unlink (tmpname);
if (mp)
- gtk_object_unref((GtkObject *)mp);
+ gtk_object_unref (GTK_OBJECT (mp));
- errno = count;
return -1;
}
+
+
+
+
+
diff --git a/camel/providers/mbox/camel-mbox-summary.h b/camel/providers/mbox/camel-mbox-summary.h
index ad7af33e91..fb31002320 100644
--- a/camel/providers/mbox/camel-mbox-summary.h
+++ b/camel/providers/mbox/camel-mbox-summary.h
@@ -24,6 +24,7 @@
#include <gtk/gtk.h>
#include <camel/camel-folder-summary.h>
+#include <camel/camel-exception.h>
#include <libibex/ibex.h>
#define CAMEL_MBOX_SUMMARY(obj) GTK_CHECK_CAST (obj, camel_mbox_summary_get_type (), CamelMboxSummary)
@@ -72,6 +73,7 @@ int camel_mbox_summary_load(CamelMboxSummary *mbs, int forceindex);
/* incremental update */
int camel_mbox_summary_update(CamelMboxSummary *mbs, off_t offset);
/* perform a folder sync or expunge, if needed */
-int camel_mbox_summary_sync (CamelMboxSummary *mbs, gboolean expunge);
+int camel_mbox_summary_sync (CamelMboxSummary *mbs, gboolean expunge, CamelException *ex);
#endif /* ! _CAMEL_MBOX_SUMMARY_H */
+