Exemplo n.º 1
0
static void
send_receive (EMailSession *session,
              gboolean allow_send)
{
	CamelFolder *local_outbox;
	struct _send_data *data;
	GList *scan;
	
	if (send_data) /* Send Receive is already in progress */
		return;

	if (!camel_session_get_online (CAMEL_SESSION (session)))
		return;
	local_outbox = e_mail_session_get_local_folder (
			session, E_MAIL_LOCAL_FOLDER_OUTBOX);

	data = build_infra (session, allow_send);

	for (scan = data->infos; scan != NULL; scan = scan->next) {
		struct _send_info *info = scan->data;

		if (!CAMEL_IS_SERVICE (info->service))
			continue;

		switch (info->type) {
		case SEND_RECEIVE:
			mail_fetch_mail (
				CAMEL_STORE (info->service),
				CAMEL_FETCH_OLD_MESSAGES, -1,
				E_FILTER_SOURCE_INCOMING,
				mail_provider_fetch_lock, mail_provider_fetch_unlock, mail_provider_fetch_inbox_folder,
				info->cancellable,
				receive_get_folder, info,
				receive_status, info,
				receive_done, info);
			break;
		case SEND_SEND:
			/* todo, store the folder in info? */
			mail_send_queue (
				session, local_outbox,
				CAMEL_TRANSPORT (info->service),
				E_FILTER_SOURCE_OUTGOING,
				info->cancellable,
				receive_get_folder, info,
				receive_status, info,
				send_done, info);
			break;
		case SEND_UPDATE:
			receive_update_got_store (
				CAMEL_STORE (info->service), info);
			break;
		default:
			break;
		}
	}

	return ;
}
Exemplo n.º 2
0
void
e_mail_store_remove_by_account (EMailBackend *backend,
                                EAccount *account)
{
	EMailSession *session;
	CamelService *service;
	CamelProvider *provider;
	const gchar *uid;

	g_return_if_fail (E_IS_MAIL_BACKEND (backend));
	g_return_if_fail (E_IS_ACCOUNT (account));

	uid = account->uid;
	session = e_mail_backend_get_session (backend);

	service = camel_session_get_service (CAMEL_SESSION (session), uid);
	g_return_if_fail (CAMEL_IS_STORE (service));

	provider = camel_service_get_provider (service);
	g_return_if_fail (provider != NULL);

	if (!(provider->flags & CAMEL_PROVIDER_IS_STORAGE))
		return;

	e_mail_store_remove (backend, CAMEL_STORE (service));
}
Exemplo n.º 3
0
static gpointer
worker (gpointer d)
{
	gint i;
	CamelStore *store;
	CamelService *service;
	CamelFolder *folder;

	for (i = 0; i < MAX_LOOP; i++) {
		gchar *uid;

		uid = g_strdup_printf ("test-uid-%d", i);
		service = camel_session_add_service (
			session, uid, path, CAMEL_PROVIDER_STORE, NULL);
		g_free (uid);

		check (CAMEL_IS_STORE (service));
		store = CAMEL_STORE (service);

		folder = camel_store_get_folder_sync (
			store, "testbox",
			CAMEL_STORE_FOLDER_CREATE, NULL, NULL);
		if (testid == 0) {
			g_object_unref (folder);
			g_object_unref (store);
		} else {
			g_object_unref (store);
			g_object_unref (folder);
		}
	}

	return NULL;
}
Exemplo n.º 4
0
static gboolean
ews_utils_rename_folder (CamelEwsStore *store,
                         EEwsFolderType ftype,
                         const gchar *fid,
                         const gchar *changekey,
                         const gchar *pfid,
                         const gchar *display_name,
                         const gchar *old_fname,
                         GError **error)
{
	CamelEwsStoreSummary *ews_summary = store->summary;
	CamelFolderInfo *fi;

	camel_ews_store_summary_set_change_key (ews_summary, fid, changekey);
	if (display_name)
		camel_ews_store_summary_set_folder_name (
			ews_summary, fid, display_name);
	if (pfid)
		camel_ews_store_summary_set_parent_folder_id (
			ews_summary, fid, pfid);

	if (ftype == E_EWS_FOLDER_TYPE_MAILBOX) {
		fi = camel_ews_utils_build_folder_info (store, fid);
		camel_store_folder_renamed (CAMEL_STORE (store), old_fname, fi);
	}

	return TRUE;
}
Exemplo n.º 5
0
static void
sync_deleted_folders (CamelEwsStore *store,
                      GSList *deleted_folders)
{
	CamelEwsStoreSummary *ews_summary = store->summary;
	GSList *l;

	for (l = deleted_folders; l != NULL; l = g_slist_next (l)) {
		const gchar *fid = l->data;
		EEwsFolderType ftype;
		CamelFolderInfo *fi;
		GError *error = NULL;

		if (!camel_ews_store_summary_has_folder (ews_summary, fid))
			continue;

		ftype = camel_ews_store_summary_get_folder_type (
			ews_summary, fid, NULL);
		if (ftype == E_EWS_FOLDER_TYPE_MAILBOX) {
			fi = camel_ews_utils_build_folder_info (store, fid);

			if (!camel_ews_store_summary_remove_folder (ews_summary, fid, &error)) {
				if (error != NULL) {
					g_warning ("%s: %s", G_STRFUNC, error->message);
					g_clear_error (&error);
				}
				continue;
			}

			camel_subscribable_folder_unsubscribed (CAMEL_SUBSCRIBABLE (store), fi);
			camel_store_folder_deleted (CAMEL_STORE (store), fi);
		}
	}
}
static void
groupwise_forget_folder (CamelGroupwiseStore *gw_store, const gchar *folder_name, GError **error)
{
	CamelGroupwiseStorePrivate *priv = gw_store->priv;
	gchar *state_file;
	gchar *folder_dir, *storage_path;
	CamelFolderInfo *fi;

	storage_path = g_strdup_printf ("%s/folders", priv->storage_path);
	folder_dir = e_path_to_physical (storage_path,folder_name);

	if (g_access (folder_dir, F_OK) != 0) {
		g_free (folder_dir);
		return;
	}

	state_file = g_strdup_printf ("%s/cmeta", folder_dir);
	g_unlink (state_file);
	g_free (state_file);

	g_rmdir (folder_dir);
	g_free (folder_dir);

	camel_store_summary_remove_path ( (CamelStoreSummary *)gw_store->summary, folder_name);
	camel_store_summary_save ( (CamelStoreSummary *)gw_store->summary);

	fi = groupwise_build_folder_info (gw_store, NULL, folder_name);
	camel_store_folder_deleted (CAMEL_STORE (gw_store), fi);
	camel_folder_info_free (fi);
}
Exemplo n.º 7
0
static void
search_results_exec (SearchResultsMsg *msg,
                     GCancellable *cancellable,
                     GError **error)
{
	GList *folders = NULL, *link;

	for (link = msg->stores_list; link != NULL; link = link->next) {
		CamelStore *store = CAMEL_STORE (link->data);

		if (g_cancellable_is_cancelled (cancellable))
			break;

		add_folders_from_store (&folders, store, cancellable, error);
	}

	if (!g_cancellable_is_cancelled (cancellable)) {
		CamelVeeFolder *vfolder = CAMEL_VEE_FOLDER (msg->folder);

		folders = g_list_reverse (folders);

		camel_vee_folder_set_folders (vfolder, folders, cancellable);
	}

	g_list_free_full (folders, g_object_unref);
}
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;
}
Exemplo n.º 9
0
/* Helper for e_mail_store_go_online() */
static void
mail_store_go_online_thread (GSimpleAsyncResult *simple,
                             GObject *source_object,
                             GCancellable *cancellable)
{
	GError *local_error = NULL;

	e_mail_store_go_online_sync (
		CAMEL_STORE (source_object), cancellable, &local_error);

	if (local_error != NULL)
		g_simple_async_result_take_error (simple, local_error);
}
Exemplo n.º 10
0
/**
 * camel_offline_store_set_network_state:
 * @store: a #CamelOfflineStore object
 * @state: the network state
 * @ex: a #CamelException
 *
 * Set the network state to either #CAMEL_OFFLINE_STORE_NETWORK_AVAIL
 * or #CAMEL_OFFLINE_STORE_NETWORK_UNAVAIL.
 **/
