OP_SIDEBAR_PAGE_UP "Scroll the Sidebar up 1 page"
OP_SIDEBAR_PREV "Move the highlight to previous mailbox"
OP_SIDEBAR_PREV_NEW "Move the highlight to previous mailbox with new mail"
+OP_SIDEBAR_TOGGLE "toggle between mailboxes and virtual mailboxes"
OP_SIDEBAR_TOGGLE_VISIBLE "Make the Sidebar (in)visible"
{
if (mx_is_notmuch (tmp->path))
{
- unsigned new = 0, all = 0;
- nm_get_count(tmp->path, &all, &new);
- add_folder (menu, state, tmp->path, tmp->desc, NULL, new, all);
+ nm_get_count(tmp->path, &tmp->msg_count, &tmp->msg_unread);
+ add_folder (menu, state, tmp->path, tmp->desc, NULL,
+ tmp->msg_unread, tmp->msg_count);
continue;
}
}
#include "imap.h"
#endif
+#ifdef USE_NOTMUCH
+#include "mutt_notmuch.h"
+#endif
+
#include <string.h>
#include <sys/stat.h>
#include <dirent.h>
}
#endif
-int mutt_buffy_check (int force)
-{
- BUFFY *tmp;
- struct stat sb;
- struct stat contex_sb;
- time_t t;
-
- sb.st_size=0;
- contex_sb.st_dev=0;
- contex_sb.st_ino=0;
-#ifdef USE_IMAP
- /* update postponed count as well, on force */
- if (force)
- mutt_update_num_postponed ();
-#endif
-
- /* fastest return if there are no mailboxes */
- if (!Incoming)
- return 0;
- t = time (NULL);
- if (!force && (t - BuffyTime < BuffyTimeout))
- return BuffyCount;
-
- BuffyTime = t;
- BuffyCount = 0;
- BuffyNotify = 0;
+static void buffy_check(BUFFY *tmp, struct stat *contex_sb)
+{
+ struct stat sb;
-#ifdef USE_IMAP
- BuffyCount += imap_buffy_check (force);
-#endif
+ sb.st_size=0;
- /* check device ID and serial number instead of comparing paths */
- if (!Context || Context->magic == M_IMAP || Context->magic == M_POP
- || stat (Context->path, &contex_sb) != 0)
- {
- contex_sb.st_dev=0;
- contex_sb.st_ino=0;
- }
-
-#ifdef USE_SIDEBAR
- int should_refresh = sb_should_refresh();
-#endif
- for (tmp = Incoming; tmp; tmp = tmp->next)
- {
if (tmp->magic != M_IMAP)
{
tmp->new = 0;
if (mx_is_pop (tmp->path))
tmp->magic = M_POP;
else
+#endif
+#ifdef USE_NOTMUCH
+ if (mx_is_notmuch (tmp->path))
+ tmp->magic = M_NOTMUCH;
+ else
#endif
if (stat (tmp->path, &sb) != 0 || (S_ISREG(sb.st_mode) && sb.st_size == 0) ||
(!tmp->magic && (tmp->magic = mx_get_magic (tmp->path)) <= 0))
tmp->newly_created = 1;
tmp->magic = 0;
tmp->size = 0;
- continue;
+ return;
}
}
/* check to see if the folder is the currently selected folder
* before polling */
if (!Context || !Context->path ||
- (( tmp->magic == M_IMAP || tmp->magic == M_POP )
+ (( tmp->magic == M_IMAP || tmp->magic == M_POP || tmp->magic == M_NOTMUCH)
? mutt_strcmp (tmp->path, Context->path) :
- (sb.st_dev != contex_sb.st_dev || sb.st_ino != contex_sb.st_ino)))
+ (sb.st_dev != contex_sb->st_dev || sb.st_ino != contex_sb->st_ino)))
{
switch (tmp->magic)
{
case M_MBOX:
case M_MMDF:
#ifdef USE_SIDEBAR
- if (should_refresh)
+ if (option(OPTSIDEBAR))
buffy_mbox_update (tmp, &sb);
#endif
if (buffy_mbox_hasnew (tmp, &sb) > 0)
case M_MAILDIR:
#ifdef USE_SIDEBAR
- if (should_refresh)
+ if (option(OPTSIDEBAR))
buffy_maildir_update (tmp);
#endif
if (buffy_maildir_hasnew (tmp) > 0)
case M_MH:
#ifdef USE_SIDEBAR
- if (sb_should_refresh()) {
+ if (option(OPTSIDEBAR))
mh_buffy_update (tmp);
- sb_set_update_time();
- }
#endif
mh_buffy(tmp);
if (tmp->new)
BuffyCount++;
break;
+#ifdef USE_NOTMUCH
+ case M_NOTMUCH:
+ tmp->msg_count = 0;
+ tmp->msg_unread = 0;
+ tmp->msg_flagged = 0;
+ nm_get_count(tmp->path, &tmp->msg_count, &tmp->msg_unread);
+ if (tmp->msg_unread > 0)
+ BuffyCount++;
+ break;
+#endif
}
}
else if (option(OPTCHECKMBOXSIZE) && Context && Context->path)
tmp->notified = 0;
else if (!tmp->notified)
BuffyNotify++;
+}
+
+int mutt_buffy_check (int force)
+{
+ BUFFY *tmp;
+ struct stat contex_sb;
+ time_t t;
+
+ contex_sb.st_dev=0;
+ contex_sb.st_ino=0;
+
+#ifdef USE_IMAP
+ /* update postponed count as well, on force */
+ if (force)
+ mutt_update_num_postponed ();
+#endif
+
+ /* fastest return if there are no mailboxes */
+ if (!Incoming && !VirtIncoming)
+ return 0;
+ t = time (NULL);
+ if (!force && (t - BuffyTime < BuffyTimeout))
+ return BuffyCount;
+
+ BuffyTime = t;
+ BuffyCount = 0;
+ BuffyNotify = 0;
+
+#ifdef USE_IMAP
+ BuffyCount += imap_buffy_check (force);
+#endif
+
+ /* check device ID and serial number instead of comparing paths */
+ if (!Context || Context->magic == M_IMAP || Context->magic == M_POP
+ || stat (Context->path, &contex_sb) != 0)
+ {
+ contex_sb.st_dev=0;
+ contex_sb.st_ino=0;
}
+
#ifdef USE_SIDEBAR
- if (should_refresh)
- sb_set_update_time();
+ if (sb_should_refresh()) {
+ for (tmp = Incoming; tmp; tmp = tmp->next)
+ buffy_check(tmp, &contex_sb);
+ sb_set_update_time();
+ }
+#else
+ for (tmp = Incoming; tmp; tmp = tmp->next)
+ buffy_check(tmp, &contex_sb);
#endif
+ for (tmp = VirtIncoming; tmp; tmp = tmp->next)
+ buffy_check(tmp, &contex_sb);
+
BuffyDoneTime = BuffyTime;
return (BuffyCount);
}
mutt_expand_path (buf, bufsz);
#ifdef USE_SIDEBAR
if (sb_set_open_buffy (buf) == NULL)
- break;
+ return -1;
#endif
if (mx_get_magic (buf) <= 0)
{
toggle_option (OPTSIDEBAR);
menu->redraw = REDRAW_FULL;
break;
+
+ case OP_SIDEBAR_TOGGLE:
+ toggle_sidebar(menu->menu);
+ break;
#endif
default:
if (menu->menu == MENU_MAIN)
{ "sidebar-page-up", OP_SIDEBAR_PAGE_UP, NULL },
{ "sidebar-prev", OP_SIDEBAR_PREV, NULL },
{ "sidebar-prev-new", OP_SIDEBAR_PREV_NEW, NULL },
+ { "sidebar-toggle", OP_SIDEBAR_TOGGLE, NULL },
{ "sidebar-toggle-visible", OP_SIDEBAR_TOGGLE_VISIBLE, NULL },
#endif
{ "sidebar-page-up", OP_SIDEBAR_PAGE_UP, NULL },
{ "sidebar-prev", OP_SIDEBAR_PREV, NULL },
{ "sidebar-prev-new", OP_SIDEBAR_PREV_NEW, NULL },
+ { "sidebar-toggle", OP_SIDEBAR_TOGGLE, NULL },
{ "sidebar-toggle-visible", OP_SIDEBAR_TOGGLE_VISIBLE, NULL },
#endif
return res;
}
-int nm_get_count(char *path, unsigned *all, unsigned *new)
+int nm_get_count(char *path, int *all, int *new)
{
struct uri_tag *query_items = NULL, *item;
char *db_filename = NULL, *db_query = NULL;
int nm_header_get_magic(HEADER *h);
char *nm_header_get_fullpath(HEADER *h, char *buf, size_t bufsz);
char *nm_header_get_tags(HEADER *h);
-int nm_get_count(char *path, unsigned *all, unsigned *new);
+int nm_get_count(char *path, int *all, int *new);
int nm_update_filename(CONTEXT *ctx, const char *old, const char *new);
char *nm_uri_from_query(CONTEXT *ctx, char *buf, size_t bufsz);
int nm_modify_message_tags(CONTEXT *ctx, HEADER *hdr, char *tags);
#include "keymap.h"
#include "mutt_curses.h"
#include "mutt_menu.h"
+#include "mx.h"
#include "sort.h"
/* Previous values for some sidebar config */
BUFFY *buffy;
};
+enum {
+ SB_SRC_NONE = 0,
+ SB_SRC_VIRT,
+ SB_SRC_INCOMING
+};
+static int sidebar_source = SB_SRC_NONE;
+
+static BUFFY *
+get_incoming (void)
+{
+ switch (sidebar_source) {
+ case SB_SRC_NONE:
+ sidebar_source = SB_SRC_INCOMING;
+
+ if (option (OPTVIRTSPOOLFILE) && VirtIncoming) {
+ sidebar_source = SB_SRC_VIRT;
+ return VirtIncoming;
+ }
+ break;
+ case SB_SRC_VIRT:
+ if (VirtIncoming) {
+ return VirtIncoming;
+ }
+ break;
+ case SB_SRC_INCOMING:
+ break;
+ }
+
+ return Incoming; /* default */
+}
/**
* find_next_new - Find the next folder that contains new mail
do {
b = b->next;
if (!b && wrap) {
- b = Incoming;
+ b = get_incoming();
}
if (!b || (b == HilBuffy)) {
break;
static int
prepare_sidebar (int page_size)
{
- BUFFY *b = Incoming;
+ BUFFY *b = get_incoming();
if (!b)
return 0;
return 0;
int i = 0;
- for (b = Incoming; b; b = b->next, i++) {
+ for (b = get_incoming(); b; b = b->next, i++) {
arr[i] = b;
}
update_buffy_visibility (arr, count);
sort_buffy_array (arr, count);
- Incoming = arr[0];
+ if (sidebar_source == SB_SRC_INCOMING)
+ Incoming = arr[0];
int top_index = 0;
int opn_index = -1;
strncat (sidebar_folder_name, tmp_folder_name, strlen (tmp_folder_name));
}
}
+#ifdef USE_NOTMUCH
+ else if (b->magic == M_NOTMUCH)
+ sidebar_folder_name = b->desc;
+#endif
char str[SHORT_STRING];
make_sidebar_entry (str, sizeof (str), w, sidebar_folder_name, b);
printw ("%s", str);
if (div_width < 0)
return;
- if (!Incoming) {
+ if (!get_incoming()) {
int w = MIN(COLS, (SidebarWidth - div_width));
fill_empty_space (first_row, num_rows, w);
return;
break;
case OP_SIDEBAR_PAGE_UP:
HilBuffy = TopBuffy;
- if (HilBuffy != Incoming) {
+ if (HilBuffy != get_incoming()) {
HilBuffy = HilBuffy->prev;
}
break;
{
/* Even if the sidebar's hidden,
* we should take note of the new data. */
- BUFFY *b = Incoming;
+ BUFFY *b = get_incoming();
if (!ctx || !b)
return;
{
/* Even if the sidebar is hidden */
- BUFFY *b = Incoming;
+ BUFFY *b = get_incoming();
if (!path || !b)
return NULL;
Outgoing = buffy_going (Outgoing);
}
}
+
+/* switch between regualar and virtual folders */
+void toggle_sidebar(int menu)
+{
+ if (sidebar_source == -1)
+ get_incoming();
+
+#ifdef USE_NOTMUCH
+ if (sidebar_source == SB_SRC_INCOMING && VirtIncoming)
+ sidebar_source = SB_SRC_VIRT;
+ else
+#endif
+ sidebar_source = SB_SRC_INCOMING;
+
+ TopBuffy = NULL;
+ OpnBuffy = NULL;
+ HilBuffy = NULL;
+ BotBuffy = NULL;
+ Outgoing = NULL;
+
+ sb_draw();
+}
+
BUFFY * sb_set_open_buffy (const char *path);
void sb_set_update_time (void);
int sb_should_refresh (void);
+void toggle_sidebar(int menu);
#endif /* SIDEBAR_H */