NeoMutt  2021-02-05-89-gabe350
Teaching an old dog new tricks
DOXYGEN
lib.h File Reference
#include <stdbool.h>
#include <stdio.h>
#include <time.h>
#include "core/lib.h"
#include "mx.h"
+ Include dependency graph for lib.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  MboxAccountData
 Mbox-specific Account data -. More...
 

Macros

#define MMDF_SEP   "\001\001\001\001\n"
 

Functions

enum MxStatus mbox_check (struct Mailbox *m, struct stat *sb, bool check_stats)
 
enum MailboxType mbox_path_probe (const char *path, const struct stat *st)
 Is this an mbox Mailbox? - Implements MxOps::path_probe() More...
 
void mbox_reset_atime (struct Mailbox *m, struct stat *st)
 Reset the access time on the mailbox file. More...
 
bool mbox_test_new_folder (const char *path)
 Test if an mbox or mmdf mailbox has new mail. More...
 

Variables

bool C_CheckMboxSize
 Config: (mbox,mmdf) Use mailbox size as an indicator of new mail. More...
 
struct MxOps MxMboxOps
 Mbox Mailbox - Implements MxOps. More...
 
struct MxOps MxMmdfOps
 MMDF Mailbox - Implements MxOps. More...
 

Detailed Description

Mbox local mailbox type

Authors
  • Michael R. Elkins
  • Richard Russon

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file lib.h.

Macro Definition Documentation

◆ MMDF_SEP

#define MMDF_SEP   "\001\001\001\001\n"

Definition at line 64 of file lib.h.

Function Documentation

◆ mbox_check()

enum MxStatus mbox_check ( struct Mailbox m,
struct stat *  sb,
bool  check_stats 
)

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

1616 {
1617  if (!st)
1618  return MUTT_UNKNOWN;
1619 
1620  if (S_ISDIR(st->st_mode))
1621  return MUTT_UNKNOWN;
1622 
1623  if (st->st_size == 0)
1624  return MUTT_MBOX;
1625 
1626  FILE *fp = fopen(path, "r");
1627  if (!fp)
1628  return MUTT_UNKNOWN;
1629 
1630  int ch;
1631  while ((ch = fgetc(fp)) != EOF)
1632  {
1633  /* Some mailbox creation tools erroneously append a blank line to
1634  * a file before appending a mail message. This allows neomutt to
1635  * detect type for and thus open those files. */
1636  if ((ch != '\n') && (ch != '\r'))
1637  {
1638  ungetc(ch, fp);
1639  break;
1640  }
1641  }
1642 
1643  enum MailboxType type = MUTT_UNKNOWN;
1644  char tmp[256];
1645  if (fgets(tmp, sizeof(tmp), fp))
1646  {
1647  if (mutt_str_startswith(tmp, "From "))
1648  type = MUTT_MBOX;
1649  else if (mutt_str_equal(tmp, MMDF_SEP))
1650  type = MUTT_MMDF;
1651  }
1652  mutt_file_fclose(&fp);
1653 
1654  if (!C_CheckMboxSize)
1655  {
1656  /* need to restore the times here, the file was not really accessed,
1657  * only the type was accessed. This is important, because detection
1658  * of "new mail" depends on those times set correctly. */
1659 #ifdef HAVE_UTIMENSAT
1660  struct timespec ts[2];
1663  utimensat(AT_FDCWD, path, ts, 0);
1664 #else
1665  struct utimbuf times;
1666  times.actime = st->st_atime;
1667  times.modtime = st->st_mtime;
1668  utime(path, &times);
1669 #endif
1670  }
1671 
1672  return type;
1673 }
+ Here is the call graph for this function:

◆ mbox_reset_atime()

void mbox_reset_atime ( struct Mailbox m,
struct stat *  st 
)

Reset the access time on the mailbox file.

Parameters
mMailbox
stTimestamp

if mailbox has at least 1 new message, sets mtime > atime of mailbox so mailbox check reports new mail

Definition at line 833 of file mbox.c.

