NeoMutt  2022-04-29-178-g3b62e6
Teaching an old dog new tricks
DOXYGEN
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() -. More...
 
enum MailboxType imap_path_probe (const char *path, const struct stat *st)
 Is this an IMAP Mailbox? - Implements MxOps::path_probe() -. More...
 
static enum MailboxType maildir_path_probe (const char *path, const struct stat *st)
 Is this a Maildir Mailbox? - Implements MxOps::path_probe() -. More...
 
static enum MailboxType mh_path_probe (const char *path, const struct stat *st)
 Is this an mh Mailbox? - Implements MxOps::path_probe() -. More...
 
enum MailboxType mbox_path_probe (const char *path, const struct stat *st)
 Is this an mbox Mailbox? - Implements MxOps::path_probe() -. More...
 
enum MailboxType nntp_path_probe (const char *path, const struct stat *st)
 Is this an NNTP Mailbox? - Implements MxOps::path_probe() -. More...
 
enum MailboxType nm_path_probe (const char *path, const struct stat *st)
 Is this a Notmuch Mailbox? - Implements MxOps::path_probe() -. More...
 
enum MailboxType pop_path_probe (const char *path, const struct stat *st)
 Is this a POP Mailbox? - Implements MxOps::path_probe() -. More...
 

Detailed Description

Does this Mailbox type recognise this path?

Parameters
pathPath to examine
ststat buffer (for local filesystems)
Return values
numType, e.g. MUTT_IMAP

Contract

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 880 of file compress.c.

881{
882 if (!st || !S_ISREG(st->st_mode))
883 return MUTT_UNKNOWN;
884
885 if (mutt_comp_can_read(path))
886 return MUTT_COMPRESSED;
887
888 return MUTT_UNKNOWN;
889}
bool mutt_comp_can_read(const char *path)
Can we read from this file?
Definition: compress.c:391
@ 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 2400 of file imap.c.

2401{
2402 if (mutt_istr_startswith(path, "imap://"))
2403 return MUTT_IMAP;
2404
2405 if (mutt_istr_startswith(path, "imaps://"))
2406 return MUTT_IMAP;
2407
2408 return MUTT_UNKNOWN;
2409}
@ 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:239
+ 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 1627 of file maildir.c.

1628{
1629 if (!st || !S_ISDIR(st->st_mode))
1630 return MUTT_UNKNOWN;
1631
1632 char cur[PATH_MAX] = { 0 };
1633 snprintf(cur, sizeof(cur), "%s/cur", path);
1634
1635 struct stat st_cur = { 0 };
1636 if ((stat(cur, &st_cur) == 0) && S_ISDIR(st_cur.st_mode))
1637 return MUTT_MAILDIR;
1638
1639 return MUTT_UNKNOWN;
1640}
@ MUTT_MAILDIR
'Maildir' Mailbox type
Definition: mailbox.h:48
#define PATH_MAX
Definition: mutt.h:40

◆ 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 1214 of file mh.c.

1215{
1216 if (!st || !S_ISDIR(st->st_mode))
1217 return MUTT_UNKNOWN;
1218
1219 char tmp[PATH_MAX] = { 0 };
1220
1221 snprintf(tmp, sizeof(tmp), "%s/.mh_sequences", path);
1222 if (access(tmp, F_OK) == 0)
1223 return MUTT_MH;
1224
1225 snprintf(tmp, sizeof(tmp), "%s/.xmhcache", path);
1226 if (access(tmp, F_OK) == 0)
1227 return MUTT_MH;
1228
1229 snprintf(tmp, sizeof(tmp), "%s/.mew_cache", path);
1230 if (access(tmp, F_OK) == 0)
1231 return MUTT_MH;
1232
1233 snprintf(tmp, sizeof(tmp), "%s/.mew-cache", path);
1234 if (access(tmp, F_OK) == 0)
1235 return MUTT_MH;
1236
1237 snprintf(tmp, sizeof(tmp), "%s/.sylpheed_cache", path);
1238 if (access(tmp, F_OK) == 0)
1239 return MUTT_MH;
1240
1241 /* ok, this isn't an mh folder, but mh mode can be used to read
1242 * Usenet news from the spool. */
1243
1244 snprintf(tmp, sizeof(tmp), "%s/.overview", path);
1245 if (access(tmp, F_OK) == 0)
1246 return MUTT_MH;
1247
1248 return MUTT_UNKNOWN;
1249}
@ 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 1648 of file mbox.c.

1649{
1650 if (!st)
1651 return MUTT_UNKNOWN;
1652
1653 if (S_ISDIR(st->st_mode))
1654 return MUTT_UNKNOWN;
1655
1656 if (st->st_size == 0)
1657 return MUTT_MBOX;
1658
1659 FILE *fp = fopen(path, "r");
1660 if (!fp)
1661 return MUTT_UNKNOWN;
1662
1663 int ch;
1664 while ((ch = fgetc(fp)) != EOF)
1665 {
1666 /* Some mailbox creation tools erroneously append a blank line to
1667 * a file before appending a mail message. This allows neomutt to
1668 * detect type for and thus open those files. */
1669 if ((ch != '\n') && (ch != '\r'))
1670 {
1671 ungetc(ch, fp);
1672 break;
1673 }
1674 }
1675
1676 enum MailboxType type = MUTT_UNKNOWN;
1677 char tmp[256] = { 0 };
1678 if (fgets(tmp, sizeof(tmp), fp))
1679 {
1680 if (mutt_str_startswith(tmp, "From "))
1681 type = MUTT_MBOX;
1682 else if (mutt_str_equal(tmp, MMDF_SEP))
1683 type = MUTT_MMDF;
1684 }
1685 mutt_file_fclose(&fp);
1686
1687 const bool c_check_mbox_size = cs_subset_bool(NeoMutt->sub, "check_mbox_size");
1688 if (!c_check_mbox_size)
1689 {
1690 /* need to restore the times here, the file was not really accessed,
1691 * only the type was accessed. This is important, because detection
1692 * of "new mail" depends on those times set correctly. */
1693#ifdef HAVE_UTIMENSAT
1694 struct timespec ts[2];
1697 utimensat(AT_FDCWD, path, ts, 0);
1698#else
1699 struct utimbuf times;
1700 times.actime = st->st_atime;
1701 times.modtime = st->st_mtime;
1702 utime(path, &times);
1703#endif
1704 }
1705
1706 return type;
1707}
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:73
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:1611
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:62
@ MUTT_STAT_MTIME
File/dir's mtime - last modified time.
Definition: file.h:63
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:60
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:784
size_t mutt_str_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix.
Definition: string.c:227
Container for Accounts, Notifications.
Definition: neomutt.h:37
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
Time value with nanosecond precision.
Definition: file.h:49
+ 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 2703 of file nntp.c.

2704{
2705 if (mutt_istr_startswith(path, "news://"))
2706 return MUTT_NNTP;
2707
2708 if (mutt_istr_startswith(path, "snews://"))
2709 return MUTT_NNTP;
2710
2711 return MUTT_UNKNOWN;
2712}
@ 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 2432 of file notmuch.c.

2433{
2435 return MUTT_UNKNOWN;
2436
2437 return MUTT_NOTMUCH;
2438}
@ MUTT_NOTMUCH
'Notmuch' (virtual) Mailbox type
Definition: mailbox.h:51
const char NmUrlProtocol[]
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 1157 of file pop.c.

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