void
camel_offline_store_set_network_state (CamelOfflineStore *store, int state, CamelException *ex)
{
	CamelException lex;
	CamelService *service = CAMEL_SERVICE (store);
	gboolean network_state = camel_session_get_network_state (service->session);

	if (store->state == state)
		return;

	camel_exception_init (&lex);
	if (store->state == CAMEL_OFFLINE_STORE_NETWORK_AVAIL) {
		/* network available -> network unavailable */
		if (network_state) {
			if (((CamelStore *) store)->folders) {
				GPtrArray *folders;
				CamelFolder *folder;
				int i, sync;

				sync = camel_url_get_param (((CamelService *) store)->url, "sync_offline") != NULL;

				folders = camel_object_bag_list (((CamelStore *) store)->folders);
				for (i = 0; i < folders->len; i++) {
					folder = folders->pdata[i];

					if (CAMEL_CHECK_TYPE (folder, CAMEL_OFFLINE_FOLDER_TYPE)
					    && (sync || ((CamelOfflineFolder *) folder)->sync_offline)) {
						camel_offline_folder_downsync ((CamelOfflineFolder *) folder, NULL, &lex);
						camel_exception_clear (&lex);
					}

					camel_object_unref (folder);
				}

				g_ptr_array_free (folders, TRUE);
			}

			camel_store_sync (CAMEL_STORE (store), FALSE, &lex);
			camel_exception_clear (&lex);
		}

		if (!camel_service_disconnect (CAMEL_SERVICE (store), network_state, ex))
			return;
	} else {
		/* network unavailable -> network available */
		if (!camel_service_connect (CAMEL_SERVICE (store), ex))
			return;
	}

	store->state = state;
}
Exemplo n.º 11
0
static void
mail_store_create_folder_thread (GSimpleAsyncResult *simple,
                                 GObject *object,
                                 GCancellable *cancellable)
{
	AsyncContext *context;
	GError *error = NULL;

	context = g_simple_async_result_get_op_res_gpointer (simple);

	e_mail_store_create_folder_sync (
		CAMEL_STORE (object), context->full_name,
		cancellable, &error);

	if (error != NULL)
		g_simple_async_result_take_error (simple, error);
}
Exemplo n.º 12
0
static void
sync_created_folders (CamelEwsStore *ews_store,
                      GSList *created_folders,
		      GSList **created_folder_ids)
{
	GSList *l;

	for (l = created_folders; l != NULL; l = g_slist_next (l)) {
		EEwsFolder *folder = (EEwsFolder *) l->data;
		EEwsFolderType ftype;
		CamelFolderInfo *fi;
		const EwsFolderId *fid;

		ftype = e_ews_folder_get_folder_type (folder);
		if (ftype != E_EWS_FOLDER_TYPE_MAILBOX)
			continue;

		fid = e_ews_folder_get_id (folder);

		/* FIXME: Sort folders so that a child is always added *after*
		 * its parent. But since the old code was already completely
		 * broken and would just go into an endless loop if the server
		 * didn't return the folders in the 'right' order for that,
		 * let's worry about that in a later commit. */
		add_folder_to_summary (ews_store, folder);

		if (created_folder_ids) {
			*created_folder_ids = g_slist_append (*created_folder_ids, g_strdup (fid->id));
		} else {
			fi = camel_ews_utils_build_folder_info (
				ews_store, fid->id);
			camel_store_folder_created (
				CAMEL_STORE (ews_store), fi);
			camel_subscribable_folder_subscribed (
				CAMEL_SUBSCRIBABLE (ews_store), fi);
			camel_folder_info_free (fi);
		}
	}
}
Exemplo n.º 13
0
void
camel_ews_utils_sync_deleted_items (CamelEwsFolder *ews_folder,
                                    GSList *items_deleted,
				    CamelFolderChangeInfo *change_info)
{
	CamelStore *store;
	CamelFolder *folder;
	const gchar *full_name;
	CamelEwsStore *ews_store;
	GSList *l;
	GList *items_deleted_list = NULL;

	folder = CAMEL_FOLDER (ews_folder);
	full_name = camel_folder_get_full_name (folder);

	store = camel_folder_get_parent_store (folder);
	ews_store = CAMEL_EWS_STORE (store);

	for (l = items_deleted; l != NULL; l = g_slist_next (l)) {
		const gchar *id = l->data;

		items_deleted_list = g_list_prepend (
			items_deleted_list, (gpointer) id);

		camel_folder_summary_remove_uid (camel_folder_get_folder_summary (folder), id);
		camel_folder_change_info_remove_uid (change_info, id);
	}

	items_deleted_list = g_list_reverse (items_deleted_list);
	camel_db_delete_uids (
		camel_store_get_db (CAMEL_STORE (ews_store)),
		full_name, items_deleted_list, NULL);
	g_list_free (items_deleted_list);

	g_slist_foreach (items_deleted, (GFunc) g_free, NULL);
	g_slist_free (items_deleted);
}
Exemplo n.º 14
0
gboolean
camel_ews_utils_delete_folders_from_summary_recursive (CamelEwsStore *ews_store,
						       CamelFolderInfo *folder_info,
						       gboolean send_signals,
						       GError **error)
{
	gboolean success = TRUE;

	while (folder_info != NULL) {
		gchar *fid;

		if (folder_info->child != NULL) {
			success = camel_ews_utils_delete_folders_from_summary_recursive (
				ews_store, folder_info->child, send_signals, error);

			if (!success)
				break;
		}

		fid = camel_ews_store_summary_get_folder_id_from_name (ews_store->summary, folder_info->full_name);
		success = camel_ews_store_summary_remove_folder (ews_store->summary, fid, error);
		g_free (fid);

		if (!success)
			break;

		if (send_signals) {
			camel_subscribable_folder_unsubscribed (CAMEL_SUBSCRIBABLE (ews_store), folder_info);
			camel_store_folder_deleted (CAMEL_STORE (ews_store), folder_info);
		}

		folder_info = folder_info->next;
	}

	return success;
}
Exemplo n.º 15
0
/* TODO: Add subscription stuff */
void
test_folder_basic (CamelSession *session,
                   const gchar *storename,
                   gint local,
                   gint spool)
{
	CamelStore *store;
	CamelFolder *folder;
	CamelService *service;
	gchar *what = g_strdup_printf ("testing store: %s", storename);
	GError *error = NULL;

	camel_test_start (what);
	test_free (what);

	push ("getting store");
	service = camel_session_add_service (
		session, storename, storename, CAMEL_PROVIDER_STORE, &error);
	check_msg (error == NULL, "adding store: %s", error->message);
	check (CAMEL_IS_STORE (service));
	store = CAMEL_STORE (service);
	pull ();

	/* local providers == no inbox */
	push ("getting inbox folder");
	folder = camel_store_get_inbox_folder_sync (store, NULL, &error);
	if (local) {
		/* Well, maildir can have an inbox */
		if (folder) {
			check (error == NULL);
			check_unref (folder, 1);
		} else {
			check (error != NULL);
		}
	} else {
		check_msg (error == NULL, "%s", error->message);
		check (folder != NULL);
		check_unref (folder, 2);
	}
	g_clear_error (&error);
	pull ();

	push ("getting a non-existant folder, no create");
	folder = camel_store_get_folder_sync (
		store, "unknown", 0, NULL, &error);
	check (error != NULL);
	check (folder == NULL);
	g_clear_error (&error);
	pull ();

	if (!spool) {
		push ("getting a non-existant folder, with create");
		folder = camel_store_get_folder_sync (
			store, "testbox", CAMEL_STORE_FOLDER_CREATE,
			NULL, &error);
		check_msg (error == NULL, "%s", error->message);
		check (folder != NULL);
		if (local)
			check_unref (folder, 1);
		else
			check_unref (folder, 2);
		g_clear_error (&error);
		pull ();

		push ("getting an existing folder");
		folder = camel_store_get_folder_sync (
			store, "testbox", 0, NULL, &error);
		check_msg (error == NULL, "%s", error->message);
		check (folder != NULL);
		if (local)
			check_unref (folder, 1);
		else
			check_unref (folder, 2);
		g_clear_error (&error);
		pull ();

		push ("renaming a non-existant folder");
		camel_store_rename_folder_sync (
			store, "unknown1", "unknown2", NULL, &error);
		check (error != NULL);
		g_clear_error (&error);
		pull ();

		push ("renaming an existing folder");
		camel_store_rename_folder_sync (
			store, "testbox", "testbox2", NULL, &error);
		check_msg (error == NULL, "%s", error->message);
		g_clear_error (&error);
		pull ();

		push ("opening the old name of a renamed folder");
		folder = camel_store_get_folder_sync (
			store, "testbox", 0, NULL, &error);
		check (error != NULL);
		check (folder == NULL);
		g_clear_error (&error);
		pull ();

		push ("opening the new name of a renamed folder");
		folder = camel_store_get_folder_sync (
			store, "testbox2", 0, NULL, &error);
		check_msg (error == NULL, "%s", error->message);
		check (folder != NULL);
		if (local)
			check_unref (folder, 1);
		else
			check_unref (folder, 2);
		pull ();
	}

	push ("deleting a non-existant folder");
	camel_store_delete_folder_sync (store, "unknown", NULL, &error);
	check (error != NULL);
	g_clear_error (&error);
	pull ();

	if (!spool) {
		push ("deleting an existing folder");
		camel_store_delete_folder_sync (
			store, "testbox2", NULL, &error);
		check_msg (error == NULL, "%s", error->message);
		g_clear_error (&error);
		pull ();
	}

	push ("opening a folder that has been deleted");
	folder = camel_store_get_folder_sync (
		store, "testbox2", 0, NULL, &error);
	check (error != NULL);
	check (folder == NULL);
	g_clear_error (&error);
	pull ();

	check_unref (store, 1);

	camel_test_end ();
}
Exemplo n.º 16
0
gint
main (gint argc,
      gchar **argv)
{
	CamelService *service;
	CamelSession *session;
	CamelStore *store;
	CamelFolder *folder;
	CamelMimeMessage *msg;
	gint i, j;
	gint indexed;
	GPtrArray *uids;
	GError *error = NULL;

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

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

	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 */

	/* we iterate over all stores we want to test, with indexing or indexing turned on or off */
	for (i = 0; i < G_N_ELEMENTS (stores); i++) {
		const gchar *name = stores[i];
		for (indexed = 0; indexed < 2; indexed++) {
			gchar *what = g_strdup_printf ("folder search: %s (%sindexed)", name, indexed?"":"non-");
			gchar *uid;
			gint flags;

			camel_test_start (what);
			test_free (what);

			push ("getting store");
			uid = g_strdup_printf ("test-uid-%d", i);
			service = camel_session_add_service (
				session, uid, stores[i],
				CAMEL_PROVIDER_STORE, &error);
			g_free (uid);
			check_msg (error == NULL, "adding store: %s", error->message);
			check (CAMEL_IS_STORE (service));
			store = CAMEL_STORE (service);
			g_clear_error (&error);
			pull ();

			push ("creating %sindexed folder", indexed?"":"non-");
			if (indexed)
				flags = CAMEL_STORE_FOLDER_CREATE | CAMEL_STORE_FOLDER_BODY_INDEX;
			else
				flags = CAMEL_STORE_FOLDER_CREATE;
			folder = camel_store_get_folder_sync (
				store, "testbox", flags, NULL, &error);
			check_msg (error == NULL, "%s", error->message);
			check (folder != NULL);

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

			/* append a bunch of messages with specific content */
			push ("appending 100 test messages");
			for (j = 0; j < 100; j++) {
				gchar *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 ();

				push ("appending simple message %d", j);
				camel_folder_append_message_sync (
					folder, msg, NULL, NULL, NULL, &error);
				check_msg (error == NULL, "%s", error->message);
				g_clear_error (&error);
				pull ();

				test_free (subject);

				check_unref (msg, 1);
			}
			pull ();

			push ("Setting up some flags &c");
			uids = camel_folder_get_uids (folder);
			check (uids->len == 100);
			for (j = 0; j < 100; j++) {
				gchar *uid = uids->pdata[j];

				if ((j / 13) * 13 == j) {
					camel_folder_set_message_user_flag (folder, uid, "every13", TRUE);
				}
				if ((j / 17) * 17 == j) {
					camel_folder_set_message_user_flag (folder, uid, "every17", TRUE);
				}
				if ((j / 7) * 7 == j) {
					gchar *tag = g_strdup_printf ("7tag%d", j / 7);
					camel_folder_set_message_user_tag (folder, uid, "every7", tag);
					test_free (tag);
				}
				if ((j / 11) * 11 == j) {
					camel_folder_set_message_user_tag (folder, uid, "every11", "11tag");
				}
			}
			camel_folder_free_uids (folder, uids);
			pull ();

			camel_test_nonfatal ("Index not guaranteed to be accurate before sync: should be fixed eventually");
			push ("Search before sync");
			run_search (folder, 100);
			pull ();
			camel_test_fatal ();

			push ("syncing folder, searching");
			camel_folder_synchronize_sync (
				folder, FALSE, NULL, NULL);
			run_search (folder, 100);
			pull ();

			push ("syncing wiht expunge, search");
			camel_folder_synchronize_sync (
				folder, TRUE, NULL, NULL);
			run_search (folder, 100);
			pull ();

			push ("deleting every 2nd message");
			uids = camel_folder_get_uids (folder);
			check (uids->len == 100);
			for (j = 0; j < uids->len; j+=2) {
				camel_folder_delete_message (folder, uids->pdata[j]);
			}
			camel_folder_free_uids (folder, uids);
			run_search (folder, 100);

			push ("syncing");
			camel_folder_synchronize_sync (
				folder, FALSE, NULL, &error);
			check_msg (error == NULL, "%s", error->message);
			run_search (folder, 100);
			g_clear_error (&error);
			pull ();

			push ("expunging");
			camel_folder_expunge_sync (folder, NULL, &error);
			check_msg (error == NULL, "%s", error->message);
			run_search (folder, 50);
			g_clear_error (&error);
			pull ();

			pull ();

			push ("closing and re-opening folder");
			check_unref (folder, 1);
			folder = camel_store_get_folder_sync (
				store, "testbox",
				flags & ~(CAMEL_STORE_FOLDER_CREATE),
				NULL, &error);
			check_msg (error == NULL, "%s", error->message);
			check (folder != NULL);
			g_clear_error (&error);

			push ("deleting remaining messages");
			uids = camel_folder_get_uids (folder);
			check (uids->len == 50);
			for (j = 0; j < uids->len; j++) {
				camel_folder_delete_message (folder, uids->pdata[j]);
			}
			camel_folder_free_uids (folder, uids);
			run_search (folder, 50);

			push ("syncing");
			camel_folder_synchronize_sync (
				folder, FALSE, NULL, &error);
			check_msg (error == NULL, "%s", error->message);
			run_search (folder, 50);
			g_clear_error (&error);
			pull ();

			push ("expunging");
			camel_folder_expunge_sync (folder, NULL, &error);
			check_msg (error == NULL, "%s", error->message);
			run_search (folder, 0);
			g_clear_error (&error);
			pull ();

			pull ();

			check_unref (folder, 1);
			pull ();

			push ("deleting test folder, with no messages in it");
			camel_store_delete_folder_sync (
				store, "testbox", NULL, &error);
			check_msg (error == NULL, "%s", error->message);
			g_clear_error (&error);
			pull ();

			check_unref (store, 1);
			camel_test_end ();
		}
	}

	check_unref (session, 1);

	return 0;
}
static gboolean
groupwise_store_construct (CamelService *service, CamelSession *session,
			   CamelProvider *provider, CamelURL *url,
			   GError **error)
{
	CamelServiceClass *service_class;
	CamelGroupwiseStore *groupwise_store = CAMEL_GROUPWISE_STORE (service);
	CamelStore *store = CAMEL_STORE (service);
	const gchar *property_value;
	CamelGroupwiseStorePrivate *priv = groupwise_store->priv;
	gchar *path = NULL;

	d(printf ("\nin groupwise store constrcut\n"));

	/* Chain up to parent's construct() method. */
	service_class = CAMEL_SERVICE_CLASS (camel_groupwise_store_parent_class);
	if (!service_class->construct (service, session, provider, url, error))
		return FALSE;

	if (!(url->host || url->user)) {
		g_set_error (
			error, CAMEL_SERVICE_ERROR,
			CAMEL_SERVICE_ERROR_INVALID,
			_("Host or user not available in url"));
	}

	/*storage path*/
	priv->storage_path = camel_session_get_storage_path (session, service, error);
	if (!priv->storage_path)
		return FALSE;

	/*store summary*/
	path = g_alloca (strlen (priv->storage_path) + 32);
	sprintf (path, "%s/.summary", priv->storage_path);
	groupwise_store->summary = camel_groupwise_store_summary_new ();
	camel_store_summary_set_filename ((CamelStoreSummary *)groupwise_store->summary, path);
	camel_store_summary_touch ((CamelStoreSummary *)groupwise_store->summary);
	camel_store_summary_load ((CamelStoreSummary *) groupwise_store->summary);

	/*host and user*/
	priv->server_name = g_strdup (url->host);
	priv->user = g_strdup (url->user);

	/*base url*/
	priv->base_url = camel_url_to_string (service->url, (CAMEL_URL_HIDE_PASSWORD |
						       CAMEL_URL_HIDE_PARAMS   |
						       CAMEL_URL_HIDE_AUTH)  );

	/*soap port*/
	property_value =  camel_url_get_param (url, "soap_port");
	if (property_value == NULL)
		priv->port = g_strdup ("7191");
	else if (strlen (property_value) == 0)
		priv->port = g_strdup ("7191");
	else
		priv->port = g_strdup (property_value);

	/*filter*/
	if (camel_url_get_param (url, "filter"))
		store->flags |= CAMEL_STORE_FILTER_INBOX;

	/*Hash Table*/
	priv->id_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
	priv->name_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
	priv->parent_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);

	/*ssl*/
	priv->use_ssl = g_strdup (camel_url_get_param (url, "use_ssl"));

	store->flags &= ~CAMEL_STORE_VJUNK;
	store->flags &= ~CAMEL_STORE_VTRASH;

	return TRUE;
}
static gboolean
groupwise_auth_loop (CamelService *service,
                     GCancellable *cancellable,
                     GError **error)
{
	CamelSession *session = camel_service_get_session (service);
	CamelStore *store = CAMEL_STORE (service);
	CamelGroupwiseStore *groupwise_store = CAMEL_GROUPWISE_STORE (store);
	CamelGroupwiseStorePrivate *priv = groupwise_store->priv;
	gboolean authenticated = FALSE;
	gchar *uri;
	guint32 prompt_flags = CAMEL_SESSION_PASSWORD_SECRET;
	EGwConnectionErrors errors = {E_GW_CONNECTION_STATUS_INVALID_OBJECT, NULL};

	if (priv->use_ssl && !g_str_equal (priv->use_ssl, "never"))
		uri = g_strconcat ("https://", priv->server_name, ":", priv->port, "/soap", NULL);
	else
		uri = g_strconcat ("http://", priv->server_name, ":", priv->port, "/soap", NULL);
	service->url->passwd = NULL;

	while (!authenticated) {

		if (!service->url->passwd && !(store->flags & CAMEL_STORE_PROXY)) {
			gchar *prompt;

			prompt = camel_session_build_password_prompt (
				"GroupWise", service->url->user, service->url->host);
			service->url->passwd =
				camel_session_get_password (session, service, "Groupwise",
							    prompt, "password", prompt_flags, error);
			g_free (prompt);

			if (!service->url->passwd) {
				g_set_error (
					error, G_IO_ERROR,
					G_IO_ERROR_CANCELLED,
					_("You did not enter a password."));
				return FALSE;
			}
		}

		priv->cnc = e_gw_connection_new_with_error_handler (uri, priv->user, service->url->passwd, &errors);
		if (!E_IS_GW_CONNECTION(priv->cnc) && priv->use_ssl && g_str_equal (priv->use_ssl, "when-possible")) {
			gchar *http_uri = g_strconcat ("http://", uri + 8, NULL);
			priv->cnc = e_gw_connection_new (http_uri, priv->user, service->url->passwd);
			g_free (http_uri);
		}
		if (!E_IS_GW_CONNECTION (priv->cnc)) {
			if (errors.status == E_GW_CONNECTION_STATUS_INVALID_PASSWORD) {
				/* We need to un-cache the password before prompting again */
				prompt_flags |= CAMEL_SESSION_PASSWORD_REPROMPT;
				g_free (service->url->passwd);
				service->url->passwd = NULL;
			} else {
				g_set_error (
					error, CAMEL_SERVICE_ERROR,
					CAMEL_SERVICE_ERROR_UNAVAILABLE,
					"%s", errors.description ?
					errors.description :
					_("You must be working online to complete this operation"));
				return FALSE;
			}
		} else
			authenticated = TRUE;

	}

	return TRUE;
}
Exemplo n.º 19
0
static gboolean
migrate_mbox_to_maildir (EShell *shell,
                         CamelSession *session,
                         ESource *mbox_source)
{
	ESourceRegistry *registry;
	ESourceExtension *extension;
	const gchar *extension_name;
	CamelService *mbox_service = NULL;
	CamelService *maildir_service = NULL;
	CamelSettings *settings;
	const gchar *data_dir;
	const gchar *mbox_uid;
	gchar *path;
	struct MigrateStore ms;
	GThread *thread;
	GError *error = NULL;

	registry = e_shell_get_registry (shell);

	data_dir = camel_session_get_user_data_dir (session);

	mbox_uid = e_source_get_uid (mbox_source);
	e_source_set_display_name (mbox_source, "local_mbox");

	extension_name = E_SOURCE_EXTENSION_MAIL_ACCOUNT;
	extension = e_source_get_extension (mbox_source, extension_name);

	e_source_backend_set_backend_name (
		E_SOURCE_BACKEND (extension), "mbox");

	extension_name = e_source_camel_get_extension_name ("mbox");
	extension = e_source_get_extension (mbox_source, extension_name);
	settings = e_source_camel_get_settings (E_SOURCE_CAMEL (extension));

	path = g_build_filename (data_dir, mbox_uid, NULL);
	g_object_set (settings, "path", path, NULL);
	g_free (path);

	e_source_registry_commit_source_sync (
		registry, mbox_source, NULL, &error);

	if (error == NULL)
		mbox_service = camel_session_add_service (
			session, mbox_uid, "mbox",
			CAMEL_PROVIDER_STORE, &error);

	if (error == NULL)
		maildir_service = camel_session_add_service (
			session, "local", "maildir",
			CAMEL_PROVIDER_STORE, &error);

	if (error != NULL) {
		if (mbox_service != NULL)
			g_object_unref (mbox_service);
		if (maildir_service != NULL)
			g_object_unref (maildir_service);
		g_warning ("%s: %s", G_STRFUNC, error->message);
		g_error_free (error);
		return FALSE;
	}

	g_return_val_if_fail (CAMEL_IS_STORE (mbox_service), FALSE);
	g_return_val_if_fail (CAMEL_IS_STORE (maildir_service), FALSE);

	camel_service_set_settings (mbox_service, settings);

	settings = camel_service_ref_settings (maildir_service);

	path = g_build_filename (data_dir, "local", NULL);
	g_object_set (settings, "path", path, NULL);
	if (g_mkdir (path, 0700) == -1)
		g_warning (
			"%s: Failed to make directory '%s': %s",
			G_STRFUNC, path, g_strerror (errno));
	g_free (path);

	g_object_unref (settings);

	ms.mail_store = CAMEL_STORE (mbox_service);
	ms.maildir_store = CAMEL_STORE (maildir_service);
	ms.session = session;
	ms.complete = FALSE;

	thread = g_thread_new (NULL, (GThreadFunc) migrate_stores, &ms);
	/* coverity[loop_condition] */
	while (!ms.complete)
		g_main_context_iteration (NULL, TRUE);

	g_object_unref (mbox_service);
	g_object_unref (maildir_service);
	g_thread_unref (thread);

	return TRUE;
}
Exemplo n.º 20
0
gint main (gint argc, gchar **argv)
{
	CamelService *service;
	CamelSession *session;
	CamelStore *store;
	CamelFolder *folder;
	CamelMimeMessage *msg;
	gint i, j;
	CamelStream *mbox;
	CamelFilterDriver *driver;
	GError *error = NULL;

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

	/* 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");
	service = camel_session_add_service (
		session, "test-uid", "mbox:///tmp/camel-test/mbox",
		CAMEL_PROVIDER_STORE, &error);
	check_msg (error == NULL, "getting store: %s", error->message);
	check (CAMEL_IS_STORE (service));
	store = CAMEL_STORE (service);
	g_clear_error (&error);
	pull ();

	push ("Creating output folders");
	for (i = 0; i < G_N_ELEMENTS (mailboxes); i++) {
		push ("creating %s", mailboxes[i].name);
		mailboxes[i].folder = folder = camel_store_get_folder_sync (
			store, mailboxes[i].name,
			CAMEL_STORE_FOLDER_CREATE, NULL, &error);
		check_msg (error == NULL, "%s", error->message);
		check (folder != NULL);

		/* we need an empty folder for this to work */
		test_folder_counts (folder, 0, 0);
		g_clear_error (&error);
		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, NULL);
	for (j = 0; j < 100; j++) {
		gchar *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_write_string (mbox, "From \n", NULL, NULL);
		check (camel_data_wrapper_write_to_stream_sync (
			CAMEL_DATA_WRAPPER (msg), mbox, NULL, NULL) != -1);
#if 0
		push ("appending simple message %d", j);
		camel_folder_append_message (folder, msg, NULL, ex);
		check_msg (error == NULL, "%s", error->message);
		g_clear_error (&error);
		pull ();
#endif
		test_free (subject);

		check_unref (msg, 1);
	}
	check (camel_stream_close (mbox, NULL, NULL) != -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 < G_N_ELEMENTS (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);
#if 0  /* FIXME We no longer filter mbox files. */
	camel_filter_driver_filter_mbox (
		driver, "/tmp/camel-test/inbox", NULL, NULL, &error);
#endif
	check_msg (error == NULL, "%s", error->message);

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

	check_unref (driver, 1);
	g_clear_error (&error);
	pull ();

	/* this tests that invalid rules are caught */
	push ("Testing broken match rules");
	for (i = 0; i < G_N_ELEMENTS (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);
#if 0  /* FIXME We no longer filter mbox files. */
		camel_filter_driver_filter_mbox (
			driver, "/tmp/camel-test/inbox", NULL, NULL, &error);
#endif
		check (error != NULL);
		check_unref (driver, 1);
		g_clear_error (&error);
		pull ();
	}
	pull ();

	push ("Testing broken action rules");
	for (i = 0; i < G_N_ELEMENTS (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);
#if 0  /* FIXME We no longer filter mbox files. */
		camel_filter_driver_filter_mbox (
			driver, "/tmp/camel-test/inbox", NULL, NULL, &error);
#endif
		check (error != NULL);
		check_unref (driver, 1);
		g_clear_error (&error);
		pull ();
	}
	pull ();

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

	check_unref (store, 1);

	check_unref (session, 1);

	camel_test_end ();

	return 0;
}
Exemplo n.º 21
0
CamelStore *
e_mail_store_add_by_account (EMailBackend *backend,
                             EAccount *account)
{
	EMailSession *session;
	CamelService *service = NULL;
	CamelProvider *provider;
	CamelURL *url;
	gboolean skip = FALSE, transport_only;
	GError *error = NULL;

	g_return_val_if_fail (E_IS_MAIL_BACKEND (backend), NULL);
	g_return_val_if_fail (E_IS_ACCOUNT (account), NULL);

	session = e_mail_backend_get_session (backend);

	/* check whether it's transport-only accounts */
	transport_only = !account->source || !account->source->url || !*account->source->url;
	if (transport_only)
		goto handle_transport;

	/* Load the service, but don't connect.  Check its provider,
	 * and if this belongs in the folder tree model, add it. */

	provider = camel_provider_get (account->source->url, &error);
	if (provider == NULL) {
	/* In case we do not have a provider here, we handle
	 * the special case of having multiple mail identities
	 * eg. a dummy account having just SMTP server defined */
		goto handle_transport;
	}

	service = camel_session_add_service (
		CAMEL_SESSION (session),
		account->uid, account->source->url,
		CAMEL_PROVIDER_STORE, &error);

	camel_service_set_display_name (service, account->name);

handle_transport:

	if (account->transport) {
		/* While we're at it, add the account's transport to the
		 * CamelSession.  The transport's UID is a kludge for now.
		 * We take the EAccount's UID and tack on "-transport". */
		gchar *transport_uid;
		GError *transport_error = NULL;

		transport_uid = g_strconcat (
			account->uid, "-transport", NULL);

		camel_session_add_service (
			CAMEL_SESSION (session),
			transport_uid, account->transport->url,
			CAMEL_PROVIDER_TRANSPORT, &transport_error);

		g_free (transport_uid);

		if (transport_error) {
			g_warning (
				"%s: Failed to add transport service: %s",
				G_STRFUNC, transport_error->message);
			g_error_free (transport_error);
		}
	}

	if (transport_only)
		return NULL;

	if (!CAMEL_IS_STORE (service))
		goto fail;

	/* Do not add local-delivery files,
	 * but make them ready for later use. */
	url = camel_url_new (account->source->url, NULL);
	if (url != NULL) {
		skip = em_utils_is_local_delivery_mbox_file (url);
		camel_url_free (url);
	}

	if (!skip && (provider->flags & CAMEL_PROVIDER_IS_STORAGE))
		e_mail_store_add (backend, CAMEL_STORE (service));

	return CAMEL_STORE (service);

fail:
	/* FIXME: Show an error dialog. */
	g_warning (
		"Couldn't get service: %s: %s", account->name,
		error ? error->message : "Not a CamelStore");
	if (error)
		g_error_free (error);

	return NULL;
}
Exemplo n.º 22
0
static void
mail_shell_view_execute_search (EShellView *shell_view)
{
	EMailShellViewPrivate *priv;
	EMailShellContent *mail_shell_content;
	EMailShellSidebar *mail_shell_sidebar;
	EShellWindow *shell_window;
	EShellBackend *shell_backend;
	EShellContent *shell_content;
	EShellSidebar *shell_sidebar;
	EShellSearchbar *searchbar;
	EActionComboBox *combo_box;
	EMailBackend *backend;
	EMailSession *session;
	ESourceRegistry *registry;
	EMFolderTree *folder_tree;
	GtkWidget *message_list;
	EFilterRule *rule;
	EMailReader *reader;
	EMailView *mail_view;
	CamelVeeFolder *search_folder;
	CamelFolder *folder;
	CamelService *service;
	CamelStore *store;
	GtkAction *action;
	EMailLabelListStore *label_store;
	GtkTreePath *path;
	GtkTreeIter tree_iter;
	GString *string;
	GList *list, *iter;
	GSList *search_strings = NULL;
	const gchar *text;
	gboolean valid;
	gchar *query;
	gchar *temp;
	gchar *tag;
	const gchar *use_tag;
	gint value;

	priv = E_MAIL_SHELL_VIEW_GET_PRIVATE (shell_view);

	shell_window = e_shell_view_get_shell_window (shell_view);
	shell_backend = e_shell_view_get_shell_backend (shell_view);
	shell_content = e_shell_view_get_shell_content (shell_view);
	shell_sidebar = e_shell_view_get_shell_sidebar (shell_view);

	backend = E_MAIL_BACKEND (shell_backend);
	session = e_mail_backend_get_session (backend);

	mail_shell_content = E_MAIL_SHELL_CONTENT (shell_content);
	mail_view = e_mail_shell_content_get_mail_view (mail_shell_content);
	searchbar = e_mail_shell_content_get_searchbar (mail_shell_content);

	mail_shell_sidebar = E_MAIL_SHELL_SIDEBAR (shell_sidebar);
	folder_tree = e_mail_shell_sidebar_get_folder_tree (mail_shell_sidebar);

	reader = E_MAIL_READER (mail_view);
	folder = e_mail_reader_ref_folder (reader);
	message_list = e_mail_reader_get_message_list (reader);

	registry = e_mail_session_get_registry (session);
	label_store = e_mail_ui_session_get_label_store (
		E_MAIL_UI_SESSION (session));

	action = ACTION (MAIL_SEARCH_SUBJECT_OR_ADDRESSES_CONTAIN);
	value = gtk_radio_action_get_current_value (GTK_RADIO_ACTION (action));

	text = e_shell_searchbar_get_search_text (searchbar);
	if (value == MAIL_SEARCH_ADVANCED || text == NULL || *text == '\0') {
		if (value != MAIL_SEARCH_ADVANCED)
			e_shell_view_set_search_rule (shell_view, NULL);

		query = e_shell_view_get_search_query (shell_view);

		if (!query)
			query = g_strdup ("");

		goto filter;
	}

	/* Replace variables in the selected rule with the
	 * current search text and extract a query string. */

	g_return_if_fail (value >= 0 && value < MAIL_NUM_SEARCH_RULES);
	rule = priv->search_rules[value];

	/* Set the search rule in EShellView so that "Create
	 * Search Folder from Search" works for quick searches. */
	e_shell_view_set_search_rule (shell_view, rule);

	for (iter = rule->parts; iter != NULL; iter = iter->next) {
		EFilterPart *part = iter->data;
		EFilterElement *element = NULL;

		if (strcmp (part->name, "subject") == 0)
			element = e_filter_part_find_element (part, "subject");
		else if (strcmp (part->name, "body") == 0)
			element = e_filter_part_find_element (part, "word");
		else if (strcmp (part->name, "sender") == 0)
			element = e_filter_part_find_element (part, "sender");
		else if (strcmp (part->name, "to") == 0)
			element = e_filter_part_find_element (part, "recipient");

		if (strcmp (part->name, "body") == 0) {
			struct _camel_search_words *words;
			gint ii;

			words = camel_search_words_split ((guchar *) text);
			for (ii = 0; ii < words->len; ii++)
				search_strings = g_slist_prepend (
					search_strings, g_strdup (
					words->words[ii]->word));
			camel_search_words_free (words);
		}

		if (element != NULL) {
			EFilterInput *input = E_FILTER_INPUT (element);
			e_filter_input_set_value (input, text);
		}
	}

	string = g_string_sized_new (1024);
	e_filter_rule_build_code (rule, string);
	query = g_string_free (string, FALSE);

filter:

	/* Apply selected filter. */

	combo_box = e_shell_searchbar_get_filter_combo_box (searchbar);
	value = e_action_combo_box_get_current_value (combo_box);
	switch (value) {
		case MAIL_FILTER_ALL_MESSAGES:
			break;

		case MAIL_FILTER_UNREAD_MESSAGES:
			temp = g_strdup_printf (
				"(and %s (match-all (not "
				"(system-flag \"Seen\"))))", query);
			g_free (query);
			query = temp;
			break;

		case MAIL_FILTER_NO_LABEL:
			string = g_string_sized_new (1024);
			g_string_append_printf (
				string, "(and %s (and ", query);
			valid = gtk_tree_model_get_iter_first (
				GTK_TREE_MODEL (label_store), &tree_iter);
			while (valid) {
				tag = e_mail_label_list_store_get_tag (
					label_store, &tree_iter);
				use_tag = tag;
				if (g_str_has_prefix (use_tag, "$Label"))
					use_tag += 6;
				g_string_append_printf (
					string, " (match-all (not (or "
					"(= (user-tag \"label\") \"%s\") "
					"(user-flag \"$Label%s\") "
					"(user-flag \"%s\"))))",
					use_tag, use_tag, use_tag);
				g_free (tag);

				valid = gtk_tree_model_iter_next (
					GTK_TREE_MODEL (label_store),
					&tree_iter);
			}
			g_string_append_len (string, "))", 2);
			g_free (query);
			query = g_string_free (string, FALSE);
			break;

		case MAIL_FILTER_READ_MESSAGES:
			temp = g_strdup_printf (
				"(and %s (match-all "
				"(system-flag \"Seen\")))", query);
			g_free (query);
			query = temp;
			break;

		case MAIL_FILTER_LAST_5_DAYS_MESSAGES:
			if (em_utils_folder_is_sent (registry, folder))
				temp = g_strdup_printf (
					"(and %s (match-all "
					"(> (get-sent-date) "
					"(- (get-current-date) 432000))))",
					query);
			else
				temp = g_strdup_printf (
					"(and %s (match-all "
					"(> (get-received-date) "
					"(- (get-current-date) 432000))))",
					query);
			g_free (query);
			query = temp;
			break;

		case MAIL_FILTER_MESSAGES_WITH_ATTACHMENTS:
			temp = g_strdup_printf (
				"(and %s (match-all "
				"(system-flag \"Attachments\")))", query);
			g_free (query);
			query = temp;
			break;

		case MAIL_FILTER_IMPORTANT_MESSAGES:
			temp = g_strdup_printf (
				"(and %s (match-all "
				"(system-flag \"Flagged\")))", query);
			g_free (query);
			query = temp;
			break;

		case MAIL_FILTER_MESSAGES_NOT_JUNK:
			temp = g_strdup_printf (
				"(and %s (match-all (not "
				"(system-flag \"junk\"))))", query);
			g_free (query);
			query = temp;
			break;

		default:
			/* The action value also serves as a path for
			 * the label list store.  That's why we number
			 * the label actions from zero. */
			path = gtk_tree_path_new_from_indices (value, -1);
			gtk_tree_model_get_iter (
				GTK_TREE_MODEL (label_store),
				&tree_iter, path);
			gtk_tree_path_free (path);

			tag = e_mail_label_list_store_get_tag (
				label_store, &tree_iter);
			use_tag = tag;
			if (g_str_has_prefix (use_tag, "$Label"))
				use_tag += 6;
			temp = g_strdup_printf (
				"(and %s (match-all (or "
				"(= (user-tag \"label\") \"%s\") "
				"(user-flag \"$Label%s\") "
				"(user-flag \"%s\"))))",
				query, use_tag, use_tag, use_tag);
			g_free (tag);

			g_free (query);
			query = temp;
			break;
	}

	/* Apply selected scope. */

	combo_box = e_shell_searchbar_get_scope_combo_box (searchbar);
	value = e_action_combo_box_get_current_value (combo_box);
	switch (value) {
		case MAIL_SCOPE_CURRENT_FOLDER:
			goto execute;

		case MAIL_SCOPE_CURRENT_ACCOUNT:
			goto current_account;

		case MAIL_SCOPE_ALL_ACCOUNTS:
			goto all_accounts;

		default:
			g_warn_if_reached ();
			goto execute;
	}

all_accounts:

	/* Prepare search folder for all accounts. */

	/* If the search text is empty, cancel any
	 * account-wide searches still in progress. */
	text = e_shell_searchbar_get_search_text (searchbar);
	if (text == NULL || *text == '\0') {
		CamelStore *selected_store = NULL;
		gchar *selected_folder_name = NULL;

		if (priv->search_account_all != NULL) {
			g_object_unref (priv->search_account_all);
			priv->search_account_all = NULL;
		}

		if (priv->search_account_cancel != NULL) {
			g_cancellable_cancel (priv->search_account_cancel);
			g_object_unref (priv->search_account_cancel);
			priv->search_account_cancel = NULL;
		}

		/* Reset the message list to the current folder tree
		 * selection.  This needs to happen synchronously to
		 * avoid search conflicts, so we can't just grab the
		 * folder URI and let the asynchronous callbacks run
		 * after we've already kicked off the search. */
		em_folder_tree_get_selected (
			folder_tree, &selected_store, &selected_folder_name);
		if (selected_store != NULL && selected_folder_name != NULL) {
			folder = camel_store_get_folder_sync (
				selected_store, selected_folder_name,
				CAMEL_STORE_FOLDER_INFO_FAST, NULL, NULL);
			e_mail_reader_set_folder (reader, folder);
			g_object_unref (folder);
		}

		g_clear_object (&selected_store);
		g_free (selected_folder_name);

		gtk_widget_set_sensitive (GTK_WIDGET (combo_box), TRUE);

		goto execute;
	}

	search_folder = priv->search_account_all;

	/* Skip the search if we already have the results. */
	if (search_folder != NULL) {
		const gchar *vf_query;

		vf_query = camel_vee_folder_get_expression (search_folder);
		if (g_strcmp0 (query, vf_query) == 0)
			goto all_accounts_setup;
	}

	/* Disable the scope combo while search is in progress. */
	gtk_widget_set_sensitive (GTK_WIDGET (combo_box), FALSE);

	/* If we already have a search folder, reuse it. */
	if (search_folder != NULL) {
		if (priv->search_account_cancel != NULL) {
			g_cancellable_cancel (priv->search_account_cancel);
			g_object_unref (priv->search_account_cancel);
			priv->search_account_cancel = NULL;
		}

		camel_vee_folder_set_expression (search_folder, query);

		goto all_accounts_setup;
	}

	/* Create a new search folder. */

	/* FIXME Complete lack of error checking here. */
	service = camel_session_ref_service (
		CAMEL_SESSION (session), E_MAIL_SESSION_VFOLDER_UID);
	camel_service_connect_sync (service, NULL, NULL);

	search_folder = (CamelVeeFolder *) camel_vee_folder_new (
		CAMEL_STORE (service),
		_("All Account Search"),
		CAMEL_STORE_FOLDER_PRIVATE);
	priv->search_account_all = search_folder;

	g_object_unref (service);

	camel_vee_folder_set_expression (search_folder, query);

all_accounts_setup:

	list = em_folder_tree_model_list_stores (EM_FOLDER_TREE_MODEL (
		gtk_tree_view_get_model (GTK_TREE_VIEW (folder_tree))));
	g_list_foreach (list, (GFunc) g_object_ref, NULL);

	priv->search_account_cancel = camel_operation_new ();

	/* This takes ownership of the stores list. */
	mail_shell_view_setup_search_results_folder (
		CAMEL_FOLDER (search_folder), list,
		priv->search_account_cancel);

	mail_shell_view_show_search_results_folder (
		E_MAIL_SHELL_VIEW (shell_view),
		CAMEL_FOLDER (search_folder));

	goto execute;

current_account:

	/* Prepare search folder for current account only. */

	/* If the search text is empty, cancel any
	 * account-wide searches still in progress. */
	text = e_shell_searchbar_get_search_text (searchbar);
	if (text == NULL || *text == '\0') {
		CamelStore *selected_store = NULL;
		gchar *selected_folder_name = NULL;

		if (priv->search_account_current != NULL) {
			g_object_unref (priv->search_account_current);
			priv->search_account_current = NULL;
		}

		if (priv->search_account_cancel != NULL) {
			g_cancellable_cancel (priv->search_account_cancel);
			g_object_unref (priv->search_account_cancel);
			priv->search_account_cancel = NULL;
		}

		/* Reset the message list to the current folder tree
		 * selection.  This needs to happen synchronously to
		 * avoid search conflicts, so we can't just grab the
		 * folder URI and let the asynchronous callbacks run
		 * after we've already kicked off the search. */
		em_folder_tree_get_selected (
			folder_tree, &selected_store, &selected_folder_name);
		if (selected_store != NULL && selected_folder_name != NULL) {
			folder = camel_store_get_folder_sync (
				selected_store, selected_folder_name,
				CAMEL_STORE_FOLDER_INFO_FAST, NULL, NULL);
			e_mail_reader_set_folder (reader, folder);
			g_object_unref (folder);
		}

		g_clear_object (&selected_store);
		g_free (selected_folder_name);

		gtk_widget_set_sensitive (GTK_WIDGET (combo_box), TRUE);

		goto execute;
	}

	search_folder = priv->search_account_current;

	/* Skip the search if we already have the results. */
	if (search_folder != NULL) {
		const gchar *vf_query;

		vf_query = camel_vee_folder_get_expression (search_folder);
		if (g_strcmp0 (query, vf_query) == 0)
			goto current_accout_setup;
	}

	/* Disable the scope combo while search is in progress. */
	gtk_widget_set_sensitive (GTK_WIDGET (combo_box), FALSE);

	/* If we already have a search folder, reuse it. */
	if (search_folder != NULL) {
		if (priv->search_account_cancel != NULL) {
			g_cancellable_cancel (priv->search_account_cancel);
			g_object_unref (priv->search_account_cancel);
			priv->search_account_cancel = NULL;
		}

		camel_vee_folder_set_expression (search_folder, query);

		goto current_accout_setup;
	}

	/* Create a new search folder. */

	/* FIXME Complete lack of error checking here. */
	service = camel_session_ref_service (
		CAMEL_SESSION (session), E_MAIL_SESSION_VFOLDER_UID);
	camel_service_connect_sync (service, NULL, NULL);

	search_folder = (CamelVeeFolder *) camel_vee_folder_new (
		CAMEL_STORE (service),
		_("Account Search"),
		CAMEL_STORE_FOLDER_PRIVATE);
	priv->search_account_current = search_folder;

	g_object_unref (service);

	camel_vee_folder_set_expression (search_folder, query);

current_accout_setup:

	if (folder != NULL && folder != CAMEL_FOLDER (search_folder)) {
		store = camel_folder_get_parent_store (folder);
		if (store != NULL)
			g_object_ref (store);
	} else {
		store = NULL;
		em_folder_tree_get_selected (folder_tree, &store, NULL);
	}

	list = NULL;  /* list of CamelStore-s */

	if (store != NULL)
		list = g_list_append (NULL, store);

	priv->search_account_cancel = camel_operation_new ();

	/* This takes ownership of the stores list. */
	mail_shell_view_setup_search_results_folder (
		CAMEL_FOLDER (search_folder), list,
		priv->search_account_cancel);

	mail_shell_view_show_search_results_folder (
		E_MAIL_SHELL_VIEW (shell_view),
		CAMEL_FOLDER (search_folder));

execute:

	/* Finally, execute the search. */

	message_list_set_search (MESSAGE_LIST (message_list), query);

	e_mail_view_set_search_strings (mail_view, search_strings);

	g_slist_foreach (search_strings, (GFunc) g_free, NULL);
	g_slist_free (search_strings);

	g_free (query);

	g_clear_object (&folder);
}
Exemplo n.º 23
0
static void
mail_shell_view_update_actions (EShellView *shell_view)
{
	EMailShellView *mail_shell_view;
	EMailShellContent *mail_shell_content;
	EMailShellSidebar *mail_shell_sidebar;
	EShellSidebar *shell_sidebar;
	EShellWindow *shell_window;
	EMFolderTree *folder_tree;
	EMFolderTreeModel *model;
	EMailReader *reader;
	EMailView *mail_view;
	GtkAction *action;
	CamelStore *store = NULL;
	GList *list, *link;
	gchar *folder_name = NULL;
	gboolean sensitive;
	guint32 state;

	/* Be descriptive. */
	gboolean folder_allows_children;
	gboolean folder_can_be_deleted;
	gboolean folder_is_outbox;
	gboolean folder_is_selected = FALSE;
	gboolean folder_is_store;
	gboolean folder_is_trash;
	gboolean folder_is_virtual;
	gboolean folder_has_unread = FALSE;
	gboolean folder_has_unread_rec = FALSE;
	gboolean folder_tree_and_message_list_agree = TRUE;
	gboolean store_is_builtin;
	gboolean store_is_subscribable;
	gboolean store_can_be_disabled;
	gboolean any_store_is_subscribable = FALSE;

	/* Chain up to parent's update_actions() method. */
	E_SHELL_VIEW_CLASS (e_mail_shell_view_parent_class)->
		update_actions (shell_view);

	shell_window = e_shell_view_get_shell_window (shell_view);

	mail_shell_view = E_MAIL_SHELL_VIEW (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);
	state = e_mail_reader_check_state (reader);
	e_mail_reader_update_actions (reader, state);

	mail_shell_sidebar = mail_shell_view->priv->mail_shell_sidebar;
	folder_tree = e_mail_shell_sidebar_get_folder_tree (mail_shell_sidebar);

	shell_sidebar = e_shell_view_get_shell_sidebar (shell_view);
	state = e_shell_sidebar_check_state (shell_sidebar);

	model = em_folder_tree_model_get_default ();

	folder_allows_children =
		(state & E_MAIL_SIDEBAR_FOLDER_ALLOWS_CHILDREN);
	folder_can_be_deleted =
		(state & E_MAIL_SIDEBAR_FOLDER_CAN_DELETE);
	folder_is_outbox =
		(state & E_MAIL_SIDEBAR_FOLDER_IS_OUTBOX);
	folder_is_store =
		(state & E_MAIL_SIDEBAR_FOLDER_IS_STORE);
	folder_is_trash =
		(state & E_MAIL_SIDEBAR_FOLDER_IS_TRASH);
	folder_is_virtual =
		(state & E_MAIL_SIDEBAR_FOLDER_IS_VIRTUAL);
	store_is_builtin =
		(state & E_MAIL_SIDEBAR_STORE_IS_BUILTIN);
	store_is_subscribable =
		(state & E_MAIL_SIDEBAR_STORE_IS_SUBSCRIBABLE);
	store_can_be_disabled =
		(state & E_MAIL_SIDEBAR_STORE_CAN_BE_DISABLED);

	if (em_folder_tree_get_selected (folder_tree, &store, &folder_name)) {
		GtkTreeRowReference *reference;
		CamelFolder *folder;

		folder_is_selected = TRUE;

		folder = e_mail_reader_ref_folder (reader);

		/* XXX If the user right-clicks on a folder other than what
		 *     the message list is showing, disable folder rename.
		 *     Between fetching the CamelFolder asynchronously and
		 *     knowing when NOT to move the folder tree selection
		 *     back to where it was to avoid cancelling the inline
		 *     folder tree editing, it's just too hairy to try to
		 *     get right.  So we're punting. */
		if (folder != NULL) {
			gchar *uri1, *uri2;

			uri1 = e_mail_folder_uri_from_folder (folder);
			uri2 = e_mail_folder_uri_build (store, folder_name);

			folder_tree_and_message_list_agree =
				(g_strcmp0 (uri1, uri2) == 0);

			g_free (uri1);
			g_free (uri2);

			g_object_unref (folder);
		}

		reference = em_folder_tree_model_get_row_reference (
			model, store, folder_name);
		if (reference != NULL) {
			GtkTreePath *path;
			GtkTreeIter iter;

			path = gtk_tree_row_reference_get_path (reference);
			gtk_tree_model_get_iter (
				GTK_TREE_MODEL (model), &iter, path);
			has_unread_mail (
				GTK_TREE_MODEL (model), &iter,
				TRUE, &folder_has_unread,
				&folder_has_unread_rec);
			gtk_tree_path_free (path);
		}

		g_clear_object (&store);
		g_free (folder_name);
		folder_name = NULL;
	}

	/* Look for a CamelStore that supports subscriptions. */
	list = em_folder_tree_model_list_stores (model);
	for (link = list; link != NULL; link = g_list_next (link)) {
		CamelStore *store = CAMEL_STORE (link->data);

		if (CAMEL_IS_SUBSCRIBABLE (store)) {
			any_store_is_subscribable = TRUE;
			break;
		}
	}
	g_list_free (list);

	action = ACTION (MAIL_ACCOUNT_DISABLE);
	sensitive = folder_is_store && store_can_be_disabled;
	gtk_action_set_sensitive (action, sensitive);

	action = ACTION (MAIL_ACCOUNT_EXPUNGE);
	sensitive = folder_is_trash;
	gtk_action_set_sensitive (action, sensitive);

	action = ACTION (MAIL_ACCOUNT_PROPERTIES);
	sensitive = folder_is_store && !store_is_builtin;
	gtk_action_set_sensitive (action, sensitive);

	action = ACTION (MAIL_ACCOUNT_REFRESH);
	sensitive = folder_is_store;
	gtk_action_set_sensitive (action, sensitive);

	action = ACTION (MAIL_FLUSH_OUTBOX);
	sensitive = folder_is_outbox;
	gtk_action_set_sensitive (action, sensitive);

	action = ACTION (MAIL_FOLDER_COPY);
	sensitive = folder_is_selected;
	gtk_action_set_sensitive (action, sensitive);

	action = ACTION (MAIL_FOLDER_DELETE);
	sensitive = folder_is_selected && folder_can_be_deleted;
	gtk_action_set_sensitive (action, sensitive);

	action = ACTION (MAIL_FOLDER_EXPUNGE);
	sensitive = folder_is_selected && !folder_is_virtual;
	gtk_action_set_sensitive (action, sensitive);

	action = ACTION (MAIL_FOLDER_MOVE);
	sensitive = folder_is_selected && folder_can_be_deleted;
	gtk_action_set_sensitive (action, sensitive);

	action = ACTION (MAIL_FOLDER_NEW);
	sensitive = folder_allows_children;
	gtk_action_set_sensitive (action, sensitive);

	action = ACTION (MAIL_FOLDER_PROPERTIES);
	sensitive = folder_is_selected;
	gtk_action_set_sensitive (action, sensitive);

	action = ACTION (MAIL_FOLDER_REFRESH);
	sensitive = folder_is_selected;
	gtk_action_set_sensitive (action, sensitive);

	action = ACTION (MAIL_FOLDER_RENAME);
	sensitive =
		folder_is_selected &&
		folder_can_be_deleted &&
		folder_tree_and_message_list_agree;
	gtk_action_set_sensitive (action, sensitive);

	action = ACTION (MAIL_FOLDER_SELECT_THREAD);
	sensitive = folder_is_selected;
	gtk_action_set_sensitive (action, sensitive);

	action = ACTION (MAIL_FOLDER_SELECT_SUBTHREAD);
	sensitive = folder_is_selected;
	gtk_action_set_sensitive (action, sensitive);

	action = ACTION (MAIL_FOLDER_UNSUBSCRIBE);
	sensitive =
		folder_is_selected &&
		store_is_subscribable &&
		!folder_is_virtual;
	gtk_action_set_sensitive (action, sensitive);

	action = ACTION (MAIL_FOLDER_MARK_ALL_AS_READ);
	sensitive = folder_is_selected && folder_has_unread;
	gtk_action_set_sensitive (action, sensitive);

	action = ACTION (MAIL_POPUP_FOLDER_MARK_ALL_AS_READ);
	sensitive = folder_is_selected && folder_has_unread_rec;
	gtk_action_set_visible (action, sensitive);

	action = ACTION (MAIL_MANAGE_SUBSCRIPTIONS);
	sensitive = folder_is_store && store_is_subscribable;
	gtk_action_set_sensitive (action, sensitive);

	action = ACTION (MAIL_TOOLS_SUBSCRIPTIONS);
	sensitive = any_store_is_subscribable;
	gtk_action_set_sensitive (action, sensitive);

	/* folder_is_store + folder_is_virtual == "Search Folders" */
	action = ACTION (MAIL_VFOLDER_UNMATCHED_ENABLE);
	gtk_action_set_visible (action, folder_is_store && folder_is_virtual);

	e_mail_shell_view_update_popup_labels (mail_shell_view);
}
Exemplo n.º 24
0
/* We setup the download info's in a hashtable, if we later
 * need to build the gui, we insert them in to add them. */
GCancellable *
mail_receive_service (CamelService *service)
{
	struct _send_info *info;
	struct _send_data *data;
	CamelFolder *local_outbox;
	const gchar *uid;
	EMailSession *session;

	send_info_t type = SEND_INVALID;

	g_return_val_if_fail (CAMEL_IS_SERVICE (service), NULL);

	session = (EMailSession *)camel_service_get_session (service);
	uid = camel_service_get_uid (service);

	data = setup_send_data (session);
	info = g_hash_table_lookup (data->active, uid);

	if (info != NULL)
		return info->cancellable;

	type = get_receive_type (service);

	if (type == SEND_INVALID || type == SEND_SEND)
		return NULL;

	info = g_malloc0 (sizeof (*info));
	info->type = type;
	info->session = g_object_ref (session);
	info->service = g_object_ref (service);
	info->keep_on_server = mail_get_keep_on_server (service);	
	info->cancellable = camel_operation_new ();
	info->data = data;
	info->state = SEND_ACTIVE;
	info->timeout_id = 0;

	g_signal_connect (
		info->cancellable, "status",
		G_CALLBACK (operation_status), info);

	d(printf("Adding new info %p\n", info));

	g_hash_table_insert (data->active, g_strdup(uid), info);

	switch (info->type) {
	case SEND_RECEIVE:
		mail_fetch_mail (
			CAMEL_STORE (service),
			CAMEL_FETCH_OLD_MESSAGES, -1,
			E_FILTER_SOURCE_INCOMING,
			mail_provider_fetch_lock, mail_provider_fetch_unlock, mail_provider_fetch_inbox_folder,
			info->cancellable,
			receive_get_folder, info,
			receive_status, info,
			receive_done, info);
		break;
	case SEND_SEND:
		/* todo, store the folder in info? */
		local_outbox =
			e_mail_session_get_local_folder (
			session, E_MAIL_LOCAL_FOLDER_OUTBOX);
		mail_send_queue (
			info->session,
			local_outbox,
			CAMEL_TRANSPORT (service),
			E_FILTER_SOURCE_OUTGOING,
			info->cancellable,
			receive_get_folder, info,
			receive_status, info,
			send_done, info);
		break;
	case SEND_UPDATE:
		receive_update_got_store (CAMEL_STORE (service), info);
		break;
	default:
		g_return_val_if_reached (NULL);
	}

	return info->cancellable;
}
Exemplo n.º 25
0
gint
main (gint argc,
      gchar **argv)
{
	CamelFolder *f1, *f2;
	CamelStore *store;
	CamelService *service;
	CamelFolderInfo *fi;
	GError *error = NULL;

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

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

	session = camel_test_session_new ("/tmp/camel-test");
	service = camel_session_add_service (
		session, "test-uid",
		"maildir:///tmp/camel-test/maildir",
		CAMEL_PROVIDER_STORE, NULL);
	store = CAMEL_STORE (service);

	camel_test_start ("Maildir backward compatability tests");

	camel_test_push ("./ prefix path, one level");
	f1 = camel_store_get_folder_sync (
		store, "testbox",
		CAMEL_STORE_FOLDER_CREATE, NULL, &error);
	check_msg (error == NULL, "%s", error->message);
	g_clear_error (&error);
	f2 = camel_store_get_folder_sync (
		store, "./testbox",
		CAMEL_STORE_FOLDER_CREATE, NULL, &error);
	check_msg (error == NULL, "%s", error->message);
	g_clear_error (&error);
	check (f1 == f2);
	check_unref (f2, 2);
	check_unref (f1, 1);
	camel_test_pull ();

	camel_test_push ("./ prefix path, one level, no create");
	f1 = camel_store_get_folder_sync (
		store, "testbox2",
		CAMEL_STORE_FOLDER_CREATE, NULL, &error);
	check_msg (error == NULL, "%s", error->message);
	g_clear_error (&error);
	f2 = camel_store_get_folder_sync (
		store, "./testbox2", 0, NULL, &error);
	check_msg (error == NULL, "%s", error->message);
	g_clear_error (&error);
	check (f1 == f2);
	check_unref (f2, 2);
	check_unref (f1, 1);
	camel_test_pull ();

	camel_test_push ("./ prefix path, two levels");
	f1 = camel_store_get_folder_sync (
		store, "testbox/foo",
		CAMEL_STORE_FOLDER_CREATE, NULL, &error);
	check_msg (error == NULL, "%s", error->message);
	g_clear_error (&error);
	f2 = camel_store_get_folder_sync (
		store, "./testbox/foo",
		CAMEL_STORE_FOLDER_CREATE, NULL, &error);
	check_msg (error == NULL, "%s", error->message);
	g_clear_error (&error);
	check (f1 == f2);
	check_unref (f2, 2);
	check_unref (f1, 1);
	camel_test_pull ();

	camel_test_push ("'.' == Inbox");
	f2 = camel_store_get_inbox_folder_sync (store, NULL, &error);
	check_msg (error == NULL, "%s", error->message);
	g_clear_error (&error);
	f1 = camel_store_get_folder_sync (store, ".", 0, NULL, &error);
	check_msg (error == NULL, "%s", error->message);
	g_clear_error (&error);
	check (f1 == f2);
	check_unref (f2, 2);
	check_unref (f1, 1);
	camel_test_pull ();

	camel_test_push ("folder info, recursive");
	fi = camel_store_get_folder_info_sync (
		store, "",
		CAMEL_STORE_FOLDER_INFO_RECURSIVE,
		NULL, &error);
	check_msg (error == NULL, "%s", error->message);
	g_clear_error (&error);
	check (fi != NULL);
	check_fi (fi, fi_list_1, G_N_ELEMENTS (fi_list_1));
	camel_test_pull ();

	camel_test_push ("folder info, flat");
	fi = camel_store_get_folder_info_sync (store, "", 0, NULL, &error);
	check_msg (error == NULL, "%s", error->message);
	g_clear_error (&error);
	check (fi != NULL);
	check_fi (fi, fi_list_2, G_N_ELEMENTS (fi_list_2));
	camel_test_pull ();

	camel_test_push ("folder info, recursive, non root");
	fi = camel_store_get_folder_info_sync (
		store, "testbox",
		CAMEL_STORE_FOLDER_INFO_RECURSIVE,
		NULL, &error);
	check_msg (error == NULL, "%s", error->message);
	g_clear_error (&error);
	check (fi != NULL);
	check_fi (fi, fi_list_3, G_N_ELEMENTS (fi_list_3));
	camel_test_pull ();

	check_unref (store, 1);
	check_unref (session, 1);

	camel_test_end ();

	return 0;
}
static gboolean
groupwise_auth_loop (CamelService *service, CamelException *ex)
{
	CamelSession *session = camel_service_get_session (service);
	CamelStore *store = CAMEL_STORE (service);
	CamelGroupwiseStore *groupwise_store = CAMEL_GROUPWISE_STORE (store);
	CamelGroupwiseStorePrivate *priv = groupwise_store->priv;
	gboolean authenticated = FALSE;
	char *uri;
	EGwConnectionErrors errors;

	if (priv->use_ssl && !g_str_equal (priv->use_ssl, "never"))
		uri = g_strconcat ("https://", priv->server_name, ":", priv->port, "/soap", NULL);
	else
		uri = g_strconcat ("http://", priv->server_name, ":", priv->port, "/soap", NULL);
	service->url->passwd = NULL;


	while (!authenticated) {
	
		if (!service->url->passwd && !(store->flags & CAMEL_STORE_PROXY)) {
			char *prompt;

			prompt = camel_session_build_password_prompt (
				"GroupWise", service->url->user, service->url->host);
			service->url->passwd =
				camel_session_get_password (session, service, "Groupwise",
							    prompt, "password", CAMEL_SESSION_PASSWORD_SECRET, ex);
			g_free (prompt);

			if (!service->url->passwd) {
				camel_exception_set (ex, CAMEL_EXCEPTION_USER_CANCEL,
						     _("You did not enter a password."));
				return FALSE;
			}
		}

		priv->cnc = e_gw_connection_new_with_error_handler (uri, priv->user, service->url->passwd, &errors);
		if (!E_IS_GW_CONNECTION(priv->cnc) && priv->use_ssl && g_str_equal (priv->use_ssl, "when-possible")) {
			char *http_uri = g_strconcat ("http://", uri + 8, NULL);
			priv->cnc = e_gw_connection_new (http_uri, priv->user, service->url->passwd);
			g_free (http_uri);
		}
		if (!E_IS_GW_CONNECTION(priv->cnc)) {
			if (errors.status == E_GW_CONNECTION_STATUS_INVALID_PASSWORD) {
				/* We need to un-cache the password before prompting again */
				camel_session_forget_password (session, service, "Groupwise", "password", ex);
				g_free (service->url->passwd);
				service->url->passwd = NULL;
				camel_exception_clear (ex);
			} else {
				camel_exception_set (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE, g_strdup (errors.description));
				return FALSE;
			}
		} else
			authenticated = TRUE;

	}

	return TRUE;
}
Exemplo n.º 27
0
/* this should probably take a folder instead of a session ... */
void
test_folder_message_ops (CamelSession *session,
                         const gchar *name,
                         gint local,
                         const gchar *mailbox)
{
	CamelStore *store;
	CamelService *service;
	CamelFolder *folder;
	CamelMimeMessage *msg;
	gint j;
	gint indexed, max;
	GPtrArray *uids;
	CamelMessageInfo *info;
	GError *error = NULL;

	max = local ? 2 : 1;

	for (indexed = 0; indexed < max; indexed++) {
		gchar *what = g_strdup_printf ("folder ops: %s %s", name, local ? (indexed?"indexed":"non-indexed"):"");
		gint flags;

		camel_test_start (what);
		test_free (what);

		push ("getting store");
		service = camel_session_add_service (
			session, name, name, CAMEL_PROVIDER_STORE, &error);
		check_msg (error == NULL, "adding store: %s", error->message);
		check (CAMEL_IS_STORE (service));
		store = CAMEL_STORE (service);
		g_clear_error (&error);
		pull ();

		push ("creating %sindexed folder", indexed?"":"non-");
		if (indexed)
			flags = CAMEL_STORE_FOLDER_CREATE | CAMEL_STORE_FOLDER_BODY_INDEX;
		else
			flags = CAMEL_STORE_FOLDER_CREATE;
		folder = camel_store_get_folder_sync (
			store, mailbox, flags, NULL, &error);

		/* we can't create mailbox outside of namespace, since we have no api for it, try
		 * using inbox namespace, works for courier */
		if (folder == NULL) {
			gchar *mbox = g_strdup_printf ("INBOX/%s", mailbox);
			mailbox = mbox;
			g_clear_error (&error);
			folder = camel_store_get_folder_sync (
				store, mailbox, flags, NULL, &error);
		}

		check_msg (error == NULL, "%s", error->message);
		check (folder != NULL);

		/* verify empty/can't get nonexistant stuff */
		test_folder_counts (folder, 0, 0);
		test_folder_not_message (folder, "0");
		test_folder_not_message (folder, "");

		for (j = 0; j < 10; j++) {
			gchar *content, *subject;

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

			push ("appending simple message %d", j);
			camel_folder_append_message_sync (
				folder, msg, NULL, NULL, NULL, &error);
			check_msg (error == NULL, "%s", error->message);

#if 0
			/* sigh, this shouldn't be required, but the imap code is too dumb to do it itself */
			if (!local) {
				push ("forcing a refresh of folder updates");
				camel_folder_refresh_info (folder, ex);
				check_msg (error == NULL, "%s", error->message);
				pull ();
			}
#endif
			/*if (!local)
			  camel_test_nonfatal ("unread counts dont seem right for imap");*/

			test_folder_counts (folder, j + 1, j + 1);

			/*if (!local)
			  camel_test_fatal ();*/

			push ("checking it is in the right uid slot & exists");
			uids = camel_folder_get_uids (folder);
			check (uids != NULL);
			check (uids->len == j + 1);
			if (uids->len > j)
				test_folder_message (folder, uids->pdata[j]);
			pull ();

			push ("checking it is the right message (subject): %s", subject);
			if (uids->len > j) {
				info = camel_folder_get_message_info (folder, uids->pdata[j]);
				check (info != NULL);
				check_msg (
					strcmp (camel_message_info_get_subject (info), subject) == 0,
					"info->subject %s", camel_message_info_get_subject (info));
				camel_message_info_unref (info);
			}
			camel_folder_free_uids (folder, uids);
			pull ();

			test_free (subject);

			/*if (!local)
			  camel_test_fatal ();*/

			check_unref (msg, 1);
			pull ();
		}

		if (local)
			check_unref (folder, 1);
		else
			check_unref (folder, 2);
		pull ();

#if 0
		push ("deleting test folder, with messages in it");
		camel_store_delete_folder (store, mailbox, ex);
		check (camel_exception_is_set (ex));
		camel_exception_clear (ex);
		pull ();
#endif

		push ("re-opening folder");
		folder = camel_store_get_folder_sync (
			store, mailbox, flags, NULL, &error);
		check_msg (error == NULL, "%s", error->message);
		check (folder != NULL);
		g_clear_error (&error);

			/* verify counts */
		test_folder_counts (folder, 10, 10);

		/* re-check uid's, after a reload */
		uids = camel_folder_get_uids (folder);
		check (uids != NULL);
		check (uids->len == 10);
		for (j = 0; j < 10; j++) {
			gchar *subject = g_strdup_printf ("Test message %d", j);

			push ("verify reload of %s", subject);
			test_folder_message (folder, uids->pdata[j]);

			info = camel_folder_get_message_info (folder, uids->pdata[j]);
			check_msg (
				strcmp (camel_message_info_get_subject (info), subject) == 0,
				"info->subject %s", camel_message_info_get_subject (info));
			test_free (subject);
			camel_message_info_unref (info);
			pull ();
		}

		push ("deleting first message & expunging");
		camel_folder_delete_message (folder, uids->pdata[0]);
		test_folder_counts (folder, 10, 9);
		camel_folder_expunge_sync (folder, NULL, &error);
		check_msg (error == NULL, "%s", error->message);
		g_clear_error (&error);
		test_folder_not_message (folder, uids->pdata[0]);
		test_folder_counts (folder, 9, 9);

		camel_folder_free_uids (folder, uids);

		uids = camel_folder_get_uids (folder);
		check (uids != NULL);
		check (uids->len == 9);
		for (j = 0; j < 9; j++) {
			gchar *subject = g_strdup_printf ("Test message %d", j + 1);

			push ("verify after expunge of %s", subject);
			test_folder_message (folder, uids->pdata[j]);

			info = camel_folder_get_message_info (folder, uids->pdata[j]);
			check_msg (
				strcmp (camel_message_info_get_subject (info), subject) == 0,
				"info->subject %s", camel_message_info_get_subject (info));
			test_free (subject);
			camel_message_info_unref (info);
			pull ();
		}
		pull ();

		push ("deleting last message & expunging");
		camel_folder_delete_message (folder, uids->pdata[8]);
		/* sync? */
		test_folder_counts (folder, 9, 8);
		camel_folder_expunge_sync (folder, NULL, &error);
		check_msg (error == NULL, "%s", error->message);
		g_clear_error (&error);
		test_folder_not_message (folder, uids->pdata[8]);
		test_folder_counts (folder, 8, 8);

		camel_folder_free_uids (folder, uids);

		uids = camel_folder_get_uids (folder);
		check (uids != NULL);
		check (uids->len == 8);
		for (j = 0; j < 8; j++) {
			gchar *subject = g_strdup_printf ("Test message %d", j + 1);

			push ("verify after expunge of %s", subject);
			test_folder_message (folder, uids->pdata[j]);

			info = camel_folder_get_message_info (folder, uids->pdata[j]);
			check_msg (
				strcmp (camel_message_info_get_subject (info), subject) == 0,
				"info->subject %s", camel_message_info_get_subject (info));
			test_free (subject);
			camel_message_info_unref (info);
			pull ();
		}
		pull ();

		push ("deleting all messages & expunging");
		for (j = 0; j < 8; j++) {
			camel_folder_delete_message (folder, uids->pdata[j]);
		}
		/* sync? */
		test_folder_counts (folder, 8, 0);
		camel_folder_expunge_sync (folder, NULL, &error);
		check_msg (error == NULL, "%s", error->message);
		g_clear_error (&error);
		for (j = 0; j < 8; j++) {
			test_folder_not_message (folder, uids->pdata[j]);
		}
		test_folder_counts (folder, 0, 0);

		camel_folder_free_uids (folder, uids);
		pull ();

		if (local)
			check_unref (folder, 1);
		else
			check_unref (folder, 2);
		pull (); /* re-opening folder */

		if (g_ascii_strcasecmp (mailbox, "INBOX") != 0) {
			push ("deleting test folder, with no messages in it");
			camel_store_delete_folder_sync (
				store, mailbox, NULL, &error);
			check_msg (error == NULL, "%s", error->message);
			g_clear_error (&error);
			pull ();
		}

		if (!local) {
			push ("disconneect service");
			camel_service_disconnect_sync (
				CAMEL_SERVICE (store), TRUE, NULL, &error);
			check_msg (error == NULL, "%s", error->message);
			g_clear_error (&error);
			pull ();
		}

		check_unref (store, 1);
		camel_test_end ();
	}
}
static void
groupwise_store_construct (CamelService *service, CamelSession *session,
			   CamelProvider *provider, CamelURL *url,
			   CamelException *ex)
{
	CamelGroupwiseStore *groupwise_store = CAMEL_GROUPWISE_STORE (service);
	CamelStore *store = CAMEL_STORE (service);
	const char *property_value;
	CamelGroupwiseStorePrivate *priv = groupwise_store->priv;
	char *path = NULL;

	d(printf ("\nin groupwise store constrcut\n"));

	CAMEL_SERVICE_CLASS (parent_class)->construct (service, session, provider, url, ex);
	if (camel_exception_is_set (ex))
		return;

	if (!(url->host || url->user)) {
		camel_exception_set (ex, CAMEL_EXCEPTION_SERVICE_INVALID,
				     _("Host or user not available in url"));
	}

	/*XXX: The number 3 assigned to the list_loaded variable denotes
	 * the number of times the get_folder_info is called during startup.
	 * We are just trying to minimize the call.
	 * This is a dirty hack. But it *WORKS*
	 */
	groupwise_store->list_loaded = 3;

	/*storage path*/
	priv->storage_path = camel_session_get_storage_path (session, service, ex);
	if (!priv->storage_path)
		return;

	/*store summary*/
	path = g_alloca (strlen (priv->storage_path) + 32);
	sprintf (path, "%s/.summary", priv->storage_path);
	groupwise_store->summary = camel_groupwise_store_summary_new ();
	camel_store_summary_set_filename ((CamelStoreSummary *)groupwise_store->summary, path);
	camel_store_summary_touch ((CamelStoreSummary *)groupwise_store->summary);
	camel_store_summary_load ((CamelStoreSummary *) groupwise_store->summary);

	/*host and user*/
	priv->server_name = g_strdup (url->host);
	priv->user = g_strdup (url->user);

	/*base url*/
	priv->base_url = camel_url_to_string (service->url, (CAMEL_URL_HIDE_PASSWORD |
						       CAMEL_URL_HIDE_PARAMS   |
						       CAMEL_URL_HIDE_AUTH)  );

	/*soap port*/
	property_value =  camel_url_get_param (url, "soap_port");
	if (property_value == NULL)
		priv->port = g_strdup ("7191");
	else if(strlen(property_value) == 0)
		priv->port = g_strdup ("7191");
	else
		priv->port = g_strdup (property_value);

	/*filter*/
	if (camel_url_get_param (url, "filter"))
		store->flags |= CAMEL_STORE_FILTER_INBOX;

	/*Hash Table*/
	priv->id_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
	priv->name_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
	priv->parent_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);

	/*ssl*/
	priv->use_ssl = g_strdup (camel_url_get_param (url, "use_ssl"));

	store->flags &= ~CAMEL_STORE_VJUNK;
	store->flags &= ~CAMEL_STORE_VTRASH;
}
Exemplo n.º 29
0
gint main (gint argc, gchar **argv)
{
	CamelSession *session;
	gint i, j, index;
	gchar *path;
	CamelStore *store;
	CamelService *service;
	GThread *threads[MAX_THREADS];
	struct _threadinfo *info;
	CamelFolder *folder;
	GPtrArray *uids;
	GError *error = NULL;

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

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

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

	for (j = 0; j < G_N_ELEMENTS (local_providers); j++) {
		for (index = 0; index < 2; index++) {
			gchar *uid;

			path = g_strdup_printf ("method %s %s", local_providers[j], index?"indexed":"nonindexed");
			camel_test_start (path);
			test_free (path);

			push ("trying %s index %d", local_providers[j], index);
			uid = g_strdup_printf ("test-uid-%d", j);
			path = g_strdup_printf ("%s:///tmp/camel-test/%s", local_providers[j], local_providers[j]);
			service = camel_session_add_service (
				session, uid, path,
				CAMEL_PROVIDER_STORE, &error);
			g_free (uid);
			check_msg (error == NULL, "%s", error->message);
			check (CAMEL_IS_STORE (service));
			store = CAMEL_STORE (service);
			test_free (path);

			if (index == 0)
				folder = camel_store_get_folder_sync (
					store, "testbox",
					CAMEL_STORE_FOLDER_CREATE,
					NULL, &error);
			else
				folder = camel_store_get_folder_sync (
					store, "testbox",
					CAMEL_STORE_FOLDER_CREATE |
					CAMEL_STORE_FOLDER_BODY_INDEX,
					NULL, &error);
			check_msg (error == NULL, "%s", error->message);
			g_clear_error (&error);

			for (i = 0; i < MAX_THREADS; i++) {
				GError *error = NULL;

				info = g_malloc (sizeof (*info));
				info->id = i * MAX_MESSAGES;
				info->folder = folder;

				threads[i] = g_thread_try_new (NULL, worker, info, &error);
				check_msg (error == NULL, "g_thread_try_new() failed: %s", error->message);
			}

			for (i = 0; i < MAX_THREADS; i++) {
				if (threads[i]) {
					info = g_thread_join (threads[i]);
					g_free (info);
				}
			}
			pull ();

			push ("deleting remaining messages");
			uids = camel_folder_get_uids (folder);
			for (i = 0; i < uids->len; i++) {
				camel_folder_delete_message (folder, uids->pdata[i]);
			}
			camel_folder_free_uids (folder, uids);

			camel_folder_expunge_sync (folder, NULL, &error);
			check_msg (error == NULL, "%s", error->message);

			check_unref (folder, 1);

			camel_store_delete_folder_sync (
				store, "testbox", NULL, &error);
			check_msg (error == NULL, "%s", error->message);
			g_clear_error (&error);

			check_unref (store, 1);

			pull ();

			camel_test_end ();
		}
	}

	g_object_unref (session);

	return 0;
}
Exemplo n.º 30
0
gint
main (gint argc,
      gchar *argv[])
{
	CamelSession *session;
	CamelService *service;
	ESourceRegistry *registry;
	GList *list, *link;
	const gchar *extension_name;

	g_type_init ();
	
	system ("rm -rf /tmp/test-map");
	camel_init ("/tmp/test-map", TRUE);
	e_source_camel_register_types ();

	session = g_object_new (
		CAMEL_TYPE_SESSION,
		"user-data-dir", "/tmp/test-map", 
		"user-cache-dir", "/tmp/test-map/cache", NULL);


	/* Browse through the ESource registry to find out the MAP account */
	registry = e_source_registry_new_sync (NULL, NULL);
	extension_name = E_SOURCE_EXTENSION_MAIL_ACCOUNT;
	list = e_source_registry_list_sources (registry, extension_name);

	for (link = list; link != NULL; link = g_list_next (link)) {
		ESource *source = E_SOURCE (link->data);
		const gchar *uid;
		const gchar *backend_name = "INVALID";
		const gchar *display_name;
		ESourceBackend *extension;
		
		if (!e_source_get_enabled (source))
			continue;
		uid = e_source_get_uid (source);
		display_name = e_source_get_display_name (source);
		printf("Looking for: %s\n", display_name);

		extension = e_source_get_extension (source, extension_name);
		backend_name = e_source_backend_get_backend_name (extension);

		if (strcmp (backend_name, "map") == 0) {
			/* Lets add just map backend to the session. */
			CamelFolderInfo *info;
			CamelFolder *folder;
			GPtrArray *uids;
			int i;
			GError *error=NULL;
			service = camel_session_add_service (
				CAMEL_SESSION (session), uid,
				backend_name, CAMEL_PROVIDER_STORE, NULL);
			e_source_camel_configure_service (source, service);
			camel_service_connect_sync (service, NULL, NULL);
			info = camel_store_get_folder_info_sync (
				CAMEL_STORE (service), "", 0, NULL, NULL);
			print_folder_info (info, 0);
			folder = camel_store_get_folder_sync (
				CAMEL_STORE (service), "inbox", 0, NULL, NULL);
			camel_folder_refresh_info_sync (folder, NULL, &error);
			if (error)
				printf("Refresh info failed: %s\n", error->message);

			uids = camel_folder_get_uids (folder);
			printf("Length of messages: %p %d\n", folder, uids->len);
			for (i=0; i<uids->len; i++)
				printf("UID: %s\n", (char *)uids->pdata[i]);
		}
		


	}
	
	return 0;
}