NeoMutt  2024-04-16-36-g75b6fb
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
mutt_mailbox.h File Reference

Mailbox helper functions. More...

#include <stdbool.h>
#include "core/lib.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.

Functions

int mutt_mailbox_check (struct Mailbox *m_cur, CheckStatsFlags flags)
 Check all all Mailboxes for new mail.
 
void mailbox_restore_timestamp (const char *path, struct stat *st)
 Restore the timestamp of a mailbox.
 
bool mutt_mailbox_list (void)
 Show a message with the list of mailboxes with new mail.
 
struct Mailboxmutt_mailbox_next (struct Mailbox *m_cur, struct Buffer *s)
 Incoming folders completion routine.
 
struct Mailboxmutt_mailbox_next_unread (struct Mailbox *m_cur, struct Buffer *s)
 Find next mailbox with unread mail.
 
bool mutt_mailbox_notify (struct Mailbox *m_cur)
 Notify the user if there's new mail.
 
void mutt_mailbox_set_notified (struct Mailbox *m)
 Note when the user was last notified of new mail.
 

Detailed Description

Mailbox helper functions.

Authors
  • Richard Russon
  • Pietro Cerutti

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

Function Documentation

◆ mutt_mailbox_check()

int mutt_mailbox_check ( struct Mailbox m_cur,
CheckStatsFlags  flags 
)

Check all all Mailboxes for new mail.

Parameters
m_curCurrent Mailbox
flagsFlags, e.g. MUTT_MAILBOX_CHECK_FORCE
Return values
numNumber of mailboxes with new mail

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

Definition at line 168 of file mutt_mailbox.c.

169{
170 if (TAILQ_EMPTY(&NeoMutt->accounts)) // fast return if there are no mailboxes
171 return 0;
172
173 if (flags & MUTT_MAILBOX_CHECK_FORCE)
175
176 const short c_mail_check = cs_subset_number(NeoMutt->sub, "mail_check");
177 const bool c_mail_check_stats = cs_subset_bool(NeoMutt->sub, "mail_check_stats");
178 const short c_mail_check_stats_interval = cs_subset_number(NeoMutt->sub, "mail_check_stats_interval");
179
180 time_t t = mutt_date_now();
181 if ((flags == MUTT_MAILBOX_CHECK_NO_FLAGS) && ((t - MailboxTime) < c_mail_check))
182 return MailboxCount;
183
184 if ((flags & MUTT_MAILBOX_CHECK_FORCE_STATS) ||
185 (c_mail_check_stats && ((t - MailboxStatsTime) >= c_mail_check_stats_interval)))
186 {
189 }
190
191 MailboxTime = t;
192 MailboxCount = 0;
193 MailboxNotify = 0;
194
195 /* check device ID and serial number instead of comparing paths */
196 struct stat st_cur = { 0 };
197 if (!m_cur || (m_cur->type == MUTT_IMAP) || (m_cur->type == MUTT_POP) ||
198 (m_cur->type == MUTT_NNTP) || stat(mailbox_path(m_cur), &st_cur) != 0)
199 {
200 st_cur.st_dev = 0;
201 st_cur.st_ino = 0;
202 }
203
204 struct MailboxList ml = STAILQ_HEAD_INITIALIZER(ml);
206 struct MailboxNode *np = NULL;
207 STAILQ_FOREACH(np, &ml, entries)
208 {
209 struct Mailbox *m = np->mailbox;
210
211 if (!m->visible || !m->poll_new_mail)
212 continue;
213
214 CheckStatsFlags m_flags = flags;
215 if (!m->first_check_stats_done && c_mail_check_stats)
216 {
218 }
219 mailbox_check(m_cur, m, &st_cur, m_flags);
220 if (m->has_new)
221 MailboxCount++;
222 m->first_check_stats_done = true;
223 }
225
226 return MailboxCount;
227}
short cs_subset_number(const struct ConfigSubset *sub, const char *name)
Get a number config item by name.
Definition: helpers.c:144
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:48
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox's path string.
Definition: mailbox.h:223
@ MUTT_POP
'POP3' Mailbox type
Definition: mailbox.h:52
@ MUTT_NNTP
'NNTP' (Usenet) Mailbox type
Definition: mailbox.h:49
@ MUTT_IMAP
'IMAP' Mailbox type
Definition: mailbox.h:50
@ MUTT_MAILBOX_ANY
Match any Mailbox type.
Definition: mailbox.h:42
time_t mutt_date_now(void)
Return the number of seconds since the Unix epoch.
Definition: date.c:455
static time_t MailboxStatsTime
last time we check performed mail_check_stats
Definition: mutt_mailbox.c:44
static short MailboxCount
how many boxes with new mail
Definition: mutt_mailbox.c:45
static short MailboxNotify
Definition: mutt_mailbox.c:46
static void mailbox_check(struct Mailbox *m_cur, struct Mailbox *m_check, struct stat *st_cur, CheckStatsFlags flags)
Check a mailbox for new mail.
Definition: mutt_mailbox.c:82
static time_t MailboxTime
last time we started checking for mail
Definition: mutt_mailbox.c:43
#define MUTT_MAILBOX_CHECK_NO_FLAGS
No flags are set.
Definition: mxapi.h:53
#define MUTT_MAILBOX_CHECK_FORCE_STATS
Ignore MailboxType and calculate statistics.
Definition: mxapi.h:55
#define MUTT_MAILBOX_CHECK_FORCE
Ignore MailboxTime and check for new mail.
Definition: mxapi.h:54
uint8_t CheckStatsFlags
Flags for mutt_mailbox_check.
Definition: mxapi.h:52
void neomutt_mailboxlist_clear(struct MailboxList *ml)
Free a Mailbox List.
Definition: neomutt.c:163
size_t neomutt_mailboxlist_get_all(struct MailboxList *head, struct NeoMutt *n, enum MailboxType type)
Get a List of all Mailboxes.
Definition: neomutt.c:186
void mutt_update_num_postponed(void)
Force the update of the number of postponed messages.
Definition: postpone.c:177
#define STAILQ_HEAD_INITIALIZER(head)
Definition: queue.h:324
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:352
#define TAILQ_EMPTY(head)
Definition: queue.h:721
List of Mailboxes.
Definition: mailbox.h:166
struct Mailbox * mailbox
Mailbox in the list.
Definition: mailbox.h:167
A mailbox.
Definition: mailbox.h:79
bool has_new
Mailbox has new mail.
Definition: mailbox.h:85
bool first_check_stats_done
True when the check have been done at least one time.
Definition: mailbox.h:112
enum MailboxType type
Mailbox type.
Definition: mailbox.h:102
bool poll_new_mail
Check for new mail.
Definition: mailbox.h:115
bool visible
True if a result of "mailboxes".
Definition: mailbox.h:130
Container for Accounts, Notifications.
Definition: neomutt.h:41
struct AccountList accounts
List of all Accounts.
Definition: neomutt.h:46
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:45
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mailbox_restore_timestamp()

void mailbox_restore_timestamp ( 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 402 of file mutt_mailbox.c.

403{
404#ifdef HAVE_UTIMENSAT
405 struct timespec ts[2] = { { 0 }, { 0 } };
406#else
407 struct utimbuf ut = { 0 };
408#endif
409
410 const bool c_check_mbox_size = cs_subset_bool(NeoMutt->sub, "check_mbox_size");
411 if (c_check_mbox_size)
412 {
413 struct Mailbox *m = mailbox_find(path);
414 if (m && !m->has_new)
416 }
417 else
418 {
419 /* fix up the times so mailbox won't get confused */
420 if (st->st_mtime > st->st_atime)
421 {
422#ifdef HAVE_UTIMENSAT
423 ts[0].tv_sec = 0;
424 ts[0].tv_nsec = UTIME_OMIT;
425 ts[1].tv_sec = 0;
426 ts[1].tv_nsec = UTIME_NOW;
427 utimensat(AT_FDCWD, buf, ts, 0);
428#else
429 ut.actime = st->st_atime;
430 ut.modtime = mutt_date_now();
431 utime(path, &ut);
432#endif
433 }
434 else
435 {
436#ifdef HAVE_UTIMENSAT
437 ts[0].tv_sec = 0;
438 ts[0].tv_nsec = UTIME_NOW;
439 ts[1].tv_sec = 0;
440 ts[1].tv_nsec = UTIME_NOW;
441 utimensat(AT_FDCWD, buf, ts, 0);
442#else
443 utime(path, NULL);
444#endif
445 }
446 }
447}
void mailbox_update(struct Mailbox *m)
Get the mailbox's current size.
Definition: mailbox.c:216
struct Mailbox * mailbox_find(const char *path)
Find the mailbox with a given path.
Definition: mailbox.c:151
Time value with nanosecond precision.
Definition: file.h:51
long tv_nsec
Number of nanosecond, on top.
Definition: file.h:53
time_t tv_sec
Number of seconds since the epoch.
Definition: file.h:52
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_mailbox_list()

bool mutt_mailbox_list ( void  )

Show a message with the list of mailboxes with new mail.

Return values
trueThere is new mail

Definition at line 247 of file mutt_mailbox.c.

248{
249 int have_unnotified = MailboxNotify;
250
251 struct Buffer *path = buf_pool_get();
252 struct Buffer *mailboxlist = buf_pool_get();
253
254 buf_addstr(mailboxlist, _("New mail in "));
255 struct MailboxList ml = STAILQ_HEAD_INITIALIZER(ml);
257 struct MailboxNode *np = NULL;
258 STAILQ_FOREACH(np, &ml, entries)
259 {
260 /* Is there new mail in this mailbox? */
261 if (!np->mailbox->has_new || (have_unnotified && np->mailbox->notified))
262 continue;
263
264 buf_strcpy(path, mailbox_path(np->mailbox));
265 buf_pretty_mailbox(path);
266
267 if (!buf_is_empty(mailboxlist))
268 buf_addstr(mailboxlist, ", ");
269
270 if (!np->mailbox->notified)
271 {
272 np->mailbox->notified = true;
274 }
275 buf_addstr(mailboxlist, buf_string(path));
276 }
278
279 buf_pool_release(&path);
280
281 if (!buf_is_empty(mailboxlist))
282 {
283 mutt_message("%s", buf_string(mailboxlist));
284 buf_pool_release(&mailboxlist);
285 return true;
286 }
287
288 /* there were no mailboxes needing to be notified, so clean up since
289 * MailboxNotify has somehow gotten out of sync */
290 MailboxNotify = 0;
291 buf_pool_release(&mailboxlist);
292 return false;
293}
bool buf_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition: buffer.c:290
size_t buf_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition: buffer.c:225
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:394
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:96
#define mutt_message(...)
Definition: logging2.h:91
#define _(a)
Definition: message.h:28
void buf_pretty_mailbox(struct Buffer *buf)
Shorten a mailbox path using '~' or '='.
Definition: muttlib.c:554
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:81
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition: pool.c:94
String manipulation buffer.
Definition: buffer.h:36
bool notified
User has been notified.
Definition: mailbox.h:101
+ 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 356 of file mutt_mailbox.c.

357{
359
361 {
362 struct Mailbox *m_res = find_next_mailbox(s, true);
363 if (m_res)
364 return m_res;
365
366 mutt_mailbox_check(m_cur, MUTT_MAILBOX_CHECK_FORCE); /* mailbox was wrong - resync things */
367 }
368
369 buf_reset(s); // no folders with new mail
370 return NULL;
371}
void buf_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition: buffer.c:75
int mutt_mailbox_check(struct Mailbox *m_cur, CheckStatsFlags flags)
Check all all Mailboxes for new mail.
Definition: mutt_mailbox.c:168
static struct Mailbox * find_next_mailbox(struct Buffer *s, bool find_new)
Find the next mailbox with new or unread mail.
Definition: mutt_mailbox.c:317
void buf_expand_path(struct Buffer *buf)
Create the canonical path.
Definition: muttlib.c:328
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_mailbox_next_unread()

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

Find next mailbox with unread mail.

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

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

Definition at line 382 of file mutt_mailbox.c.

383{
385
386 struct Mailbox *m_res = find_next_mailbox(s, false);
387 if (m_res)
388 return m_res;
389
390 buf_reset(s); // no folders with new mail
391 return NULL;
392}
+ 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
trueThere is new mail

Definition at line 234 of file mutt_mailbox.c.

235{
237 {
238 return mutt_mailbox_list();
239 }
240 return false;
241}
bool mutt_mailbox_list(void)
Show a message with the list of mailboxes with new mail.
Definition: mutt_mailbox.c:247
+ 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 299 of file mutt_mailbox.c.

300{
301 if (!m)
302 return;
303
304 m->notified = true;
306}
void mutt_time_now(struct timespec *tp)
Set the provided time field to the current time.
Definition: date.c:479
struct timespec last_visited
Time of last exit from this mailbox.
Definition: mailbox.h:104
+ Here is the call graph for this function:
+ Here is the caller graph for this function: