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