834 {
835  struct utimbuf utimebuf;
836  struct stat st2;
837 
838  if (!st)
839  {
840  if (stat(mailbox_path(m), &st2) < 0)
841  return;
842  st = &st2;
843  }
844 
845  utimebuf.actime = st->st_atime;
846  utimebuf.modtime = st->st_mtime;
847 
848  /* When $mbox_check_recent is set, existing new mail is ignored, so do not
849  * reset the atime to mtime-1 to signal new mail. */
850  if (!C_MailCheckRecent && (utimebuf.actime >= utimebuf.modtime) && mbox_has_new(m))
851  {
852  utimebuf.actime = utimebuf.modtime - 1;
853  }
854 
855  utime(mailbox_path(m), &utimebuf);
856 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mbox_test_new_folder()

bool mbox_test_new_folder ( const char *  path)

Test if an mbox or mmdf mailbox has new mail.

Parameters
pathPath to the mailbox
Return values
booltrue if the folder contains new mail

Definition at line 806 of file mbox.c.

807 {
808  bool rc = false;
809 
810  enum MailboxType type = mx_path_probe(path);
811 
812  if ((type != MUTT_MBOX) && (type != MUTT_MMDF))
813  return false;
814 
815  FILE *fp = fopen(path, "rb");
816  if (fp)
817  {
818  rc = test_last_status_new(fp);
819  mutt_file_fclose(&fp);
820  }
821 
822  return rc;
823 }
+ Here is the call graph for this function:

Variable Documentation

◆ C_CheckMboxSize

bool C_CheckMboxSize

Config: (mbox,mmdf) Use mailbox size as an indicator of new mail.

Definition at line 36 of file config.c.

◆ MxMboxOps

struct MxOps MxMboxOps

Mbox Mailbox - Implements MxOps.

Definition at line 1807 of file mbox.c.

◆ MxMmdfOps

struct MxOps MxMmdfOps

MMDF Mailbox - Implements MxOps.

Definition at line 1837 of file mbox.c.

MUTT_MMDF
@ MUTT_MMDF
'mmdf' Mailbox type
Definition: mailbox.h:49
mutt_file_fclose
int mutt_file_fclose(FILE **fp)
Close a FILE handle (and NULL the pointer)
Definition: file.c:153
MUTT_STAT_MTIME
@ MUTT_STAT_MTIME
File/dir's mtime - last modified time.
Definition: file.h:64
mbox_has_new
static bool mbox_has_new(struct Mailbox *m)
Does the mailbox have new mail.
Definition: mbox.c:711
MUTT_STAT_ATIME
@ MUTT_STAT_ATIME
File/dir's atime - last accessed time.
Definition: file.h:63
C_CheckMboxSize
bool C_CheckMboxSize
Config: (mbox,mmdf) Use mailbox size as an indicator of new mail.
Definition: config.c:36
Email::path
char * path
Path of Email (for local Mailboxes)
Definition: email.h:92
mx_path_probe
enum MailboxType mx_path_probe(const char *path)
Find a mailbox that understands a path.
Definition: mx.c:1335
mutt_str_equal
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:871
MUTT_UNKNOWN
@ MUTT_UNKNOWN
Mailbox wasn't recognised.
Definition: mailbox.h:47
C_MailCheckRecent
WHERE bool C_MailCheckRecent
Config: Notify the user about new mail since the last time the mailbox was opened.
Definition: mutt_globals.h:150
MMDF_SEP
#define MMDF_SEP
Definition: lib.h:64
mutt_file_get_stat_timespec
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:1537
MailboxType
MailboxType
Supported mailbox formats.
Definition: mailbox.h:43
mailbox_path
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox's path string.
Definition: mailbox.h:206
timespec
Time value with nanosecond precision.
Definition: file.h:49
test_last_status_new
static bool test_last_status_new(FILE *fp)
Is the last message new.
Definition: mbox.c:781
mutt_str_startswith
size_t mutt_str_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix.
Definition: string.c:160
MUTT_MBOX
@ MUTT_MBOX
'mbox' Mailbox type
Definition: mailbox.h:48