NeoMutt  2024-11-14-138-ge5ca67
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() -.
 
enum MailboxType maildir_path_probe (const char *path, const struct stat *st)
 Is this a Maildir 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() -.
 
static enum MailboxType mh_path_probe (const char *path, const struct stat *st)
 Is this an mh 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 865 of file compress.c.

866{
867 if (!st || !S_ISREG(st->st_mode))
868 return MUTT_UNKNOWN;
869
870 if (mutt_comp_can_read(path))
871 return MUTT_COMPRESSED;
872
873 return MUTT_UNKNOWN;
874}
bool mutt_comp_can_read(const char *path)
Can we read from this file?
Definition: compress.c:366
@ 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 2344 of file imap.c.

2345{
2346 if (mutt_istr_startswith(path, "imap://"))
2347 return MUTT_IMAP;
2348
2349 if (mutt_istr_startswith(path, "imaps://"))
2350 return MUTT_IMAP;
2351
2352 return MUTT_UNKNOWN;
2353}
@ 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:242
+ 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? - Implements MxOps::path_probe() -.

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 < mutt_array_size(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:48
#define mutt_array_size(x)
Definition: memory.h:38
#define PATH_MAX
Definition: mutt.h:42

◆ 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 1542 of file mbox.c.

1543{
1544 if (!st)
1545 return MUTT_UNKNOWN;
1546
1547 if (S_ISDIR(st->st_mode))
1548 return MUTT_UNKNOWN;
1549
1550 if (st->st_size == 0)
1551 return MUTT_MBOX;
1552
1553 FILE *fp = mutt_file_fopen(path, "r");
1554 if (!fp)
1555 return MUTT_UNKNOWN;
1556
1557 int ch;
1558 while ((ch = fgetc(fp)) != EOF)
1559 {
1560 /* Some mailbox creation tools erroneously append a blank line to
1561 * a file before appending a mail message. This allows neomutt to
1562 * detect type for and thus open those files. */
1563 if ((ch != '\n') && (ch != '\r'))
1564 {
1565 ungetc(ch, fp);
1566 break;
1567 }
1568 }
1569
1570 enum MailboxType type = MUTT_UNKNOWN;
1571 char tmp[256] = { 0 };
1572 if (fgets(tmp, sizeof(tmp), fp))
1573 {
1574 if (mutt_str_startswith(tmp, "From "))
1575 type = MUTT_MBOX;
1576 else if (mutt_str_equal(tmp, MMDF_SEP))
1577 type = MUTT_MMDF;
1578 }
1579 mutt_file_fclose(&fp);
1580
1581 const bool c_check_mbox_size = cs_subset_bool(NeoMutt->sub, "check_mbox_size");
1582 if (!c_check_mbox_size)
1583 {
1584 /* need to restore the times here, the file was not really accessed,
1585 * only the type was accessed. This is important, because detection
1586 * of "new mail" depends on those times set correctly. */
1587#ifdef HAVE_UTIMENSAT
1588 struct timespec ts[2] = { { 0 }, { 0 } };
1591 utimensat(AT_FDCWD, path, ts, 0);
1592#else
1593 struct utimbuf times = { 0 };
1594 times.actime = st->st_atime;
1595 times.modtime = st->st_mtime;
1596 utime(path, &times);
1597#endif
1598 }
1599
1600 return type;
1601}
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:41
@ MUTT_MMDF
'mmdf' Mailbox type
Definition: mailbox.h:46
@ MUTT_MBOX
'mbox' Mailbox type
Definition: mailbox.h:45
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:1579
#define mutt_file_fclose(FP)
Definition: file.h:138
#define mutt_file_fopen(PATH, MODE)
Definition: file.h:137
@ 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:62
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:660
size_t mutt_str_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix.
Definition: string.c:230
Container for Accounts, Notifications.
Definition: neomutt.h:42
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:46
+ 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? - Implements MxOps::path_probe() -.

Definition at line 1199 of file mh.c.

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

◆ 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 2786 of file nntp.c.

2787{
2788 if (mutt_istr_startswith(path, "news://"))
2789 return MUTT_NNTP;
2790
2791 if (mutt_istr_startswith(path, "snews://"))
2792 return MUTT_NNTP;
2793
2794 return MUTT_UNKNOWN;
2795}
@ 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 2457 of file notmuch.c.

2458{
2460 return MUTT_UNKNOWN;
2461
2462 return MUTT_NOTMUCH;
2463}
@ MUTT_NOTMUCH
'Notmuch' (virtual) Mailbox type
Definition: mailbox.h:51
const char NmUrlProtocol[]
Protocol string for Notmuch URLs.
Definition: notmuch.c:101
+ 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 1156 of file pop.c.

1157{
1158 if (mutt_istr_startswith(path, "pop://"))
1159 return MUTT_POP;
1160
1161 if (mutt_istr_startswith(path, "pops://"))
1162 return MUTT_POP;
1163
1164 return MUTT_UNKNOWN;
1165}
@ 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: