folder_tree_model_sort (GtkTreeModel *model,
			GtkTreeIter *a,
			GtkTreeIter *b,
			gpointer unused)
{
	gchar *aname, *bname;
	guint32 aflags, bflags;
	gint ret = -2;

	gtk_tree_model_get (
		model, a,
		COL_FOLDER_NAME, &aname,
		COL_FOLDER_FLAGS, &aflags,
		-1);

	gtk_tree_model_get (
		model, b,
		COL_FOLDER_NAME, &bname,
		COL_FOLDER_FLAGS, &bflags,
		-1);

	/* Inbox is always first. */
	if ((aflags & CAMEL_FOLDER_TYPE_MASK) == CAMEL_FOLDER_TYPE_INBOX)
		ret = -1;
	else if ((bflags & CAMEL_FOLDER_TYPE_MASK) == CAMEL_FOLDER_TYPE_INBOX)
		ret = 1;
	else {
		if (aname != NULL && bname != NULL)
			ret = g_utf8_collate (aname, bname);
		else if (aname == bname)
			ret = 0;
		else if (aname == NULL)
			ret = -1;
		else
			ret = 1;
	}

	g_free (aname);
	g_free (bname);

	return ret;
}
folder_tree_model_sort (GtkTreeModel *model,
			GtkTreeIter *a,
			GtkTreeIter *b,
			gpointer unused)
{
	gchar *aname, *bname;
	guint32 aflags, bflags;
	gint ret = -2;

	gtk_tree_model_get (
		model, a,
		COL_FOLDER_NAME, &aname,
		COL_FOLDER_FLAGS, &aflags,
		-1);

	gtk_tree_model_get (
		model, b,
		COL_FOLDER_NAME, &bname,
		COL_FOLDER_FLAGS, &bflags,
		-1);

	 
	if ((aflags & CAMEL_FOLDER_TYPE_MASK) == CAMEL_FOLDER_TYPE_INBOX)
		ret = -1;
	else if ((bflags & CAMEL_FOLDER_TYPE_MASK) == CAMEL_FOLDER_TYPE_INBOX)
		ret = 1;
	else {
		if (aname != NULL && bname != NULL)
			ret = g_utf8_collate (aname, bname);
		else if (aname == bname)
			ret = 0;
		else if (aname == NULL)
			ret = -1;
		else
			ret = 1;
	}

	g_free (aname);
	g_free (bname);

	return ret;
}