mirror of https://github.com/djcb/mu.git
* mu-config,mu-util.[ch]: try MAILDIR, they ~/Maildir as a guess for the maildir
This commit is contained in:
parent
1e2054d19b
commit
b48e44f7c9
|
@ -105,6 +105,8 @@ mu_config_options_group_query (MuConfigOptions *opts)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
mu_config_init (MuConfigOptions *opts)
|
mu_config_init (MuConfigOptions *opts)
|
||||||
{
|
{
|
||||||
|
@ -120,8 +122,9 @@ mu_config_init (MuConfigOptions *opts)
|
||||||
opts->log_append = TRUE;
|
opts->log_append = TRUE;
|
||||||
opts->log_stderr = FALSE;
|
opts->log_stderr = FALSE;
|
||||||
|
|
||||||
/* indexing */
|
/* indexing */
|
||||||
opts->maildir = mu_util_dir_expand ("~/Maildir");
|
opts->maildir = mu_util_guess_maildir ();
|
||||||
|
|
||||||
opts->cleanup = FALSE;
|
opts->cleanup = FALSE;
|
||||||
opts->reindex = FALSE;
|
opts->reindex = FALSE;
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,11 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
|
||||||
#include "mu-util.h"
|
#include "mu-util.h"
|
||||||
|
|
||||||
char*
|
char*
|
||||||
|
@ -76,3 +81,34 @@ mu_util_strlist_free (GSList *lst)
|
||||||
g_slist_foreach (lst, (GFunc)g_free, NULL);
|
g_slist_foreach (lst, (GFunc)g_free, NULL);
|
||||||
g_slist_free (lst);
|
g_slist_free (lst);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
_is_readable_dir (const gchar* path)
|
||||||
|
{
|
||||||
|
struct stat statbuf;
|
||||||
|
|
||||||
|
return path &&
|
||||||
|
access (path, F_OK) &&
|
||||||
|
stat (path, &statbuf) == 0 &&
|
||||||
|
S_ISDIR(statbuf.st_mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
gchar*
|
||||||
|
mu_util_guess_maildir (void)
|
||||||
|
{
|
||||||
|
char *dir;
|
||||||
|
|
||||||
|
/* first, try MAILDIR */
|
||||||
|
dir = getenv ("MAILDIR");
|
||||||
|
if (_is_readable_dir (dir))
|
||||||
|
return g_strdup (dir);
|
||||||
|
|
||||||
|
/* then, try ~/Maildir */
|
||||||
|
dir = mu_util_dir_expand ("~/Maildir");
|
||||||
|
if (_is_readable_dir (dir))
|
||||||
|
return dir;
|
||||||
|
|
||||||
|
/* nope; nothing found */
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
|
@ -35,6 +35,15 @@ G_BEGIN_DECLS
|
||||||
char* mu_util_dir_expand (const char* path);
|
char* mu_util_dir_expand (const char* path);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* guess the maildir; first try MAILDIR, then try ~/Maildir
|
||||||
|
* if both fail, return NULL
|
||||||
|
*
|
||||||
|
* @return full path of the guessed Maildir, or NULL; must be freed (gfree)
|
||||||
|
*/
|
||||||
|
char* mu_util_guess_maildir (void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* take a char*[] and turn it into a GSList
|
* take a char*[] and turn it into a GSList
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue