struct dirent *de;
char *p;
int rc = 0;
+ struct stat sb;
snprintf (path, sizeof (path), "%s/new", mailbox->path);
+ /* when $mail_check_recent is set, if the new/ directory hasn't been modified since
+ * the user last exited the mailbox, then we know there is no recent mail.
+ */
+ if (option(OPTMAILCHECKRECENT))
+ {
+ if (stat(path, &sb) == 0 && sb.st_mtime < mailbox->last_visited)
+ return 0;
+ }
+
if ((dirp = opendir (path)) == NULL)
{
mailbox->magic = 0;
if (*de->d_name == '.')
continue;
- if (!(p = strstr (de->d_name, ":2,")) || !strchr (p + 3, 'T')) {
+ if (!(p = strstr (de->d_name, ":2,")) || !strchr (p + 3, 'T'))
+ {
+ if (option(OPTMAILCHECKRECENT))
+ {
+ char msgpath[_POSIX_PATH_MAX];
+
+ snprintf(msgpath, sizeof(msgpath), "%s/%s", path, de->d_name);
+ /* ensure this message was received since leaving this mailbox */
+ if (stat(msgpath, &sb) == 0 && (sb.st_ctime <= mailbox->last_visited))
+ continue;
+ }
/* one new and undeleted message is enough */
mailbox->new = 1;
rc = 1;
|| (mailbox->newly_created && sb->st_ctime == sb->st_mtime && sb->st_ctime == sb->st_atime);
if (statcheck)
{
- rc = 1;
- mailbox->new = 1;
+ if (!option(OPTMAILCHECKRECENT) || sb->st_mtime > mailbox->last_visited)
+ {
+ rc = 1;
+ mailbox->new = 1;
+ }
}
else if (option(OPTCHECKMBOXSIZE))
{
for (tmp = Incoming; tmp; tmp = tmp->next)
{
- if (tmp->magic != M_IMAP)
- tmp->new = 0;
-
if (tmp->magic != M_IMAP)
{
+ tmp->new = 0;
#ifdef USE_POP
if (mx_is_pop (tmp->path))
tmp->magic = M_POP;
return;
buffy->notified = 1;
+ time(&buffy->last_visited);
}
int mutt_buffy_notify (void)
short notified; /* user has been notified */
short magic; /* mailbox type */
short newly_created; /* mbox or mmdf just popped into existence */
+ time_t last_visited; /* time of last exit from this mailbox */
}
BUFFY;
dprint (3, (debugfile, "Found %s in buffy list (OV: %d ON: %d U: %d)\n",
mailbox, olduv, oldun, status->unseen));
- if (olduv && olduv == status->uidvalidity)
+ if (option(OPTMAILCHECKRECENT))
+ {
+ /*
+ * the \Recent flag will be set on messages that have been delivered since the mailbox
+ * was last opened.
+ */
+ inc->new = status->recent;
+ }
+ else if (olduv && olduv == status->uidvalidity)
{
if (oldun < status->uidnext)
inc->new = status->unseen;
}
- else if (!olduv && !oldun)
- /* first check per session, use recent. might need a flag for this. */
- inc->new = status->recent;
else
inc->new = status->unseen;
** This variable configures how often (in seconds) mutt should look for
** new mail. Also see the $$timeout variable.
*/
+ { "mail_check_recent",DT_BOOL, R_NONE, OPTMAILCHECKRECENT, 0 },
+ /*
+ ** .pp
+ ** When \fIset\fP, Mutt will only notify you about new mail that has been received
+ ** since the last time you opened the mailbox. When \fIunset\fP, Mutt will notify you
+ ** if any new mail exists in the mailbox, regardless of whether you have visited it
+ ** recently.
+ ** .pp
+ ** When \fI$$mark_old\fP is set, Mutt does not consider the mailbox to contain new
+ ** mail if only old messages exist.
+ */
{ "mailcap_path", DT_STR, R_NONE, UL &MailcapPath, 0 },
/*
** .pp
return (-1);
}
+/*
+ * Returns 1 if the mailbox has at least 1 new messages (not old)
+ * otherwise returns 0.
+ */
+static int mbox_has_new(CONTEXT *ctx)
+{
+ int i;
+
+ for (i = 0; i < ctx->msgcount; i++)
+ if (!ctx->hdrs[i]->deleted && !ctx->hdrs[i]->read && !ctx->hdrs[i]->old)
+ return 1;
+ return 0;
+}
+
/* if mailbox has at least 1 new message, sets mtime > atime of mailbox
* so buffy check reports new mail */
void mbox_reset_atime (CONTEXT *ctx, struct stat *st)
{
struct utimbuf utimebuf;
- int i, found = 0;
+ int i;
struct stat _st;
if (!st)
utimebuf.actime = st->st_atime;
utimebuf.modtime = st->st_mtime;
- for (i = 0; !found && i < ctx->msgcount; i++)
- if (!ctx->hdrs[i]->deleted && !ctx->hdrs[i]->read && !ctx->hdrs[i]->old)
- found = 1;
-
- if (found && utimebuf.actime >= utimebuf.modtime)
+ /*
+ * When $mbox_check_recent is set, existing new mail is ignored, so do not
+ * recent the atime to mtime-1 to signal new mail.
+ */
+ if (!option(OPTMAILCHECKRECENT) && utimebuf.actime >= utimebuf.modtime && mbox_has_new(ctx))
utimebuf.actime = utimebuf.modtime - 1;
utime (ctx->path, &utimebuf);
OPTINCLUDEONLYFIRST,
OPTKEEPFLAGGED,
OPTMAILCAPSANITIZE,
+ OPTMAILCHECKRECENT,
OPTMAILDIRTRASH,
OPTMARKERS,
OPTMARKOLD,