NeoMutt  2021-02-05-666-ge300cd
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 874 of file compress.c.

875 {
876  if (!st || !S_ISREG(st->st_mode))
877  return MUTT_UNKNOWN;
878 
879  if (mutt_comp_can_read(path))
880  return MUTT_COMPRESSED;
881 
882  return MUTT_UNKNOWN;
883 }
Mailbox wasn't recognised.
Definition: mailbox.h:47
Compressed file Mailbox type.
Definition: mailbox.h:56
bool mutt_comp_can_read(const char *path)
Can we read from this file?
Definition: compress.c:388
+ 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 2402 of file imap.c.

2403 {
2404  if (mutt_istr_startswith(path, "imap://"))
2405  return MUTT_IMAP;
2406 
2407  if (mutt_istr_startswith(path, "imaps://"))
2408  return MUTT_IMAP;
2409 
2410  return MUTT_UNKNOWN;
2411 }
Mailbox wasn't recognised.
Definition: mailbox.h:47
size_t mutt_istr_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix, ignoring case.
Definition: string.c:172
'IMAP' Mailbox type
Definition: mailbox.h:53
+ 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 1629 of file maildir.c.

1630 {
1631  if (!st || !S_ISDIR(st->st_mode))
1632  return MUTT_UNKNOWN;
1633 
1634  char cur[PATH_MAX];
1635  snprintf(cur, sizeof(cur), "%s/cur", path);
1636 
1637  struct stat stc;
1638  if ((stat(cur, &stc) == 0) && S_ISDIR(stc.st_mode))
1639  return MUTT_MAILDIR;
1640 
1641  return MUTT_UNKNOWN;
1642 }
Mailbox wasn't recognised.
Definition: mailbox.h:47
'Maildir' Mailbox type
Definition: mailbox.h:51
#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 1207 of file mh.c.

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

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

1634 {
1635  if (!st)
1636  return MUTT_UNKNOWN;
1637 
1638  if (S_ISDIR(st->st_mode))
1639  return MUTT_UNKNOWN;
1640 
1641  if (st->st_size == 0)
1642  return MUTT_MBOX;
1643 
1644  FILE *fp = fopen(path, "r");
1645  if (!fp)
1646  return MUTT_UNKNOWN;
1647 
1648  int ch;
1649  while ((ch = fgetc(fp)) != EOF)
1650  {
1651  /* Some mailbox creation tools erroneously append a blank line to
1652  * a file before appending a mail message. This allows neomutt to
1653  * detect type for and thus open those files. */
1654  if ((ch != '\n') && (ch != '\r'))
1655  {
1656  ungetc(ch, fp);
1657  break;
1658  }
1659  }
1660 
1661  enum MailboxType type = MUTT_UNKNOWN;
1662  char tmp[256];
1663  if (fgets(tmp, sizeof(tmp), fp))
1664  {
1665  if (mutt_str_startswith(tmp, "From "))
1666  type = MUTT_MBOX;
1667  else if (mutt_str_equal(tmp, MMDF_SEP))
1668  type = MUTT_MMDF;
1669  }
1670  mutt_file_fclose(&fp);
1671 
1672  const bool c_check_mbox_size =
1673  cs_subset_bool(NeoMutt->sub, "check_mbox_size");
1674  if (!c_check_mbox_size)
1675  {
1676  /* need to restore the times here, the file was not really accessed,
1677  * only the type was accessed. This is important, because detection
1678  * of "new mail" depends on those times set correctly. */
1679 #ifdef HAVE_UTIMENSAT
1680  struct timespec ts[2];
1683  utimensat(AT_FDCWD, path, ts, 0);
1684 #else
1685  struct utimbuf times;
1686  times.actime = st->st_atime;
1687  times.modtime = st->st_mtime;
1688  utime(path, &times);
1689 #endif
1690  }
1691 
1692  return type;
1693 }
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:904
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 *sb, enum MuttStatType type)
Read the stat() time into a time value.
Definition: file.c:1540
Mailbox wasn't recognised.
Definition: mailbox.h:47
Container for Accounts, Notifications.
Definition: neomutt.h:36
int mutt_file_fclose(FILE **fp)
Close a FILE handle (and NULL the pointer)
Definition: file.c:153
File/dir's mtime - last modified time.
Definition: file.h:63
size_t mutt_str_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix.
Definition: string.c:160
'mmdf' Mailbox type
Definition: mailbox.h:49
#define MMDF_SEP
Definition: lib.h:60
'mbox' Mailbox type
Definition: mailbox.h:48
MailboxType
Supported mailbox formats.
Definition: mailbox.h:43
Time value with nanosecond precision.
Definition: file.h:48
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
File/dir's atime - last accessed time.
Definition: file.h:62
+ 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 2709 of file nntp.c.

2710 {
2711  if (mutt_istr_startswith(path, "news://"))
2712  return MUTT_NNTP;
2713 
2714  if (mutt_istr_startswith(path, "snews://"))
2715  return MUTT_NNTP;
2716 
2717  return MUTT_UNKNOWN;
2718 }
'NNTP' (Usenet) Mailbox type
Definition: mailbox.h:52
Mailbox wasn't recognised.
Definition: mailbox.h:47
size_t mutt_istr_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix, ignoring case.
Definition: string.c:172
+ 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 2458 of file notmuch.c.

2459 {
2460  if (!mutt_istr_startswith(path, NmUrlProtocol))
2461  return MUTT_UNKNOWN;
2462 
2463  return MUTT_NOTMUCH;
2464 }
Mailbox wasn't recognised.
Definition: mailbox.h:47
size_t mutt_istr_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix, ignoring case.
Definition: string.c:172
'Notmuch' (virtual) Mailbox type
Definition: mailbox.h:54
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 1165 of file pop.c.

1166 {
1167  if (mutt_istr_startswith(path, "pop://"))
1168  return MUTT_POP;
1169 
1170  if (mutt_istr_startswith(path, "pops://"))
1171  return MUTT_POP;
1172 
1173  return MUTT_UNKNOWN;
1174 }
Mailbox wasn't recognised.
Definition: mailbox.h:47
'POP3' Mailbox type
Definition: mailbox.h:55
size_t mutt_istr_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix, ignoring case.
Definition: string.c:172
+ Here is the call graph for this function:
+ Here is the caller graph for this function: