* mu-config,mu-util.[ch]: try MAILDIR, they ~/Maildir as a guess for the maildir

This commit is contained in:
Dirk-Jan C. Binnema
2009-12-09 19:53:30 +02:00
parent 1e2054d19b
commit b48e44f7c9
3 changed files with 50 additions and 2 deletions

View File

@ -23,6 +23,11 @@
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include "mu-util.h"
char*
@ -76,3 +81,34 @@ mu_util_strlist_free (GSList *lst)
g_slist_foreach (lst, (GFunc)g_free, NULL);
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;
}