NeoMutt  2021-10-29-220-g2b1eec
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 860 of file compress.c.

878 {
879  if (!st || !S_ISREG(st->st_mode))
880  return MUTT_UNKNOWN;
881 
882  if (mutt_comp_can_read(path))
883  return MUTT_COMPRESSED;
884 
885  return MUTT_UNKNOWN;
886 }
bool mutt_comp_can_read(const char *path)
Can we read from this file?
Definition: compress.c:388
@ MUTT_COMPRESSED
Compressed file Mailbox type.
Definition: mailbox.h:56
@ MUTT_UNKNOWN
Mailbox wasn't recognised.
Definition: mailbox.h:47

◆ 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 2340 of file imap.c.

2406 {
2407  if (mutt_istr_startswith(path, "imap://"))
2408  return MUTT_IMAP;
2409 
2410  if (mutt_istr_startswith(path, "imaps://"))
2411  return MUTT_IMAP;
2412 
2413  return MUTT_UNKNOWN;
2414 }
@ MUTT_IMAP
'IMAP' Mailbox type
Definition: mailbox.h:53
size_t mutt_istr_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix, ignoring case.
Definition: string.c:170
+ 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 1620 of file maildir.c.

1635 {
1636  if (!st || !S_ISDIR(st->st_mode))
1637  return MUTT_UNKNOWN;
1638 
1639  char cur[PATH_MAX];
1640  snprintf(cur, sizeof(cur), "%s/cur", path);
1641 
1642  struct stat st_cur = { 0 };
1643  if ((stat(cur, &st_cur) == 0) && S_ISDIR(st_cur.st_mode))
1644  return MUTT_MAILDIR;
1645 
1646  return MUTT_UNKNOWN;
1647 }
@ MUTT_MAILDIR
'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 1204 of file mh.c.

1219 {
1220  if (!st || !S_ISDIR(st->st_mode))
1221  return MUTT_UNKNOWN;
1222 
1223  char tmp[PATH_MAX];
1224 
1225  snprintf(tmp, sizeof(tmp), "%s/.mh_sequences", path);
1226  if (access(tmp, F_OK) == 0)
1227  return MUTT_MH;
1228 
1229  snprintf(tmp, sizeof(tmp), "%s/.xmhcache", 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/.mew-cache", path);
1238  if (access(tmp, F_OK) == 0)
1239  return MUTT_MH;
1240 
1241  snprintf(tmp, sizeof(tmp), "%s/.sylpheed_cache", path);
1242  if (access(tmp, F_OK) == 0)
1243  return MUTT_MH;
1244 
1245  /* ok, this isn't an mh folder, but mh mode can be used to read
1246  * Usenet news from the spool. */
1247 
1248  snprintf(tmp, sizeof(tmp), "%s/.overview", path);
1249  if (access(tmp, F_OK) == 0)
1250  return MUTT_MH;
1251 
1252  return MUTT_UNKNOWN;
1253 }
@ MUTT_MH
'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 1640 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];
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 =
1688  cs_subset_bool(NeoMutt->sub, "check_mbox_size");
1689  if (!c_check_mbox_size)
1690  {
1691  /* need to restore the times here, the file was not really accessed,
1692  * only the type was accessed. This is important, because detection
1693  * of "new mail" depends on those times set correctly. */
1694 #ifdef HAVE_UTIMENSAT
1695  struct timespec ts[2];
1698  utimensat(AT_FDCWD, path, ts, 0);
1699 #else
1700  struct utimbuf times;
1701  times.actime = st->st_atime;
1702  times.modtime = st->st_mtime;
1703  utime(path, &times);
1704 #endif
1705  }
1706 
1707  return type;
1708 }
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:1586
int mutt_file_fclose(FILE **fp)
Close a FILE handle (and NULL the pointer)
Definition: file.c:153
@ 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
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:73
MailboxType
Supported mailbox formats.
Definition: mailbox.h:44
@ MUTT_MMDF
'mmdf' Mailbox type
Definition: mailbox.h:49
@ MUTT_MBOX
'mbox' Mailbox type
Definition: mailbox.h:48
#define MMDF_SEP
Definition: lib.h:60
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:715
size_t mutt_str_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix.
Definition: string.c:158
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

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

2713 {
2714  if (mutt_istr_startswith(path, "news://"))
2715  return MUTT_NNTP;
2716 
2717  if (mutt_istr_startswith(path, "snews://"))
2718  return MUTT_NNTP;
2719 
2720  return MUTT_UNKNOWN;
2721 }
@ MUTT_NNTP
'NNTP' (Usenet) Mailbox type
Definition: mailbox.h:52
+ 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 2414 of file notmuch.c.

2454 {
2455  if (!mutt_istr_startswith(path, NmUrlProtocol))
2456  return MUTT_UNKNOWN;
2457 
2458  return MUTT_NOTMUCH;
2459 }
@ MUTT_NOTMUCH
'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 1148 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 }
@ MUTT_POP
'POP3' Mailbox type
Definition: mailbox.h:55
+ Here is the caller graph for this function: