NeoMutt  2025-01-09-117-gace867
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
path.c File Reference

Maildir Path handling. More...

#include "config.h"
#include <dirent.h>
#include <limits.h>
#include <stdbool.h>
#include <stdio.h>
#include <sys/stat.h>
#include "mutt/lib.h"
#include "path.h"
+ Include dependency graph for path.c:

Go to the source code of this file.

Functions

int maildir_path_canon (struct Buffer *path)
 Canonicalise a Mailbox path - Implements MxOps::path_canon() -.
 
int maildir_path_is_empty (struct Buffer *path)
 Is the mailbox empty.
 
enum MailboxType maildir_path_probe (const char *path, const struct stat *st)
 Is this a Maildir Mailbox? - Implements MxOps::path_probe() -.
 

Detailed Description

Maildir Path handling.

Authors
  • Richard Russon

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file path.c.

Function Documentation

◆ maildir_path_is_empty()

int maildir_path_is_empty ( struct Buffer path)

Is the mailbox empty.

Parameters
pathMailbox to check
Return values
1Mailbox is empty
0Mailbox contains mail
-1Error

Definition at line 56 of file path.c.

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}
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:96
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
#define PATH_MAX
Definition: mutt.h:42
+ Here is the call graph for this function: