NeoMutt  2018-07-16 +1783-b00bd9
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_buffer_mailbox (struct Mailbox *m_cur, struct Buffer *s)
 incoming folders completion routine 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...
 
void mutt_mailbox_size_add (struct Mailbox *m, const struct Email *e)
 Add an email's size to the total size of a Mailbox. More...
 
void mutt_mailbox_size_sub (struct Mailbox *m, const struct Email *e)
 Subtract an email's size from the total size of 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  m->pathbuf = mutt_buffer_new();
97 
98  return m;
99 }
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
struct Buffer * mutt_buffer_new(void)
Create and initialise a Buffer.
Definition: buffer.c:52
struct Buffer * pathbuf
Definition: mailbox.h:85

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

106 {
107  if (!ptr || !*ptr)
108  return;
109 
110  struct Mailbox *m = *ptr;
112 
114  FREE(&m->desc);
115  if (m->mdata && m->free_mdata)
116  m->free_mdata(&m->mdata);
117  FREE(&m->realpath);
118  FREE(ptr);
119 }
char * desc
Definition: mailbox.h:87
char * realpath
used for duplicate detection, context comparison, and the sidebar
Definition: mailbox.h:86
Mailbox was closed.
Definition: mailbox.h:54
void(* free_mdata)(void **)
driver-specific data free function
Definition: mailbox.h:137
void mutt_buffer_free(struct Buffer **p)
Release a Buffer and its contents.
Definition: buffer.c:138
void * mdata
driver specific data
Definition: mailbox.h:136
A mailbox.
Definition: mailbox.h:83
struct Buffer * pathbuf
Definition: mailbox.h:85
#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:559

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

130 {
131  struct stat sb = { 0 };
132 
133 #ifdef USE_SIDEBAR
134  short orig_new = m_check->has_new;
135  int orig_count = m_check->msg_count;
136  int orig_unread = m_check->msg_unread;
137  int orig_flagged = m_check->msg_flagged;
138 #endif
139 
140  enum MailboxType mb_magic = mx_path_probe(mutt_b2s(m_check->pathbuf), NULL);
141 
142  switch (mb_magic)
143  {
144  case MUTT_POP:
145  case MUTT_NNTP:
146  case MUTT_NOTMUCH:
147  case MUTT_IMAP:
148  if (mb_magic != MUTT_IMAP)
149  m_check->has_new = false;
150  m_check->magic = mb_magic;
151  break;
152  default:
153  m_check->has_new = false;
154 
155  if ((stat(mutt_b2s(m_check->pathbuf), &sb) != 0) ||
156  (S_ISREG(sb.st_mode) && (sb.st_size == 0)) ||
157  ((m_check->magic == MUTT_UNKNOWN) &&
158  ((m_check->magic = mx_path_probe(mutt_b2s(m_check->pathbuf), NULL)) <= 0)))
159  {
160  /* if the mailbox still doesn't exist, set the newly created flag to be
161  * ready for when it does. */
162  m_check->newly_created = true;
163  m_check->magic = MUTT_UNKNOWN;
164  m_check->size = 0;
165  return;
166  }
167  break; // kept for consistency.
168  }
169 
170  /* check to see if the folder is the currently selected folder before polling */
171  if (!m_cur || mutt_buffer_is_empty(m_cur->pathbuf) ||
172  (((m_check->magic == MUTT_IMAP) || (m_check->magic == MUTT_NNTP) ||
173  (m_check->magic == MUTT_NOTMUCH) || (m_check->magic == MUTT_POP)) ?
174  (mutt_str_strcmp(mutt_b2s(m_check->pathbuf), mutt_b2s(m_cur->pathbuf)) != 0) :
175  ((sb.st_dev != ctx_sb->st_dev) || (sb.st_ino != ctx_sb->st_ino))))
176  {
177  switch (m_check->magic)
178  {
179  case MUTT_IMAP:
180  case MUTT_MBOX:
181  case MUTT_MMDF:
182  case MUTT_MAILDIR:
183  case MUTT_MH:
184  case MUTT_NOTMUCH:
185  if (mx_mbox_check_stats(m_check, 0) == 0)
186  MailboxCount++;
187  break;
188  default:; /* do nothing */
189  }
190  }
191  else if (C_CheckMboxSize && m_cur && mutt_buffer_is_empty(m_cur->pathbuf))
192  m_check->size = (off_t) sb.st_size; /* update the size of current folder */
193 
194 #ifdef USE_SIDEBAR
195  if ((orig_new != m_check->has_new) || (orig_count != m_check->msg_count) ||
196  (orig_unread != m_check->msg_unread) || (orig_flagged != m_check->msg_flagged))
197  {
199  }
200 #endif
201 
202  if (!m_check->has_new)
203  m_check->notified = false;
204  else if (!m_check->notified)
205  MailboxNotify++;
206 }
&#39;Notmuch&#39; (virtual) Mailbox type
Definition: magic.h:43
int msg_count
total number of messages
Definition: mailbox.h:92
off_t size
Definition: mailbox.h:88
int msg_unread
number of unread messages
Definition: mailbox.h:93
&#39;NNTP&#39; (Usenet) Mailbox type
Definition: magic.h:41
int msg_flagged
number of flagged messages
Definition: mailbox.h:94
&#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:204
#define REDRAW_SIDEBAR
Redraw the sidebar.
Definition: mutt_menu.h:51
bool has_new
mailbox has new mail
Definition: mailbox.h:89
enum MailboxType magic
mailbox type
Definition: mailbox.h:105
#define mutt_b2s(buf)
Definition: buffer.h:42
&#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:106
struct Buffer * pathbuf
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:1582
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:104
bool mutt_buffer_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition: buffer.c:291
enum MailboxType mx_path_probe(const char *path, struct stat *st)
Find a mailbox that understands a path.
Definition: mx.c:1226
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:618
&#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 216 of file mailbox.c.

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

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

268 {
269  if (!path)
270  return NULL;
271 
272  struct stat sb;
273  struct stat tmp_sb;
274 
275  if (stat(path, &sb) != 0)
276  return NULL;
277 
278  struct MailboxNode *np = NULL;
279  STAILQ_FOREACH(np, &AllMailboxes, entries)
280  {
281  if ((stat(mutt_b2s(np->mailbox->pathbuf), &tmp_sb) == 0) &&
282  (sb.st_dev == tmp_sb.st_dev) && (sb.st_ino == tmp_sb.st_ino))
283  {
284  return np->mailbox;
285  }
286  }
287 
288  return NULL;
289 }
#define mutt_b2s(buf)
Definition: buffer.h:42
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:350
struct MailboxList AllMailboxes
List of all Mailboxes.
Definition: mailbox.c:86
struct Buffer * pathbuf
Definition: mailbox.h:85
List of Mailboxes.
Definition: mailbox.h:146
struct Mailbox * mailbox
Definition: mailbox.h:148

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

298 {
299  if (!desc)
300  return NULL;
301 
302  struct MailboxNode *np = NULL;
303  STAILQ_FOREACH(np, &AllMailboxes, entries)
304  {
305  if (np->mailbox->desc && (mutt_str_strcmp(np->mailbox->desc, desc) == 0))
306  return np->mailbox;
307  }
308 
309  return NULL;
310 }
char * desc
Definition: mailbox.h:87
#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:146
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:618
struct Mailbox * mailbox
Definition: mailbox.h:148

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

317 {
318  struct stat sb;
319 
320  if (!m)
321  return;
322 
323  if (stat(mutt_b2s(m->pathbuf), &sb) == 0)
324  m->size = (off_t) sb.st_size;
325  else
326  m->size = 0;
327 }
off_t size
Definition: mailbox.h:88
#define mutt_b2s(buf)
Definition: buffer.h:42
struct Buffer * pathbuf
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 341 of file mailbox.c.

342 {
343  struct stat contex_sb;
344  time_t t;
345  bool check_stats = false;
346  contex_sb.st_dev = 0;
347  contex_sb.st_ino = 0;
348 
349 #ifdef USE_IMAP
350  /* update postponed count as well, on force */
351  if (force & MUTT_MAILBOX_CHECK_FORCE)
353 #endif
354 
355  /* fastest return if there are no mailboxes */
357  return 0;
358 
359  t = time(NULL);
360  if (!force && (t - MailboxTime < C_MailCheck))
361  return MailboxCount;
362 
363  if ((force & MUTT_MAILBOX_CHECK_FORCE_STATS) ||
365  {
366  check_stats = true;
367  MailboxStatsTime = t;
368  }
369 
370  MailboxTime = t;
371  MailboxCount = 0;
372  MailboxNotify = 0;
373 
374  /* check device ID and serial number instead of comparing paths */
375  if (!m_cur || (m_cur->magic == MUTT_IMAP) || (m_cur->magic == MUTT_POP)
376 #ifdef USE_NNTP
377  || (m_cur->magic == MUTT_NNTP)
378 #endif
379  || stat(mutt_b2s(m_cur->pathbuf), &contex_sb) != 0)
380  {
381  contex_sb.st_dev = 0;
382  contex_sb.st_ino = 0;
383  }
384 
385  struct MailboxNode *np = NULL;
386  STAILQ_FOREACH(np, &AllMailboxes, entries)
387  {
388  mailbox_check(m_cur, np->mailbox, &contex_sb,
389  check_stats || (!np->mailbox->first_check_stats_done && C_MailCheckStats));
390  np->mailbox->first_check_stats_done = true;
391  }
392 
393  return MailboxCount;
394 }
&#39;NNTP&#39; (Usenet) Mailbox type
Definition: magic.h:41
#define MUTT_MAILBOX_CHECK_FORCE_STATS
Definition: mailbox.h:169
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:116
&#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:105
#define mutt_b2s(buf)
Definition: buffer.h:42
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:168
#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
struct Buffer * pathbuf
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:146
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:128
&#39;POP3&#39; Mailbox type
Definition: magic.h:44
struct Mailbox * mailbox
Definition: mailbox.h:148
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 400 of file mailbox.c.

401 {
402  char mailboxlist[512];
403  size_t pos = 0;
404  int first = 1;
405 
406  int have_unnotified = MailboxNotify;
407 
408  struct Buffer *path = mutt_buffer_pool_get();
409 
410  mailboxlist[0] = '\0';
411  pos += strlen(strncat(mailboxlist, _("New mail in "), sizeof(mailboxlist) - 1 - pos));
412  struct MailboxNode *np = NULL;
413  STAILQ_FOREACH(np, &AllMailboxes, entries)
414  {
415  /* Is there new mail in this mailbox? */
416  if (!np->mailbox->has_new || (have_unnotified && np->mailbox->notified))
417  continue;
418 
421 
422  if (!first && (MuttMessageWindow->cols >= 7) &&
423  ((pos + mutt_buffer_len(path)) >= ((size_t) MuttMessageWindow->cols - 7)))
424  {
425  break;
426  }
427 
428  if (!first)
429  pos += strlen(strncat(mailboxlist + pos, ", ", sizeof(mailboxlist) - 1 - pos));
430 
431  /* Prepend an asterisk to mailboxes not already notified */
432  if (!np->mailbox->notified)
433  {
434  /* pos += strlen (strncat(mailboxlist + pos, "*", sizeof(mailboxlist)-1-pos)); */
435  np->mailbox->notified = true;
436  MailboxNotify--;
437  }
438  pos += strlen(strncat(mailboxlist + pos, mutt_b2s(path), sizeof(mailboxlist) - 1 - pos));
439  first = 0;
440  }
441 
442  if (!first && np)
443  {
444  strncat(mailboxlist + pos, ", ...", sizeof(mailboxlist) - 1 - pos);
445  }
446 
448 
449  if (!first)
450  {
451  mutt_message("%s", mailboxlist);
452  return true;
453  }
454  else
455  {
456  /* there were no mailboxes needing to be notified, so clean up since
457  * MailboxNotify has somehow gotten out of sync */
458  MailboxNotify = 0;
459  return false;
460  }
461 }
void mutt_buffer_pretty_mailbox(struct Buffer *s)
Shorten a mailbox path using &#39;~&#39; or &#39;=&#39;.
Definition: muttlib.c:688
#define mutt_message(...)
Definition: logging.h:82
String manipulation buffer.
Definition: buffer.h:33
#define _(a)
Definition: message.h:28
bool has_new
mailbox has new mail
Definition: mailbox.h:89
#define mutt_b2s(buf)
Definition: buffer.h:42
void mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:322
size_t mutt_buffer_len(const struct Buffer *buf)
Calculate the length of a Buffer.
Definition: buffer.c:438
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:350
struct MailboxList AllMailboxes
List of all Mailboxes.
Definition: mailbox.c:86
struct Buffer * pathbuf
Definition: mailbox.h:85
static short MailboxNotify
of unnotified new boxes
Definition: mailbox.c:84
bool notified
user has been notified
Definition: mailbox.h:104
struct MuttWindow * MuttMessageWindow
Message Window.
Definition: mutt_window.c:41
List of Mailboxes.
Definition: mailbox.h:146
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: buffer.c:409
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Definition: buffer.c:398
struct Mailbox * mailbox
Definition: mailbox.h:148

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

468 {
469  if (!m)
470  return;
471 
472  m->notified = true;
473 #if HAVE_CLOCK_GETTIME
474  clock_gettime(CLOCK_REALTIME, &m->last_visited);
475 #else
476  m->last_visited.tv_nsec = 0;
477  time(&m->last_visited.tv_sec);
478 #endif
479 }
time_t tv_sec
Definition: file.h:46
struct timespec last_visited
time of last exit from this mailbox
Definition: mailbox.h:108
long tv_nsec
Definition: file.h:47
bool notified
user has been notified
Definition: mailbox.h:104

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

487 {
488  if (mutt_mailbox_check(m_cur, 0) && MailboxNotify)
489  {
490  return mutt_mailbox_list();
491  }
492  return false;
493 }
int mutt_mailbox_check(struct Mailbox *m_cur, int force)
Check all AllMailboxes for new mail.
Definition: mailbox.c:341
bool mutt_mailbox_list(void)
List the mailboxes with new mail.
Definition: mailbox.c:400
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_buffer_mailbox ( struct Mailbox m_cur,
struct Buffer s 
)

incoming folders completion routine

Parameters
m_curCurrent Mailbox
sBuffer containing name of current mailbox

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

Definition at line 502 of file mailbox.c.

503 {
505 
506  if (mutt_mailbox_check(m_cur, 0))
507  {
508  int found = 0;
509  for (int pass = 0; pass < 2; pass++)
510  {
511  struct MailboxNode *np = NULL;
512  STAILQ_FOREACH(np, &AllMailboxes, entries)
513  {
514  if (np->mailbox->magic == MUTT_NOTMUCH) /* only match real mailboxes */
515  continue;
517  if ((found || pass) && np->mailbox->has_new)
518  {
521  return;
522  }
523  if (mutt_str_strcmp(mutt_b2s(s), mutt_b2s(np->mailbox->pathbuf)) == 0)
524  found = 1;
525  }
526  }
527 
528  mutt_mailbox_check(m_cur, MUTT_MAILBOX_CHECK_FORCE); /* mailbox was wrong - resync things */
529  }
530 
531  /* no folders with new mail */
533 }
void mutt_buffer_pretty_mailbox(struct Buffer *s)
Shorten a mailbox path using &#39;~&#39; or &#39;=&#39;.
Definition: muttlib.c:688
&#39;Notmuch&#39; (virtual) Mailbox type
Definition: magic.h:43
void mutt_buffer_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition: buffer.c:83
bool has_new
mailbox has new mail
Definition: mailbox.h:89
enum MailboxType magic
mailbox type
Definition: mailbox.h:105
int mutt_mailbox_check(struct Mailbox *m_cur, int force)
Check all AllMailboxes for new mail.
Definition: mailbox.c:341
#define mutt_b2s(buf)
Definition: buffer.h:42
void mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:322
#define MUTT_MAILBOX_CHECK_FORCE
Definition: mailbox.h:168
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:350
struct MailboxList AllMailboxes
List of all Mailboxes.
Definition: mailbox.c:86
struct Buffer * pathbuf
Definition: mailbox.h:85
void mutt_buffer_expand_path(struct Buffer *buf)
Create the canonical path.
Definition: muttlib.c:324
List of Mailboxes.
Definition: mailbox.h:146
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:618
struct Mailbox * mailbox
Definition: mailbox.h:148

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

544 {
545  struct Buffer *s_buf = mutt_buffer_pool_get();
546 
547  mutt_buffer_addstr(s_buf, NONULL(s));
548  mutt_buffer_mailbox(m_cur, s_buf);
549  mutt_str_strfcpy(s, mutt_b2s(s_buf), slen);
550 
551  mutt_buffer_pool_release(&s_buf);
552 }
#define NONULL(x)
Definition: string2.h:36
void mutt_buffer_mailbox(struct Mailbox *m_cur, struct Buffer *s)
incoming folders completion routine
Definition: mailbox.c:502
String manipulation buffer.
Definition: buffer.h:33
size_t mutt_buffer_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition: buffer.c:264
#define mutt_b2s(buf)
Definition: buffer.h:42
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:753
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: buffer.c:409
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Definition: buffer.c:398

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

560 {
561  if (!m || !m->notify)
562  return;
563 
564  m->notify(m, action);
565 }
void(* notify)(struct Mailbox *m, enum MailboxNotification action)
Notification callback.
Definition: mailbox.h:139

+ Here is the caller graph for this function:

void mutt_mailbox_size_add ( struct Mailbox m,
const struct Email e 
)

Add an email's size to the total size of a Mailbox.

Parameters
mMailbox
eEmail

Definition at line 572 of file mailbox.c.

573 {
574  m->size += mutt_email_size(e);
575 }
off_t size
Definition: mailbox.h:88
size_t mutt_email_size(const struct Email *e)
compute the size of an email
Definition: email.c:109

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void mutt_mailbox_size_sub ( struct Mailbox m,
const struct Email e 
)

Subtract an email's size from the total size of a Mailbox.

Parameters
mMailbox
eEmail

Definition at line 582 of file mailbox.c.

583 {
584  m->size -= mutt_email_size(e);
585 }
off_t size
Definition: mailbox.h:88
size_t mutt_email_size(const struct Email *e)
compute the size of an email
Definition: email.c:109

+ Here is the call graph for this function:

+ 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.