NeoMutt  2018-07-16 +952-a2da0a
Teaching an old dog new tricks
DOXYGEN
mailbox.c File Reference

Representation of a mailbox. More...

#include "config.h"
#include <dirent.h>
#include <limits.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <utime.h>
#include "mutt/mutt.h"
#include "config/lib.h"
#include "email/lib.h"
#include "mutt.h"
#include "mailbox.h"
#include "account.h"
#include "context.h"
#include "globals.h"
#include "maildir/lib.h"
#include "mbox/mbox.h"
#include "menu.h"
#include "mutt_window.h"
#include "muttlib.h"
#include "mx.h"
#include "protos.h"
#include "sidebar.h"
#include "imap/imap.h"
#include "notmuch/mutt_notmuch.h"
#include "nntp/nntp.h"
#include "pop/pop.h"
+ Include dependency graph for mailbox.c:

Go to the source code of this file.

Functions

struct Mailboxmailbox_new (void)
 Create a new Mailbox. More...
 
void mailbox_free (struct Mailbox **m)
 Free a Mailbox. More...
 
static void mailbox_check (struct Mailbox *m, struct stat *ctx_sb, bool check_stats)
 Check a mailbox for new mail. More...
 
void mutt_mailbox_cleanup (const char *path, struct stat *st)
 Restore the timestamp of a mailbox. More...
 
struct Mailboxmutt_find_mailbox (const char *path)
 Find the mailbox with a given path. More...
 
void mutt_update_mailbox (struct Mailbox *m)
 Get the mailbox's current size. More...
 
int mutt_parse_mailboxes (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'mailboxes' command - Implements command_t. More...
 
int mutt_parse_unmailboxes (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err)
 Parse the 'unmailboxes' command - Implements command_t. More...
 
int mutt_mailbox_check (int force)
 Check all AllMailboxes for new mail. More...
 
bool mutt_mailbox_list (void)
 List the mailboxes with new mail. More...
 
void mutt_mailbox_setnotified (struct Mailbox *m)
 Note when the user was last notified of new mail. More...
 
bool mutt_mailbox_notify (void)
 Notify the user if there's new mail. More...
 
void mutt_mailbox (char *s, size_t slen)
 incoming folders completion routine More...
 
void mutt_context_free (struct Context **ctx)
 Free a Context. More...
 

Variables

short MailCheck
 Config: Number of seconds before NeoMutt checks for new mail. More...
 
bool MailCheckStats
 Config: Periodically check for new mail. More...
 
short MailCheckStatsInterval
 Config: How often to check for new mail. More...
 
bool MaildirCheckCur
 Config: Check both 'new' and 'cur' directories for new mail. More...
 
static time_t MailboxTime = 0
 last time we started checking for mail More...
 
static time_t MailboxStatsTime = 0
 last time we check performed mail_check_stats More...
 
static short MailboxCount = 0
 how many boxes with new mail More...
 
static short MailboxNotify = 0
 

of unnotified new boxes

More...
 
struct MailboxList AllMailboxes = STAILQ_HEAD_INITIALIZER(AllMailboxes)
 List of all Mailboxes. More...
 

Detailed Description

Representation of a mailbox.

Authors
  • Michael R. Elkins
  • Kevin J. McCarthy
  • 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 mailbox.c.

Function Documentation

struct Mailbox* mailbox_new ( void  )

Create a new Mailbox.

Return values
ptrNew Mailbox

Definition at line 91 of file mailbox.c.

92 {
93  // char rp[PATH_MAX] = "";
94 
95  struct Mailbox *m = mutt_mem_calloc(1, sizeof(struct Mailbox));
96  // mutt_str_strfcpy(m->path, path, sizeof(m->path));
97  // char *r = realpath(path, rp);
98  // mutt_str_strfcpy(m->realpath, r ? rp : path, sizeof(m->realpath));
99  // m->magic = MUTT_UNKNOWN;
100  // m->desc = get_mailbox_description(m->path);
101 
102  return m;
103 }
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:51
A mailbox.
Definition: mailbox.h:76

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void mailbox_free ( struct Mailbox **  m)

Free a Mailbox.

Parameters
mMailbox to free

Definition at line 109 of file mailbox.c.

110 {
111  if (!m || !*m)
112  return;
113 
114  if (Context && Context->mailbox && Context->mailbox == *m)
115  {
117  FREE(&Context);
118  }
119 
120  FREE(&(*m)->desc);
121  if ((*m)->mdata && (*m)->free_mdata)
122  (*m)->free_mdata(&(*m)->mdata);
123  FREE(m);
124 }
The "current" mailbox.
Definition: context.h:36
struct Mailbox * mailbox
Definition: context.h:50
void mx_cleanup_context(struct Context *ctx)
Release memory and initialize a Context object.
Definition: mx.c:1762
#define FREE(x)
Definition: memory.h:46

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void mailbox_check ( struct Mailbox m,
struct stat *  ctx_sb,
bool  check_stats 
)
static

Check a mailbox for new mail.

Parameters
mMailbox to check
ctx_sbstat() info for the current mailbox (Context)
check_statsIf true, also count the total, new and flagged messages

Definition at line 132 of file mailbox.c.

133 {
134  struct stat sb = { 0 };
135 
136 #ifdef USE_SIDEBAR
137  short orig_new = m->has_new;
138  int orig_count = m->msg_count;
139  int orig_unread = m->msg_unread;
140  int orig_flagged = m->msg_flagged;
141 #endif
142 
143  enum MailboxType mb_magic = mx_path_probe(m->path, NULL);
144 
145  switch (mb_magic)
146  {
147  case MUTT_POP:
148  case MUTT_NNTP:
149  case MUTT_NOTMUCH:
150  case MUTT_IMAP:
151  if (mb_magic != MUTT_IMAP)
152  m->has_new = false;
153  m->magic = mb_magic;
154  break;
155  default:
156  m->has_new = false;
157 
158  if (stat(m->path, &sb) != 0 || (S_ISREG(sb.st_mode) && sb.st_size == 0) ||
159  ((m->magic == MUTT_UNKNOWN) && (m->magic = mx_path_probe(m->path, NULL)) <= 0))
160  {
161  /* if the mailbox still doesn't exist, set the newly created flag to be
162  * ready for when it does. */
163  m->newly_created = true;
164  m->magic = MUTT_UNKNOWN;
165  m->size = 0;
166  return;
167  }
168  break; // kept for consistency.
169  }
170 
171  /* check to see if the folder is the currently selected folder before polling */
172  if (!Context || (Context->mailbox->path[0] == '\0') ||
173  ((m->magic == MUTT_IMAP || m->magic == MUTT_NNTP ||
174  m->magic == MUTT_NOTMUCH || m->magic == MUTT_POP) ?
175  (mutt_str_strcmp(m->path, Context->mailbox->path) != 0) :
176  (sb.st_dev != ctx_sb->st_dev || sb.st_ino != ctx_sb->st_ino)))
177  {
178  switch (m->magic)
179  {
180  case MUTT_IMAP:
181  case MUTT_MBOX:
182  case MUTT_MMDF:
183  case MUTT_MAILDIR:
184  case MUTT_MH:
185  case MUTT_NOTMUCH:
186  if (mx_mbox_check_stats(m, 0) == 0)
187  MailboxCount++;
188  break;
189  default:; /* do nothing */
190  }
191  }
192  else if (CheckMboxSize && Context && (Context->mailbox->path[0] != '\0'))
193  m->size = (off_t) sb.st_size; /* update the size of current folder */
194 
195 #ifdef USE_SIDEBAR
196  if ((orig_new != m->has_new) || (orig_count != m->msg_count) ||
197  (orig_unread != m->msg_unread) || (orig_flagged != m->msg_flagged))
198  {
200  }
201 #endif
202 
203  if (!m->has_new)
204  m->notified = false;
205  else if (!m->notified)
206  MailboxNotify++;
207 }
The "current" mailbox.
Definition: context.h:36
&#39;Notmuch&#39; (virtual) Mailbox type
Definition: magic.h:43
int msg_count
total number of messages
Definition: mailbox.h:86
off_t size
Definition: mailbox.h:82
int msg_unread
number of unread messages
Definition: mailbox.h:87
&#39;NNTP&#39; (Usenet) Mailbox type
Definition: magic.h:41
int msg_flagged
number of flagged messages
Definition: mailbox.h:88
&#39;Maildir&#39; Mailbox type
Definition: magic.h:40
&#39;mmdf&#39; Mailbox type
Definition: magic.h:38
&#39;IMAP&#39; Mailbox type
Definition: magic.h:42
bool has_new
mailbox has new mail
Definition: mailbox.h:83
struct Mailbox * mailbox
Definition: context.h:50
enum MailboxType magic
mailbox type
Definition: mailbox.h:99
&#39;mbox&#39; Mailbox type
Definition: magic.h:37
MailboxType
Supported mailbox formats.
Definition: magic.h:33
WHERE bool CheckMboxSize
Config: (mbox,mmdf) Use mailbox size as an indicator of new mail.
Definition: globals.h:208
bool newly_created
mbox or mmdf just popped into existence
Definition: mailbox.h:100
char path[PATH_MAX]
Definition: mailbox.h:78
Mailbox wasn&#39;t recognised.
Definition: magic.h:36
int mx_mbox_check_stats(struct Mailbox *m, int flags)
Check the statistics for a mailbox - Wrapper for MxOps::mbox_check_stats.
Definition: mx.c:1773
static short MailboxCount
how many boxes with new mail
Definition: mailbox.c:82
&#39;MH&#39; Mailbox type
Definition: magic.h:39
static short MailboxNotify
of unnotified new boxes
Definition: mailbox.c:83
bool notified
user has been notified
Definition: mailbox.h:98
enum MailboxType mx_path_probe(const char *path, struct stat *st)
Find a mailbox that understands a path.
Definition: mx.c:1438
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:612
&#39;POP3&#39; Mailbox type
Definition: magic.h:44

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void mutt_mailbox_cleanup ( const char *  path,
struct stat *  st 
)

Restore the timestamp of a mailbox.

Parameters
pathPath to the mailbox
stTimestamp info from stat()

Fix up the atime and mtime after mbox/mmdf mailbox was modified according to stat() info taken before a modification.

Definition at line 217 of file mailbox.c.

218 {
219 #ifdef HAVE_UTIMENSAT
220  struct timespec ts[2];
221 #else
222  struct utimbuf ut;
223 #endif
224 
225  if (CheckMboxSize)
226  {
227  struct Mailbox *m = mutt_find_mailbox(path);
228  if (m && !m->has_new)
230  }
231  else
232  {
233  /* fix up the times so mailbox won't get confused */
234  if (st->st_mtime > st->st_atime)
235  {
236 #ifdef HAVE_UTIMENSAT
237  ts[0].tv_sec = 0;
238  ts[0].tv_nsec = UTIME_OMIT;
239  ts[1].tv_sec = 0;
240  ts[1].tv_nsec = UTIME_NOW;
241  utimensat(0, buf, ts, 0);
242 #else
243  ut.actime = st->st_atime;
244  ut.modtime = time(NULL);
245  utime(path, &ut);
246 #endif
247  }
248  else
249  {
250 #ifdef HAVE_UTIMENSAT
251  ts[0].tv_sec = 0;
252  ts[0].tv_nsec = UTIME_NOW;
253  ts[1].tv_sec = 0;
254  ts[1].tv_nsec = UTIME_NOW;
255  utimensat(0, buf, ts, 0);
256 #else
257  utime(path, NULL);
258 #endif
259  }
260  }
261 }
void mutt_update_mailbox(struct Mailbox *m)
Get the mailbox&#39;s current size.
Definition: mailbox.c:296
struct Mailbox * mutt_find_mailbox(const char *path)
Find the mailbox with a given path.
Definition: mailbox.c:268
bool has_new
mailbox has new mail
Definition: mailbox.h:83
A mailbox.
Definition: mailbox.h:76
WHERE bool CheckMboxSize
Config: (mbox,mmdf) Use mailbox size as an indicator of new mail.
Definition: globals.h:208
char path[PATH_MAX]
Definition: mailbox.h:78
Time value with nanosecond precision.
Definition: file.h:43

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

struct Mailbox* mutt_find_mailbox ( const char *  path)

Find the mailbox with a given path.

Parameters
pathPath to match
Return values
ptrMatching Mailbox

Definition at line 268 of file mailbox.c.

269 {
270  if (!path)
271  return NULL;
272 
273  struct stat sb;
274  struct stat tmp_sb;
275 
276  if (stat(path, &sb) != 0)
277  return NULL;
278 
279  struct MailboxNode *np = NULL;
280  STAILQ_FOREACH(np, &AllMailboxes, entries)
281  {
282  if ((stat(np->m->path, &tmp_sb) == 0) && (sb.st_dev == tmp_sb.st_dev) &&
283  (sb.st_ino == tmp_sb.st_ino))
284  {
285  return np->m;
286  }
287  }
288 
289  return NULL;
290 }
struct Mailbox * m
Definition: mailbox.h:139
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:350
struct MailboxList AllMailboxes
List of all Mailboxes.
Definition: mailbox.c:85
char path[PATH_MAX]
Definition: mailbox.h:78
List of Mailboxes.
Definition: mailbox.h:137

+ Here is the caller graph for this function:

void mutt_update_mailbox ( struct Mailbox m)

Get the mailbox's current size.

Parameters
mMailbox to check

Definition at line 296 of file mailbox.c.

297 {
298  struct stat sb;
299 
300  if (!m)
301  return;
302 
303  if (stat(m->path, &sb) == 0)
304  m->size = (off_t) sb.st_size;
305  else
306  m->size = 0;
307 }
off_t size
Definition: mailbox.h:82
char path[PATH_MAX]
Definition: mailbox.h:78

+ Here is the caller graph for this function:

int mutt_parse_mailboxes ( struct Buffer buf,
struct Buffer s,
unsigned long  data,
struct Buffer err 
)

Parse the 'mailboxes' command - Implements command_t.

This is also used by 'virtual-mailboxes'.

Definition at line 314 of file mailbox.c.

316 {
317  // char canon[PATH_MAX];
318  // struct stat sb = { 0 };
319 #if 0
320  char f1[PATH_MAX];
321  char *p = NULL;
322 #endif
323 
324  while (MoreArgs(s))
325  {
326  // char *desc = NULL;
327 
328  struct Mailbox *m = mailbox_new();
329 
330  if (data & MUTT_NAMED)
331  {
332  mutt_extract_token(buf, s, 0);
333  if (buf->data && *buf->data)
334  {
335  m->desc = mutt_str_strdup(buf->data);
336  }
337  else
338  {
339  mailbox_free(&m);
340  continue;
341  }
342  }
343 
344  mutt_extract_token(buf, s, 0);
345  if (mutt_buffer_is_empty(buf))
346  {
347  /* Skip empty tokens. */
348  mailbox_free(&m);
349  continue;
350  }
351 
352  mutt_str_strfcpy(m->path, buf->data, sizeof(m->path));
353  /* int rc = */ mx_path_canon2(m, Folder);
354 
355  bool new_account = false;
356  struct Account *a = mx_ac_find(m);
357  if (!a)
358  {
359  a = account_new();
360  a->magic = m->magic;
361  TAILQ_INSERT_TAIL(&AllAccounts, a, entries);
362  new_account = true;
363  }
364 
365  if (!new_account)
366  {
367  struct Mailbox *old_m = mx_mbox_find(a, m->realpath);
368  if (old_m)
369  {
370  if (old_m->flags == MB_HIDDEN)
371  {
372  old_m->flags = MB_NORMAL;
373  mutt_sb_notify_mailbox(old_m, true);
374  struct MailboxNode *mn = mutt_mem_calloc(1, sizeof(*mn));
375  mn->m = old_m;
376  STAILQ_INSERT_TAIL(&AllMailboxes, mn, entries);
377  }
378  mailbox_free(&m);
379  continue;
380  }
381  }
382 
383  if (mx_ac_add(a, m) < 0)
384  {
385  //error
386  mailbox_free(&m);
387  continue;
388  }
389 
390  // SUCCESS
391 
392 #if 0
393 #ifdef USE_NOTMUCH
394  if (nm_path_probe(buf->data, NULL) == MUTT_NOTMUCH)
395  nm_normalize_uri(buf->data, canon, sizeof(canon));
396  else
397 #endif
398  mutt_str_strfcpy(canon, buf->data, sizeof(canon));
399 
400  mutt_expand_path(canon, sizeof(canon));
401 
402  /* Skip empty tokens. */
403  if (!*canon)
404  {
405  FREE(&desc);
406  continue;
407  }
408 
409  /* avoid duplicates */
410  p = realpath(canon, f1);
411  struct MailboxNode *np = NULL;
412  STAILQ_FOREACH(np, &AllMailboxes, entries)
413  {
414  if (mutt_str_strcmp(p ? p : canon, np->m->realpath) == 0)
415  {
416  mutt_debug(3, "mailbox '%s' already registered as '%s'\n", canon, np->m->path);
417  break;
418  }
419  }
420 
421  if (np)
422  {
423  FREE(&desc);
424  continue;
425  }
426 
427  m = mailbox_new(canon);
428 
429  m->notified = true;
430  m->desc = desc;
431 #ifdef USE_NOTMUCH
432  if (nm_path_probe(m->path, NULL) == MUTT_NOTMUCH)
433  {
434  m->magic = MUTT_NOTMUCH;
435  }
436  else
437 #endif
438  {
439  /* for check_mbox_size, it is important that if the folder is new (tested by
440  * reading it), the size is set to 0 so that later when we check we see
441  * that it increased. without check_mbox_size we probably don't care.
442  */
443  if (CheckMboxSize && (stat(m->path, &sb) == 0) && !mbox_test_new_folder(m->path))
444  {
445  /* some systems out there don't have an off_t type */
446  m->size = (off_t) sb.st_size;
447  }
448  }
449 #endif
450 
451  struct MailboxNode *mn = mutt_mem_calloc(1, sizeof(*mn));
452  mn->m = m;
453  STAILQ_INSERT_TAIL(&AllMailboxes, mn, entries);
454 
455 #ifdef USE_SIDEBAR
456  mutt_sb_notify_mailbox(m, true);
457 #endif
458 #ifdef USE_INOTIFY
459  m->magic = mx_path_probe(m->path, NULL);
460  mutt_monitor_add(m);
461 #endif
462  }
463  return 0;
464 }
&#39;Notmuch&#39; (virtual) Mailbox type
Definition: magic.h:43
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:51
off_t size
Definition: mailbox.h:82
enum MailboxType nm_path_probe(const char *path, const struct stat *st)
Is this a Notmuch mailbox? - Implements MxOps::path_probe()
int mx_ac_add(struct Account *a, struct Mailbox *m)
Add a Mailbox to an Account - Wrapper for MxOps::ac_add.
Definition: mx.c:1737
int mx_path_canon2(struct Mailbox *m, const char *folder)
XXX canonicalise the path to realpath.
Definition: mx.c:1597
char * desc
Definition: mailbox.h:81
XXX.
Definition: account.h:36
bool mbox_test_new_folder(const char *path)
Test if an mbox or mmdf mailbox has new mail.
Definition: mbox.c:841
struct Mailbox * mx_mbox_find(struct Account *a, const char *path)
XXX.
Definition: mx.c:1694
#define STAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:387
int mutt_monitor_add(struct Mailbox *m)
Add a watch for a mailbox.
Definition: monitor.c:440
struct Account * mx_ac_find(struct Mailbox *m)
XXX.
Definition: mx.c:1671
struct Mailbox * m
Definition: mailbox.h:139
char * mutt_expand_path(char *buf, size_t buflen)
Create the canonical path.
Definition: muttlib.c:157
#define MoreArgs(buf)
Definition: buffer.h:44
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, int flags)
Extract one token from a string.
Definition: init.c:2520
struct AccountList AllAccounts
List of all Accounts.
Definition: account.c:33
enum MailboxType magic
mailbox type
Definition: mailbox.h:99
int flags
e.g.
Definition: mailbox.h:128
A folder/dir in the browser.
Definition: browser.h:47
#define MB_HIDDEN
Definition: mailbox.h:50
A mailbox.
Definition: mailbox.h:76
#define PATH_MAX
Definition: mutt.h:46
enum MailboxType magic
Definition: account.h:38
char * data
pointer to data
Definition: buffer.h:35
WHERE bool CheckMboxSize
Config: (mbox,mmdf) Use mailbox size as an indicator of new mail.
Definition: globals.h:208
size_t mutt_str_strfcpy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:742
#define TAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:803
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:350
struct MailboxList AllMailboxes
List of all Mailboxes.
Definition: mailbox.c:85
char path[PATH_MAX]
Definition: mailbox.h:78
struct Mailbox * mailbox_new(void)
Create a new Mailbox.
Definition: mailbox.c:91
#define MUTT_NAMED
Definition: mailbox.h:46
char * mutt_str_strdup(const char *str)
Copy a string, safely.
Definition: string.c:384
bool notified
user has been notified
Definition: mailbox.h:98
#define FREE(x)
Definition: memory.h:46
List of Mailboxes.
Definition: mailbox.h:137
void mailbox_free(struct Mailbox **m)
Free a Mailbox.
Definition: mailbox.c:109
char realpath[PATH_MAX]
used for duplicate detection, context comparison, and the sidebar
Definition: mailbox.h:79
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
struct Account * account_new(void)
Create a new Account.
Definition: account.c:39
bool mutt_buffer_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition: buffer.c:285
enum MailboxType mx_path_probe(const char *path, struct stat *st)
Find a mailbox that understands a path.
Definition: mx.c:1438
#define MB_NORMAL
Definition: mailbox.h:49
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:612

