+
+ int lines = option (OPTHELP) ? 1 : 0, draw_devider = 1, i = 0;
+ BUFFY *tmp;
+ short delim_len = safe_strlen (SidebarDelim);
+ char blank[SHORT_STRING];
+
+ /* initialize first time */
+ if (!initialized) {
+ prev_show_value = option (OPTMBOXPANE);
+ saveSidebarWidth = SidebarWidth;
+ if (!option (OPTMBOXPANE)){
+ SidebarWidth = 0;
+ draw_devider = 1;
+ }
+ initialized = 1;
+ }
+
+ /* save or restore the value SidebarWidth */
+ if (prev_show_value != option (OPTMBOXPANE)) {
+ if (prev_show_value && !option (OPTMBOXPANE)) {
+ saveSidebarWidth = SidebarWidth;
+ SidebarWidth = 0;
+ }
+ else if (!prev_show_value && option (OPTMBOXPANE)) {
+ SidebarWidth = saveSidebarWidth;
+ /* after toggle: force recounting of all mail */
+ buffy_check (2);
+ }
+ prev_show_value = option (OPTMBOXPANE);
+ }
+
+ if (SidebarWidth > 0 && option (OPTMBOXPANE)
+ && safe_strlen (SidebarDelim) >= SidebarWidth) {
+ mutt_error (_("Value for sidebar_delim is too long. Disabling sidebar."));
+ sleep (2);
+ unset_option (OPTMBOXPANE);
+ return (0);
+ }
+
+ if (SidebarWidth == 0 || !option (OPTMBOXPANE))
+ return 0;
+ /* draw devider only if necessary (if the sidebar becomes visible e.g.)*/
+ if (draw_devider == 1){
+ /* draw the divider */
+ SETCOLOR (MT_COLOR_SIDEBAR);
+ for (lines = 1;
+ lines < LINES - 1 - (menu != MENU_PAGER || option (OPTSTATUSONTOP));
+ lines++) {
+ move (lines, SidebarWidth - delim_len);
+ if (option (OPTASCIICHARS))
+ addstr (NONULL (SidebarDelim));
+ else if (!option (OPTASCIICHARS) && !safe_strcmp (SidebarDelim, "|"))
+ addch (ACS_VLINE);
+ else if ((Charset_is_utf8) && !safe_strcmp (SidebarDelim, "|"))
+ addstr ("\342\224\202");
+ else
+ addstr (NONULL (SidebarDelim));
+ }
+ }
+ SETCOLOR (MT_COLOR_NORMAL);
+
+ if (list_empty(Incoming))
+ return 0;
+ lines = option (OPTHELP) ? 1 : 0; /* go back to the top */
+ calc_boundaries (menu);
+
+ /* actually print items */
+ for (i = TopBuffy; i < Incoming->length && lines < LINES - 1 -
+ (menu != MENU_PAGER || option (OPTSTATUSONTOP)); i++) {
+ tmp = (BUFFY*) Incoming->data[i];
+
+ if (i == CurBuffy)
+ SETCOLOR (MT_COLOR_INDICATOR);
+ else if (tmp->msg_flagged > 0)
+ SETCOLOR (MT_COLOR_FLAGGED);
+ else if (tmp->new > 0)
+ SETCOLOR (MT_COLOR_NEW);
+ else
+ SETCOLOR (MT_COLOR_NORMAL);
+
+ move (lines, 0);
+ lines += make_sidebar_entry (tmp->path, i, SidebarWidth-delim_len);
+ }
+
+ /* fill with blanks to bottom */
+ memset (&blank, ' ', sizeof (blank));
+ SETCOLOR (MT_COLOR_NORMAL);
+ for (; lines < LINES - 1 - (menu != MENU_PAGER || option (OPTSTATUSONTOP)); lines++) {
+ move (lines, 0);
+ addnstr (blank, SidebarWidth-delim_len);
+ }
+ return 0;
+}
+
+/* returns index of new item with new mail or -1 */
+static int exist_next_new () {
+ int i = 0;
+ if (list_empty(Incoming))
+ return (-1);
+ i = CurBuffy + 1;
+ while (i < Incoming->length)
+ if (((BUFFY*) Incoming->data[i++])->new > 0)
+ return (i-1);
+ return (-1);
+}
+
+/* returns index of prev item with new mail or -1 */
+static int exist_prev_new () {
+ int i = 0;
+ if (list_empty(Incoming))
+ return (-1);
+ i = CurBuffy - 1;
+ while (i >= 0)
+ if (((BUFFY*) Incoming->data[i--])->new > 0)
+ return (i+1);
+ return (-1);
+}
+
+void sidebar_scroll (int op, int menu) {
+ int i = 0;
+
+ if (!SidebarWidth || list_empty(Incoming))
+ return;
+
+ switch (op) {
+ case OP_SIDEBAR_NEXT:
+ if (!option (OPTSIDEBARNEWMAILONLY)) {
+ if (CurBuffy + 1 == Incoming->length) {
+ mutt_error (_("You are on the last mailbox."));
+ return;
+ }
+ CurBuffy++;
+ break;
+ } /* the fall-through is intentional */
+ case OP_SIDEBAR_NEXT_NEW:
+ if ((i = exist_next_new ()) < 0) {
+ mutt_error (_("No next mailboxes with new mail."));
+ return;
+ }
+ else
+ CurBuffy = i;
+ break;
+ case OP_SIDEBAR_PREV:
+ if (!option (OPTSIDEBARNEWMAILONLY)) {
+ if (CurBuffy == 0) {
+ mutt_error (_("You are on the first mailbox."));
+ return;
+ }
+ CurBuffy--;
+ break;
+ } /* the fall-through is intentional */
+ case OP_SIDEBAR_PREV_NEW:
+ if ((i = exist_prev_new ()) < 0) {
+ mutt_error (_("No previous mailbox with new mail."));
+ return;
+ }
+ else
+ CurBuffy = i;
+ break;
+
+ case OP_SIDEBAR_SCROLL_UP:
+ if (CurBuffy == 0) {
+ mutt_error (_("You are on the first mailbox."));
+ return;
+ }
+ CurBuffy -= known_lines;
+ if (CurBuffy < 0)
+ CurBuffy = 0;
+ break;
+ case OP_SIDEBAR_SCROLL_DOWN:
+ if (CurBuffy + 1 == Incoming->length) {
+ mutt_error (_("You are on the last mailbox."));
+ return;
+ }
+ CurBuffy += known_lines;
+ if (CurBuffy >= Incoming->length)
+ CurBuffy = Incoming->length - 1;
+ break;
+ default:
+ return;
+ }
+ calc_boundaries (menu);
+ sidebar_draw (menu);