コード例 #1
0
static send_info_t
get_receive_type (CamelService *service)
{
	CamelProvider *provider;
	CamelURL *url;
	const gchar *uid;
	gboolean is_local_delivery;

	/* Disregard CamelNullStores. */
	if (CAMEL_IS_NULL_STORE (service))
		return SEND_INVALID;

	url = camel_service_new_camel_url (service);
	is_local_delivery = em_utils_is_local_delivery_mbox_file (url);
	camel_url_free (url);

	/* mbox pointing to a file is a 'Local delivery'
	 * source which requires special processing. */
	if (is_local_delivery)
		return SEND_RECEIVE;

	provider = camel_service_get_provider (service);

	if (!provider)
		return SEND_INVALID;

	/* skip some well-known services */
	uid = camel_service_get_uid (service);
	if (g_strcmp0 (uid, E_MAIL_SESSION_LOCAL_UID) == 0)
		return SEND_INVALID;
	if (g_strcmp0 (uid, E_MAIL_SESSION_VFOLDER_UID) == 0)
 		return SEND_INVALID;

	if (provider->object_types[CAMEL_PROVIDER_STORE]) {
		if (provider->flags & CAMEL_PROVIDER_IS_STORAGE)
			return SEND_UPDATE;
		else
			return SEND_RECEIVE;
	}

	if (provider->object_types[CAMEL_PROVIDER_TRANSPORT])
		return SEND_SEND;

	return SEND_INVALID;
}
コード例 #2
0
ファイル: e-mail-store.c プロジェクト: jdapena/evolution
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;
}