Пример #1
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);
}
Пример #2
0
/* FIXME: This should be a property on CamelFolder */
char *
mail_tools_folder_to_url (CamelFolder *folder)
{
	CamelURL *url;
	char *out;

	g_return_val_if_fail (CAMEL_IS_FOLDER (folder), NULL);

	url = camel_url_copy(((CamelService *)folder->parent_store)->url);
	if (((CamelService *)folder->parent_store)->provider->url_flags  & CAMEL_URL_FRAGMENT_IS_PATH) {
		camel_url_set_fragment(url, folder->full_name);
	} else {
		char *name = g_alloca(strlen(folder->full_name)+2);

		sprintf(name, "/%s", folder->full_name);
		camel_url_set_path(url, name);
	}

	out = camel_url_to_string(url, CAMEL_URL_HIDE_ALL);
	camel_url_free(url);

	return out;
}
ECalComponent*
kolab_cal_util_fb_new_ecalcomp_from_request (KolabUtilHttpJob *job,
                                             Kolab_conv_freebusy_type listtype,
                                             GError **err)
{
	CamelURL *camel_url = NULL;
	gchar *url_string = NULL;
	gchar *servername = NULL;
	gboolean use_ssl = FALSE;
	gssize nbytes = 0;
	ECalComponent *ecalcomp = NULL;
	GError *tmp_err = NULL;

	/* preconditions */
	g_assert (job != NULL);
	g_assert (job->buffer == NULL);
	g_return_val_if_fail (err == NULL || *err == NULL, NULL);

	url_string = camel_url_to_string (job->url, 0);
	g_assert (url_string != NULL);

	servername = g_strdup (job->url->host);
	use_ssl = kolab_util_http_protocol_is_ssl (url_string);

	g_free (url_string);

	url_string = kolabconv_cal_util_freebusy_new_fb_url (servername,
	                                                     job->url->user,
	                                                     use_ssl,
	                                                     listtype);
	g_assert (url_string != NULL);
	g_debug ("%s: \n\t\t\t\t%s", __func__, url_string);

	/* FIXME create a new extended CamelURL from url_string
	 *
	 * - merge the old and the new CamelURL
	 * - pay attention to passwd,authmech,... set
	 *   on the original CamelURL
	 *
	 */
	camel_url = camel_url_new (url_string, NULL);
	g_assert (camel_url != NULL);
	g_free (url_string);
	camel_url_set_user (camel_url, job->url->user);
	/* TODO authmech ? */

	camel_url_set_port (camel_url, job->url->port);
	if (job->url->query) camel_url_set_query (camel_url, job->url->query);
	if (job->url->fragment) camel_url_set_fragment (camel_url, job->url->fragment);
	camel_url_free (job->url);
	job->url = camel_url;

	job->buffer = g_byte_array_new ();
	g_assert (job->buffer != NULL);

	/* issue HTTP GET request */
	nbytes = kolab_util_http_get (job, &tmp_err);
	if (tmp_err != NULL)
		goto skip;

	job->nbytes = nbytes; /* save number of bytes read since buffer will be destroyed */
	g_debug ("%s: read %d bytes", __func__, nbytes);

	/* create new ECalComponent */
	ecalcomp = kolabconv_cal_util_freebusy_ecalcomp_new_from_ics ((gchar*)(job->buffer->data),
	                                                              nbytes,
	                                                              &tmp_err);
 skip:
	if ((ecalcomp == NULL) && (tmp_err != NULL))
		g_propagate_error (err, tmp_err);

	g_byte_array_unref (job->buffer);
	job->buffer = NULL;
	g_free (servername);

	/* postconditions */
	g_assert (job->buffer == NULL);

	return ecalcomp;
}
static CamelFolderInfo *
scan_dir (CamelStore *store, CamelURL *url, GHashTable *visited, CamelFolderInfo *parent, const gchar *root,
	 const gchar *name, guint32 flags, GError **error)
{
	CamelFolderInfo *folders, *tail, *fi;
	GHashTable *folder_hash;
	const gchar *dent;
	GDir *dir;

	tail = folders = NULL;

	if (!(dir = g_dir_open (root, 0, NULL)))
		return NULL;

	folder_hash = g_hash_table_new (g_str_hash, g_str_equal);

	/* FIXME: it would be better if we queue'd up the recursive
	 * scans till the end so that we can limit the number of
	 * directory descriptors open at any given time... */

	while ((dent = g_dir_read_name (dir))) {
		gchar *short_name, *full_name, *path, *ext;
		struct stat st;

		if (dent[0] == '.')
			continue;

		if (ignore_file (dent, FALSE))
			continue;

		path = g_strdup_printf("%s/%s", root, dent);
		if (g_stat (path, &st) == -1) {
			g_free (path);
			continue;
		}
#ifndef G_OS_WIN32
		if (S_ISDIR (st.st_mode)) {
			struct _inode in = { st.st_dev, st.st_ino };

			if (g_hash_table_lookup (visited, &in)) {
				g_free (path);
				continue;
			}
		}
#endif
		short_name = g_strdup (dent);
		if ((ext = strrchr(short_name, '.')) && !strcmp(ext, ".sbd"))
			*ext = '\0';

		if (name != NULL)
			full_name = g_strdup_printf("%s/%s", name, short_name);
		else
			full_name = g_strdup (short_name);

		if ((fi = g_hash_table_lookup (folder_hash, short_name)) != NULL) {
			g_free (short_name);
			g_free (full_name);

			if (S_ISDIR (st.st_mode)) {
				fi->flags =(fi->flags & ~CAMEL_FOLDER_NOCHILDREN) | CAMEL_FOLDER_CHILDREN;
			} else {
				fi->flags &= ~CAMEL_FOLDER_NOSELECT;
			}
		} else {
			fi = camel_folder_info_new ();
			fi->parent = parent;

			camel_url_set_fragment (url, full_name);

			fi->uri = camel_url_to_string (url, 0);
			fi->name = short_name;
			fi->full_name = full_name;
			fi->unread = -1;
			fi->total = -1;

			if (S_ISDIR (st.st_mode))
				fi->flags = CAMEL_FOLDER_NOSELECT;
			else
				fi->flags = CAMEL_FOLDER_NOCHILDREN;

			if (tail == NULL)
				folders = fi;
			else
				tail->next = fi;

			tail = fi;

			g_hash_table_insert (folder_hash, fi->name, fi);
		}

		if (!S_ISDIR (st.st_mode)) {
			fill_fi (store, fi, flags);
		} else if ((flags & CAMEL_STORE_FOLDER_INFO_RECURSIVE)) {
			struct _inode in = { st.st_dev, st.st_ino };

			if (g_hash_table_lookup (visited, &in) == NULL) {
#ifndef G_OS_WIN32
				struct _inode *inew = g_new (struct _inode, 1);

				*inew = in;
				g_hash_table_insert (visited, inew, inew);
#endif
				if ((fi->child = scan_dir (store, url, visited, fi, path, fi->full_name, flags, error)))
					fi->flags |= CAMEL_FOLDER_CHILDREN;
				else
					fi->flags =(fi->flags & ~CAMEL_FOLDER_CHILDREN) | CAMEL_FOLDER_NOCHILDREN;
			}
		}

		g_free (path);
	}

	g_dir_close (dir);

	g_hash_table_destroy (folder_hash);

	return folders;
}