#include <stdio.h>
static time_t BuffyTime = 0; /* last time we started checking for mail */
+static time_t BuffyStatsTime = 0; /* last time we check performed mail_check_stats */
time_t BuffyDoneTime = 0; /* last time we knew for sure how much mail there was. */
static short BuffyCount = 0; /* how many boxes with new mail */
static short BuffyNotify = 0; /* # of unnotified new boxes */
return 0;
}
-#ifdef USE_SIDEBAR
/**
* buffy_maildir_update_dir - Update counts for one directory
* @mailbox: BUFFY representing a maildir mailbox
void
buffy_maildir_update (BUFFY *mailbox)
{
- if (!option (OPTSIDEBAR))
- return;
-
mailbox->msg_count = 0;
mailbox->msg_unread = 0;
mailbox->msg_flagged = 0;
mailbox->new = 1;
}
buffy_maildir_update_dir (mailbox, "cur");
-
- mailbox->sb_last_checked = time (NULL);
}
-#endif
-
/* returns 1 if mailbox has new mail */
static int buffy_mbox_hasnew (BUFFY* mailbox, struct stat *sb)
{
return rc;
}
-#ifdef USE_SIDEBAR
/**
* buffy_mbox_update - Update messages counts for an mbox mailbox
* @mailbox: BUFFY representing an mbox mailbox
{
CONTEXT *ctx = NULL;
- if (!option (OPTSIDEBAR))
- return;
- if ((mailbox->sb_last_checked > sb->st_mtime) && (mailbox->msg_count != 0))
+ if ((mailbox->stats_last_checked > sb->st_mtime) && (mailbox->msg_count != 0))
return; /* no check necessary */
ctx = mx_open_mailbox (mailbox->path, MUTT_READONLY | MUTT_QUIET | MUTT_NOSORT | MUTT_PEEK, NULL);
mailbox->msg_count = ctx->msgcount;
mailbox->msg_unread = ctx->unread;
mailbox->msg_flagged = ctx->flagged;
- mailbox->sb_last_checked = time (NULL);
+ mailbox->stats_last_checked = time (NULL);
mx_close_mailbox (ctx, 0);
}
}
-#endif
int mutt_buffy_check (int force)
{
struct stat sb;
struct stat contex_sb;
time_t t;
+ int check_stats = 0;
+#ifdef USE_SIDEBAR
+ short orig_new;
+ int orig_count, orig_unread, orig_flagged;
+#endif
sb.st_size=0;
contex_sb.st_dev=0;
t = time (NULL);
if (!force && (t - BuffyTime < BuffyTimeout))
return BuffyCount;
-
+
+ if (option (OPTMAILCHECKSTATS) &&
+ (t - BuffyStatsTime >= BuffyCheckStatsInterval))
+ {
+ check_stats = 1;
+ BuffyStatsTime = t;
+ }
+
BuffyTime = t;
BuffyCount = 0;
BuffyNotify = 0;
#ifdef USE_IMAP
- BuffyCount += imap_buffy_check (force);
+ BuffyCount += imap_buffy_check (force, check_stats);
#endif
/* check device ID and serial number instead of comparing paths */
contex_sb.st_ino=0;
}
-#ifdef USE_SIDEBAR
- int should_refresh = mutt_sb_should_refresh();
-#endif
for (tmp = Incoming; tmp; tmp = tmp->next)
{
if (tmp->magic != MUTT_IMAP)
}
}
+#ifdef USE_SIDEBAR
+ orig_new = tmp->new;
+ orig_count = tmp->msg_count;
+ orig_unread = tmp->msg_unread;
+ orig_flagged = tmp->msg_flagged;
+#endif
+
/* check to see if the folder is the currently selected folder
* before polling */
if (!Context || !Context->path ||
{
case MUTT_MBOX:
case MUTT_MMDF:
-#ifdef USE_SIDEBAR
- if (should_refresh)
+ if (check_stats)
buffy_mbox_update (tmp, &sb);
-#endif
if (buffy_mbox_hasnew (tmp, &sb) > 0)
BuffyCount++;
break;
case MUTT_MAILDIR:
-#ifdef USE_SIDEBAR
- if (should_refresh)
+ if (check_stats)
buffy_maildir_update (tmp);
-#endif
if (buffy_maildir_hasnew (tmp) > 0)
BuffyCount++;
break;
case MUTT_MH:
-#ifdef USE_SIDEBAR
- if (should_refresh)
+ if (check_stats)
mh_buffy_update (tmp);
-#endif
mh_buffy(tmp);
if (tmp->new)
BuffyCount++;
else if (option(OPTCHECKMBOXSIZE) && Context && Context->path)
tmp->size = (off_t) sb.st_size; /* update the size of current folder */
+#ifdef USE_SIDEBAR
+ if ((orig_new != tmp->new) ||
+ (orig_count != tmp->msg_count) ||
+ (orig_unread != tmp->msg_unread) ||
+ (orig_flagged != tmp->msg_flagged))
+ SidebarNeedsRedraw = 1;
+#endif
+
if (!tmp->new)
tmp->notified = 0;
else if (!tmp->notified)
BuffyNotify++;
}
-#ifdef USE_SIDEBAR
- if (should_refresh)
- {
- SidebarNeedsRedraw = 1;
- mutt_sb_set_update_time();
- }
-#endif
BuffyDoneTime = BuffyTime;
return (BuffyCount);
struct buffy_t *prev;
#endif
short new; /* mailbox has new mail */
-#ifdef USE_SIDEBAR
+
+ /* These next three are only set when OPTMAILCHECKSTATS is set */
int msg_count; /* total number of messages */
int msg_unread; /* number of unread messages */
int msg_flagged; /* number of flagged messages */
+
+#ifdef USE_SIDEBAR
short is_hidden; /* is hidden from the sidebar */
#endif
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 */
-#ifdef USE_SIDEBAR
- time_t sb_last_checked; /* time of last buffy check from sidebar */
-#endif
+ time_t stats_last_checked; /* time of last mail_check_stats calculation */
}
BUFFY;
WHERE BUFFY *Incoming INITVAL (0);
WHERE short BuffyTimeout INITVAL (3);
+WHERE short BuffyCheckStatsInterval INITVAL (60);
extern time_t BuffyDoneTime; /* last time we knew for sure how much mail there was */
# Note: Only the first character of this string is used.
set sidebar_divider_char = '|'
+# Enable extended buffy mode to calculate total, new, and flagged
+# message counts for each mailbox.
+set mail_check_stats
+
# Display the Sidebar mailboxes using this format string.
set sidebar_format = '%B%?F? [%F]?%* %?N?%N/?%S'
<entry>boolean</entry>
<entry><literal>no</literal></entry>
</row>
- <row>
- <entry><literal>sidebar_refresh_time</literal></entry>
- <entry>number</entry>
- <entry><literal>60</literal></entry>
- </row>
<row>
<entry><literal>sidebar_short_path</literal></entry>
<entry>boolean</entry>
#ifdef USE_SIDEBAR
WHERE short SidebarWidth;
-WHERE short SidebarRefreshTime;
WHERE LIST *SidebarWhitelist INITVAL(0);
WHERE int SidebarNeedsRedraw INITVAL (0);
#endif
IMAP_STATUS *status;
unsigned int olduv, oldun;
long litlen;
+ short new = 0;
mailbox = imap_next_word (s);
if (olduv && olduv == status->uidvalidity)
{
if (oldun < status->uidnext)
- inc->new = status->unseen;
+ new = (status->unseen > 0);
}
else if (!olduv && !oldun)
/* first check per session, use recent. might need a flag for this. */
- inc->new = status->recent;
+ new = (status->recent > 0);
else
- inc->new = status->unseen;
+ new = (status->unseen > 0);
}
else
- inc->new = status->unseen;
+ new = (status->unseen > 0);
+
+#ifdef USE_SIDEBAR
+ if ((inc->new != new) ||
+ (inc->msg_count != status->messages) ||
+ (inc->msg_unread != status->unseen))
+ SidebarNeedsRedraw = 1;
+#endif
+ inc->new = new;
+ inc->msg_count = status->messages;
+ inc->msg_unread = status->unseen;
if (inc->new)
/* force back to keep detecting new mail until the mailbox is
opened */
status->uidnext = oldun;
-#ifdef USE_SIDEBAR
- /* Make the sidebar show the correct numbers */
- if (status->messages) {
- inc->msg_count = status->messages;
- inc->msg_unread = status->unseen;
- }
-#endif
-
FREE (&value);
return;
}
/* check for new mail in any subscribed mailboxes. Given a list of mailboxes
* rather than called once for each so that it can batch the commands and
* save on round trips. Returns number of mailboxes with new mail. */
-int imap_buffy_check (int force)
+int imap_buffy_check (int force, int check_stats)
{
IMAP_DATA* idata;
IMAP_DATA* lastdata = NULL;
if (mailbox->magic != MUTT_IMAP)
continue;
- mailbox->new = 0;
-
if (imap_get_mailbox (mailbox->path, &idata, name, sizeof (name)) < 0)
continue;
lastdata = idata;
imap_munge_mbox_name (idata, munged, sizeof (munged), name);
- snprintf (command, sizeof (command),
-#ifdef USE_SIDEBAR
+ if (check_stats)
+ snprintf (command, sizeof (command),
"STATUS %s (UIDNEXT UIDVALIDITY UNSEEN RECENT MESSAGES)", munged);
-#else
+ else
+ snprintf (command, sizeof (command),
"STATUS %s (UIDNEXT UIDVALIDITY UNSEEN RECENT)", munged);
-#endif
if (imap_exec (idata, command, IMAP_CMD_QUEUE) < 0)
{
int imap_open_mailbox_append (CONTEXT *ctx);
int imap_sync_mailbox (CONTEXT *ctx, int expunge, int *index_hint);
int imap_close_mailbox (CONTEXT *ctx);
-int imap_buffy_check (int force);
+int imap_buffy_check (int force, int check_stats);
int imap_status (char *path, int queue);
int imap_search (CONTEXT* ctx, const pattern_t* pat);
int imap_subscribe (char *path, int subscribe);
** When \fI$$mark_old\fP is set, Mutt does not consider the mailbox to contain new
** mail if only old messages exist.
*/
+ { "mail_check_stats", DT_BOOL, R_NONE, OPTMAILCHECKSTATS, 0 },
+ /*
+ ** .pp
+ ** When \fIset\fP, mutt will periodically calculate message
+ ** statistics of a mailbox while polling for new mail. It will
+ ** check for unread, flagged, and total message counts. Because
+ ** this operation is more performance intensive, it defaults to
+ ** \fIunset\fP, and has a separate option, $$mail_check_stats_interval, to
+ ** control how often to update these counts.
+ */
+ { "mail_check_stats_interval", DT_NUM, R_NONE, UL &BuffyCheckStatsInterval, 60 },
+ /*
+ ** .pp
+ ** When $$mail_check_stats is \fIset\fP, this variable configures
+ ** how often (in seconds) mutt will update message counts.
+ */
{ "mailcap_path", DT_STR, R_NONE, UL &MailcapPath, 0 },
/*
** .pp
** * = Can be optionally printed if nonzero
** @ = Only applicable to the current folder
** .pp
- ** A useful value for this is "%B%?F? [%F]?%* %?N?%N/?%S".
+ ** In order to use %S, %N, %F, and %!, $$mail_check_stats must
+ ** be \fIset\fP. When set, a useful value for this setting is
+ ** "%B%?F? [%F]?%* %?N?%N/?%S".
*/
{ "sidebar_indent_string", DT_STR, R_BOTH, UL &SidebarIndentString, UL " " },
/*
** \fC<sidebar-prev-new>\fP command is similarly affected, wrapping around to
** the end of the list.
*/
- { "sidebar_refresh_time", DT_NUM, R_BOTH, UL &SidebarRefreshTime, 60 },
- /*
- ** .pp
- ** Set sidebar_refresh_time to the minimum number of seconds between refreshes.
- ** This will reduced network traffic.
- ** .pp
- ** \fBNote:\fP Set to 0 to disable refreshing.
- */
{ "sidebar_short_path", DT_BOOL, R_BOTH, OPTSIDEBARSHORTPATH, 0 },
/*
** .pp
#define MUTT_READONLY (1<<2) /* open in read-only mode */
#define MUTT_QUIET (1<<3) /* do not print any messages */
#define MUTT_NEWFOLDER (1<<4) /* create a new folder - same as MUTT_APPEND, but uses
- * safe_fopen() for mbox-style folders.
- */
-#ifdef USE_SIDEBAR
+ * safe_fopen() for mbox-style folders. */
#define MUTT_PEEK (1<<5) /* revert atime back after taking a look (if applicable) */
-#endif
/* mx_open_new_message() */
#define MUTT_ADD_FROM (1<<0) /* add a From_ line */
mutt_perror (ctx->path);
return (-1);
}
-#ifdef USE_SIDEBAR
ctx->atime = sb.st_atime;
-#endif
ctx->mtime = sb.st_mtime;
ctx->size = sb.st_size;
ctx->size = sb.st_size;
ctx->mtime = sb.st_mtime;
-#ifdef USE_SIDEBAR
ctx->atime = sb.st_atime;
-#endif
#ifdef NFS_ATTRIBUTE_HACK
if (sb.st_mtime > sb.st_atime)
mhs_free_sequences (&mhs);
}
-#ifdef USE_SIDEBAR
/**
* mh_buffy_update - Update messages counts for an mh mailbox
* @mailbox: BUFFY representing a maildir mailbox
if (!mailbox)
return;
- if (!option (OPTSIDEBAR))
- return;
-
memset (&mhs, 0, sizeof (mhs));
if (mh_read_sequences (&mhs, mailbox->path) < 0)
mailbox->msg_flagged++;
}
mhs_free_sequences (&mhs);
- mailbox->sb_last_checked = time (NULL);
}
-#endif
static int mh_mkstemp (CONTEXT * dest, FILE ** fp, char **tgt)
{
OPTKEEPFLAGGED,
OPTMAILCAPSANITIZE,
OPTMAILCHECKRECENT,
+ OPTMAILCHECKSTATS,
OPTMAILDIRTRASH,
OPTMAILDIRCHECKCUR,
OPTMARKERS,
{
char *path;
FILE *fp;
-#ifdef USE_SIDEBAR
time_t atime;
-#endif
time_t mtime;
off_t size;
off_t vsize;
unsigned int quiet : 1; /* inhibit status messages? */
unsigned int collapsed : 1; /* are all threads collapsed? */
unsigned int closing : 1; /* mailbox is being closed */
-#ifdef USE_SIDEBAR
unsigned int peekonly : 1; /* just taking a glance, revert atime */
-#endif
/* driver hooks */
void *data; /* driver specific data */
ctx->quiet = 1;
if (flags & MUTT_READONLY)
ctx->readonly = 1;
-#ifdef USE_SIDEBAR
if (flags & MUTT_PEEK)
ctx->peekonly = 1;
-#endif
if (flags & (MUTT_APPEND|MUTT_NEWFOLDER))
{
void mx_fastclose_mailbox (CONTEXT *ctx)
{
int i;
+ struct utimbuf ut;
if(!ctx)
return;
-#ifdef USE_SIDEBAR
/* fix up the times so buffy won't get confused */
- struct utimbuf ut;
if (ctx->peekonly && ctx->path && (ctx->mtime > ctx->atime)) {
ut.actime = ctx->atime;
ut.modtime = ctx->mtime;
utime (ctx->path, &ut);
}
-#endif
/* never announce that a mailbox we've just left has new mail. #3290
* XXX: really belongs in mx_close_mailbox, but this is a nice hook point */
-#ifdef USE_SIDEBAR
if (!ctx->peekonly)
-#endif
- mutt_buffy_setnotified(ctx->path);
+ mutt_buffy_setnotified(ctx->path);
if (ctx->mx_ops)
ctx->mx_ops->close (ctx);
void mbox_reset_atime (CONTEXT *, struct stat *);
int mh_sync_mailbox (CONTEXT *, int *);
-#ifdef USE_SIDEBAR
void mh_buffy_update (BUFFY *mailbox);
-#endif
int mh_check_empty (const char *);
int maildir_check_empty (const char *);
/* Previous values for some sidebar config */
static short PreviousSort; /* sidebar_sort_method */
-static time_t LastRefresh; /* Time of last refresh */
/* Keep track of various BUFFYs */
static BUFFY *TopBuffy; /* First mailbox visible in sidebar */
draw_sidebar (num_rows, num_cols, div_width);
}
-/**
- * mutt_sb_should_refresh - Check if the sidebar is due to be refreshed
- *
- * The "sidebar_refresh_time" config option allows the user to limit the frequency
- * with which the sidebar is refreshed.
- *
- * Returns:
- * 1 Yes, refresh is due
- * 0 No, refresh happened recently
- */
-int mutt_sb_should_refresh (void)
-{
- if (!option (OPTSIDEBAR))
- return 0;
-
- if (SidebarRefreshTime == 0)
- return 0;
-
- time_t diff = (time (NULL) - LastRefresh);
-
- return (diff >= SidebarRefreshTime);
-}
-
/**
* mutt_sb_change_mailbox - Change the selected mailbox
* @op: Operation code
return OpnBuffy;
}
-/**
- * mutt_sb_set_update_time - Note the time that the sidebar was updated
- *
- * Update the timestamp representing the last sidebar update. If the user
- * configures "sidebar_refresh_time", this will help to reduce traffic.
- */
-void mutt_sb_set_update_time (void)
-{
- /* XXX - should this be public? */
-
- LastRefresh = time (NULL);
-}
-
/**
* mutt_sb_notify_mailbox - The state of a BUFFY is about to change
*
void mutt_sb_notify_mailbox (BUFFY *b, int created);
void mutt_sb_set_buffystats (const CONTEXT *ctx);
BUFFY * mutt_sb_set_open_buffy (const char *path);
-void mutt_sb_set_update_time (void);
-int mutt_sb_should_refresh (void);
#endif /* SIDEBAR_H */