NeoMutt  2024-11-14-34-g5aaf0d
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 "globals.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 57 of file path.c.

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}
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:642
@ 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: