NeoMutt  2018-07-16 +1360-3df4a2
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 "mutt_commands.h"
#include "mutt_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 **ptr)
 Free a Mailbox. More...
 
static void mailbox_check (struct Mailbox *m_cur, struct Mailbox *m_check, 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...
 
struct Mailboxmutt_find_mailbox_desc (const char *desc)
 Find the mailbox with a given description. More...
 
void mutt_update_mailbox (struct Mailbox *m)
 Get the mailbox's current size. More...
 
int mutt_mailbox_check (struct Mailbox *m_cur, 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 (struct Mailbox *m_cur)
 Notify the user if there's new mail. More...
 
void mutt_mailbox (struct Mailbox *m_cur, char *s, size_t slen)
 incoming folders completion routine More...
 
void mutt_mailbox_changed (struct Mailbox *m, enum MailboxNotification action)
 Notify listeners of a change to a Mailbox. More...
 

Variables

short C_MailCheck
 Config: Number of seconds before NeoMutt checks for new mail. More...
 
bool C_MailCheckStats
 Config: Periodically check for new mail. More...
 
short C_MailCheckStatsInterval
 Config: How often to check for new mail. More...
 
bool C_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 92 of file mailbox.c.

93 {
94  struct Mailbox *m = mutt_mem_calloc(1, sizeof(struct Mailbox));
95 
96  return m;
97 }
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:83

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void mailbox_free ( struct Mailbox **  ptr)

Free a Mailbox.

Parameters
[out]ptrMailbox to free

Definition at line 103 of file mailbox.c.

104 {
105  if (!ptr || !*ptr)
106  return;
107 
108  struct Mailbox *m = *ptr;
110 
111  FREE(&m->desc);
112  if (m->mdata && m->free_mdata)
113  m->free_mdata(&m->mdata);
114  FREE(ptr);
115 }
char * desc
Definition: mailbox.h:88
Mailbox was closed.
Definition: mailbox.h:54
void(* free_mdata)(void **)
driver-specific data free function
Definition: mailbox.h:138
void * mdata
driver specific data
Definition: mailbox.h:137
A mailbox.
Definition: mailbox.h:83
#define FREE(x)
Definition: memory.h:40
void mutt_mailbox_changed(struct Mailbox *m, enum MailboxNotification action)
Notify listeners of a change to a Mailbox.
Definition: mailbox.c:529

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Check a mailbox for new mail.

Parameters
m_curCurrent Mailbox
m_checkMailbox to check
ctx_sbstat() info for the current Mailbox
check_statsIf true, also count the total, new and flagged messages

Definition at line 124 of file mailbox.c.

126 {
127  struct stat sb = { 0 };
128 
129 #ifdef USE_SIDEBAR
130  short orig_new = m_check->has_new;
131  int orig_count = m_check->msg_count;
132  int orig_unread = m_check->msg_unread;
133  int orig_flagged = m_check->msg_flagged;
134 #endif
135 
136  enum MailboxType mb_magic = mx_path_probe(m_check->path, NULL);
137 
138  switch (mb_magic)
139  {
140  case MUTT_POP:
141  case MUTT_NNTP:
142  case MUTT_NOTMUCH:
143  case MUTT_IMAP:
144  if (mb_magic != MUTT_IMAP)
145  m_check->has_new = false;
146  m_check->magic = mb_magic;
147  break;
148  default:
149  m_check->has_new = false;
150 
151  if ((stat(m_check->path, &sb) != 0) || (S_ISREG(sb.st_mode) && (sb.st_size == 0)) ||
152  ((m_check->magic == MUTT_UNKNOWN) &&
153  ((m_check->magic = mx_path_probe(m_check->path, NULL)) <= 0)))
154  {
155  /* if the mailbox still doesn't exist, set the newly created flag to be
156  * ready for when it does. */
157  m_check->newly_created = true;
158  m_check->magic = MUTT_UNKNOWN;
159  m_check->size = 0;
160  return;
161  }
162  break; // kept for consistency.
163  }
164 
165  /* check to see if the folder is the currently selected folder before polling */
166  if (!m_cur || (m_cur->path[0] == '\0') ||
167  (((m_check->magic == MUTT_IMAP) || (m_check->magic == MUTT_NNTP) ||
168  (m_check->magic == MUTT_NOTMUCH) || (m_check->magic == MUTT_POP)) ?
169  (mutt_str_strcmp(m_check->path, m_cur->path) != 0) :
170  ((sb.st_dev != ctx_sb->st_dev) || (sb.st_ino != ctx_sb->st_ino))))
171  {
172  switch (m_check->magic)
173  {
174  case MUTT_IMAP:
175  case MUTT_MBOX:
176  case MUTT_MMDF:
177  case MUTT_MAILDIR:
178  case MUTT_MH:
179  case MUTT_NOTMUCH:
180  if (mx_mbox_check_stats(m_check, 0) == 0)
181  MailboxCount++;
182  break;
183  default:; /* do nothing */
184  }
185  }
186  else if (C_CheckMboxSize && m_cur && (m_cur->path[0] != '\0'))
187  m_check->size = (off_t) sb.st_size; /* update the size of current folder */
188 
189 #ifdef USE_SIDEBAR
190  if ((orig_new != m_check->has_new) || (orig_count != m_check->msg_count) ||
191  (orig_unread != m_check->msg_unread) || (orig_flagged != m_check->msg_flagged))
192  {
194  }
195 #endif
196 
197  if (!m_check->has_new)
198  m_check->notified = false;
199  else if (!m_check->notified)
200  MailboxNotify++;
201 }
&#39;Notmuch&#39; (virtual) Mailbox type
Definition: magic.h:43
int msg_count
total number of messages
Definition: mailbox.h:93
off_t size
Definition: mailbox.h:89
int msg_unread
number of unread messages
Definition: mailbox.h:94
&#39;NNTP&#39; (Usenet) Mailbox type
Definition: magic.h:41
int msg_flagged
number of flagged messages
Definition: mailbox.h:95
&#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
WHERE bool C_CheckMboxSize
Config: (mbox,mmdf) Use mailbox size as an indicator of new mail.
Definition: globals.h:212
#define REDRAW_SIDEBAR
Redraw the sidebar.
Definition: mutt_menu.h:51
bool has_new
mailbox has new mail
Definition: mailbox.h:90
enum MailboxType magic
mailbox type
Definition: mailbox.h:106
&#39;mbox&#39; Mailbox type
Definition: magic.h:37
MailboxType
Supported mailbox formats.
Definition: magic.h:33
bool newly_created
mbox or mmdf just popped into existence
Definition: mailbox.h:107
char path[PATH_MAX]
Definition: mailbox.h:85
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:1557
static short MailboxCount
how many boxes with new mail
Definition: mailbox.c:83
&#39;MH&#39; Mailbox type
Definition: magic.h:39
static short MailboxNotify
of unnotified new boxes
Definition: mailbox.c:84
bool notified
user has been notified
Definition: mailbox.h:105
enum MailboxType mx_path_probe(const char *path, struct stat *st)
Find a mailbox that understands a path.
Definition: mx.c:1207
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:611
&#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 211 of file mailbox.c.

212 {
213 #ifdef HAVE_UTIMENSAT
214  struct timespec ts[2];
215 #else
216  struct utimbuf ut;
217 #endif
218 
219  if (C_CheckMboxSize)
220  {
221  struct Mailbox *m = mutt_find_mailbox(path);
222  if (m && !m->has_new)
224  }
225  else
226  {
227  /* fix up the times so mailbox won't get confused */
228  if (st->st_mtime > st->st_atime)
229  {
230 #ifdef HAVE_UTIMENSAT
231  ts[0].tv_sec = 0;
232  ts[0].tv_nsec = UTIME_OMIT;
233  ts[1].tv_sec = 0;
234  ts[1].tv_nsec = UTIME_NOW;
235  utimensat(0, buf, ts, 0);
236 #else
237  ut.actime = st->st_atime;
238  ut.modtime = time(NULL);
239  utime(path, &ut);
240 #endif
241  }
242  else
243  {
244 #ifdef HAVE_UTIMENSAT
245  ts[0].tv_sec = 0;
246  ts[0].tv_nsec = UTIME_NOW;
247  ts[1].tv_sec = 0;
248  ts[1].tv_nsec = UTIME_NOW;
249  utimensat(0, buf, ts, 0);
250 #else
251  utime(path, NULL);
252 #endif
253  }
254  }
255 }
void mutt_update_mailbox(struct Mailbox *m)
Get the mailbox&#39;s current size.
Definition: mailbox.c:311
struct Mailbox * mutt_find_mailbox(const char *path)
Find the mailbox with a given path.
Definition: mailbox.c:262
WHERE bool C_CheckMboxSize
Config: (mbox,mmdf) Use mailbox size as an indicator of new mail.
Definition: globals.h:212
bool has_new
mailbox has new mail
Definition: mailbox.h:90
A mailbox.
Definition: mailbox.h:83
char path[PATH_MAX]
Definition: mailbox.h:85
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 262 of file mailbox.c.

263 {
264  if (!path)
265  return NULL;
266 
267  struct stat sb;
268  struct stat tmp_sb;
269 
270  if (stat(path, &sb) != 0)
271  return NULL;
272 
273  struct MailboxNode *np = NULL;
274  STAILQ_FOREACH(np, &AllMailboxes, entries)
275  {
276  if ((stat(np->mailbox->path, &tmp_sb) == 0) &&
277  (sb.st_dev == tmp_sb.st_dev) && (sb.st_ino == tmp_sb.st_ino))
278  {
279  return np->mailbox;
280  }
281  }
282 
283  return NULL;
284 }
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:350
struct MailboxList AllMailboxes
List of all Mailboxes.
Definition: mailbox.c:86
char path[PATH_MAX]
Definition: mailbox.h:85
List of Mailboxes.
Definition: mailbox.h:147
struct Mailbox * mailbox
Definition: mailbox.h:149

+ Here is the caller graph for this function:

struct Mailbox* mutt_find_mailbox_desc ( const char *  desc)

Find the mailbox with a given description.

Parameters
descDescription to match
Return values
ptrMatching Mailbox
NULLNo matching mailbox found

Definition at line 292 of file mailbox.c.

293 {
294  if (!desc)
295  return NULL;
296 
297  struct MailboxNode *np = NULL;
298  STAILQ_FOREACH(np, &AllMailboxes, entries)
299  {
300  if (np->mailbox->desc && (mutt_str_strcmp(np->mailbox->desc, desc) == 0))
301  return np->mailbox;
302  }
303 
304  return NULL;
305 }
char * desc
Definition: mailbox.h:88
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:350
struct MailboxList AllMailboxes
List of all Mailboxes.
Definition: mailbox.c:86
List of Mailboxes.
Definition: mailbox.h:147
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:611
struct Mailbox * mailbox
Definition: mailbox.h:149

+ Here is the call graph for this function:

+ 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 311 of file mailbox.c.

312 {
313  struct stat sb;
314 
315  if (!m)
316  return;
317 
318  if (stat(m->path, &sb) == 0)
319  m->size = (off_t) sb.st_size;
320  else
321  m->size = 0;
322 }
off_t size
Definition: mailbox.h:89
char path[PATH_MAX]
Definition: mailbox.h:85

+ Here is the caller graph for this function:

int mutt_mailbox_check ( struct Mailbox m_cur,
int  force 
)

Check all AllMailboxes for new mail.

Parameters
m_curCurrent Mailbox
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 336 of file mailbox.c.

337 {
338  struct stat contex_sb;
339  time_t t;
340  bool check_stats = false;
341  contex_sb.st_dev = 0;
342  contex_sb.st_ino = 0;
343 
344 #ifdef USE_IMAP
345  /* update postponed count as well, on force */
346  if (force & MUTT_MAILBOX_CHECK_FORCE)
348 #endif
349 
350  /* fastest return if there are no mailboxes */
352  return 0;
353 
354  t = time(NULL);
355  if (!force && (t - MailboxTime < C_MailCheck))
356  return MailboxCount;
357 
358  if ((force & MUTT_MAILBOX_CHECK_FORCE_STATS) ||
360  {
361  check_stats = true;
362  MailboxStatsTime = t;
363  }
364 
365  MailboxTime = t;
366  MailboxCount = 0;
367  MailboxNotify = 0;
368 
369  /* check device ID and serial number instead of comparing paths */
370  if (!m_cur || (m_cur->magic == MUTT_IMAP) || (m_cur->magic == MUTT_POP)
371 #ifdef USE_NNTP
372  || (m_cur->magic == MUTT_NNTP)
373 #endif
374  || stat(m_cur->path, &contex_sb) != 0)
375  {
376  contex_sb.st_dev = 0;
377  contex_sb.st_ino = 0;
378  }
379 
380  struct MailboxNode *np = NULL;
381  STAILQ_FOREACH(np, &AllMailboxes, entries)
382  {
383  mailbox_check(m_cur, np->mailbox, &contex_sb,
384  check_stats || (!np->mailbox->first_check_stats_done && C_MailCheckStats));
385  np->mailbox->first_check_stats_done = true;
386  }
387 
388  return MailboxCount;
389 }
&#39;NNTP&#39; (Usenet) Mailbox type
Definition: magic.h:41
#define MUTT_MAILBOX_CHECK_FORCE_STATS
Definition: mailbox.h:171
bool C_MailCheckStats
Config: Periodically check for new mail.
Definition: mailbox.c:77
bool first_check_stats_done
true when the check have been done at least on time
Definition: mailbox.h:117
&#39;IMAP&#39; Mailbox type
Definition: magic.h:42
short C_MailCheck
Config: Number of seconds before NeoMutt checks for new mail.
Definition: mailbox.c:76
enum MailboxType magic
mailbox type
Definition: mailbox.h:106
static time_t MailboxTime
last time we started checking for mail
Definition: mailbox.c:81
static time_t MailboxStatsTime
last time we check performed mail_check_stats
Definition: mailbox.c:82
#define MUTT_MAILBOX_CHECK_FORCE
Definition: mailbox.h:170
#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:195
struct MailboxList AllMailboxes
List of all Mailboxes.
Definition: mailbox.c:86
char path[PATH_MAX]
Definition: mailbox.h:85
static short MailboxCount
how many boxes with new mail
Definition: mailbox.c:83
static short MailboxNotify
of unnotified new boxes
Definition: mailbox.c:84
#define STAILQ_EMPTY(head)
Definition: queue.h:346
List of Mailboxes.
Definition: mailbox.h:147
static void mailbox_check(struct Mailbox *m_cur, struct Mailbox *m_check, struct stat *ctx_sb, bool check_stats)
Check a mailbox for new mail.
Definition: mailbox.c:124
&#39;POP3&#39; Mailbox type
Definition: magic.h:44
struct Mailbox * mailbox
Definition: mailbox.h:149
short C_MailCheckStatsInterval
Config: How often to check for new mail.
Definition: mailbox.c:78

+ 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 395 of file mailbox.c.

396 {
397  char path[PATH_MAX];
398  char mailboxlist[512];
399  size_t pos = 0;
400  int first = 1;
401 
402  int have_unnotified = MailboxNotify;
403 
404  mailboxlist[0] = '\0';
405  pos += strlen(strncat(mailboxlist, _("New mail in "), sizeof(mailboxlist) - 1 - pos));
406  struct MailboxNode *np = NULL;
407  STAILQ_FOREACH(np, &AllMailboxes, entries)
408  {
409  /* Is there new mail in this mailbox? */
410  if (!np->mailbox->has_new || (have_unnotified && np->mailbox->notified))
411  continue;
412 
413  mutt_str_strfcpy(path, np->mailbox->path, sizeof(path));
414  mutt_pretty_mailbox(path, sizeof(path));
415 
416  if (!first && (MuttMessageWindow->cols >= 7) &&
417  (pos + strlen(path) >= (size_t) MuttMessageWindow->cols - 7))
418  {
419  break;
420  }
421 
422  if (!first)
423  pos += strlen(strncat(mailboxlist + pos, ", ", sizeof(mailboxlist) - 1 - pos));
424 
425  /* Prepend an asterisk to mailboxes not already notified */
426  if (!np->mailbox->notified)
427  {
428  /* pos += strlen (strncat(mailboxlist + pos, "*", sizeof(mailboxlist)-1-pos)); */
429  np->mailbox->notified = true;
430  MailboxNotify--;
431  }
432  pos += strlen(strncat(mailboxlist + pos, path, sizeof(mailboxlist) - 1 - pos));
433  first = 0;
434  }
435 
436  if (!first && np)
437  {
438  strncat(mailboxlist + pos, ", ...", sizeof(mailboxlist) - 1 - pos);
439  }
440  if (!first)
441  {
442  mutt_message("%s", mailboxlist);
443  return true;
444  }
445  /* there were no mailboxes needing to be notified, so clean up since
446  * MailboxNotify has somehow gotten out of sync */
447  MailboxNotify = 0;
448  return false;
449 }
void mutt_pretty_mailbox(char *s, size_t buflen)
Shorten a mailbox path using &#39;~&#39; or &#39;=&#39;.
Definition: muttlib.c:605
#define mutt_message(...)
Definition: logging.h:87
#define _(a)
Definition: message.h:28
bool has_new
mailbox has new mail
Definition: mailbox.h:90
#define PATH_MAX
Definition: mutt.h:48
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:741
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:350
struct MailboxList AllMailboxes
List of all Mailboxes.
Definition: mailbox.c:86
char path[PATH_MAX]
Definition: mailbox.h:85
static short MailboxNotify
of unnotified new boxes
Definition: mailbox.c:84
bool notified
user has been notified
Definition: mailbox.h:105
struct MuttWindow * MuttMessageWindow
Message Window.
Definition: mutt_window.c:41
List of Mailboxes.
Definition: mailbox.h:147
struct Mailbox * mailbox
Definition: mailbox.h:149

+ 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 455 of file mailbox.c.

456 {
457  if (!m)
458  return;
459 
460  m->notified = true;
461 #if HAVE_CLOCK_GETTIME
462  clock_gettime(CLOCK_REALTIME, &m->last_visited);
463 #else
464  m->last_visited.tv_nsec = 0;
465  time(&m->last_visited.tv_sec);
466 #endif
467 }
time_t tv_sec
Definition: file.h:45
struct timespec last_visited
time of last exit from this mailbox
Definition: mailbox.h:109
long tv_nsec
Definition: file.h:46
bool notified
user has been notified
Definition: mailbox.h:105

+ Here is the caller graph for this function:

bool mutt_mailbox_notify ( struct Mailbox m_cur)

Notify the user if there's new mail.

Parameters
m_curCurrent Mailbox
Return values
trueIf there is new mail

Definition at line 474 of file mailbox.c.

475 {
476  if (mutt_mailbox_check(m_cur, 0) && MailboxNotify)
477  {
478  return mutt_mailbox_list();
479  }
480  return false;
481 }
int mutt_mailbox_check(struct Mailbox *m_cur, int force)
Check all AllMailboxes for new mail.
Definition: mailbox.c:336
bool mutt_mailbox_list(void)
List the mailboxes with new mail.
Definition: mailbox.c:395
static short MailboxNotify
of unnotified new boxes
Definition: mailbox.c:84

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void mutt_mailbox ( struct Mailbox m_cur,
char *  s,
size_t  slen 
)

incoming folders completion routine

Parameters
m_curCurrent Mailbox
sBuffer containing name of current mailbox
slenBuffer length

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

Definition at line 491 of file mailbox.c.

492 {
493  mutt_expand_path(s, slen);
494 
495  if (mutt_mailbox_check(m_cur, 0))
496  {
497  int found = 0;
498  for (int pass = 0; pass < 2; pass++)
499  {
500  struct MailboxNode *np = NULL;
501  STAILQ_FOREACH(np, &AllMailboxes, entries)
502  {
503  if (np->mailbox->magic == MUTT_NOTMUCH) /* only match real mailboxes */
504  continue;
505  mutt_expand_path(np->mailbox->path, sizeof(np->mailbox->path));
506  if ((found || pass) && np->mailbox->has_new)
507  {
508  mutt_str_strfcpy(s, np->mailbox->path, slen);
509  mutt_pretty_mailbox(s, slen);
510  return;
511  }
512  if (mutt_str_strcmp(s, np->mailbox->path) == 0)
513  found = 1;
514  }
515  }
516 
517  mutt_mailbox_check(m_cur, MUTT_MAILBOX_CHECK_FORCE); /* mailbox was wrong - resync things */
518  }
519 
520  /* no folders with new mail */
521  *s = '\0';
522 }
&#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:605
bool has_new
mailbox has new mail
Definition: mailbox.h:90
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:106
int mutt_mailbox_check(struct Mailbox *m_cur, int force)
Check all AllMailboxes for new mail.
Definition: mailbox.c:336
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:741
#define MUTT_MAILBOX_CHECK_FORCE
Definition: mailbox.h:170
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:350
struct MailboxList AllMailboxes
List of all Mailboxes.
Definition: mailbox.c:86
char path[PATH_MAX]
Definition: mailbox.h:85
List of Mailboxes.
Definition: mailbox.h:147
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:611
struct Mailbox * mailbox
Definition: mailbox.h:149

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void mutt_mailbox_changed ( struct Mailbox m,
enum MailboxNotification  action 
)

Notify listeners of a change to a Mailbox.

Parameters
mMailbox
actionChange to Mailbox

Definition at line 529 of file mailbox.c.

530 {
531  if (!m || !m->notify)
532  return;
533 
534  m->notify(m, action);
535 }
void(* notify)(struct Mailbox *m, enum MailboxNotification action)
Notification callback.
Definition: mailbox.h:140

+ Here is the caller graph for this function:

Variable Documentation

short C_MailCheck

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

Definition at line 76 of file mailbox.c.

bool C_MailCheckStats

Config: Periodically check for new mail.

Definition at line 77 of file mailbox.c.

short C_MailCheckStatsInterval

Config: How often to check for new mail.

Definition at line 78 of file mailbox.c.

bool C_MaildirCheckCur

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

Definition at line 79 of file mailbox.c.

time_t MailboxTime = 0
static

last time we started checking for mail

Definition at line 81 of file mailbox.c.

time_t MailboxStatsTime = 0
static

last time we check performed mail_check_stats

Definition at line 82 of file mailbox.c.

short MailboxCount = 0
static

how many boxes with new mail

Definition at line 83 of file mailbox.c.

short MailboxNotify = 0
static

of unnotified new boxes

Definition at line 84 of file mailbox.c.

struct MailboxList AllMailboxes = STAILQ_HEAD_INITIALIZER(AllMailboxes)

List of all Mailboxes.

Definition at line 86 of file mailbox.c.