static CamelFolder *
diary_decode_folder (CamelDiscoDiary *diary)
{
	CamelFolder *folder;
	char *name;

	if (camel_file_util_decode_string (diary->file, &name) == -1)
		return NULL;
	folder = g_hash_table_lookup (diary->folders, name);
	if (!folder) {
		CamelException ex;
		char *msg;

		camel_exception_init (&ex);
		folder = camel_store_get_folder (CAMEL_STORE (diary->store),
						 name, 0, &ex);
		if (folder)
			g_hash_table_insert (diary->folders, name, folder);
		else {
			msg = g_strdup_printf (_("Could not open `%s':\n%s\nChanges made to this folder will not be resynchronized."),
					       name, camel_exception_get_description (&ex));
			camel_exception_clear (&ex);
			camel_session_alert_user (camel_service_get_session (CAMEL_SERVICE (diary->store)),
						  CAMEL_SESSION_ALERT_WARNING,
						  msg, FALSE);
			g_free (msg);
			g_free (name);
		}
	} else
		g_free (name);
	return folder;
}
static void *
worker(void *d)
{
	int i;
	CamelException *ex = camel_exception_new();
	CamelStore *store;
	CamelFolder *folder;

	for (i=0;i<MAX_LOOP;i++) {
		store = camel_session_get_store(session, path, ex);
		camel_exception_clear(ex);
		folder = camel_store_get_folder(store, "testbox", CAMEL_STORE_FOLDER_CREATE, ex);
		camel_exception_clear(ex);
		if (testid == 0) {
			camel_object_unref(folder);
			camel_object_unref(store);
		} else {
			camel_object_unref(store);
			camel_object_unref(folder);
		}
	}

	camel_exception_free(ex);

	return NULL;
}
static int
groupwise_entry_play_transfer (CamelOfflineJournal *journal, CamelGroupwiseJournalEntry *entry, CamelException *ex)
{
	CamelGroupwiseFolder *gw_folder = (CamelGroupwiseFolder *) journal->folder;
	CamelFolder *folder = journal->folder;
	CamelGroupwiseMessageInfo *real;
	CamelMessageInfoBase *info;
	GPtrArray *xuids, *uids;
	CamelException lex;
	CamelFolder *src;
	const char *name;

	if (!(info = (CamelMessageInfoBase *) camel_folder_summary_uid (folder->summary, entry->uid))) {
		/* Note: this should never happen, but rather than crash lets make a new info */
		info = camel_message_info_new (NULL);
	}

	name = camel_groupwise_store_folder_lookup ((CamelGroupwiseStore *) folder->parent_store, entry->source_container);
	if (name && (src = camel_store_get_folder (folder->parent_store, name, 0, ex))) {
		uids = g_ptr_array_sized_new (1);
		g_ptr_array_add (uids, entry->original_uid);

		camel_exception_init (&lex);
		camel_folder_transfer_messages_to (src, uids, folder, &xuids, FALSE, &lex);
		if (!camel_exception_is_set (&lex)) {
			real = (CamelGroupwiseMessageInfo *) camel_folder_summary_uid (folder->summary, xuids->pdata[0]);

			/* transfer all the system flags, user flags/tags, etc */
			gw_message_info_dup_to ((CamelMessageInfoBase *) real, (CamelMessageInfoBase *) info);
			camel_message_info_free (real);
		} else {
			camel_exception_xfer (ex, &lex);
			goto exception;
		}

		g_ptr_array_free (xuids, TRUE);
		g_ptr_array_free (uids, TRUE);
		camel_object_unref (src);
	} else if (!name) {
		camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, _("Cannot get folder container %s"),
				      entry->source_container);
		goto exception;
	}

	/* message was successfully transferred, remove the fake item from the cache/summary */
	camel_folder_summary_remove_uid (folder->summary, entry->uid);
	camel_data_cache_remove (gw_folder->cache, "cache", entry->uid, NULL);
	camel_message_info_free (info);

	return 0;

 exception:

	camel_message_info_free (info);

	return -1;
}
Example #4
0
static void
mail_shell_view_folder_tree_selected_cb (EMailShellView *mail_shell_view,
                                         CamelStore *store,
                                         const gchar *folder_name,
                                         CamelFolderInfoFlags flags,
                                         EMFolderTree *folder_tree)
{
	EMailShellContent *mail_shell_content;
	EShellView *shell_view;
	EMailReader *reader;
	EMailView *mail_view;
	GCancellable *cancellable;
	AsyncContext *context;
	EActivity *activity;

	shell_view = E_SHELL_VIEW (mail_shell_view);

	mail_shell_content = mail_shell_view->priv->mail_shell_content;
	mail_view = e_mail_shell_content_get_mail_view (mail_shell_content);

	reader = E_MAIL_READER (mail_view);

	/* Cancel any unfinished open folder operations. */
	if (mail_shell_view->priv->opening_folder != NULL) {
		g_cancellable_cancel (mail_shell_view->priv->opening_folder);
		g_object_unref (mail_shell_view->priv->opening_folder);
		mail_shell_view->priv->opening_folder = NULL;
	}

	/* If we are to clear the message list, do so immediately. */
	if ((flags & CAMEL_FOLDER_NOSELECT) || folder_name == NULL) {
		e_mail_reader_set_folder (reader, NULL);
		e_shell_view_update_actions_in_idle (shell_view);
		return;
	}

	g_warn_if_fail (CAMEL_IS_STORE (store));

	/* Open the selected folder asynchronously. */

	activity = e_mail_reader_new_activity (reader);
	cancellable = e_activity_get_cancellable (activity);
	mail_shell_view->priv->opening_folder = g_object_ref (cancellable);

	context = g_slice_new0 (AsyncContext);
	context->activity = activity;
	context->reader = g_object_ref (reader);
	context->shell_view = g_object_ref (shell_view);

	camel_store_get_folder (
		store, folder_name, 0, G_PRIORITY_DEFAULT, cancellable,
		(GAsyncReadyCallback) mail_shell_view_got_folder_cb, context);
}
Example #5
0
static void
mc_setup_local_store(MailComponent *mc)
{
	MailComponentPrivate *p = mc->priv;
	CamelURL *url;
	char *tmp;
	CamelException ex;
	int i;

	g_mutex_lock(p->lock);
	if (p->local_store != NULL) {
		g_mutex_unlock(p->lock);
		return;
	}

	camel_exception_init(&ex);

	url = camel_url_new("mbox:", NULL);
	tmp = g_build_filename (p->base_directory, "local", NULL);
	camel_url_set_path(url, tmp);
	g_free(tmp);
	tmp = camel_url_to_string(url, 0);
	p->local_store = (CamelStore *)camel_session_get_service(session, tmp, CAMEL_PROVIDER_STORE, &ex);
	g_free(tmp);
	if (p->local_store == NULL)
		goto fail;

	for (i=0;i<sizeof(mc_default_folders)/sizeof(mc_default_folders[0]);i++) {
		/* FIXME: should this uri be account relative? */
		camel_url_set_fragment(url, mc_default_folders[i].name);
		mc_default_folders[i].uri = camel_url_to_string(url, 0);
		mc_default_folders[i].folder = camel_store_get_folder(p->local_store, mc_default_folders[i].name,
								      CAMEL_STORE_FOLDER_CREATE, &ex);
		camel_exception_clear(&ex);
	}

	camel_url_free(url);
	g_mutex_unlock(p->lock);

	g_object_ref(mc);
	camel_object_ref(p->local_store);
	mail_async_event_emit(p->async_event, MAIL_ASYNC_GUI, (MailAsyncFunc)mc_add_local_store, p->local_store, _("On This Computer"), mc);

	return;
fail:
	g_mutex_unlock(p->lock);

	g_warning("Could not setup local store/folder: %s", ex.desc);

	camel_url_free(url);
	camel_exception_clear(&ex);
}
Example #6
0
CamelFolder *
mail_tool_uri_to_folder (const char *uri, guint32 flags, CamelException *ex)
{
	CamelURL *url;
	CamelStore *store = NULL;
	CamelFolder *folder = NULL;
	int offset = 0;
	char *curi = NULL;

	g_return_val_if_fail (uri != NULL, NULL);

	/* TODO: vtrash and vjunk are no longer used for these uri's */
	if (!strncmp (uri, "vtrash:", 7))
		offset = 7;
	else if (!strncmp (uri, "vjunk:", 6))
		offset = 6;
	else if (!strncmp(uri, "email:", 6)) {
		/* FIXME?: the filter:get_folder callback should do this itself? */
		curi = em_uri_to_camel(uri);
		if (uri == NULL) {
			camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM, _("Invalid folder: `%s'"), uri);
			return NULL;
		}
		uri = curi;
	}

	url = camel_url_new (uri + offset, ex);
	if (!url) {
		g_free(curi);
		return NULL;
	}

	store = (CamelStore *)camel_session_get_service(session, uri+offset, CAMEL_PROVIDER_STORE, ex);
	if (store) {
		const char *name;

		/* if we have a fragment, then the path is actually used by the store,
		   so the fragment is the path to the folder instead */
		if (url->fragment) {
			name = url->fragment;
		} else {
			if (url->path && *url->path)
				name = url->path + 1;
			else
				name = "";
		}

		if (offset) {
			if (offset == 7)
				folder = camel_store_get_trash (store, ex);
			else if (offset == 6)
				folder = camel_store_get_junk (store, ex);
		} else
			folder = camel_store_get_folder (store, name, flags, ex);
		camel_object_unref (store);
	}

	if (folder)
		mail_note_folder (folder);

	camel_url_free (url);
	g_free(curi);

	return folder;
}
int main(int argc, char **argv)
{
    CamelSession *session;
    CamelStore *store;
    CamelException *ex;
    CamelFolder *folder;
    CamelMimeMessage *msg;
    int i, j;
    CamelStream *mbox;
    CamelFilterDriver *driver;

    camel_test_init(argc, argv);
    camel_test_provider_init(1, local_drivers);

    ex = camel_exception_new();

    /* clear out any camel-test data */
    system("/bin/rm -rf /tmp/camel-test");

    camel_test_start("Simple filtering of mbox");

    session = camel_test_session_new ("/tmp/camel-test");

    /* todo: cross-check everything with folder_info checks as well */
    /* todo: work out how to do imap/pop/nntp tests */

    push("getting store");
    store = camel_session_get_store(session, "mbox:///tmp/camel-test/mbox", ex);
    check_msg(!camel_exception_is_set(ex), "getting store: %s", camel_exception_get_description(ex));
    check(store != NULL);
    pull();

    push("Creating output folders");
    for (i=0; i<ARRAY_LEN(mailboxes); i++) {
        push("creating %s", mailboxes[i].name);
        mailboxes[i].folder = folder = camel_store_get_folder(store, mailboxes[i].name, CAMEL_STORE_FOLDER_CREATE, ex);
        check_msg(!camel_exception_is_set(ex), "%s", camel_exception_get_description(ex));
        check(folder != NULL);

        /* we need an empty folder for this to work */
        test_folder_counts(folder, 0, 0);
        pull();
    }
    pull();

    /* append a bunch of messages with specific content */
    push("creating 100 test message mbox");
    mbox = camel_stream_fs_new_with_name("/tmp/camel-test/inbox", O_WRONLY|O_CREAT|O_EXCL, 0600);
    for (j=0; j<100; j++) {
        char *content, *subject;

        push("creating test message");
        msg = test_message_create_simple();
        content = g_strdup_printf("data%d content\n", j);
        test_message_set_content_simple((CamelMimePart *)msg, 0, "text/plain",
                                        content, strlen(content));
        test_free(content);
        subject = g_strdup_printf("Test%d message%d subject", j, 100-j);
        camel_mime_message_set_subject(msg, subject);

        camel_mime_message_set_date(msg, j*60*24, 0);
        pull();

        camel_stream_printf(mbox, "From \n");
        check(camel_data_wrapper_write_to_stream((CamelDataWrapper *)msg, mbox) != -1);
#if 0
        push("appending simple message %d", j);
        camel_folder_append_message(folder, msg, NULL, ex);
        check_msg(!camel_exception_is_set(ex), "%s", camel_exception_get_description(ex));
        pull();
#endif
        test_free(subject);

        check_unref(msg, 1);
    }
    check(camel_stream_close(mbox) != -1);
    check_unref(mbox, 1);
    pull();

    push("Building filters");
    driver = camel_filter_driver_new(session);
    camel_filter_driver_set_folder_func(driver, get_folder, NULL);
    for (i=0; i<ARRAY_LEN(rules); i++) {
        camel_filter_driver_add_rule(driver, rules[i].name, rules[i].match, rules[i].action);
    }
    pull();

    push("Executing filters");
    camel_filter_driver_set_default_folder(driver, mailboxes[0].folder);
    camel_filter_driver_filter_mbox(driver, "/tmp/camel-test/inbox", NULL, ex);
    check_msg(!camel_exception_is_set(ex), "%s", camel_exception_get_description(ex));

    /* now need to check the folder counts/etc */

    check_unref(driver, 1);
    pull();

    /* this tests that invalid rules are caught */
    push("Testing broken match rules");
    for (i=0; i<ARRAY_LEN(brokens); i++) {
        push("rule %s", brokens[i].match);
        driver = camel_filter_driver_new(session);
        camel_filter_driver_set_folder_func(driver, get_folder, NULL);
        camel_filter_driver_add_rule(driver, brokens[i].name, brokens[i].match, brokens[i].action);
        camel_filter_driver_filter_mbox(driver, "/tmp/camel-test/inbox", NULL, ex);
        check(camel_exception_is_set(ex));
        camel_exception_clear(ex);
        check_unref(driver, 1);
        pull();
    }
    pull();

    push("Testing broken action rules");
    for (i=0; i<ARRAY_LEN(brokena); i++) {
        push("rule %s", brokena[i].action);
        driver = camel_filter_driver_new(session);
        camel_filter_driver_set_folder_func(driver, get_folder, NULL);
        camel_filter_driver_add_rule(driver, brokena[i].name, brokena[i].match, brokena[i].action);
        camel_filter_driver_filter_mbox(driver, "/tmp/camel-test/inbox", NULL, ex);
        check(camel_exception_is_set(ex));
        camel_exception_clear(ex);
        check_unref(driver, 1);
        pull();
    }
    pull();


    for (i=0; i<ARRAY_LEN(mailboxes); i++) {
        check_unref(mailboxes[i].folder, 1);
    }

    check_unref(store, 1);

    check_unref(session, 1);
    camel_exception_free(ex);

    camel_test_end();

    return 0;
}