NeoMutt  2025-12-11-694-ga89709
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
path_probe()

Does this Mailbox type recognise this path? More...

+ Collaboration diagram for path_probe():

Functions

static enum MailboxType comp_path_probe (const char *path, const struct stat *st)
 Is this a compressed Mailbox?
 
enum MailboxType imap_path_probe (const char *path, const struct stat *st)
 Is this an IMAP Mailbox?
 
enum MailboxType maildir_path_probe (const char *path, const struct stat *st)
 Is this a Maildir Mailbox?
 
enum MailboxType mbox_path_probe (const char *path, const struct stat *st)
 Is this an mbox Mailbox?
 
static enum MailboxType mh_path_probe (const char *path, const struct stat *st)
 Is this an mh Mailbox?
 
enum MailboxType nntp_path_probe (const char *path, const struct stat *st)
 Is this an NNTP Mailbox?
 
enum MailboxType nm_path_probe (const char *path, const struct stat *st)
 Is this a Notmuch Mailbox?
 
enum MailboxType pop_path_probe (const char *path, const struct stat *st)
 Is this a POP Mailbox?
 

Detailed Description

Does this Mailbox type recognise this path?

Parameters
pathPath to examine
ststat buffer (for local filesystems)
Return values
enumMailboxType, e.g. MUTT_IMAP
Precondition
path is not NULL

Function Documentation

◆ comp_path_probe()

static enum MailboxType comp_path_probe ( const char * path,
const struct stat * st )
static

Is this a compressed Mailbox?

Definition at line 864 of file compress.c.

865{
866 if (!st || !S_ISREG(st->st_mode))
867 return MUTT_UNKNOWN;
868
869 if (mutt_comp_can_read(path))
870 return MUTT_COMPRESSED;
871
872 return MUTT_UNKNOWN;
873}
bool mutt_comp_can_read(const char *path)
Can we read from this file?
Definition compress.c:367
@ MUTT_COMPRESSED
Compressed file Mailbox type.
Definition mailbox.h:52
@ MUTT_UNKNOWN
Mailbox wasn't recognised.
Definition mailbox.h:43
+ Here is the call graph for this function:

◆ imap_path_probe()

enum MailboxType imap_path_probe ( const char * path,
const struct stat * st )

Is this an IMAP Mailbox?

Definition at line 2546 of file imap.c.

2547{
2548 if (mutt_istr_startswith(path, "imap://"))
2549 return MUTT_IMAP;
2550
2551 if (mutt_istr_startswith(path, "imaps://"))
2552 return MUTT_IMAP;
2553
2554 return MUTT_UNKNOWN;
2555}
@ MUTT_IMAP
'IMAP' Mailbox type
Definition mailbox.h:49
size_t mutt_istr_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix, ignoring case.
Definition string.c:246
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ maildir_path_probe()

enum MailboxType maildir_path_probe ( const char * path,
const struct stat * st )

Is this a Maildir Mailbox?

Definition at line 94 of file path.c.

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}
@ MUTT_MAILDIR
'Maildir' Mailbox type
Definition mailbox.h:47
#define countof(x)
Definition memory.h:49
#define PATH_MAX
Definition mutt.h:49

◆ mbox_path_probe()

enum MailboxType mbox_path_probe ( const char * path,
const struct stat * st )

Is this an mbox Mailbox?

Definition at line 1546 of file mbox.c.

1547{
1548 if (!st)
1549 return MUTT_UNKNOWN;
1550
1551 if (S_ISDIR(st->st_mode))
1552 return MUTT_UNKNOWN;
1553
1554 if (st->st_size == 0)
1555 return MUTT_MBOX;
1556
1557 FILE *fp = mutt_file_fopen(path, "r");
1558 if (!fp)
1559 return MUTT_UNKNOWN;
1560
1561 int ch;
1562 while ((ch = fgetc(fp)) != EOF)
1563 {
1564 /* Some mailbox creation tools erroneously append a blank line to
1565 * a file before appending a mail message. This allows neomutt to
1566 * detect type for and thus open those files. */
1567 if ((ch != '\n') && (ch != '\r'))
1568 {
1569 ungetc(ch, fp);
1570 break;
1571 }
1572 }
1573
1574 enum MailboxType type = MUTT_UNKNOWN;
1575 char tmp[256] = { 0 };
1576 if (fgets(tmp, sizeof(tmp), fp))
1577 {
1578 if (mutt_str_startswith(tmp, "From "))
1579 type = MUTT_MBOX;
1580 else if (mutt_str_equal(tmp, MMDF_SEP))
1581 type = MUTT_MMDF;
1582 }
1583 mutt_file_fclose(&fp);
1584
1585 const bool c_check_mbox_size = cs_subset_bool(NeoMutt->sub, "check_mbox_size");
1586 if (!c_check_mbox_size)
1587 {
1588 /* need to restore the times here, the file was not really accessed,
1589 * only the type was accessed. This is important, because detection
1590 * of "new mail" depends on those times set correctly. */
1591#ifdef HAVE_UTIMENSAT
1592 struct timespec ts[2] = { { 0 }, { 0 } };
1595 utimensat(AT_FDCWD, path, ts, 0);
1596#else
1597 struct utimbuf times = { 0 };
1598 times.actime = st->st_atime;
1599 times.modtime = st->st_mtime;
1600 utime(path, &times);
1601#endif
1602 }
1603
1604 return type;
1605}
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition helpers.c:47
MailboxType
Supported mailbox formats.
Definition mailbox.h:40
@ MUTT_MMDF
'mmdf' Mailbox type
Definition mailbox.h:45
@ MUTT_MBOX
'mbox' Mailbox type
Definition mailbox.h:44
void mutt_file_get_stat_timespec(struct timespec *dest, struct stat *st, enum MuttStatType type)
Read the stat() time into a time value.
Definition file.c:1474
#define mutt_file_fclose(FP)
Definition file.h:139
#define mutt_file_fopen(PATH, MODE)
Definition file.h:138
@ MUTT_STAT_ATIME
File/dir's atime - last accessed time.
Definition file.h:53
@ MUTT_STAT_MTIME
File/dir's mtime - last modified time.
Definition file.h:54
#define MMDF_SEP
Definition lib.h:63
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition string.c:665
size_t mutt_str_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix.
Definition string.c:234
Container for Accounts, Notifications.
Definition neomutt.h:41
struct ConfigSubset * sub
Inherited config items.
Definition neomutt.h:49
+ Here is the call graph for this function:

