NeoMutt
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? - Implements MxOps::path_probe() -.
 
enum MailboxType imap_path_probe (const char *path, const struct stat *st)
 Is this an IMAP Mailbox? - Implements MxOps::path_probe() -.
 
static enum MailboxType maildir_path_probe (const char *path, const struct stat *st)
 Is this a Maildir Mailbox? - Implements MxOps::path_probe() -.
 
static enum MailboxType mh_path_probe (const char *path, const struct stat *st)
 Is this an mh Mailbox? - Implements MxOps::path_probe() -.
 
enum MailboxType mbox_path_probe (const char *path, const struct stat *st)
 Is this an mbox Mailbox? - Implements MxOps::path_probe() -.
 
enum MailboxType nntp_path_probe (const char *path, const struct stat *st)
 Is this an NNTP Mailbox? - Implements MxOps::path_probe() -.
 
enum MailboxType nm_path_probe (const char *path, const struct stat *st)
 Is this a Notmuch Mailbox? - Implements MxOps::path_probe() -.
 
enum MailboxType pop_path_probe (const char *path, const struct stat *st)
 Is this a POP Mailbox? - Implements MxOps::path_probe() -.
 

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? - Implements MxOps::path_probe() -.

Definition at line 895 of file compress.c.

896{
897 if (!st || !S_ISREG(st->st_mode))
898 return MUTT_UNKNOWN;
899
900 if (mutt_comp_can_read(path))
901 return MUTT_COMPRESSED;
902
903 return MUTT_UNKNOWN;
904}
bool mutt_comp_can_read(const char *path)
Can we read from this file?
Definition: compress.c:396
@ MUTT_COMPRESSED
Compressed file Mailbox type.
Definition: mailbox.h:53
@ MUTT_UNKNOWN
Mailbox wasn't recognised.
Definition: mailbox.h:44
+ 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? - Implements MxOps::path_probe() -.

Definition at line 2329 of file imap.c.

2330{
2331 if (mutt_istr_startswith(path, "imap://"))
2332 return MUTT_IMAP;
2333
2334 if (mutt_istr_startswith(path, "imaps://"))
2335 return MUTT_IMAP;
2336
2337 return MUTT_UNKNOWN;
2338}
@ MUTT_IMAP
'IMAP' Mailbox type
Definition: mailbox.h:50
size_t mutt_istr_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix, ignoring case.
Definition: string.c:240
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ maildir_path_probe()

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

Is this a Maildir Mailbox? - Implements MxOps::path_probe() -.

Definition at line 1664 of file maildir.c.

1665{
1666 if (!st || !S_ISDIR(st->st_mode))
1667 return MUTT_UNKNOWN;
1668
1669 char sub[PATH_MAX] = { 0 };
1670 struct stat stsub = { 0 };
1671 char *subs[] = { "cur", "new" };
1672 for (size_t i = 0; i < mutt_array_size(subs); ++i)
1673 {
1674 snprintf(sub, sizeof(sub), "%s/%s", path, subs[i]);
1675 if ((stat(sub, &stsub) == 0) && S_ISDIR(stsub.st_mode))
1676 return MUTT_MAILDIR;
1677 }
1678
1679 return MUTT_UNKNOWN;
1680}
@ MUTT_MAILDIR
'Maildir' Mailbox type
Definition: mailbox.h:48
#define mutt_array_size(x)
Definition: memory.h:38
#define PATH_MAX
Definition: mutt.h:41

◆ mh_path_probe()

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

Is this an mh Mailbox? - Implements MxOps::path_probe() -.

Definition at line 1206 of file mh.c.

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

◆ mbox_path_probe()

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

Is this an mbox Mailbox? - Implements MxOps::path_probe() -.

Definition at line 1549 of file mbox.c.

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

◆ nntp_path_probe()

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

Is this an NNTP Mailbox? - Implements MxOps::path_probe() -.

Definition at line 2734 of file nntp.c.

2735{
2736 if (mutt_istr_startswith(path, "news://"))
2737 return MUTT_NNTP;
2738
2739 if (mutt_istr_startswith(path, "snews://"))
2740 return MUTT_NNTP;
2741
2742 return MUTT_UNKNOWN;
2743}
@ MUTT_NNTP
'NNTP' (Usenet) Mailbox type
Definition: mailbox.h:49
+ 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? - Implements MxOps::path_probe() -.

Definition at line 2443 of file notmuch.c.

2444{
2446 return MUTT_UNKNOWN;
2447
2448 return MUTT_NOTMUCH;
2449}
@ MUTT_NOTMUCH
'Notmuch' (virtual) Mailbox type
Definition: mailbox.h:51
const char NmUrlProtocol[]
Protocol string for Notmuch URLs.
Definition: notmuch.c:93
+ 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? - Implements MxOps::path_probe() -.

Definition at line 1154 of file pop.c.

1155{
1156 if (mutt_istr_startswith(path, "pop://"))
1157 return MUTT_POP;
1158
1159 if (mutt_istr_startswith(path, "pops://"))
1160 return MUTT_POP;
1161
1162 return MUTT_UNKNOWN;
1163}
@ MUTT_POP
'POP3' Mailbox type
Definition: mailbox.h:52
+ Here is the call graph for this function:
+ Here is the caller graph for this function: