NeoMutt  2020-08-07-1-gab41a1
Teaching an old dog new tricks
DOXYGEN
mutt_mailbox.h File Reference
#include <stdbool.h>
+ Include dependency graph for mutt_mailbox.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define MUTT_MAILBOX_CHECK_FORCE   (1 << 0)
 
#define MUTT_MAILBOX_CHECK_FORCE_STATS   (1 << 1)
 

Functions

int mutt_mailbox_check (struct Mailbox *m_cur, int force)
 Check all all Mailboxes for new mail. More...
 
void mutt_mailbox_cleanup (const char *path, struct stat *st)
 Restore the timestamp of a mailbox. More...
 
bool mutt_mailbox_list (void)
 List the mailboxes with new mail. More...
 
struct Mailboxmutt_mailbox_next (struct Mailbox *m_cur, struct Buffer *s)
 incoming folders completion routine More...
 
bool mutt_mailbox_notify (struct Mailbox *m_cur)
 Notify the user if there's new mail. More...
 
void mutt_mailbox_set_notified (struct Mailbox *m)
 Note when the user was last notified of new mail. 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...
 

Macro Definition Documentation

◆ MUTT_MAILBOX_CHECK_FORCE

#define MUTT_MAILBOX_CHECK_FORCE   (1 << 0)

Definition at line 16 of file mutt_mailbox.h.

◆ MUTT_MAILBOX_CHECK_FORCE_STATS

#define MUTT_MAILBOX_CHECK_FORCE_STATS   (1 << 1)

Definition at line 17 of file mutt_mailbox.h.

Function Documentation

◆ mutt_mailbox_check()

int mutt_mailbox_check ( struct Mailbox m_cur,
int  force 
)

Check all all Mailboxes 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 all Mailboxes for new mail and total/new/flagged messages

Definition at line 153 of file mutt_mailbox.c.

154 {
155  struct stat contex_sb;
156  time_t t;
157  bool check_stats = false;
158  contex_sb.st_dev = 0;
159  contex_sb.st_ino = 0;
160 
161 #ifdef USE_IMAP
162  /* update postponed count as well, on force */
163  if (force & MUTT_MAILBOX_CHECK_FORCE)
165 #endif
166 
167  /* fastest return if there are no mailboxes */
169  return 0;
170 
171  t = mutt_date_epoch();
172  if (!force && (t - MailboxTime < C_MailCheck))
173  return MailboxCount;
174 
175  if ((force & MUTT_MAILBOX_CHECK_FORCE_STATS) ||
177  {
178  check_stats = true;
179  MailboxStatsTime = t;
180  }
181 
182  MailboxTime = t;
183  MailboxCount = 0;
184  MailboxNotify = 0;
185 
186  /* check device ID and serial number instead of comparing paths */
187  if (!m_cur || (m_cur->type == MUTT_IMAP) || (m_cur->type == MUTT_POP)
188 #ifdef USE_NNTP
189  || (m_cur->type == MUTT_NNTP)
190 #endif
191  || stat(mailbox_path(m_cur), &contex_sb) != 0)
192  {
193  contex_sb.st_dev = 0;
194  contex_sb.st_ino = 0;
195  }
196 
197  struct MailboxList ml = STAILQ_HEAD_INITIALIZER(ml);
199  struct MailboxNode *np = NULL;
200  STAILQ_FOREACH(np, &ml, entries)
201  {
202  if (np->mailbox->flags & MB_HIDDEN)
203  continue;
204 
205  mailbox_check(m_cur, np->mailbox, &contex_sb,
206  check_stats || (!np->mailbox->first_check_stats_done && C_MailCheckStats));
207  np->mailbox->first_check_stats_done = true;
208  }
210 
211  return MailboxCount;
212 }
time_t mutt_date_epoch(void)
Return the number of seconds since the Unix epoch.
Definition: date.c:416
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox&#39;s path string.
Definition: mailbox.h:201
enum MailboxType type
Mailbox type.
Definition: mailbox.h:105
&#39;NNTP&#39; (Usenet) Mailbox type
Definition: mailbox.h:52
struct AccountList accounts
List of all Accounts.
Definition: neomutt.h:40
void neomutt_mailboxlist_clear(struct MailboxList *ml)
Free a Mailbox List.
Definition: neomutt.c:137
Match any Mailbox type.
Definition: mailbox.h:45
size_t neomutt_mailboxlist_get_all(struct MailboxList *head, struct NeoMutt *n, enum MailboxType type)
Get a List of all Mailboxes.
Definition: neomutt.c:160
bool first_check_stats_done
True when the check have been done at least on time.
Definition: mailbox.h:116
static time_t MailboxStatsTime
last time we check performed mail_check_stats
Definition: mutt_mailbox.c:46
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: mutt_mailbox.c:62
Container for Accounts, Notifications.
Definition: neomutt.h:36
static short MailboxCount
how many boxes with new mail
Definition: mutt_mailbox.c:47
int flags
e.g. MB_NORMAL
Definition: mailbox.h:134
static short MailboxNotify
of unnotified new boxes
Definition: mutt_mailbox.c:48
short C_MailCheckStatsInterval
Config: How often to check for new mail.
Definition: mutt_mailbox.c:53
#define MB_HIDDEN
Definition: mailbox.h:38
&#39;POP3&#39; Mailbox type
Definition: mailbox.h:55
static time_t MailboxTime
last time we started checking for mail
Definition: mutt_mailbox.c:45
short C_MailCheck
Config: Number of seconds before NeoMutt checks for new mail.
Definition: mutt_mailbox.c:51
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:349
void mutt_update_num_postponed(void)
Force the update of the number of postponed messages.
Definition: postpone.c:202
#define MUTT_MAILBOX_CHECK_FORCE
Definition: mutt_mailbox.h:16
#define STAILQ_HEAD_INITIALIZER(head)
Definition: queue.h:321
List of Mailboxes.
Definition: mailbox.h:150
bool C_MailCheckStats
Config: Periodically check for new mail.
Definition: mutt_mailbox.c:52
#define TAILQ_EMPTY(head)
Definition: queue.h:714
&#39;IMAP&#39; Mailbox type
Definition: mailbox.h:53
struct Mailbox * mailbox
Mailbox in the list.
Definition: mailbox.h:152
#define MUTT_MAILBOX_CHECK_FORCE_STATS
Definition: mutt_mailbox.h:17
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_mailbox_cleanup()

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 369 of file mutt_mailbox.c.

370 {
371 #ifdef HAVE_UTIMENSAT
372  struct timespec ts[2];
373 #else
374  struct utimbuf ut;
375 #endif
376 
377  if (C_CheckMboxSize)
378  {
379  struct Mailbox *m = mailbox_find(path);
380  if (m && !m->has_new)
381  mailbox_update(m);
382  }
383  else
384  {
385  /* fix up the times so mailbox won't get confused */
386  if (st->st_mtime > st->st_atime)
387  {
388 #ifdef HAVE_UTIMENSAT
389  ts[0].tv_sec = 0;
390  ts[0].tv_nsec = UTIME_OMIT;
391  ts[1].tv_sec = 0;
392  ts[1].tv_nsec = UTIME_NOW;
393  utimensat(AT_FDCWD, buf, ts, 0);
394 #else
395  ut.actime = st->st_atime;
396  ut.modtime = mutt_date_epoch();
397  utime(path, &ut);
398 #endif
399  }
400  else
401  {
402 #ifdef HAVE_UTIMENSAT
403  ts[0].tv_sec = 0;
404  ts[0].tv_nsec = UTIME_NOW;
405  ts[1].tv_sec = 0;
406  ts[1].tv_nsec = UTIME_NOW;
407  utimensat(AT_FDCWD, buf, ts, 0);
408 #else
409  utime(path, NULL);
410 #endif
411  }
412  }
413 }
time_t mutt_date_epoch(void)
Return the number of seconds since the Unix epoch.
Definition: date.c:416
struct Mailbox * mailbox_find(const char *path)
Find the mailbox with a given path.
Definition: mailbox.c:91
bool has_new
Mailbox has new mail.
Definition: mailbox.h:88
A mailbox.
Definition: mailbox.h:81
bool C_CheckMboxSize
Config: (mbox,mmdf) Use mailbox size as an indicator of new mail.
Definition: config.c:35
void mailbox_update(struct Mailbox *m)
Get the mailbox&#39;s current size.
Definition: mailbox.c:156
Time value with nanosecond precision.
Definition: file.h:46
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_mailbox_list()

bool mutt_mailbox_list ( void  )

List the mailboxes with new mail.

Return values
trueIf there is new mail

Definition at line 232 of file mutt_mailbox.c.

233 {
234  char mailboxlist[512];
235  size_t pos = 0;
236  int first = 1;
237 
238  int have_unnotified = MailboxNotify;
239 
240  struct Buffer *path = mutt_buffer_pool_get();
241 
242  mailboxlist[0] = '\0';
243  pos += strlen(strncat(mailboxlist, _("New mail in "), sizeof(mailboxlist) - 1 - pos));
244  struct MailboxList ml = STAILQ_HEAD_INITIALIZER(ml);
246  struct MailboxNode *np = NULL;
247  STAILQ_FOREACH(np, &ml, entries)
248  {
249  /* Is there new mail in this mailbox? */
250  if (!np->mailbox->has_new || (have_unnotified && np->mailbox->notified))
251  continue;
252 
255 
256  if (!first && (MessageWindow->state.cols >= 7) &&
257  ((pos + mutt_buffer_len(path)) >= ((size_t) MessageWindow->state.cols - 7)))
258  {
259  break;
260  }
261 
262  if (!first)
263  pos += strlen(strncat(mailboxlist + pos, ", ", sizeof(mailboxlist) - 1 - pos));
264 
265  /* Prepend an asterisk to mailboxes not already notified */
266  if (!np->mailbox->notified)
267  {
268  /* pos += strlen (strncat(mailboxlist + pos, "*", sizeof(mailboxlist)-1-pos)); */
269  np->mailbox->notified = true;
270  MailboxNotify--;
271  }
272  pos += strlen(strncat(mailboxlist + pos, mutt_b2s(path), sizeof(mailboxlist) - 1 - pos));
273  first = 0;
274  }
276 
277  if (!first && np)
278  {
279  strncat(mailboxlist + pos, ", ...", sizeof(mailboxlist) - 1 - pos);
280  }
281 
283 
284  if (!first)
285  {
286  mutt_message("%s", mailboxlist);
287  return true;
288  }
289 
290  /* there were no mailboxes needing to be notified, so clean up since
291  * MailboxNotify has somehow gotten out of sync */
292  MailboxNotify = 0;
293  return false;
294 }
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox&#39;s path string.
Definition: mailbox.h:201
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:101
#define mutt_message(...)
Definition: logging.h:83
void neomutt_mailboxlist_clear(struct MailboxList *ml)
Free a Mailbox List.
Definition: neomutt.c:137
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: pool.c:112
Match any Mailbox type.
Definition: mailbox.h:45
size_t neomutt_mailboxlist_get_all(struct MailboxList *head, struct NeoMutt *n, enum MailboxType type)
Get a List of all Mailboxes.
Definition: neomutt.c:160
String manipulation buffer.
Definition: buffer.h:33
#define _(a)
Definition: message.h:28
Container for Accounts, Notifications.
Definition: neomutt.h:36
void mutt_buffer_pretty_mailbox(struct Buffer *buf)
Shorten a mailbox path using &#39;~&#39; or &#39;=&#39;.
Definition: muttlib.c:598
bool has_new
Mailbox has new mail.
Definition: mailbox.h:88
short cols
Number of columns, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:57
#define mutt_b2s(buf)
Definition: buffer.h:41
static short MailboxNotify
of unnotified new boxes
Definition: mutt_mailbox.c:48
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:120
struct MuttWindow * MessageWindow
Message Window, ":set", etc.
Definition: mutt_window.c:47
size_t mutt_buffer_len(const struct Buffer *buf)
Calculate the length of a Buffer.
Definition: buffer.c:356
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:349
size_t mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:312
bool notified
User has been notified.
Definition: mailbox.h:104
#define STAILQ_HEAD_INITIALIZER(head)
Definition: queue.h:321
List of Mailboxes.
Definition: mailbox.h:150
struct Mailbox * mailbox
Mailbox in the list.
Definition: mailbox.h:152
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_mailbox_next()

struct Mailbox* mutt_mailbox_next ( struct Mailbox m_cur,
struct Buffer s 
)

incoming folders completion routine

Parameters
m_curCurrent Mailbox
sBuffer containing name of current mailbox
Return values
ptrMailbox

Given a folder name, find the next incoming folder with new mail. The Mailbox will be returned and a pretty version of the path put into s.

Definition at line 323 of file mutt_mailbox.c.

324 {
326 
327  if (mutt_mailbox_check(m_cur, 0) > 0)
328  {
329  bool found = false;
330  for (int pass = 0; pass < 2; pass++)
331  {
332  struct MailboxList ml = STAILQ_HEAD_INITIALIZER(ml);
334  struct MailboxNode *np = NULL;
335  STAILQ_FOREACH(np, &ml, entries)
336  {
337  if (np->mailbox->type == MUTT_NOTMUCH) /* only match real mailboxes */
338  continue;
340  if ((found || (pass > 0)) && np->mailbox->has_new)
341  {
344  struct Mailbox *m_result = np->mailbox;
346  return m_result;
347  }
349  found = true;
350  }
352  }
353 
354  mutt_mailbox_check(m_cur, MUTT_MAILBOX_CHECK_FORCE); /* mailbox was wrong - resync things */
355  }
356 
357  mutt_buffer_reset(s); // no folders with new mail
358  return NULL;
359 }
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:876
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox&#39;s path string.
Definition: mailbox.h:201
enum MailboxType type
Mailbox type.
Definition: mailbox.h:105
void mutt_buffer_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition: buffer.c:79
void neomutt_mailboxlist_clear(struct MailboxList *ml)
Free a Mailbox List.
Definition: neomutt.c:137
Match any Mailbox type.
Definition: mailbox.h:45
size_t neomutt_mailboxlist_get_all(struct MailboxList *head, struct NeoMutt *n, enum MailboxType type)
Get a List of all Mailboxes.
Definition: neomutt.c:160
Container for Accounts, Notifications.
Definition: neomutt.h:36
void mutt_buffer_pretty_mailbox(struct Buffer *buf)
Shorten a mailbox path using &#39;~&#39; or &#39;=&#39;.
Definition: muttlib.c:598
bool has_new
Mailbox has new mail.
Definition: mailbox.h:88
#define mutt_b2s(buf)
Definition: buffer.h:41
A mailbox.
Definition: mailbox.h:81
int mutt_mailbox_check(struct Mailbox *m_cur, int force)
Check all all Mailboxes for new mail.
Definition: mutt_mailbox.c:153
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:349
size_t mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:312
#define MUTT_MAILBOX_CHECK_FORCE
Definition: mutt_mailbox.h:16
&#39;Notmuch&#39; (virtual) Mailbox type
Definition: mailbox.h:54
void mutt_buffer_expand_path(struct Buffer *buf)
Create the canonical path.
Definition: muttlib.c:323
#define STAILQ_HEAD_INITIALIZER(head)
Definition: queue.h:321
List of Mailboxes.
Definition: mailbox.h:150
struct Buffer pathbuf
Definition: mailbox.h:83
struct Mailbox * mailbox
Mailbox in the list.
Definition: mailbox.h:152
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_mailbox_notify()

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 219 of file mutt_mailbox.c.

220 {
221  if ((mutt_mailbox_check(m_cur, 0) > 0) && MailboxNotify)
222  {
223  return mutt_mailbox_list();
224  }
225  return false;
226 }
bool mutt_mailbox_list(void)
List the mailboxes with new mail.
Definition: mutt_mailbox.c:232
static short MailboxNotify
of unnotified new boxes
Definition: mutt_mailbox.c:48
int mutt_mailbox_check(struct Mailbox *m_cur, int force)
Check all all Mailboxes for new mail.
Definition: mutt_mailbox.c:153
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_mailbox_set_notified()

void mutt_mailbox_set_notified ( struct Mailbox m)

Note when the user was last notified of new mail.

Parameters
mMailbox

Definition at line 300 of file mutt_mailbox.c.

301 {
302  if (!m)
303  return;
304 
305  m->notified = true;
306 #ifdef HAVE_CLOCK_GETTIME
307  clock_gettime(CLOCK_REALTIME, &m->last_visited);
308 #else
310  m->last_visited.tv_nsec = 0;
311 #endif
312 }
time_t mutt_date_epoch(void)
Return the number of seconds since the Unix epoch.
Definition: date.c:416
time_t tv_sec
Definition: file.h:48
struct timespec last_visited
Time of last exit from this mailbox.
Definition: mailbox.h:108
long tv_nsec
Definition: file.h:49
bool notified
User has been notified.
Definition: mailbox.h:104
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ C_MailCheck

short C_MailCheck

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

Definition at line 51 of file mutt_mailbox.c.

◆ C_MailCheckStats

bool C_MailCheckStats

Config: Periodically check for new mail.

Definition at line 52 of file mutt_mailbox.c.

◆ C_MailCheckStatsInterval

short C_MailCheckStatsInterval

Config: How often to check for new mail.

Definition at line 53 of file mutt_mailbox.c.