NeoMutt  2020-03-20-65-g141838
Teaching an old dog new tricks
DOXYGEN
mutt_mailbox.c File Reference

Mailbox helper functions. More...

#include "config.h"
#include <string.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <time.h>
#include <utime.h>
#include "mutt/lib.h"
#include "core/lib.h"
#include "gui/lib.h"
#include "mutt_mailbox.h"
#include "globals.h"
#include "mutt_menu.h"
#include "muttlib.h"
#include "mx.h"
#include "protos.h"
+ Include dependency graph for mutt_mailbox.c:

Go to the source code of this file.

Functions

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

Variables

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

Detailed Description

Mailbox helper functions.

  • 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 mutt_mailbox.c.

Function Documentation

◆ mailbox_check()

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

63 {
64  struct stat sb = { 0 };
65 
66 #ifdef USE_SIDEBAR
67  short orig_new = m_check->has_new;
68  int orig_count = m_check->msg_count;
69  int orig_unread = m_check->msg_unread;
70  int orig_flagged = m_check->msg_flagged;
71 #endif
72 
73  enum MailboxType mb_type = mx_path_probe(mailbox_path(m_check));
74 
75  if ((m_cur == m_check) && C_MailCheckRecent)
76  m_check->has_new = false;
77 
78  switch (mb_type)
79  {
80  case MUTT_POP:
81  case MUTT_NNTP:
82  case MUTT_NOTMUCH:
83  case MUTT_IMAP:
84  m_check->type = mb_type;
85  break;
86  default:
87  if ((stat(mailbox_path(m_check), &sb) != 0) ||
88  ((m_check->type == MUTT_UNKNOWN) && S_ISREG(sb.st_mode) && (sb.st_size == 0)) ||
89  ((m_check->type == MUTT_UNKNOWN) &&
90  ((m_check->type = mx_path_probe(mailbox_path(m_check))) <= 0)))
91  {
92  /* if the mailbox still doesn't exist, set the newly created flag to be
93  * ready for when it does. */
94  m_check->newly_created = true;
95  m_check->type = MUTT_UNKNOWN;
96  m_check->size = 0;
97  return;
98  }
99  break; // kept for consistency.
100  }
101 
102  /* check to see if the folder is the currently selected folder before polling */
103  if (!m_cur || mutt_buffer_is_empty(&m_cur->pathbuf) ||
104  (((m_check->type == MUTT_IMAP) || (m_check->type == MUTT_NNTP) ||
105  (m_check->type == MUTT_NOTMUCH) || (m_check->type == MUTT_POP)) ?
106  (mutt_str_strcmp(mailbox_path(m_check), mailbox_path(m_cur)) != 0) :
107  ((sb.st_dev != ctx_sb->st_dev) || (sb.st_ino != ctx_sb->st_ino))))
108  {
109  switch (m_check->type)
110  {
111  case MUTT_IMAP:
112  case MUTT_MBOX:
113  case MUTT_MMDF:
114  case MUTT_MAILDIR:
115  case MUTT_MH:
116  case MUTT_NOTMUCH:
117  if ((mx_mbox_check_stats(m_check, check_stats) > 0) && m_check->has_new)
118  MailboxCount++;
119  break;
120  default:; /* do nothing */
121  }
122  }
123  else if (C_CheckMboxSize && m_cur && mutt_buffer_is_empty(&m_cur->pathbuf))
124  m_check->size = (off_t) sb.st_size; /* update the size of current folder */
125 
126 #ifdef USE_SIDEBAR
127  if ((orig_new != m_check->has_new) || (orig_count != m_check->msg_count) ||
128  (orig_unread != m_check->msg_unread) || (orig_flagged != m_check->msg_flagged))
129  {
131  }
132 #endif
133 
134  if (!m_check->has_new)
135  m_check->notified = false;
136  else if (!m_check->notified)
137  MailboxNotify++;
138 }
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox&#39;s path string.
Definition: mailbox.h:192
enum MailboxType type
Mailbox type.
Definition: mailbox.h:105
int msg_count
Total number of messages.
Definition: mailbox.h:91
off_t size
Size of the Mailbox.
Definition: mailbox.h:87
WHERE bool C_MailCheckRecent
Config: Notify the user about new mail since the last time the mailbox was opened.
Definition: globals.h:236
if(!test_colorize_)
Definition: acutest.h:484
int msg_unread
Number of unread messages.
Definition: mailbox.h:92
&#39;NNTP&#39; (Usenet) Mailbox type
Definition: mailbox.h:52
int msg_flagged
Number of flagged messages.
Definition: mailbox.h:93
Mailbox wasn&#39;t recognised.
Definition: mailbox.h:47
WHERE bool C_CheckMboxSize
Config: (mbox,mmdf) Use mailbox size as an indicator of new mail.
Definition: globals.h:208
#define REDRAW_SIDEBAR
Redraw the sidebar.
Definition: mutt_menu.h:51
bool has_new
Mailbox has new mail.
Definition: mailbox.h:88
static short MailboxCount
how many boxes with new mail
Definition: mutt_mailbox.c:46
&#39;Maildir&#39; Mailbox type
Definition: mailbox.h:51
static short MailboxNotify
of unnotified new boxes
Definition: mutt_mailbox.c:47
&#39;POP3&#39; Mailbox type
Definition: mailbox.h:55
&#39;mmdf&#39; Mailbox type
Definition: mailbox.h:49
&#39;MH&#39; Mailbox type
Definition: mailbox.h:50
bool newly_created
Mbox or mmdf just popped into existence.
Definition: mailbox.h:106
&#39;Notmuch&#39; (virtual) Mailbox type
Definition: mailbox.h:54
&#39;mbox&#39; Mailbox type
Definition: mailbox.h:48
enum MailboxType mx_path_probe(const char *path)
Find a mailbox that understands a path.
Definition: mx.c:1318
MailboxType
Supported mailbox formats.
Definition: mailbox.h:43
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:1709
bool notified
User has been notified.
Definition: mailbox.h:104
struct Buffer pathbuf
Definition: mailbox.h:83
bool mutt_buffer_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition: buffer.c:252
&#39;IMAP&#39; Mailbox type
Definition: mailbox.h:53
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:638
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

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

153 {
154  struct stat contex_sb;
155  time_t t;
156  bool check_stats = false;
157  contex_sb.st_dev = 0;
158  contex_sb.st_ino = 0;
159 
160 #ifdef USE_IMAP
161  /* update postponed count as well, on force */
162  if (force & MUTT_MAILBOX_CHECK_FORCE)
164 #endif
165 
166  /* fastest return if there are no mailboxes */
168  return 0;
169 
170  t = mutt_date_epoch();
171  if (!force && (t - MailboxTime < C_MailCheck))
172  return MailboxCount;
173 
174  if ((force & MUTT_MAILBOX_CHECK_FORCE_STATS) ||
176  {
177  check_stats = true;
178  MailboxStatsTime = t;
179  }
180 
181  MailboxTime = t;
182  MailboxCount = 0;
183  MailboxNotify = 0;
184 
185  /* check device ID and serial number instead of comparing paths */
186  if (!m_cur || (m_cur->type == MUTT_IMAP) || (m_cur->type == MUTT_POP)
187 #ifdef USE_NNTP
188  || (m_cur->type == MUTT_NNTP)
189 #endif
190  || stat(mailbox_path(m_cur), &contex_sb) != 0)
191  {
192  contex_sb.st_dev = 0;
193  contex_sb.st_ino = 0;
194  }
195 
196  struct MailboxList ml = neomutt_mailboxlist_get_all(NeoMutt, MUTT_MAILBOX_ANY);
197  struct MailboxNode *np = NULL;
198  STAILQ_FOREACH(np, &ml, entries)
199  {
200  if (np->mailbox->flags & MB_HIDDEN)
201  continue;
202 
203  mailbox_check(m_cur, np->mailbox, &contex_sb,
204  check_stats || (!np->mailbox->first_check_stats_done && C_MailCheckStats));
205  np->mailbox->first_check_stats_done = true;
206  }
208 
209  return MailboxCount;
210 }
time_t mutt_date_epoch(void)
Return the number of seconds since the Unix epoch.
Definition: date.c:411
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox&#39;s path string.
Definition: mailbox.h:192
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:39
void neomutt_mailboxlist_clear(struct MailboxList *ml)
Free a Mailbox List.
Definition: neomutt.c:135
Match any Mailbox type.
Definition: mailbox.h:45
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:45
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:61
Container for Accounts, Notifications.
Definition: neomutt.h:35
static short MailboxCount
how many boxes with new mail
Definition: mutt_mailbox.c:46
int flags
e.g. MB_NORMAL
Definition: mailbox.h:134
static short MailboxNotify
of unnotified new boxes
Definition: mutt_mailbox.c:47
short C_MailCheckStatsInterval
Config: How often to check for new mail.
Definition: mutt_mailbox.c:52
#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:44
short C_MailCheck
Config: Number of seconds before NeoMutt checks for new mail.
Definition: mutt_mailbox.c:50
#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:199
#define MUTT_MAILBOX_CHECK_FORCE
Definition: mutt_mailbox.h:17
struct MailboxList neomutt_mailboxlist_get_all(struct NeoMutt *n, enum MailboxType type)
Get a List of all Mailboxes.
Definition: neomutt.c:157
List of Mailboxes.
Definition: mailbox.h:145
bool C_MailCheckStats
Config: Periodically check for new mail.
Definition: mutt_mailbox.c:51
#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:147
#define MUTT_MAILBOX_CHECK_FORCE_STATS
Definition: mutt_mailbox.h:18
+ 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 217 of file mutt_mailbox.c.

218 {
219  if ((mutt_mailbox_check(m_cur, 0) > 0) && MailboxNotify)
220  {
221  return mutt_mailbox_list();
222  }
223  return false;
224 }
bool mutt_mailbox_list(void)
List the mailboxes with new mail.
Definition: mutt_mailbox.c:230
static short MailboxNotify
of unnotified new boxes
Definition: mutt_mailbox.c:47
int mutt_mailbox_check(struct Mailbox *m_cur, int force)
Check all all Mailboxes for new mail.
Definition: mutt_mailbox.c:152
+ 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 230 of file mutt_mailbox.c.

231 {
232  char mailboxlist[512];
233  size_t pos = 0;
234  int first = 1;
235 
236  int have_unnotified = MailboxNotify;
237 
238  struct Buffer *path = mutt_buffer_pool_get();
239 
240  mailboxlist[0] = '\0';
241  pos += strlen(strncat(mailboxlist, _("New mail in "), sizeof(mailboxlist) - 1 - pos));
242  struct MailboxList ml = neomutt_mailboxlist_get_all(NeoMutt, MUTT_MAILBOX_ANY);
243  struct MailboxNode *np = NULL;
244  STAILQ_FOREACH(np, &ml, entries)
245  {
246  /* Is there new mail in this mailbox? */
247  if (!np->mailbox->has_new || (have_unnotified && np->mailbox->notified))
248  continue;
249 
252 
253  if (!first && (MuttMessageWindow->state.cols >= 7) &&
254  ((pos + mutt_buffer_len(path)) >= ((size_t) MuttMessageWindow->state.cols - 7)))
255  {
256  break;
257  }
258 
259  if (!first)
260  pos += strlen(strncat(mailboxlist + pos, ", ", sizeof(mailboxlist) - 1 - pos));
261 
262  /* Prepend an asterisk to mailboxes not already notified */
263  if (!np->mailbox->notified)
264  {
265  /* pos += strlen (strncat(mailboxlist + pos, "*", sizeof(mailboxlist)-1-pos)); */
266  np->mailbox->notified = true;
267  MailboxNotify--;
268  }
269  pos += strlen(strncat(mailboxlist + pos, mutt_b2s(path), sizeof(mailboxlist) - 1 - pos));
270  first = 0;
271  }
273 
274  if (!first && np)
275  {
276  strncat(mailboxlist + pos, ", ...", sizeof(mailboxlist) - 1 - pos);
277  }
278 
280 
281  if (!first)
282  {
283  mutt_message("%s", mailboxlist);
284  return true;
285  }
286 
287  /* there were no mailboxes needing to be notified, so clean up since
288  * MailboxNotify has somehow gotten out of sync */
289  MailboxNotify = 0;
290  return false;
291 }
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox&#39;s path string.
Definition: mailbox.h:192
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:135
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
String manipulation buffer.
Definition: buffer.h:33
#define _(a)
Definition: message.h:28
Container for Accounts, Notifications.
Definition: neomutt.h:35
void mutt_buffer_pretty_mailbox(struct Buffer *buf)
Shorten a mailbox path using &#39;~&#39; or &#39;=&#39;.
Definition: muttlib.c:689
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:58
#define mutt_b2s(buf)
Definition: buffer.h:41
static short MailboxNotify
of unnotified new boxes
Definition: mutt_mailbox.c:47
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:93
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
struct MailboxList neomutt_mailboxlist_get_all(struct NeoMutt *n, enum MailboxType type)
Get a List of all Mailboxes.
Definition: neomutt.c:157
bool notified
User has been notified.
Definition: mailbox.h:104
struct MuttWindow * MuttMessageWindow
Message Window.
Definition: mutt_window.c:46
List of Mailboxes.
Definition: mailbox.h:145
struct Mailbox * mailbox
Mailbox in the list.
Definition: mailbox.h:147
+ 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 297 of file mutt_mailbox.c.

298 {
299  if (!m)
300  return;
301 
302  m->notified = true;
303 #ifdef HAVE_CLOCK_GETTIME
304  clock_gettime(CLOCK_REALTIME, &m->last_visited);
305 #else
307  m->last_visited.tv_nsec = 0;
308 #endif
309 }
time_t mutt_date_epoch(void)
Return the number of seconds since the Unix epoch.
Definition: date.c:411
time_t tv_sec
Definition: file.h:47
struct timespec last_visited
Time of last exit from this mailbox.
Definition: mailbox.h:108
long tv_nsec
Definition: file.h:48
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:

◆ mutt_mailbox_next_buffer()

void mutt_mailbox_next_buffer ( 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 318 of file mutt_mailbox.c.

319 {
321 
322  if (mutt_mailbox_check(m_cur, 0) > 0)
323  {
324  bool found = false;
325  for (int pass = 0; pass < 2; pass++)
326  {
327  struct MailboxList ml = neomutt_mailboxlist_get_all(NeoMutt, MUTT_MAILBOX_ANY);
328  struct MailboxNode *np = NULL;
329  STAILQ_FOREACH(np, &ml, entries)
330  {
331  if (np->mailbox->type == MUTT_NOTMUCH) /* only match real mailboxes */
332  continue;
334  if ((found || (pass > 0)) && np->mailbox->has_new)
335  {
339  return;
340  }
341  if (mutt_str_strcmp(mutt_b2s(s), mailbox_path(np->mailbox)) == 0)
342  found = true;
343  }
345  }
346 
347  mutt_mailbox_check(m_cur, MUTT_MAILBOX_CHECK_FORCE); /* mailbox was wrong - resync things */
348  }
349 
350  /* no folders with new mail */
352 }
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox&#39;s path string.
Definition: mailbox.h:192
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:135
Match any Mailbox type.
Definition: mailbox.h:45
Container for Accounts, Notifications.
Definition: neomutt.h:35
void mutt_buffer_pretty_mailbox(struct Buffer *buf)
Shorten a mailbox path using &#39;~&#39; or &#39;=&#39;.
Definition: muttlib.c:689
bool has_new
Mailbox has new mail.
Definition: mailbox.h:88
#define mutt_b2s(buf)
Definition: buffer.h:41
int mutt_mailbox_check(struct Mailbox *m_cur, int force)
Check all all Mailboxes for new mail.
Definition: mutt_mailbox.c:152
#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:17
&#39;Notmuch&#39; (virtual) Mailbox type
Definition: mailbox.h:54
struct MailboxList neomutt_mailboxlist_get_all(struct NeoMutt *n, enum MailboxType type)
Get a List of all Mailboxes.
Definition: neomutt.c:157
void mutt_buffer_expand_path(struct Buffer *buf)
Create the canonical path.
Definition: muttlib.c:328
List of Mailboxes.
Definition: mailbox.h:145
struct Buffer pathbuf
Definition: mailbox.h:83
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:638
struct Mailbox * mailbox
Mailbox in the list.
Definition: mailbox.h:147
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_mailbox_next()

void mutt_mailbox_next ( 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 362 of file mutt_mailbox.c.

363 {
364  struct Buffer *s_buf = mutt_buffer_pool_get();
365 
366  mutt_buffer_addstr(s_buf, NONULL(s));
367  mutt_mailbox_next_buffer(m_cur, s_buf);
368  mutt_str_strfcpy(s, mutt_b2s(s_buf), slen);
369 
370  mutt_buffer_pool_release(&s_buf);
371 }
void mutt_mailbox_next_buffer(struct Mailbox *m_cur, struct Buffer *s)
incoming folders completion routine
Definition: mutt_mailbox.c:318
#define NONULL(x)
Definition: string2.h:37
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:101
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: pool.c:112
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:225
#define mutt_b2s(buf)
Definition: buffer.h:41
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:773
+ 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 381 of file mutt_mailbox.c.

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

Variable Documentation

◆ MailboxTime

time_t MailboxTime = 0
static

last time we started checking for mail

Definition at line 44 of file mutt_mailbox.c.

◆ MailboxStatsTime

time_t MailboxStatsTime = 0
static

last time we check performed mail_check_stats

Definition at line 45 of file mutt_mailbox.c.

◆ MailboxCount

short MailboxCount = 0
static

how many boxes with new mail

Definition at line 46 of file mutt_mailbox.c.

◆ MailboxNotify

short MailboxNotify = 0
static

of unnotified new boxes

Definition at line 47 of file mutt_mailbox.c.

◆ C_MailCheck

short C_MailCheck

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

Definition at line 50 of file mutt_mailbox.c.

◆ C_MailCheckStats

bool C_MailCheckStats

Config: Periodically check for new mail.

Definition at line 51 of file mutt_mailbox.c.

◆ C_MailCheckStatsInterval

short C_MailCheckStatsInterval

Config: How often to check for new mail.

Definition at line 52 of file mutt_mailbox.c.