NeoMutt  2025-01-09-117-gace867
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
path.c
Go to the documentation of this file.
1
29#include "config.h"
30#include <dirent.h>
31#include <limits.h>
32#include <stdbool.h>
33#include <stdio.h>
34#include <sys/stat.h>
35#include "mutt/lib.h"
36#include "path.h"
37
38// Mailbox API -----------------------------------------------------------------
39
43int maildir_path_canon(struct Buffer *path)
44{
45 mutt_path_canon(path, NeoMutt->home_dir, true);
46 return 0;
47}
48
57{
58 DIR *dir = NULL;
59 struct dirent *de = NULL;
60 int rc = 1; /* assume empty until we find a message */
61 char realpath[PATH_MAX] = { 0 };
62 int iter = 0;
63
64 /* Strategy here is to look for any file not beginning with a period */
65
66 do
67 {
68 /* we do "cur" on the first iteration since it's more likely that we'll
69 * find old messages without having to scan both subdirs */
70 snprintf(realpath, sizeof(realpath), "%s/%s", buf_string(path),
71 (iter == 0) ? "cur" : "new");
73 if (!dir)
74 return -1;
75 while ((de = readdir(dir)))
76 {
77 if (*de->d_name != '.')
78 {
79 rc = 0;
80 break;
81 }
82 }
83 closedir(dir);
84 iter++;
85 } while (rc && iter < 2);
86
87 return rc;
88}
89
93enum MailboxType maildir_path_probe(const char *path, const struct stat *st)
94{
95 if (!st || !S_ISDIR(st->st_mode))
96 return MUTT_UNKNOWN;
97
98 char sub[PATH_MAX] = { 0 };
99 struct stat stsub = { 0 };
100 char *subs[] = { "cur", "new" };
101 for (size_t i = 0; i < mutt_array_size(subs); i++)
102 {
103 snprintf(sub, sizeof(sub), "%s/%s", path, subs[i]);
104 if ((stat(sub, &stsub) == 0) && S_ISDIR(stsub.st_mode))
105 return MUTT_MAILDIR;
106 }
107
108 return MUTT_UNKNOWN;
109}
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:96
MailboxType
Supported mailbox formats.
Definition: mailbox.h:41
@ MUTT_UNKNOWN
Mailbox wasn't recognised.
Definition: mailbox.h:44
@ MUTT_MAILDIR
'Maildir' Mailbox type
Definition: mailbox.h:48
DIR * mutt_file_opendir(const char *path, enum MuttOpenDirMode mode)
Open a directory.
Definition: file.c:542
@ MUTT_OPENDIR_CREATE
Create the directory if it doesn't exist.
Definition: file.h:64
int maildir_path_canon(struct Buffer *path)
Canonicalise a Mailbox path - Implements MxOps::path_canon() -.
Definition: path.c:43
enum MailboxType maildir_path_probe(const char *path, const struct stat *st)
Is this a Maildir Mailbox? - Implements MxOps::path_probe() -.
Definition: path.c:93
int maildir_path_is_empty(struct Buffer *path)
Is the mailbox empty.
Definition: path.c:56
#define mutt_array_size(x)
Definition: memory.h:38
Convenience wrapper for the library headers.
bool mutt_path_canon(struct Buffer *path, const char *homedir, bool is_dir)
Create the canonical version of a path.
Definition: path.c:248
Path manipulation functions.
#define PATH_MAX
Definition: mutt.h:42
String manipulation buffer.
Definition: buffer.h:36
Container for Accounts, Notifications.
Definition: neomutt.h:43
char * home_dir
User's home directory.
Definition: neomutt.h:53