diff options
author | Not Zed <NotZed@Ximian.com> | 2002-06-26 09:07:05 +0800 |
---|---|---|
committer | Michael Zucci <zucchi@src.gnome.org> | 2002-06-26 09:07:05 +0800 |
commit | 58e9041bff92805eba3852487c374623a38e1364 (patch) | |
tree | 878c8f698d1ada89c1356959538ab251678982ed /camel/providers/local/camel-spool-folder.c | |
parent | 8a7da69e92e3a71c954c59944dc4455f2ab89337 (diff) | |
download | gsoc2013-evolution-58e9041bff92805eba3852487c374623a38e1364.tar.gz gsoc2013-evolution-58e9041bff92805eba3852487c374623a38e1364.tar.zst gsoc2013-evolution-58e9041bff92805eba3852487c374623a38e1364.zip |
Include <sys/time.h> for struct timeval.
2002-06-26 Not Zed <NotZed@Ximian.com>
* camel-gpg-context.c: Include <sys/time.h> for struct timeval.
* providers/local/camel-local-provider.c
(camel_provider_module_init): Removed spoold provider. The spool
provider does it now.
2002-06-25 Not Zed <NotZed@Ximian.com>
* providers/local/camel-spool-folder.c (camel_spool_folder_new):
Support a new xstatus option - folders update/honour the
Status/X-Status headers in addition to X-Evolution.
* providers/local/camel-local-summary.c
(camel_local_summary_write_headers): If supplied with an
additional status or xstatus arg, write a Status header and/or
X-Status. Also fix the case of properly terminating the headers
if an xev line isn't supplied.
* providers/local/Makefile.am (libcamellocalinclude_HEADERS,SOURCES):
Removed spoold-store.[ch].
* providers/local/camel-local-provider.c
(camel_provider_module_init): For the spoold type, just use the
spool store instead.
* providers/local/camel-spool-store.h: Added a type field, so the
1 store can implement different types without having to subclass.
* providers/local/camel-spool-store.c
(camel_spool_store_get_toplevel_dir): Removed, inherits from local
store now.
(construct): If we're pointing to a file, treat it as mbox mode,
otherwise treat it as 'elm' mode.
(get_folder): Only test for INBOX in mbox mode.
(get_folder_info_elm):
(get_folder_info_mbox): Two alternatives for getting folder info,
depending on the type of folder we're looking at.
(get_folder_info_mbox): Make the url include the protocol.
(scan_dir): "
* providers/local/camel-spoold-store.c
(camel_spoold_store_get_toplevel_dir): Removed, inherits from
local store now.
* camel-folder.c (get_message_user_tag): Dont use a
g_return_if_fail for info==NULL. This is not an error.
(set_message_user_tag): And same here.
(set_message_user_flag): Sigh, and here.
(get_message_user_flag): And here.
(set_message_flags): and here ...
(get_message_flags): Dum de dum, de done at last.
* providers/local/camel-mbox-folder.c (mbox_get_message): Check
for new messages whenever we retrieve one. In the common
no-update case, this is a single stat.
(mbox_get_message): If we need to rescan, then force a full rescan
to make sure it does the right thing.
(mbox_get_message): Cleanup the exception handling a bit, if we do
get an error, propagate any folder changes anyway as well.
(mbox_set_message_user_flag): Argh more of these stupid g_returns
taht shouldn't be.
(mbox_set_message_user_tag): Here too.
(mbox_set_message_flags): If the read flag is being changed, mark
it as an xevchange (i.e. Status line change).
* providers/local/camel-mbox-summary.c (summary_rebuild): Merged
into summary_update.
(summary_update): Changed to allow it to update existing lists of
messages without clearing out the summary.
(mbox_summary_check): Dont clear the summary, just re-scan.
(message_info_new): Attempt to support the 'Status: RO' elm/pine
thing.
(camel_mbox_summary_encode_status):
(camel_mbox_summary_decode_status): Util functions for
creating/parsing the Status line.
(camel_mbox_summary_sync_mbox): Write out the status line if we're
going to try support it.
(camel_mbox_summary_xstatus): Implement option to control
read/write of (x-)status.
(message_info_new): Do x-status stuff based on run-time option.
(camel_mbox_summary_sync_mbox): "
(mbox_summary_add): If x-status enabled, then always add
status/x-status headers to message.
* camel-folder-summary.c (summary_assign_uid): If the messageinfo
is already in the summary, AND is the same messageinfo, dont do
anything, return a value to indicate this.
(camel_folder_summary_add): Do nothing if this info already in the
summary, so we can perform updates.
2002-06-24 Not Zed <NotZed@Ximian.com>
* providers/local/camel-local-summary.c
(camel_local_summary_check_force): New method to force the next
summary check to be a full check, set if a mismatch occurs.
* camel-folder-summary.c (camel_folder_summary_load): If we have
no summary path set, dont do any i/o, rather than abort.
(camel_folder_summary_save): "
(camel_folder_summary_header_load): "
* providers/local/camel-spool-store.h: Inherit from camel mbox
store, even if we override almost everything.
* providers/local/camel-local-folder.c
(camel_local_folder_construct): If the base path points to a file,
use that as the folder path as well.
* providers/local/camel-spool-folder.h: Inherit from
camel-mbox-folder.
* providers/local/camel-spool-summary.c (spool_summary_sync_full):
Use camel_mbox_summary_sync_mbox to do most of the work.
* providers/local/camel-spool-summary.[ch]: Make spool-summary
inherit from mbox summary rather than foldersummary.
* providers/local/camel-mbox-summary.c (mbox_summary_sync): Make
sync_full/quick virtual methods.
(camel_mbox_summary_sync_mbox): The full sync method put into a
simple function that sync's from fd to fd.
(mbox_summary_sync_full): Use summary_sync_mbox to do the real
work.
(mbox_summary_check): Create removed events if the folder gets
cleared. Also, dont clear the summary before a rebuild, try to
merge.
svn path=/trunk/; revision=17284
Diffstat (limited to 'camel/providers/local/camel-spool-folder.c')
-rw-r--r-- | camel/providers/local/camel-spool-folder.c | 597 |
1 files changed, 40 insertions, 557 deletions
diff --git a/camel/providers/local/camel-spool-folder.c b/camel/providers/local/camel-spool-folder.c index a519c58683..55df340c26 100644 --- a/camel/providers/local/camel-spool-folder.c +++ b/camel/providers/local/camel-spool-folder.c @@ -56,101 +56,38 @@ static CamelFolderClass *parent_class = NULL; #define CF_CLASS(so) CAMEL_FOLDER_CLASS (CAMEL_OBJECT_GET_CLASS(so)) #define CSPOOLS_CLASS(so) CAMEL_STORE_CLASS (CAMEL_OBJECT_GET_CLASS(so)) -static int spool_lock(CamelSpoolFolder *lf, CamelLockType type, CamelException *ex); -static void spool_unlock(CamelSpoolFolder *lf); +static CamelLocalSummary *spool_create_summary(const char *path, const char *folder, CamelIndex *index); -static void spool_sync(CamelFolder *folder, gboolean expunge, CamelException *ex); -static void spool_expunge(CamelFolder *folder, CamelException *ex); - -static GPtrArray *spool_search_by_expression(CamelFolder *folder, const char *expression, CamelException *ex); -static GPtrArray *spool_search_by_uids(CamelFolder *folder, const char *expression, GPtrArray *uids, CamelException *ex); -static void spool_search_free(CamelFolder *folder, GPtrArray * result); - -static void spool_append_message(CamelFolder *folder, CamelMimeMessage * message, const CamelMessageInfo * info, char **appended_uid, CamelException *ex); -static CamelMimeMessage *spool_get_message(CamelFolder *folder, const gchar * uid, CamelException *ex); -static void spool_set_message_user_flag(CamelFolder *folder, const char *uid, const char *name, gboolean value); -static void spool_set_message_user_tag(CamelFolder *folder, const char *uid, const char *name, const char *value); +static int spool_lock(CamelLocalFolder *lf, CamelLockType type, CamelException *ex); +static void spool_unlock(CamelLocalFolder *lf); static void spool_finalize(CamelObject * object); static void -camel_spool_folder_class_init(CamelSpoolFolderClass * camel_spool_folder_class) +camel_spool_folder_class_init(CamelSpoolFolderClass *klass) { - CamelFolderClass *camel_folder_class = CAMEL_FOLDER_CLASS(camel_spool_folder_class); - - parent_class = CAMEL_FOLDER_CLASS(camel_type_get_global_classfuncs(camel_folder_get_type())); - - /* virtual method definition */ - - /* virtual method overload */ - camel_folder_class->sync = spool_sync; - camel_folder_class->expunge = spool_expunge; + CamelLocalFolderClass *lklass = (CamelLocalFolderClass *)klass; - camel_folder_class->search_by_expression = spool_search_by_expression; - camel_folder_class->search_by_uids = spool_search_by_uids; - camel_folder_class->search_free = spool_search_free; + parent_class = (CamelFolderClass *)camel_mbox_folder_get_type(); /* virtual method overload */ - camel_folder_class->append_message = spool_append_message; - camel_folder_class->get_message = spool_get_message; - - camel_folder_class->set_message_user_flag = spool_set_message_user_flag; - camel_folder_class->set_message_user_tag = spool_set_message_user_tag; - - camel_spool_folder_class->lock = spool_lock; - camel_spool_folder_class->unlock = spool_unlock; + lklass->create_summary = spool_create_summary; + lklass->lock = spool_lock; + lklass->unlock = spool_unlock; } static void spool_init(gpointer object, gpointer klass) { - CamelFolder *folder = object; CamelSpoolFolder *spool_folder = object; - folder->folder_flags |= (CAMEL_FOLDER_HAS_SUMMARY_CAPABILITY | - CAMEL_FOLDER_HAS_SEARCH_CAPABILITY); - - folder->permanent_flags = CAMEL_MESSAGE_ANSWERED | - CAMEL_MESSAGE_DELETED | CAMEL_MESSAGE_DRAFT | - CAMEL_MESSAGE_FLAGGED | CAMEL_MESSAGE_SEEN | CAMEL_MESSAGE_USER; - - folder->summary = NULL; - spool_folder->search = NULL; - - spool_folder->priv = g_malloc0(sizeof(*spool_folder->priv)); -#ifdef ENABLE_THREADS - spool_folder->priv->search_lock = g_mutex_new(); -#endif + spool_folder->lockid = -1; } static void spool_finalize(CamelObject * object) { - CamelSpoolFolder *spool_folder = CAMEL_SPOOL_FOLDER(object); - CamelFolder *folder = (CamelFolder *)object; - - if (folder->summary) { - camel_spool_summary_sync((CamelSpoolSummary *)folder->summary, FALSE, spool_folder->changes, NULL); - camel_object_unref((CamelObject *)folder->summary); - folder->summary = NULL; - } - - if (spool_folder->search) { - camel_object_unref((CamelObject *)spool_folder->search); - } - - while (spool_folder->locked> 0) - camel_spool_folder_unlock(spool_folder); - - g_free(spool_folder->base_path); - g_free(spool_folder->folder_path); - - camel_folder_change_info_free(spool_folder->changes); - -#ifdef ENABLE_THREADS - g_mutex_free(spool_folder->priv->search_lock); -#endif - g_free(spool_folder->priv); + /*CamelSpoolFolder *spool_folder = CAMEL_SPOOL_FOLDER(object);*/ } CamelType camel_spool_folder_get_type(void) @@ -158,7 +95,7 @@ CamelType camel_spool_folder_get_type(void) static CamelType camel_spool_folder_type = CAMEL_INVALID_TYPE; if (camel_spool_folder_type == CAMEL_INVALID_TYPE) { - camel_spool_folder_type = camel_type_register(CAMEL_FOLDER_TYPE, "CamelSpoolFolder", + camel_spool_folder_type = camel_type_register(camel_mbox_folder_get_type(), "CamelSpoolFolder", sizeof(CamelSpoolFolder), sizeof(CamelSpoolFolderClass), (CamelObjectClassInitFunc) camel_spool_folder_class_init, @@ -170,59 +107,8 @@ CamelType camel_spool_folder_get_type(void) return camel_spool_folder_type; } -CamelSpoolFolder * -camel_spool_folder_construct(CamelSpoolFolder *lf, CamelStore *parent_store, const char *full_name, const char *path, guint32 flags, CamelException *ex) -{ - CamelFolderInfo *fi; - CamelFolder *folder; - const char *root_dir_path, *name; - - folder = (CamelFolder *)lf; - - name = strrchr(full_name, '/'); - if (name) - name++; - else - name = full_name; - - camel_folder_construct(folder, parent_store, full_name, name); - - root_dir_path = camel_spool_store_get_toplevel_dir(CAMEL_SPOOL_STORE(folder->parent_store)); - -#if 0 - lf->base_path = g_strdup(root_dir_path); - lf->folder_path = g_strdup(root_dir_path); -#else - lf->base_path = g_strdup(path); - lf->folder_path = g_strdup(path); -#endif - lf->changes = camel_folder_change_info_new(); - lf->flags = flags; - - folder->summary = (CamelFolderSummary *)camel_spool_summary_new(lf->folder_path); - if (camel_spool_folder_lock(lf, CAMEL_LOCK_WRITE, ex) == -1) { - camel_object_unref((CamelObject *)lf); - return NULL; - } - - camel_spool_summary_check((CamelSpoolSummary *)folder->summary, lf->changes, ex); - camel_spool_folder_unlock(lf); - - fi = g_malloc0(sizeof(*fi)); - fi->full_name = g_strdup(full_name); - fi->name = g_strdup(name); - fi->url = g_strdup_printf("spool:%s#%s", ((CamelService *)parent_store)->url->path, full_name); - fi->unread_message_count = camel_folder_get_unread_message_count(folder); - camel_folder_info_build_path(fi, '/'); - - camel_object_trigger_event(CAMEL_OBJECT(parent_store), "folder_created", fi); - camel_folder_info_free (fi); - - return lf; -} - CamelFolder * -camel_spool_folder_new(CamelStore *parent_store, const char *full_name, const char *path, guint32 flags, CamelException *ex) +camel_spool_folder_new(CamelStore *parent_store, const char *full_name, guint32 flags, CamelException *ex) { CamelFolder *folder; @@ -233,47 +119,31 @@ camel_spool_folder_new(CamelStore *parent_store, const char *full_name, const ch if (parent_store->flags & CAMEL_STORE_FILTER_INBOX && strcmp(full_name, "INBOX") == 0) folder->folder_flags |= CAMEL_FOLDER_FILTER_RECENT; - folder = (CamelFolder *)camel_spool_folder_construct((CamelSpoolFolder *)folder, parent_store, full_name, path, flags, ex); + flags &= CAMEL_STORE_FOLDER_BODY_INDEX; - return folder; -} + folder = (CamelFolder *)camel_local_folder_construct((CamelLocalFolder *)folder, parent_store, full_name, flags, ex); -/* lock the folder, may be called repeatedly (with matching unlock calls), - with type the same or less than the first call */ -int camel_spool_folder_lock(CamelSpoolFolder *lf, CamelLockType type, CamelException *ex) -{ - if (lf->locked > 0) { - /* lets be anal here - its important the code knows what its doing */ - g_assert(lf->locktype == type || lf->locktype == CAMEL_LOCK_WRITE); - } else { - if (CSPOOLF_CLASS(lf)->lock(lf, type, ex) == -1) - return -1; - lf->locktype = type; - } - - lf->locked++; + if (camel_url_get_param(((CamelService *)parent_store)->url, "xstatus")) + camel_mbox_summary_xstatus((CamelMboxSummary *)folder->summary, TRUE); - return 0; + return folder; } -/* unlock folder */ -int camel_spool_folder_unlock(CamelSpoolFolder *lf) +static CamelLocalSummary * +spool_create_summary(const char *path, const char *folder, CamelIndex *index) { - g_assert(lf->locked>0); - lf->locked--; - if (lf->locked == 0) - CSPOOLF_CLASS(lf)->unlock(lf); - - return 0; + return (CamelLocalSummary *)camel_spool_summary_new(folder); } static int -spool_lock(CamelSpoolFolder *lf, CamelLockType type, CamelException *ex) +spool_lock(CamelLocalFolder *lf, CamelLockType type, CamelException *ex) { int retry = 0; + CamelMboxFolder *mf = (CamelMboxFolder *)lf; + CamelSpoolFolder *sf = (CamelSpoolFolder *)lf; - lf->lockfd = open(lf->folder_path, O_RDWR, 0); - if (lf->lockfd == -1) { + mf->lockfd = open(lf->folder_path, O_RDWR, 0); + if (mf->lockfd == -1) { camel_exception_setv(ex, 1, _("Cannot create folder lock on %s: %s"), lf->folder_path, strerror(errno)); return -1; } @@ -284,13 +154,13 @@ spool_lock(CamelSpoolFolder *lf, CamelLockType type, CamelException *ex) camel_exception_clear(ex); - if (camel_lock_fcntl(lf->lockfd, type, ex) == 0) { - if (camel_lock_flock(lf->lockfd, type, ex) == 0) { - if ((lf->lockid = camel_lock_helper_lock(lf->folder_path, ex)) != -1) + if (camel_lock_fcntl(mf->lockfd, type, ex) == 0) { + if (camel_lock_flock(mf->lockfd, type, ex) == 0) { + if ((sf->lockid = camel_lock_helper_lock(lf->folder_path, ex)) != -1) return 0; - camel_unlock_flock(lf->lockfd); + camel_unlock_flock(mf->lockfd); } - camel_unlock_fcntl(lf->lockfd); + camel_unlock_fcntl(mf->lockfd); } retry++; } @@ -299,403 +169,16 @@ spool_lock(CamelSpoolFolder *lf, CamelLockType type, CamelException *ex) } static void -spool_unlock(CamelSpoolFolder *lf) -{ - camel_lock_helper_unlock(lf->lockid); - lf->lockid = -1; - camel_unlock_flock(lf->lockid); - camel_unlock_fcntl(lf->lockid); - - close(lf->lockfd); - lf->lockfd = -1; -} - -static void -spool_sync(CamelFolder *folder, gboolean expunge, CamelException *ex) -{ - CamelSpoolFolder *lf = CAMEL_SPOOL_FOLDER(folder); - - d(printf("spool sync, expunge=%s\n", expunge?"true":"false")); - - if (camel_spool_folder_lock(lf, CAMEL_LOCK_WRITE, ex) == -1) - return; - - /* if sync fails, we'll pass it up on exit through ex */ - camel_spool_summary_sync((CamelSpoolSummary *)folder->summary, expunge, lf->changes, ex); - camel_spool_folder_unlock(lf); - - if (camel_folder_change_info_changed(lf->changes)) { - camel_object_trigger_event(CAMEL_OBJECT(folder), "folder_changed", lf->changes); - camel_folder_change_info_clear(lf->changes); - } -} - -static void -spool_expunge(CamelFolder *folder, CamelException *ex) -{ - d(printf("expunge\n")); - - /* Just do a sync with expunge, serves the same purpose */ - /* call the callback directly, to avoid locking problems */ - CAMEL_FOLDER_CLASS (CAMEL_OBJECT_GET_CLASS(folder))->sync(folder, TRUE, ex); -} - -static GPtrArray * -spool_search_by_expression(CamelFolder *folder, const char *expression, CamelException *ex) -{ - CamelSpoolFolder *spool_folder = CAMEL_SPOOL_FOLDER(folder); - GPtrArray *summary, *matches; - - /* NOTE: could get away without the search lock by creating a new - search object each time */ - - CAMEL_SPOOL_FOLDER_LOCK(folder, search_lock); - - if (spool_folder->search == NULL) - spool_folder->search = camel_folder_search_new(); - - camel_folder_search_set_folder(spool_folder->search, folder); - summary = camel_folder_get_summary(folder); - camel_folder_search_set_summary(spool_folder->search, summary); - - matches = camel_folder_search_execute_expression(spool_folder->search, expression, ex); - - CAMEL_SPOOL_FOLDER_UNLOCK(folder, search_lock); - - camel_folder_free_summary(folder, summary); - - return matches; -} - -static GPtrArray * -spool_search_by_uids(CamelFolder *folder, const char *expression, GPtrArray *uids, CamelException *ex) -{ - CamelSpoolFolder *spool_folder = CAMEL_SPOOL_FOLDER(folder); - GPtrArray *summary, *matches; - int i; - - /* NOTE: could get away without the search lock by creating a new - search object each time */ - - summary = g_ptr_array_new(); - for (i=0;i<uids->len;i++) { - CamelMessageInfo *info; - - info = camel_folder_get_message_info(folder, uids->pdata[i]); - if (info) - g_ptr_array_add(summary, info); - } - - if (summary->len == 0) - return summary; - - CAMEL_SPOOL_FOLDER_LOCK(folder, search_lock); - - if (spool_folder->search == NULL) - spool_folder->search = camel_folder_search_new(); - - camel_folder_search_set_folder(spool_folder->search, folder); - camel_folder_search_set_summary(spool_folder->search, summary); - - matches = camel_folder_search_execute_expression(spool_folder->search, expression, ex); - - CAMEL_SPOOL_FOLDER_UNLOCK(folder, search_lock); - - for (i=0;i<summary->len;i++) - camel_folder_free_message_info(folder, summary->pdata[i]); - g_ptr_array_free(summary, TRUE); - - return matches; -} - -static void -spool_search_free(CamelFolder *folder, GPtrArray * result) -{ - CamelSpoolFolder *spool_folder = CAMEL_SPOOL_FOLDER(folder); - - /* we need to lock this free because of the way search_free_result works */ - /* FIXME: put the lock inside search_free_result */ - CAMEL_SPOOL_FOLDER_LOCK(folder, search_lock); - - camel_folder_search_free_result(spool_folder->search, result); - - CAMEL_SPOOL_FOLDER_UNLOCK(folder, search_lock); -} - -static void -spool_append_message(CamelFolder *folder, CamelMimeMessage * message, const CamelMessageInfo * info, char **appended_uid, CamelException *ex) +spool_unlock(CamelLocalFolder *lf) { - CamelSpoolFolder *lf = (CamelSpoolFolder *)folder; - CamelStream *output_stream = NULL, *filter_stream = NULL; - CamelMimeFilter *filter_from = NULL; - CamelSpoolSummary *mbs = (CamelSpoolSummary *)folder->summary; - CamelMessageInfo *mi; - char *fromline = NULL; - int fd; - struct stat st; -#if 0 - char *xev; -#endif - /* If we can't lock, dont do anything */ - if (camel_spool_folder_lock(lf, CAMEL_LOCK_WRITE, ex) == -1) - return; - - d(printf("Appending message\n")); + CamelMboxFolder *mf = (CamelMboxFolder *)lf; + CamelSpoolFolder *sf = (CamelSpoolFolder *)lf; - /* first, check the summary is correct (updates folder_size too) */ - camel_spool_summary_check((CamelSpoolSummary *)folder->summary, lf->changes, ex); - if (camel_exception_is_set(ex)) - goto fail; + camel_lock_helper_unlock(sf->lockid); + sf->lockid = -1; + camel_unlock_flock(mf->lockfd); + camel_unlock_fcntl(mf->lockfd); - /* add it to the summary/assign the uid, etc */ - mi = camel_spool_summary_add((CamelSpoolSummary *)folder->summary, message, info, lf->changes, ex); - if (camel_exception_is_set(ex)) - goto fail; - - d(printf("Appending message: uid is %s\n", camel_message_info_uid(mi))); - - output_stream = camel_stream_fs_new_with_name(lf->folder_path, O_WRONLY|O_APPEND, 0600); - if (output_stream == NULL) { - camel_exception_setv(ex, 1, _("Cannot open mailbox: %s: %s\n"), lf->folder_path, strerror(errno)); - goto fail; - } - - /* and we need to set the frompos/XEV explicitly */ - ((CamelSpoolMessageInfo *)mi)->frompos = mbs->folder_size?mbs->folder_size+1:0; -#if 0 - xev = camel_spool_summary_encode_x_evolution((CamelLocalSummary *)folder->summary, mi); - if (xev) { - /* the x-ev header should match the 'current' flags, no problem, so store as much */ - camel_medium_set_header((CamelMedium *)message, "X-Evolution", xev); - mi->flags &= ~ CAMEL_MESSAGE_FOLDER_NOXEV|CAMEL_MESSAGE_FOLDER_FLAGGED; - g_free(xev); - } -#endif - - /* we must write this to the non-filtered stream ... prepend a \n if not at the start of the file */ - fromline = camel_spool_summary_build_from(((CamelMimePart *)message)->headers); - if (camel_stream_printf(output_stream, mbs->folder_size==0?"%s":"\n%s", fromline) == -1) - goto fail_write; - - /* 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); - if (camel_data_wrapper_write_to_stream((CamelDataWrapper *)message, filter_stream) == -1) - goto fail_write; - - if (camel_stream_close(filter_stream) == -1) - goto fail_write; - - /* unlock as soon as we can */ - camel_spool_folder_unlock(lf); - - /* filter stream ref's the output stream itself, so we need to unref it too */ - camel_object_unref((CamelObject *)filter_from); - camel_object_unref((CamelObject *)filter_stream); - camel_object_unref((CamelObject *)output_stream); - g_free(fromline); - - /* now we 'fudge' the summary to tell it its uptodate, because its idea of uptodate has just changed */ - /* the stat really shouldn't fail, we just wrote to it */ - if (stat(lf->folder_path, &st) == 0) { - mbs->folder_size = st.st_size; - ((CamelFolderSummary *)mbs)->time = st.st_mtime; - } - - if (camel_folder_change_info_changed(lf->changes)) { - camel_object_trigger_event((CamelObject *)folder, "folder_changed", lf->changes); - camel_folder_change_info_clear(lf->changes); - } - - if (appended_uid) - *appended_uid = g_strdup(camel_message_info_uid(mi)); - - return; - -fail_write: - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - _("Cannot append message to spool file: %s: %s"), - lf->folder_path, g_strerror (errno)); - - if (filter_stream) - camel_object_unref(CAMEL_OBJECT(filter_stream)); - - if (output_stream) - camel_object_unref(CAMEL_OBJECT(output_stream)); - - if (filter_from) - camel_object_unref(CAMEL_OBJECT(filter_from)); - - g_free(fromline); - - /* reset the file to original size */ - fd = open(lf->folder_path, O_WRONLY, 0600); - if (fd != -1) { - ftruncate(fd, mbs->folder_size); - close(fd); - } - - /* remove the summary info so we are not out-of-sync with the spool */ - camel_folder_summary_remove_uid (CAMEL_FOLDER_SUMMARY (mbs), camel_message_info_uid (mi)); - - /* and tell the summary its uptodate */ - if (stat(lf->folder_path, &st) == 0) { - mbs->folder_size = st.st_size; - ((CamelFolderSummary *)mbs)->time = st.st_mtime; - } - -fail: - /* make sure we unlock the folder - before we start triggering events into appland */ - camel_spool_folder_unlock(lf); - - /* cascade the changes through, anyway, if there are any outstanding */ - if (camel_folder_change_info_changed(lf->changes)) { - camel_object_trigger_event((CamelObject *)folder, "folder_changed", lf->changes); - camel_folder_change_info_clear(lf->changes); - } -} - -static CamelMimeMessage * -spool_get_message(CamelFolder *folder, const gchar * uid, CamelException *ex) -{ - CamelSpoolFolder *lf = (CamelSpoolFolder *)folder; - CamelMimeMessage *message; - CamelSpoolMessageInfo *info; - CamelMimeParser *parser; - int fd; - int retried = FALSE; - - d(printf("Getting message %s\n", uid)); - - /* lock the folder first, burn if we can't, need write lock for summary check */ - if (camel_spool_folder_lock(lf, CAMEL_LOCK_WRITE, ex) == -1) - return NULL; - - /* check for new messages, this may renumber uid's though */ - if (camel_spool_summary_check((CamelSpoolSummary *)folder->summary, lf->changes, ex) == -1) - return NULL; - -retry: - /* get the message summary info */ - info = (CamelSpoolMessageInfo *) camel_folder_summary_uid(folder->summary, uid); - - if (info == NULL) { - camel_exception_setv(ex, CAMEL_EXCEPTION_FOLDER_INVALID_UID, - _("Cannot get message: %s\n %s"), uid, _("No such message")); - camel_spool_folder_unlock(lf); - return NULL; - } - - /* no frompos, its an error in the library (and we can't do anything with it */ - g_assert(info->frompos != -1); - - /* we use an fd instead of a normal stream here - the reason is subtle, camel_mime_part will cache - the whole message in memory if the stream is non-seekable (which it is when built from a parser - with no stream). This means we dont have to lock the spool for the life of the message, but only - while it is being created. */ - - fd = open(lf->folder_path, O_RDONLY); - if (fd == -1) { - camel_exception_setv(ex, CAMEL_EXCEPTION_FOLDER_INVALID_UID, - _("Cannot get message: %s from folder %s\n %s"), uid, lf->folder_path, - strerror(errno)); - camel_spool_folder_unlock(lf); - camel_folder_summary_info_free(folder->summary, (CamelMessageInfo *)info); - return NULL; - } - - /* 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_fd(parser, fd); - camel_mime_parser_scan_from(parser, TRUE); - - camel_mime_parser_seek(parser, info->frompos, SEEK_SET); - if (camel_mime_parser_step(parser, NULL, NULL) != HSCAN_FROM - || 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, state = %d", (long int)info->frompos, - (long int)camel_mime_parser_tell_start_from(parser), - camel_mime_parser_state(parser)); - - camel_object_unref((CamelObject *)parser); - camel_folder_summary_info_free(folder->summary, (CamelMessageInfo *)info); - - if (!retried) { - retried = TRUE; - camel_spool_summary_check((CamelSpoolSummary *)folder->summary, lf->changes, ex); - if (!camel_exception_is_set(ex)) - goto retry; - } - - camel_exception_setv(ex, CAMEL_EXCEPTION_FOLDER_INVALID_UID, - _("Cannot get message: %s from folder %s\n %s"), uid, lf->folder_path, - _("The folder appears to be irrecoverably corrupted.")); - - camel_spool_folder_unlock(lf); - return NULL; - } - - camel_folder_summary_info_free(folder->summary, (CamelMessageInfo *)info); - - message = camel_mime_message_new(); - if (camel_mime_part_construct_from_parser((CamelMimePart *)message, parser) == -1) { - camel_exception_setv(ex, (errno==EINTR)?CAMEL_EXCEPTION_USER_CANCEL:CAMEL_EXCEPTION_FOLDER_INVALID_UID, - _("Cannot get message: %s from folder %s\n %s"), uid, lf->folder_path, - _("Message construction failed: Corrupt mailbox?")); - camel_object_unref((CamelObject *)parser); - camel_object_unref((CamelObject *)message); - camel_spool_folder_unlock(lf); - return NULL; - } - - /* and unlock now we're finished with it */ - camel_spool_folder_unlock(lf); - - camel_object_unref((CamelObject *)parser); - - /* use the opportunity to notify of changes (particularly if we had a rebuild) */ - if (camel_folder_change_info_changed(lf->changes)) { - camel_object_trigger_event((CamelObject *)folder, "folder_changed", lf->changes); - camel_folder_change_info_clear(lf->changes); - } - - return message; -} - -static void -spool_set_message_user_flag(CamelFolder *folder, const char *uid, const char *name, gboolean value) -{ - CamelMessageInfo *info; - - g_return_if_fail(folder->summary != NULL); - - info = camel_folder_summary_uid(folder->summary, uid); - g_return_if_fail(info != NULL); - - if (camel_flag_set(&info->user_flags, name, value)) { - info->flags |= CAMEL_MESSAGE_FOLDER_FLAGGED|CAMEL_MESSAGE_FOLDER_XEVCHANGE; - camel_folder_summary_touch(folder->summary); - camel_object_trigger_event(CAMEL_OBJECT(folder), "message_changed", (char *) uid); - } - camel_folder_summary_info_free(folder->summary, info); -} - -static void -spool_set_message_user_tag(CamelFolder *folder, const char *uid, const char *name, const char *value) -{ - CamelMessageInfo *info; - - g_return_if_fail(folder->summary != NULL); - - info = camel_folder_summary_uid(folder->summary, uid); - g_return_if_fail(info != NULL); - - if (camel_tag_set(&info->user_tags, name, value)) { - info->flags |= CAMEL_MESSAGE_FOLDER_FLAGGED|CAMEL_MESSAGE_FOLDER_XEVCHANGE; - camel_folder_summary_touch(folder->summary); - camel_object_trigger_event(CAMEL_OBJECT(folder), "message_changed", (char *) uid); - } - camel_folder_summary_info_free(folder->summary, info); + close(mf->lockfd); + mf->lockfd = -1; } |