◆ mh_path_probe()

static enum MailboxType mh_path_probe ( const char * path,
const struct stat * st )
static

Is this an mh Mailbox?

Definition at line 1201 of file mh.c.

1202{
1203 if (!st || !S_ISDIR(st->st_mode))
1204 return MUTT_UNKNOWN;
1205
1206 char tmp[PATH_MAX] = { 0 };
1207
1208 snprintf(tmp, sizeof(tmp), "%s/.mh_sequences", path);
1209 if (access(tmp, F_OK) == 0)
1210 return MUTT_MH;
1211
1212 snprintf(tmp, sizeof(tmp), "%s/.xmhcache", path);
1213 if (access(tmp, F_OK) == 0)
1214 return MUTT_MH;
1215
1216 snprintf(tmp, sizeof(tmp), "%s/.mew_cache", path);
1217 if (access(tmp, F_OK) == 0)
1218 return MUTT_MH;
1219
1220 snprintf(tmp, sizeof(tmp), "%s/.mew-cache", path);
1221 if (access(tmp, F_OK) == 0)
1222 return MUTT_MH;
1223
1224 snprintf(tmp, sizeof(tmp), "%s/.sylpheed_cache", path);
1225 if (access(tmp, F_OK) == 0)
1226 return MUTT_MH;
1227
1228 /* ok, this isn't an mh folder, but mh mode can be used to read
1229 * Usenet news from the spool. */
1230
1231 snprintf(tmp, sizeof(tmp), "%s/.overview", path);
1232 if (access(tmp, F_OK) == 0)
1233 return MUTT_MH;
1234
1235 return MUTT_UNKNOWN;
1236}
@ MUTT_MH
'MH' Mailbox type
Definition mailbox.h:46

◆ nntp_path_probe()

enum MailboxType nntp_path_probe ( const char * path,
const struct stat * st )

Is this an NNTP Mailbox?

Definition at line 2787 of file nntp.c.

2788{
2789 if (mutt_istr_startswith(path, "news://"))
2790 return MUTT_NNTP;
2791
2792 if (mutt_istr_startswith(path, "snews://"))
2793 return MUTT_NNTP;
2794
2795 return MUTT_UNKNOWN;
2796}
@ MUTT_NNTP
'NNTP' (Usenet) Mailbox type
Definition mailbox.h:48
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nm_path_probe()

enum MailboxType nm_path_probe ( const char * path,
const struct stat * st )

Is this a Notmuch Mailbox?

Definition at line 2515 of file notmuch.c.

2516{
2518 return MUTT_UNKNOWN;
2519
2520 return MUTT_NOTMUCH;
2521}
@ MUTT_NOTMUCH
'Notmuch' (virtual) Mailbox type
Definition mailbox.h:50
const char NmUrlProtocol[]
Protocol string for Notmuch URLs.
Definition notmuch.c:102
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pop_path_probe()

enum MailboxType pop_path_probe ( const char * path,
const struct stat * st )

Is this a POP Mailbox?

Definition at line 1162 of file pop.c.

1163{
1164 if (mutt_istr_startswith(path, "pop://"))
1165 return MUTT_POP;
1166
1167 if (mutt_istr_startswith(path, "pops://"))
1168 return MUTT_POP;
1169
1170 return MUTT_UNKNOWN;
1171}
@ MUTT_POP
'POP3' Mailbox type
Definition mailbox.h:51
+ Here is the call graph for this function:
+ Here is the caller graph for this function: