Esempio n. 1
0
gchar*
mu_util_guess_maildir (void)
{
        const gchar *mdir1, *home;

        /* first, try MAILDIR */
        mdir1 = g_getenv ("MAILDIR");

        if (mdir1 && mu_util_check_dir (mdir1, TRUE, FALSE))
                return g_strdup (mdir1);

        /* then, try <home>/Maildir */
        home = g_get_home_dir();
        if (home) {
                char *mdir2;
                mdir2 = g_strdup_printf ("%s%cMaildir",
                        home, G_DIR_SEPARATOR);
                if (mu_util_check_dir (mdir2, TRUE, FALSE))
                        return mdir2;
                g_free (mdir2);
        }

        /* nope; nothing found */
        return NULL;
}
Esempio n. 2
0
MuError
mu_cmd_extract (MuConfig *opts, GError **err)
{
	int rv;

	g_return_val_if_fail (opts, MU_ERROR_INTERNAL);
	g_return_val_if_fail (opts->cmd == MU_CONFIG_CMD_EXTRACT,
			      MU_ERROR_INTERNAL);

	if (!check_params (opts)) {
		g_set_error (err, MU_ERROR_DOMAIN, MU_ERROR_IN_PARAMETERS,
				     "error in parameters");
		return MU_ERROR_IN_PARAMETERS;
	}

	if (!opts->params[2] && !opts->parts &&
	    !opts->save_attachments && !opts->save_all)
		rv = show_parts (opts->params[1], opts, err); /* show, don't save */
	else {
		rv = mu_util_check_dir(opts->targetdir, FALSE, TRUE);
		if (!rv)
			mu_util_g_set_error
				(err, MU_ERROR_FILE_CANNOT_WRITE,
				 "target '%s' is not a writable directory",
				 opts->targetdir);
		else
			rv = save_parts (opts->params[1],
					 opts->params[2],
					 opts); /* save */
	}

	return rv ? MU_OK : MU_ERROR;
}
Esempio n. 3
0
gchar*
mu_util_guess_maildir (void)
{
	const gchar *mdir1;
	gchar *mdir2;

	/* first, try MAILDIR */
	mdir1 = g_getenv ("MAILDIR");

	if (mdir1 && mu_util_check_dir (mdir1, TRUE, FALSE))
		return g_strdup (mdir1);

	/* then, try ~/Maildir */
	mdir2 = mu_util_dir_expand ("~/Maildir");
	if (mu_util_check_dir (mdir2, TRUE, FALSE))
		return mdir2;

	/* nope; nothing found */
	return NULL;
}
Esempio n. 4
0
static char*
get_checked_path (const char *path)
{
	char *cpath;

	cpath = mu_util_dir_expand(path);
	if (!cpath ||
	    !mu_util_check_dir (cpath, TRUE, FALSE)) {
		print_error (MU_ERROR_IN_PARAMETERS,
			     "not a readable dir: '%s'");
		g_free (cpath);
		return NULL;
	}

	return cpath;
}
Esempio n. 5
0
static GSList*
get_script_info_list (const char *muhome, GError **err)
{
	GSList *scripts, *userscripts, *last;
	char *userpath;

	scripts = mu_script_get_script_info_list
		(MU_SCRIPTS_DIR, MU_GUILE_EXT,
		 MU_GUILE_DESCR_PREFIX,
		 err);

	if (err && *err)
		return NULL;

	userpath = g_strdup_printf ("%s%c%s",
				    muhome, G_DIR_SEPARATOR,
				    "scripts" G_DIR_SEPARATOR_S "stats");

	/* is there are userdir for scripts? */
	if (!mu_util_check_dir (userpath, TRUE, FALSE)) {
		g_free (userpath);
		return scripts;
	}

	/* append it to the list we already have */
	userscripts = mu_script_get_script_info_list (userpath, MU_GUILE_EXT,
						      MU_GUILE_DESCR_PREFIX,
						      err);
	g_free (userpath);

	/* some error, return nothing */
	if (err && *err) {
		mu_script_info_list_destroy (userscripts);
		mu_script_info_list_destroy (scripts);
		return NULL;
	}

	/* append the user scripts */
	last = g_slist_last (scripts);
	if (last) {
		last->next = userscripts;
		return scripts;
	} else
		return userscripts; /* apparently, scripts was NULL */
}
Esempio n. 6
0
static gboolean
query_params_valid (MuConfig *opts, GError **err)
{
	const gchar *xpath;

	if (!opts->params[1]) {
		mu_util_g_set_error (err, MU_ERROR_IN_PARAMETERS,
				     "missing query");
		return FALSE;
	}

	xpath = mu_runtime_path (MU_RUNTIME_PATH_XAPIANDB);
	if (mu_util_check_dir (xpath, TRUE, FALSE))
		return TRUE;

	mu_util_g_set_error (err, MU_ERROR_FILE_CANNOT_READ,
			     "'%s' is not a readable Xapian directory",
			     xpath);
	return FALSE;
}