NeoMutt
2025-12-11-1039-g550ac6
Teaching an old dog new tricks
DOXYGEN
Toggle main menu visibility
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
44
int
maildir_path_canon
(
struct
Buffer
*path)
45
{
46
mutt_path_canon
(path,
NeoMutt
->
home_dir
,
true
);
47
return
0;
48
}
49
57
int
maildir_path_is_empty
(
struct
Buffer
*path)
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"
);
73
dir =
mutt_file_opendir
(realpath,
MUTT_OPENDIR_CREATE
);
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
94
enum
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"
,
"tmp"
};
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_UNKNOWN
;
107
}
108
109
return
MUTT_MAILDIR
;
110
}
buf_string
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition
buffer.h:96
MailboxType
MailboxType
Supported mailbox formats.
Definition
mailbox.h:40
MUTT_UNKNOWN
@ MUTT_UNKNOWN
Mailbox wasn't recognised.
Definition
mailbox.h:43
MUTT_MAILDIR
@ MUTT_MAILDIR
'Maildir' Mailbox type
Definition
mailbox.h:47
mutt_file_opendir
DIR * mutt_file_opendir(const char *path, enum MuttOpenDirMode mode)
Open a directory.
Definition
file.c:535
MUTT_OPENDIR_CREATE
@ MUTT_OPENDIR_CREATE
Create the directory if it doesn't exist.
Definition
file.h:69
maildir_path_canon
int maildir_path_canon(struct Buffer *path)
Canonicalise a Mailbox path - Implements MxOps::path_canon() -.
Definition
path.c:44
maildir_path_probe
enum MailboxType maildir_path_probe(const char *path, const struct stat *st)
Is this a Maildir Mailbox?
Definition
path.c:94
maildir_path_is_empty
int maildir_path_is_empty(struct Buffer *path)
Is the mailbox empty.
Definition
path.c:57
path.h
Maildir Path handling.
countof
#define countof(x)
Definition
memory.h:49
lib.h
Convenience wrapper for the library headers.
mutt_path_canon
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_MAX
#define PATH_MAX
Definition
mutt.h:49
Buffer
String manipulation buffer.
Definition
buffer.h:36
NeoMutt
Container for Accounts, Notifications.
Definition
neomutt.h:41
NeoMutt::home_dir
char * home_dir
User's home directory.
Definition
neomutt.h:55