+ Here is the call graph for this function:

int mutt_parse_unmailboxes ( struct Buffer buf,
struct Buffer s,
unsigned long  data,
struct Buffer err 
)

Parse the 'unmailboxes' command - Implements command_t.

This is also used by 'unvirtual-mailboxes'

Definition at line 471 of file mailbox.c.

473 {
474  char tmp[PATH_MAX];
475  bool clear_all = false;
476 
477  while (!clear_all && MoreArgs(s))
478  {
479  mutt_extract_token(buf, s, 0);
480 
481  if (mutt_str_strcmp(buf->data, "*") == 0)
482  {
483  clear_all = true;
484  }
485  else
486  {
487  mutt_str_strfcpy(tmp, buf->data, sizeof(tmp));
488  mutt_expand_path(tmp, sizeof(tmp));
489  }
490 
491  struct MailboxNode *np = NULL;
492  struct MailboxNode *nptmp = NULL;
493  STAILQ_FOREACH_SAFE(np, &AllMailboxes, entries, nptmp)
494  {
495  /* Decide whether to delete all normal mailboxes or all virtual */
496  bool virt = ((np->m->magic == MUTT_NOTMUCH) && (data & MUTT_VIRTUAL));
497  bool norm = ((np->m->magic != MUTT_NOTMUCH) && !(data & MUTT_VIRTUAL));
498  bool clear_this = clear_all && (virt || norm);
499 
500  if (clear_this || (mutt_str_strcasecmp(tmp, np->m->path) == 0) ||
501  (mutt_str_strcasecmp(tmp, np->m->desc) == 0))
502  {
503 #ifdef USE_SIDEBAR
504  mutt_sb_notify_mailbox(np->m, false);
505 #endif
506 #ifdef USE_INOTIFY
507  mutt_monitor_remove(np->m);
508 #endif
509  if (Context->mailbox == np->m)
510  {
511  np->m->flags |= MB_HIDDEN;
512  }
513  else
514  {
515  mx_ac_remove(np->m);
516  mailbox_free(&np->m);
517  }
518  STAILQ_REMOVE(&AllMailboxes, np, MailboxNode, entries);
519  FREE(&np);
520  continue;
521  }
522  }
523  }
524  return 0;
525 }
The "current" mailbox.
Definition: context.h:36
&#39;Notmuch&#39; (virtual) Mailbox type
Definition: magic.h:43
#define STAILQ_REMOVE(head, elm, type, field)
Definition: queue.h:400
char * desc
Definition: mailbox.h:81
int mutt_monitor_remove(struct Mailbox *m)
Remove a watch for a mailbox.
Definition: monitor.c:478
struct Mailbox * m
Definition: mailbox.h:139
char * mutt_expand_path(char *buf, size_t buflen)
Create the canonical path.
Definition: muttlib.c:157
#define MoreArgs(buf)
Definition: buffer.h:44
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, int flags)
Extract one token from a string.
Definition: init.c:2520
struct Mailbox * mailbox
Definition: context.h:50
enum MailboxType magic
mailbox type
Definition: mailbox.h:99
#define MUTT_VIRTUAL
Definition: mailbox.h:47
#define STAILQ_FOREACH_SAFE(var, head, field, tvar)
Definition: queue.h:360
int flags
e.g.
Definition: mailbox.h:128
#define MB_HIDDEN
Definition: mailbox.h:50
#define PATH_MAX
Definition: mutt.h:46
char * data
pointer to data
Definition: buffer.h:35
size_t mutt_str_strfcpy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:742
struct MailboxList AllMailboxes
List of all Mailboxes.
Definition: mailbox.c:85
char path[PATH_MAX]
Definition: mailbox.h:78
int mutt_str_strcasecmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition: string.c:625
#define FREE(x)
Definition: memory.h:46
List of Mailboxes.
Definition: mailbox.h:137
void mailbox_free(struct Mailbox **m)
Free a Mailbox.
Definition: mailbox.c:109
int mx_ac_remove(struct Mailbox *m)
Remove a Mailbox from an Account and delete Account if empty.
Definition: mx.c:1749
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:612

+ Here is the call graph for this function:

int mutt_mailbox_check ( int  force)

Check all AllMailboxes for new mail.

Parameters
forceForce flags, see below
Return values
numNumber of mailboxes with new mail

The force argument may be any combination of the following values:

  • MUTT_MAILBOX_CHECK_FORCE ignore MailboxTime and check for new mail
  • MUTT_MAILBOX_CHECK_FORCE_STATS ignore MailboxTime and calculate statistics

Check all AllMailboxes for new mail and total/new/flagged messages

Definition at line 538 of file mailbox.c.

539 {
540  struct stat contex_sb;
541  time_t t;
542  bool check_stats = false;
543  contex_sb.st_dev = 0;
544  contex_sb.st_ino = 0;
545 
546 #ifdef USE_IMAP
547  /* update postponed count as well, on force */
548  if (force & MUTT_MAILBOX_CHECK_FORCE)
550 #endif
551 
552  /* fastest return if there are no mailboxes */
554  return 0;
555 
556  t = time(NULL);
557  if (!force && (t - MailboxTime < MailCheck))
558  return MailboxCount;
559 
560  if ((force & MUTT_MAILBOX_CHECK_FORCE_STATS) ||
562  {
563  check_stats = true;
564  MailboxStatsTime = t;
565  }
566 
567  MailboxTime = t;
568  MailboxCount = 0;
569  MailboxNotify = 0;
570 
571  /* check device ID and serial number instead of comparing paths */
572  if (!Context || !Context->mailbox || (Context->mailbox->magic == MUTT_IMAP) ||
574 #ifdef USE_NNTP
575  || (Context->mailbox->magic == MUTT_NNTP)
576 #endif
577  || stat(Context->mailbox->path, &contex_sb) != 0)
578  {
579  contex_sb.st_dev = 0;
580  contex_sb.st_ino = 0;
581  }
582 
583  struct MailboxNode *np = NULL;
584  STAILQ_FOREACH(np, &AllMailboxes, entries)
585  {
586  mailbox_check(np->m, &contex_sb,
587  check_stats || (!np->m->first_check_stats_done && MailCheckStats));
588  np->m->first_check_stats_done = true;
589  }
590 
591  return MailboxCount;
592 }
The "current" mailbox.
Definition: context.h:36
bool MailCheckStats
Config: Periodically check for new mail.
Definition: mailbox.c:76
&#39;NNTP&#39; (Usenet) Mailbox type
Definition: magic.h:41
short MailCheckStatsInterval
Config: How often to check for new mail.
Definition: mailbox.c:77
#define MUTT_MAILBOX_CHECK_FORCE_STATS
Definition: mailbox.h:161
bool first_check_stats_done
true when the check have been done at least on time
Definition: mailbox.h:110
&#39;IMAP&#39; Mailbox type
Definition: magic.h:42
static void mailbox_check(struct Mailbox *m, struct stat *ctx_sb, bool check_stats)
Check a mailbox for new mail.
Definition: mailbox.c:132
struct Mailbox * m
Definition: mailbox.h:139
struct Mailbox * mailbox
Definition: context.h:50
enum MailboxType magic
mailbox type
Definition: mailbox.h:99
static time_t MailboxTime
last time we started checking for mail
Definition: mailbox.c:80
static time_t MailboxStatsTime
last time we check performed mail_check_stats
Definition: mailbox.c:81
#define MUTT_MAILBOX_CHECK_FORCE
Definition: mailbox.h:160
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:350
void mutt_update_num_postponed(void)
Force the update of the number of postponed messages.
Definition: postpone.c:192
struct MailboxList AllMailboxes
List of all Mailboxes.
Definition: mailbox.c:85
char path[PATH_MAX]
Definition: mailbox.h:78
short MailCheck
Config: Number of seconds before NeoMutt checks for new mail.
Definition: mailbox.c:75
static short MailboxCount
how many boxes with new mail
Definition: mailbox.c:82
static short MailboxNotify
of unnotified new boxes
Definition: mailbox.c:83
#define STAILQ_EMPTY(head)
Definition: queue.h:346
List of Mailboxes.
Definition: mailbox.h:137
&#39;POP3&#39; Mailbox type
Definition: magic.h:44

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool mutt_mailbox_list ( void  )

List the mailboxes with new mail.

Return values
trueIf there is new mail

Definition at line 598 of file mailbox.c.

599 {
600  char path[PATH_MAX];
601  char mailboxlist[2 * STRING];
602  size_t pos = 0;
603  int first = 1;
604 
605  int have_unnotified = MailboxNotify;
606 
607  mailboxlist[0] = '\0';
608  pos += strlen(strncat(mailboxlist, _("New mail in "), sizeof(mailboxlist) - 1 - pos));
609  struct MailboxNode *np = NULL;
610  STAILQ_FOREACH(np, &AllMailboxes, entries)
611  {
612  /* Is there new mail in this mailbox? */
613  if (!np->m->has_new || (have_unnotified && np->m->notified))
614  continue;
615 
616  mutt_str_strfcpy(path, np->m->path, sizeof(path));
617  mutt_pretty_mailbox(path, sizeof(path));
618 
619  if (!first && (MuttMessageWindow->cols >= 7) &&
620  (pos + strlen(path) >= (size_t) MuttMessageWindow->cols - 7))
621  {
622  break;
623  }
624 
625  if (!first)
626  pos += strlen(strncat(mailboxlist + pos, ", ", sizeof(mailboxlist) - 1 - pos));
627 
628  /* Prepend an asterisk to mailboxes not already notified */
629  if (!np->m->notified)
630  {
631  /* pos += strlen (strncat(mailboxlist + pos, "*", sizeof(mailboxlist)-1-pos)); */
632  np->m->notified = true;
633  MailboxNotify--;
634  }
635  pos += strlen(strncat(mailboxlist + pos, path, sizeof(mailboxlist) - 1 - pos));
636  first = 0;
637  }
638 
639  if (!first && np)
640  {
641  strncat(mailboxlist + pos, ", ...", sizeof(mailboxlist) - 1 - pos);
642  }
643  if (!first)
644  {
645  mutt_message("%s", mailboxlist);
646  return true;
647  }
648  /* there were no mailboxes needing to be notified, so clean up since
649  * MailboxNotify has somehow gotten out of sync
650  */
651  MailboxNotify = 0;
652  return false;
653 }
void mutt_pretty_mailbox(char *s, size_t buflen)
Shorten a mailbox path using &#39;~&#39; or &#39;=&#39;.
Definition: muttlib.c:606
#define mutt_message(...)
Definition: logging.h:87
#define _(a)
Definition: message.h:28
struct Mailbox * m
Definition: mailbox.h:139
bool has_new
mailbox has new mail
Definition: mailbox.h:83
#define PATH_MAX
Definition: mutt.h:46
size_t mutt_str_strfcpy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:742
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:350
struct MailboxList AllMailboxes
List of all Mailboxes.
Definition: mailbox.c:85
char path[PATH_MAX]
Definition: mailbox.h:78
#define STRING
Definition: string2.h:35
static short MailboxNotify
of unnotified new boxes
Definition: mailbox.c:83
bool notified
user has been notified
Definition: mailbox.h:98
struct MuttWindow * MuttMessageWindow
Message Window.
Definition: mutt_window.c:41
List of Mailboxes.
Definition: mailbox.h:137

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void mutt_mailbox_setnotified ( struct Mailbox m)

Note when the user was last notified of new mail.

mark mailbox just left as already notified

Parameters
mMailbox

Definition at line 659 of file mailbox.c.

660 {
661  if (!m)
662  return;
663 
664  m->notified = true;
665 #if HAVE_CLOCK_GETTIME
666  clock_gettime(CLOCK_REALTIME, &m->last_visited);
667 #else
668  m->last_visited.tv_nsec = 0;
669  time(&m->last_visited.tv_sec);
670 #endif
671 }
time_t tv_sec
Definition: file.h:45
struct timespec last_visited
time of last exit from this mailbox
Definition: mailbox.h:102
long tv_nsec
Definition: file.h:46
bool notified
user has been notified
Definition: mailbox.h:98

+ Here is the caller graph for this function:

bool mutt_mailbox_notify ( void  )

Notify the user if there's new mail.

Return values
trueIf there is new mail

Definition at line 677 of file mailbox.c.

678 {
680  {
681  return mutt_mailbox_list();
682  }
683  return false;
684 }
int mutt_mailbox_check(int force)
Check all AllMailboxes for new mail.
Definition: mailbox.c:538
bool mutt_mailbox_list(void)
List the mailboxes with new mail.
Definition: mailbox.c:598
static short MailboxNotify
of unnotified new boxes
Definition: mailbox.c:83

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void mutt_mailbox ( char *  s,
size_t  slen 
)

incoming folders completion routine

Parameters
sBuffer containing name of current mailbox
slenBuffer length

Given a folder name, find the next incoming folder with new mail.

Definition at line 693 of file mailbox.c.

694 {
695  mutt_expand_path(s, slen);
696 
697  if (mutt_mailbox_check(0))
698  {
699  int found = 0;
700  for (int pass = 0; pass < 2; pass++)
701  {
702  struct MailboxNode *np = NULL;
703  STAILQ_FOREACH(np, &AllMailboxes, entries)
704  {
705  if (np->m->magic == MUTT_NOTMUCH) /* only match real mailboxes */
706  continue;
707  mutt_expand_path(np->m->path, sizeof(np->m->path));
708  if ((found || pass) && np->m->has_new)
709  {
710  mutt_str_strfcpy(s, np->m->path, slen);
711  mutt_pretty_mailbox(s, slen);
712  return;
713  }
714  if (mutt_str_strcmp(s, np->m->path) == 0)
715  found = 1;
716  }
717  }
718 
719  mutt_mailbox_check(MUTT_MAILBOX_CHECK_FORCE); /* mailbox was wrong - resync things */
720  }
721 
722  /* no folders with new mail */
723  *s = '\0';
724 }
&#39;Notmuch&#39; (virtual) Mailbox type
Definition: magic.h:43
void mutt_pretty_mailbox(char *s, size_t buflen)
Shorten a mailbox path using &#39;~&#39; or &#39;=&#39;.
Definition: muttlib.c:606
int mutt_mailbox_check(int force)
Check all AllMailboxes for new mail.
Definition: mailbox.c:538
struct Mailbox * m
Definition: mailbox.h:139
bool has_new
mailbox has new mail
Definition: mailbox.h:83
char * mutt_expand_path(char *buf, size_t buflen)
Create the canonical path.
Definition: muttlib.c:157
enum MailboxType magic
mailbox type
Definition: mailbox.h:99
size_t mutt_str_strfcpy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:742
#define MUTT_MAILBOX_CHECK_FORCE
Definition: mailbox.h:160
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:350
struct MailboxList AllMailboxes
List of all Mailboxes.
Definition: mailbox.c:85
char path[PATH_MAX]
Definition: mailbox.h:78
List of Mailboxes.
Definition: mailbox.h:137
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:612

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void mutt_context_free ( struct Context **  ctx)

Free a Context.

Parameters
ctxContext to free

Definition at line 730 of file mailbox.c.

731 {
732  if (!ctx || !*ctx)
733  return;
734 
735  mailbox_free(&(*ctx)->mailbox);
736  FREE(ctx);
737 }
#define FREE(x)
Definition: memory.h:46
void mailbox_free(struct Mailbox **m)
Free a Mailbox.
Definition: mailbox.c:109

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Variable Documentation

short MailCheck

Config: Number of seconds before NeoMutt checks for new mail.

Definition at line 75 of file mailbox.c.

bool MailCheckStats

Config: Periodically check for new mail.

Definition at line 76 of file mailbox.c.

short MailCheckStatsInterval

Config: How often to check for new mail.

Definition at line 77 of file mailbox.c.

bool MaildirCheckCur

Config: Check both 'new' and 'cur' directories for new mail.

Definition at line 78 of file mailbox.c.

time_t MailboxTime = 0
static

last time we started checking for mail

Definition at line 80 of file mailbox.c.

time_t MailboxStatsTime = 0
static

last time we check performed mail_check_stats

Definition at line 81 of file mailbox.c.

short MailboxCount = 0
static

how many boxes with new mail

Definition at line 82 of file mailbox.c.

short MailboxNotify = 0
static

of unnotified new boxes

Definition at line 83 of file mailbox.c.

struct MailboxList AllMailboxes = STAILQ_HEAD_INITIALIZER(AllMailboxes)

List of all Mailboxes.

Definition at line 85 of file mailbox.c.