Commit 2ee52979 authored by Michael Elkins's avatar Michael Elkins

add $mail_check_recent boolean to control whether Mutt will notify about all...

add $mail_check_recent boolean to control whether Mutt will notify about all new mail, or just new mail received since the last visit to a mailbox

closes #3271

partly addresses #3310
parent 271a43a1
......@@ -293,9 +293,19 @@ static int buffy_maildir_hasnew (BUFFY* mailbox)
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;
......@@ -307,7 +317,17 @@ static int buffy_maildir_hasnew (BUFFY* mailbox)
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;
......@@ -333,8 +353,11 @@ static int buffy_mbox_hasnew (BUFFY* mailbox, struct stat *sb)
|| (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))
{
......@@ -390,11 +413,9 @@ int mutt_buffy_check (int force)
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;
......@@ -513,6 +534,7 @@ void mutt_buffy_setnotified (const char *path)
return;
buffy->notified = 1;
time(&buffy->last_visited);
}
int mutt_buffy_notify (void)
......
......@@ -29,6 +29,7 @@ typedef struct buffy_t
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;
......
......@@ -990,14 +990,19 @@ static void cmd_parse_status (IMAP_DATA* idata, char* s)
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;
......
......@@ -1335,6 +1335,17 @@ struct option_t MuttVars[] = {
** 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
......
......@@ -671,12 +671,26 @@ int mbox_check_mailbox (CONTEXT *ctx, int *index_hint)
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)
......@@ -689,11 +703,11 @@ void mbox_reset_atime (CONTEXT *ctx, struct stat *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);
......
......@@ -384,6 +384,7 @@ enum
OPTINCLUDEONLYFIRST,
OPTKEEPFLAGGED,
OPTMAILCAPSANITIZE,
OPTMAILCHECKRECENT,
OPTMAILDIRTRASH,
OPTMARKERS,
OPTMARKOLD,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment