1 This is the sidebar patch.
3 When enabled, mutt will show a list of mailboxes with (new) message counts in a
4 separate column on the left side of the screen.
6 As this feature is still considered to be unstable, this patch is only applied
7 in the "mutt-patched" package.
9 * Configuration variables:
11 sidebar_delim (string, default "|")
13 This specifies the delimiter between the sidebar (if visible) and
16 sidebar_visible (boolean, default no)
18 This specifies whether or not to show sidebar (left-side list of folders).
20 sidebar_width (integer, default 0)
22 The width of the sidebar.
25 - http://www.lunar-linux.org/index.php?page=mutt-sidebar
26 - http://lunar-linux.org/~tchan/mutt/patch-1.5.19.sidebar.20090522.txt
29 - 2008-08-02 myon: Refreshed patch using quilt push -f to remove hunks we do
30 not need (Makefile.in).
35 char path[_POSIX_PATH_MAX];
36 struct stat contex_sb;
41 /* update postponed count as well, on force */
45 for (tmp = Incoming; tmp; tmp = tmp->next)
47 + if ( tmp->new == 1 )
50 if (tmp->magic != M_IMAP)
58 + if (STAT_CHECK || tmp->msgcount == 0)
65 + /* parse the mailbox, to see how much mail there is */
66 + ctx = mx_open_mailbox( tmp->path, M_READONLY | M_QUIET | M_NOSORT | M_PEEK, NULL);
69 + msgcount = ctx->msgcount;
70 + msg_unread = ctx->unread;
71 + mx_close_mailbox(ctx, 0);
74 + tmp->msgcount = msgcount;
75 + tmp->msg_unread = msg_unread;
77 + tmp->has_new = tmp->new = 1;
81 else if (option(OPTCHECKMBOXSIZE))
84 if (tmp->newly_created &&
85 (sb.st_ctime != sb.st_mtime || sb.st_ctime != sb.st_atime))
86 tmp->newly_created = 0;
93 + /* count new message */
94 snprintf (path, sizeof (path), "%s/new", tmp->path);
95 if ((dirp = opendir (path)) == NULL)
101 + tmp->msg_unread = 0;
102 + tmp->msg_flagged = 0;
103 while ((de = readdir (dirp)) != NULL)
106 if (*de->d_name != '.' &&
107 (!(p = strstr (de->d_name, ":2,")) || !strchr (p + 3, 'T')))
109 - /* one new and undeleted message is enough */
113 + tmp->has_new = tmp->new = 1;
118 + if(tmp->msg_unread)
124 + * count read messages (for folderlist (sidebar) we also need to count
125 + * messages in cur so that we the total number of messages
127 + snprintf (path, sizeof (path), "%s/cur", tmp->path);
128 + if ((dirp = opendir (path)) == NULL)
133 + while ((de = readdir (dirp)) != NULL)
136 + if (*de->d_name != '.') {
137 + if ((p = strstr (de->d_name, ":2,"))) {
138 + if (!strchr (p + 3, 'T')) {
140 + if ( !strchr (p + 3, 'S'))
142 + if (strchr(p + 3, 'F'))
143 + tmp->msg_flagged++;
156 if ((tmp->new = mh_buffy (tmp->path)) > 0)
159 + if ((dp = opendir (path)) == NULL)
162 + while ((de = readdir (dp)))
164 + if (mh_valid_message (de->d_name))
167 + tmp->has_new = tmp->new = 1;
180 struct buffy_t *next;
181 + struct buffy_t *prev;
182 short new; /* mailbox has new mail */
183 + short has_new; /* set it new if new and not read */
184 + int msgcount; /* total number of messages */
185 + int msg_unread; /* number of unread messages */
186 + int msg_flagged; /* number of flagged messages */
187 short notified; /* user has been notified */
188 short magic; /* mailbox type */
189 short newly_created; /* mbox or mmdf just popped into existence */
193 { "bold", MT_COLOR_BOLD },
194 { "underline", MT_COLOR_UNDERLINE },
195 { "index", MT_COLOR_INDEX },
196 + { "sidebar_new", MT_COLOR_NEW },
197 + { "sidebar_flagged", MT_COLOR_FLAGGED },
205 #define HDR_XOFFSET 10
206 #define TITLE_FMT "%10s" /* Used for Prompts, which are ASCII */
207 -#define W (COLS - HDR_XOFFSET)
208 +#define W (COLS - HDR_XOFFSET - SidebarWidth)
210 static char *Prompts[] =
212 @@ -115,16 +115,16 @@
213 if ((WithCrypto & APPLICATION_PGP) && (WithCrypto & APPLICATION_SMIME))
216 - mvaddstr (HDR_CRYPT, 0, "Security: ");
217 + mvaddstr (HDR_CRYPT, SidebarWidth, "Security: ");
218 else if (msg->security & APPLICATION_SMIME)
219 - mvaddstr (HDR_CRYPT, 0, " S/MIME: ");
220 + mvaddstr (HDR_CRYPT, SidebarWidth, " S/MIME: ");
221 else if (msg->security & APPLICATION_PGP)
222 - mvaddstr (HDR_CRYPT, 0, " PGP: ");
223 + mvaddstr (HDR_CRYPT, SidebarWidth, " PGP: ");
225 else if ((WithCrypto & APPLICATION_SMIME))
226 - mvaddstr (HDR_CRYPT, 0, " S/MIME: ");
227 + mvaddstr (HDR_CRYPT, SidebarWidth, " S/MIME: ");
228 else if ((WithCrypto & APPLICATION_PGP))
229 - mvaddstr (HDR_CRYPT, 0, " PGP: ");
230 + mvaddstr (HDR_CRYPT, SidebarWidth, " PGP: ");
238 - move (HDR_CRYPTINFO, 0);
239 + move (HDR_CRYPTINFO, SidebarWidth);
241 if ((WithCrypto & APPLICATION_PGP)
242 && msg->security & APPLICATION_PGP && msg->security & SIGN)
244 && (msg->security & ENCRYPT)
247 - mvprintw (HDR_CRYPTINFO, 40, "%s%s", _("Encrypt with: "),
248 + mvprintw (HDR_CRYPTINFO, SidebarWidth + 40, "%s%s", _("Encrypt with: "),
249 NONULL(SmimeCryptAlg));
256 - mvaddstr (HDR_MIX, 0, " Mix: ");
257 + mvaddstr (HDR_MIX, SidebarWidth, " Mix: ");
262 if (t && t[0] == '0' && t[1] == '\0')
265 - if (c + mutt_strlen (t) + 2 >= COLS)
266 + if (c + mutt_strlen (t) + 2 >= COLS - SidebarWidth)
273 rfc822_write_address (buf, sizeof (buf), addr, 1);
274 - mvprintw (line, 0, TITLE_FMT, Prompts[line - 1]);
275 + mvprintw (line, SidebarWidth, TITLE_FMT, Prompts[line - 1]);
276 mutt_paddstr (W, buf);
279 @@ -255,10 +255,10 @@
280 draw_envelope_addr (HDR_TO, msg->env->to);
281 draw_envelope_addr (HDR_CC, msg->env->cc);
282 draw_envelope_addr (HDR_BCC, msg->env->bcc);
283 - mvprintw (HDR_SUBJECT, 0, TITLE_FMT, Prompts[HDR_SUBJECT - 1]);
284 + mvprintw (HDR_SUBJECT, SidebarWidth, TITLE_FMT, Prompts[HDR_SUBJECT - 1]);
285 mutt_paddstr (W, NONULL (msg->env->subject));
286 draw_envelope_addr (HDR_REPLYTO, msg->env->reply_to);
287 - mvprintw (HDR_FCC, 0, TITLE_FMT, Prompts[HDR_FCC - 1]);
288 + mvprintw (HDR_FCC, SidebarWidth, TITLE_FMT, Prompts[HDR_FCC - 1]);
289 mutt_paddstr (W, fcc);
295 SETCOLOR (MT_COLOR_STATUS);
296 - mvaddstr (HDR_ATTACH - 1, 0, _("-- Attachments"));
297 + mvaddstr (HDR_ATTACH - 1, SidebarWidth, _("-- Attachments"));
298 BKGDSET (MT_COLOR_STATUS);
302 /* redraw the expanded list so the user can see the result */
304 rfc822_write_address (buf, sizeof (buf), *addr, 1);
305 - move (line, HDR_XOFFSET);
306 + move (line, HDR_XOFFSET+SidebarWidth);
307 mutt_paddstr (W, buf);
311 if (mutt_get_field ("Subject: ", buf, sizeof (buf), 0) == 0)
313 mutt_str_replace (&msg->env->subject, buf);
314 - move (HDR_SUBJECT, HDR_XOFFSET);
315 + move (HDR_SUBJECT, HDR_XOFFSET + SidebarWidth);
317 if (msg->env->subject)
318 mutt_paddstr (W, msg->env->subject);
321 strfcpy (fcc, buf, fcclen);
322 mutt_pretty_mailbox (fcc, fcclen);
323 - move (HDR_FCC, HDR_XOFFSET);
324 + move (HDR_FCC, HDR_XOFFSET + SidebarWidth);
325 mutt_paddstr (W, fcc);
336 +#include "sidebar.h"
341 menu->redraw |= REDRAW_STATUS;
344 - if (mutt_buffy_notify () && option (OPTBEEPNEW))
346 + if (mutt_buffy_notify ())
348 + menu->redraw |= REDRAW_FULL;
349 + if (option (OPTBEEPNEW))
356 if (menu->redraw & REDRAW_FULL)
358 menu_redraw_full (menu);
359 + draw_sidebar(menu->menu);
363 @@ -571,10 +578,13 @@
365 if (menu->redraw & REDRAW_STATUS)
368 menu_status_line (buf, sizeof (buf), menu, NONULL (Status));
370 CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES-2);
371 SETCOLOR (MT_COLOR_STATUS);
372 BKGDSET (MT_COLOR_STATUS);
373 + set_buffystats(Context);
374 mutt_paddstr (COLS, buf);
375 SETCOLOR (MT_COLOR_NORMAL);
376 BKGDSET (MT_COLOR_NORMAL);
378 menu->oldcurrent = -1;
380 if (option (OPTARROWCURSOR))
381 - move (menu->current - menu->top + menu->offset, 2);
382 + move (menu->current - menu->top + menu->offset, SidebarWidth + 2);
383 else if (option (OPTBRAILLEFRIENDLY))
384 move (menu->current - menu->top + menu->offset, 0);
386 @@ -1068,6 +1078,7 @@
387 menu->redraw = REDRAW_FULL;
390 + case OP_SIDEBAR_OPEN:
391 case OP_MAIN_CHANGE_FOLDER:
392 case OP_MAIN_NEXT_UNREAD_MAILBOX:
394 @@ -1099,7 +1110,11 @@
396 mutt_buffy (buf, sizeof (buf));
398 - if (mutt_enter_fname (cp, buf, sizeof (buf), &menu->redraw, 1) == -1)
399 + if ( op == OP_SIDEBAR_OPEN ) {
402 + strncpy( buf, CurBuffy->path, sizeof(buf) );
403 + } else if (mutt_enter_fname (cp, buf, sizeof (buf), &menu->redraw, 1) == -1)
405 if (menu->menu == MENU_PAGER)
407 @@ -1117,6 +1132,7 @@
410 mutt_expand_path (buf, sizeof (buf));
412 if (mx_get_magic (buf) <= 0)
414 mutt_error (_("%s is not a mailbox."), buf);
415 @@ -2209,6 +2225,12 @@
419 + case OP_SIDEBAR_SCROLL_UP:
420 + case OP_SIDEBAR_SCROLL_DOWN:
421 + case OP_SIDEBAR_NEXT:
422 + case OP_SIDEBAR_PREV:
423 + scroll_sidebar(op, menu->menu);
426 if (menu->menu == MENU_MAIN)
427 km_error_key (MENU_MAIN);
433 #include "mutt_curses.h"
434 +#include "mutt_menu.h"
437 +#include "sidebar.h"
439 void _mutt_set_flag (CONTEXT *ctx, HEADER *h, int flag, int bf, int upd_ctx)
443 if (h->searched && (changed != h->changed || deleted != ctx->deleted || tagged != ctx->tagged || flagged != ctx->flagged))
448 void mutt_tag_set_flag (int flag, int bf)
452 { "decrypt-save", OP_DECRYPT_SAVE, NULL },
455 + { "sidebar-scroll-up", OP_SIDEBAR_SCROLL_UP, NULL },
456 + { "sidebar-scroll-down", OP_SIDEBAR_SCROLL_DOWN, NULL },
457 + { "sidebar-next", OP_SIDEBAR_NEXT, NULL },
458 + { "sidebar-prev", OP_SIDEBAR_PREV, NULL },
459 + { "sidebar-open", OP_SIDEBAR_OPEN, NULL },
465 { "what-key", OP_WHAT_KEY, NULL },
467 + { "sidebar-scroll-up", OP_SIDEBAR_SCROLL_UP, NULL },
468 + { "sidebar-scroll-down", OP_SIDEBAR_SCROLL_DOWN, NULL },
469 + { "sidebar-next", OP_SIDEBAR_NEXT, NULL },
470 + { "sidebar-prev", OP_SIDEBAR_PREV, NULL },
471 + { "sidebar-open", OP_SIDEBAR_OPEN, NULL },
478 WHERE char *SendCharset;
479 WHERE char *Sendmail;
481 +WHERE char *SidebarDelim;
482 WHERE char *Signature;
483 WHERE char *SimpleSearch;
486 WHERE short ScoreThresholdRead;
487 WHERE short ScoreThresholdFlag;
489 +WHERE struct buffy_t *CurBuffy INITVAL(0);
490 +WHERE short DrawFullLine INITVAL(0);
491 +WHERE short SidebarWidth;
493 WHERE short ImapKeepalive;
494 WHERE short ImapPipelineDepth;
497 @@ -1594,6 +1594,22 @@
498 ** you may \fIunset\fP this setting.
501 + {"sidebar_delim", DT_STR, R_BOTH, UL &SidebarDelim, "|"},
504 + ** This specifies the delimiter between the sidebar (if visible) and
507 + { "sidebar_visible", DT_BOOL, R_BOTH, OPTSIDEBAR, 0 },
510 + ** This specifies whether or not to show sidebar (left-side list of folders).
512 + { "sidebar_width", DT_NUM, R_BOTH, UL &SidebarWidth, 0 },
515 + ** The width of the sidebar.
517 { "pgp_use_gpg_agent", DT_BOOL, R_NONE, OPTUSEGPGAGENT, 0},
523 #define M_NEWFOLDER (1<<4) /* create a new folder - same as M_APPEND, but uses
524 * safe_fopen() for mbox-style folders.
526 +#define M_PEEK (1<<5) /* revert atime back after taking a look (if applicable) */
528 /* mx_open_new_message() */
529 #define M_ADD_FROM 1 /* add a From_ line */
533 score.c send.c sendlib.c signal.c sort.c \
534 status.c system.c thread.c charset.c history.c lib.c \
535 muttlib.c editmsg.c mbyte.c \
536 - url.c ascii.c crypt-mod.c crypt-mod.h
537 + url.c ascii.c crypt-mod.c crypt-mod.h \
540 nodist_mutt_SOURCES = $(BUILT_SOURCES)
545 mutt_perror (ctx->path);
548 + ctx->atime = sb.st_atime;
549 ctx->mtime = sb.st_mtime;
550 ctx->size = sb.st_size;
554 ctx->size = sb.st_size;
555 ctx->mtime = sb.st_mtime;
556 + ctx->atime = sb.st_atime;
558 #ifdef NFS_ATTRIBUTE_HACK
559 if (sb.st_mtime > sb.st_atime)
563 #include "mutt_curses.h"
564 #include "mutt_menu.h"
566 +#include "sidebar.h"
572 char *scratch = safe_strdup (s);
573 int shift = option (OPTARROWCURSOR) ? 3 : 0;
574 - int cols = COLS - shift;
575 + int cols = COLS - shift - SidebarWidth;
577 mutt_format_string (s, n, cols, cols, FMT_LEFT, ' ', scratch, mutt_strlen (scratch), 1);
580 char buf[LONG_STRING];
584 for (i = menu->top; i < menu->top + menu->pagelen; i++)
588 if (option (OPTARROWCURSOR))
590 attrset (menu->color (i));
591 - CLEARLINE (i - menu->top + menu->offset);
592 + CLEARLINE_WIN (i - menu->top + menu->offset);
594 if (i == menu->current)
596 @@ -246,14 +248,14 @@
597 BKGDSET (MT_COLOR_INDICATOR);
600 - CLEARLINE (i - menu->top + menu->offset);
601 + CLEARLINE_WIN (i - menu->top + menu->offset);
602 print_enriched_string (menu->color(i), (unsigned char *) buf, i != menu->current);
603 SETCOLOR (MT_COLOR_NORMAL);
604 BKGDSET (MT_COLOR_NORMAL);
608 - CLEARLINE (i - menu->top + menu->offset);
609 + CLEARLINE_WIN (i - menu->top + menu->offset);
617 - move (menu->oldcurrent + menu->offset - menu->top, 0);
618 + move (menu->oldcurrent + menu->offset - menu->top, SidebarWidth);
619 SETCOLOR (MT_COLOR_NORMAL);
620 BKGDSET (MT_COLOR_NORMAL);
622 @@ -283,13 +285,13 @@
624 menu_make_entry (buf, sizeof (buf), menu, menu->oldcurrent);
625 menu_pad_string (buf, sizeof (buf));
626 - move (menu->oldcurrent + menu->offset - menu->top, 3);
627 + move (menu->oldcurrent + menu->offset - menu->top, SidebarWidth + 3);
628 print_enriched_string (menu->color(menu->oldcurrent), (unsigned char *) buf, 1);
629 SETCOLOR (MT_COLOR_NORMAL);
632 /* now draw it in the new location */
633 - move (menu->current + menu->offset - menu->top, 0);
634 + move (menu->current + menu->offset - menu->top, SidebarWidth);
635 attrset (menu->color (menu->current));
636 ADDCOLOR (MT_COLOR_INDICATOR);
639 attrset (menu->color (menu->current));
640 ADDCOLOR (MT_COLOR_INDICATOR);
641 BKGDSET (MT_COLOR_INDICATOR);
642 - CLEARLINE (menu->current - menu->top + menu->offset);
643 + CLEARLINE_WIN (menu->current - menu->top + menu->offset);
644 print_enriched_string (menu->color(menu->current), (unsigned char *) buf, 0);
645 SETCOLOR (MT_COLOR_NORMAL);
646 BKGDSET (MT_COLOR_NORMAL);
649 char buf[LONG_STRING];
651 - move (menu->current + menu->offset - menu->top, 0);
652 + move (menu->current + menu->offset - menu->top, SidebarWidth);
653 menu_make_entry (buf, sizeof (buf), menu, menu->current);
654 menu_pad_string (buf, sizeof (buf));
659 if (option (OPTARROWCURSOR))
660 - move (menu->current - menu->top + menu->offset, 2);
661 + move (menu->current - menu->top + menu->offset, SidebarWidth + 2);
662 else if (option (OPTBRAILLEFRIENDLY))
663 move (menu->current - menu->top + menu->offset, 0);
671 +#define CLEARLINE_WIN(x) move(x,SidebarWidth), clrtoeol()
672 #define CLEARLINE(x) move(x,0), clrtoeol()
673 #define CENTERLINE(x,y) move(y, (COLS-strlen(x))/2), addstr(x)
674 #define BEEP() do { if (option (OPTBEEP)) beep(); } while (0)
703 unsigned int quiet : 1; /* inhibit status messages? */
704 unsigned int collapsed : 1; /* are all threads collapsed? */
705 unsigned int closing : 1; /* mailbox is being closed */
706 + unsigned int peekonly : 1; /* just taking a glance, revert atime */
709 void *data; /* driver specific data */
712 @@ -1217,6 +1217,8 @@
715 /* see if there's room to add content, else ignore */
716 + if ( DrawFullLine )
718 if ((col < COLS && wlen < destlen) || soft)
721 @@ -1259,6 +1261,52 @@
728 + if ((col < COLS-SidebarWidth && wlen < destlen) || soft)
732 + /* get contents after padding */
733 + mutt_FormatString (buf, sizeof (buf), 0, src + pl, callback, data, flags);
734 + len = mutt_strlen (buf);
735 + wid = mutt_strwidth (buf);
737 + /* try to consume as many columns as we can, if we don't have
738 + * memory for that, use as much memory as possible */
739 + pad = (COLS - SidebarWidth - col - wid) / pw;
740 + if (pad > 0 && wlen + (pad * pl) + len > destlen)
741 + pad = ((signed)(destlen - wlen - len)) / pl;
746 + memcpy (wptr, src, pl);
752 + else if (soft && pad < 0)
754 + /* \0-terminate dest for length computation in mutt_wstr_trunc() */
756 + /* make sure right part is at most as wide as display */
757 + len = mutt_wstr_trunc (buf, destlen, COLS, &wid);
758 + /* truncate left so that right part fits completely in */
759 + wlen = mutt_wstr_trunc (dest, destlen - len, col + pad, &col);
760 + wptr = dest + wlen;
762 + if (len + wlen > destlen)
763 + len = mutt_wstr_trunc (buf, destlen - wlen, COLS - SidebarWidth - col, NULL);
764 + memcpy (wptr, buf, len);
771 break; /* skip rest of input */
777 * M_APPEND open mailbox for appending
778 * M_READONLY open mailbox in read-only mode
779 * M_QUIET only print error messages
780 + * M_PEEK revert atime where applicable
781 * ctx if non-null, context struct to use
783 CONTEXT *mx_open_mailbox (const char *path, int flags, CONTEXT *pctx)
786 if (flags & M_READONLY)
788 + if (flags & M_PEEK)
791 if (flags & (M_APPEND|M_NEWFOLDER))
794 void mx_fastclose_mailbox (CONTEXT *ctx)
804 + /* fix up the times so buffy won't get confused */
805 + if (ctx->peekonly && ctx->path && ctx->mtime > ctx->atime)
807 + ut.actime = ctx->atime;
808 + ut.modtime = ctx->mtime;
809 + utime (ctx->path, &ut);
818 OP_MAIN_SHOW_LIMIT "show currently active limit pattern"
819 OP_MAIN_COLLAPSE_THREAD "collapse/uncollapse current thread"
820 OP_MAIN_COLLAPSE_ALL "collapse/uncollapse all threads"
821 +OP_SIDEBAR_SCROLL_UP "scroll the mailbox pane up 1 page"
822 +OP_SIDEBAR_SCROLL_DOWN "scroll the mailbox pane down 1 page"
823 +OP_SIDEBAR_NEXT "go down to next mailbox"
824 +OP_SIDEBAR_PREV "go to previous mailbox"
825 +OP_SIDEBAR_OPEN "open hilighted mailbox"
832 +#include "sidebar.h"
834 #include "mutt_crypt.h"
836 @@ -1060,6 +1061,8 @@
839 int wrap_cols = mutt_term_width ((flags & M_PAGER_NOWRAP) ? 0 : Wrap);
841 + wrap_cols -= SidebarWidth;
843 /* FIXME: this should come from lineInfo */
844 memset(&mbstate, 0, sizeof(mbstate));
845 @@ -1694,7 +1697,7 @@
846 if ((redraw & REDRAW_BODY) || topline != oldtopline)
849 - move (bodyoffset, 0);
850 + move (bodyoffset, SidebarWidth);
851 curline = oldtopline = topline;
854 @@ -1707,6 +1710,7 @@
855 &QuoteList, &q_level, &force_redraw, &SearchRE) > 0)
858 + move(lines + bodyoffset, SidebarWidth);
860 last_offset = lineInfo[curline].offset;
861 } while (force_redraw);
862 @@ -1720,6 +1724,7 @@
866 + move(lines + bodyoffset, SidebarWidth);
868 /* We are going to update the pager status bar, so it isn't
869 * necessary to reset to normal color now. */
870 @@ -1743,22 +1748,22 @@
871 /* print out the pager status bar */
872 SETCOLOR (MT_COLOR_STATUS);
873 BKGDSET (MT_COLOR_STATUS);
874 - CLEARLINE (statusoffset);
875 + CLEARLINE_WIN (statusoffset);
876 if (IsHeader (extra))
878 - size_t l1 = COLS * MB_LEN_MAX;
879 + size_t l1 = (COLS-SidebarWidth) * MB_LEN_MAX;
880 size_t l2 = sizeof (buffer);
881 hfi.hdr = extra->hdr;
882 mutt_make_string_info (buffer, l1 < l2 ? l1 : l2, NONULL (PagerFmt), &hfi, M_FORMAT_MAKEPRINT);
884 else if (IsMsgAttach (extra))
886 - size_t l1 = COLS * MB_LEN_MAX;
887 + size_t l1 = (COLS-SidebarWidth) * MB_LEN_MAX;
888 size_t l2 = sizeof (buffer);
889 hfi.hdr = extra->bdy->hdr;
890 mutt_make_string_info (buffer, l1 < l2 ? l1 : l2, NONULL (PagerFmt), &hfi, M_FORMAT_MAKEPRINT);
892 - mutt_paddstr (COLS, IsHeader (extra) || IsMsgAttach (extra) ? buffer : banner);
893 + mutt_paddstr (COLS-SidebarWidth, IsHeader (extra) || IsMsgAttach (extra) ? buffer : banner);
894 BKGDSET (MT_COLOR_NORMAL);
895 SETCOLOR (MT_COLOR_NORMAL);
896 if (option(OPTXTERMSETTITLES))
897 @@ -1775,18 +1780,23 @@
898 /* redraw the pager_index indicator, because the
899 * flags for this message might have changed. */
900 menu_redraw_current (index);
901 + draw_sidebar(MENU_PAGER);
903 /* print out the index status bar */
904 menu_status_line (buffer, sizeof (buffer), index, NONULL(Status));
906 - move (indexoffset + (option (OPTSTATUSONTOP) ? 0 : (indexlen - 1)), 0);
907 + move (indexoffset + (option (OPTSTATUSONTOP) ? 0 : (indexlen - 1)), SidebarWidth);
908 SETCOLOR (MT_COLOR_STATUS);
909 BKGDSET (MT_COLOR_STATUS);
910 - mutt_paddstr (COLS, buffer);
911 + mutt_paddstr (COLS-SidebarWidth, buffer);
912 SETCOLOR (MT_COLOR_NORMAL);
913 BKGDSET (MT_COLOR_NORMAL);
916 + /* if we're not using the index, update every time */
918 + draw_sidebar(MENU_PAGER);
922 if (option(OPTBRAILLEFRIENDLY)) {
923 @@ -2684,6 +2694,13 @@
927 + case OP_SIDEBAR_SCROLL_UP:
928 + case OP_SIDEBAR_SCROLL_DOWN:
929 + case OP_SIDEBAR_NEXT:
930 + case OP_SIDEBAR_PREV:
931 + scroll_sidebar(ch, MENU_PAGER);
941 + * Copyright (C) ????-2004 Justin Hibbits <jrh29@po.cwru.edu>
942 + * Copyright (C) 2004 Thomer M. Gil <mutt@thomer.com>
944 + * This program is free software; you can redistribute it and/or modify
945 + * it under the terms of the GNU General Public License as published by
946 + * the Free Software Foundation; either version 2 of the License, or
947 + * (at your option) any later version.
949 + * This program is distributed in the hope that it will be useful,
950 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
951 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
952 + * GNU General Public License for more details.
954 + * You should have received a copy of the GNU General Public License
955 + * along with this program; if not, write to the Free Software
956 + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
961 +# include "config.h"
965 +#include "mutt_menu.h"
966 +#include "mutt_curses.h"
967 +#include "sidebar.h"
971 +#include <stdbool.h>
973 +/*BUFFY *CurBuffy = 0;*/
974 +static BUFFY *TopBuffy = 0;
975 +static BUFFY *BottomBuffy = 0;
976 +static int known_lines = 0;
978 +static int quick_log10(int n)
981 + sprintf(string, "%d", n);
982 + return strlen(string);
985 +void calc_boundaries (int menu)
987 + BUFFY *tmp = Incoming;
989 + if ( known_lines != LINES ) {
990 + TopBuffy = BottomBuffy = 0;
991 + known_lines = LINES;
993 + for ( ; tmp->next != 0; tmp = tmp->next )
994 + tmp->next->prev = tmp;
996 + if ( TopBuffy == 0 && BottomBuffy == 0 )
997 + TopBuffy = Incoming;
998 + if ( BottomBuffy == 0 ) {
999 + int count = LINES - 2 - (menu != MENU_PAGER || option(OPTSTATUSONTOP));
1000 + BottomBuffy = TopBuffy;
1001 + while ( --count && BottomBuffy->next )
1002 + BottomBuffy = BottomBuffy->next;
1004 + else if ( TopBuffy == CurBuffy->next ) {
1005 + int count = LINES - 2 - (menu != MENU_PAGER);
1006 + BottomBuffy = CurBuffy;
1007 + tmp = BottomBuffy;
1008 + while ( --count && tmp->prev)
1012 + else if ( BottomBuffy == CurBuffy->prev ) {
1013 + int count = LINES - 2 - (menu != MENU_PAGER);
1014 + TopBuffy = CurBuffy;
1016 + while ( --count && tmp->next )
1018 + BottomBuffy = tmp;
1022 +char *make_sidebar_entry(char *box, int size, int new, int flagged)
1024 + static char *entry = 0;
1027 + int delim_len = strlen(SidebarDelim);
1029 + c = realloc(entry, SidebarWidth - delim_len + 2);
1030 + if ( c ) entry = c;
1031 + entry[SidebarWidth - delim_len + 1] = 0;
1032 + for (; i < SidebarWidth - delim_len + 1; entry[i++] = ' ' );
1034 + strncpy( entry, box, i < (SidebarWidth - delim_len + 1) ? i : (SidebarWidth - delim_len + 1) );
1037 + sprintf(entry + SidebarWidth - delim_len - 3, "?");
1039 + if (flagged > 0) {
1041 + entry + SidebarWidth - delim_len - 5 - quick_log10(size) - quick_log10(new) - quick_log10(flagged),
1042 + "% d(%d)[%d]", size, new, flagged);
1045 + entry + SidebarWidth - delim_len - 3 - quick_log10(size) - quick_log10(new),
1046 + "% d(%d)", size, new);
1048 + } else if (flagged > 0) {
1049 + sprintf( entry + SidebarWidth - delim_len - 3 - quick_log10(size) - quick_log10(flagged), "% d[%d]", size, flagged);
1051 + sprintf( entry + SidebarWidth - delim_len - 1 - quick_log10(size), "% d", size);
1056 +void set_curbuffy(char buf[LONG_STRING])
1058 + BUFFY* tmp = CurBuffy = Incoming;
1064 + if(!strcmp(tmp->path, buf)) {
1076 +int draw_sidebar(int menu) {
1078 + int lines = option(OPTHELP) ? 1 : 0;
1080 +#ifndef USE_SLANG_CURSES
1083 + short delim_len = strlen(SidebarDelim);
1086 + static bool initialized = false;
1087 + static int prev_show_value;
1088 + static short saveSidebarWidth;
1090 + /* initialize first time */
1091 + if(!initialized) {
1092 + prev_show_value = option(OPTSIDEBAR);
1093 + saveSidebarWidth = SidebarWidth;
1094 + if(!option(OPTSIDEBAR)) SidebarWidth = 0;
1095 + initialized = true;
1098 + /* save or restore the value SidebarWidth */
1099 + if(prev_show_value != option(OPTSIDEBAR)) {
1100 + if(prev_show_value && !option(OPTSIDEBAR)) {
1101 + saveSidebarWidth = SidebarWidth;
1103 + } else if(!prev_show_value && option(OPTSIDEBAR)) {
1104 + SidebarWidth = saveSidebarWidth;
1106 + prev_show_value = option(OPTSIDEBAR);
1110 +// if ( SidebarWidth == 0 ) return 0;
1111 + if (SidebarWidth > 0 && option (OPTSIDEBAR)
1112 + && delim_len >= SidebarWidth) {
1113 + unset_option (OPTSIDEBAR);
1114 + /* saveSidebarWidth = SidebarWidth; */
1115 + if (saveSidebarWidth > delim_len) {
1116 + SidebarWidth = saveSidebarWidth;
1117 + mutt_error (_("Value for sidebar_delim is too long. Disabling sidebar."));
1121 + mutt_error (_("Value for sidebar_delim is too long. Disabling sidebar. Please set your sidebar_width to a sane value."));
1122 + sleep (4); /* the advise to set a sane value should be seen long enough */
1124 + saveSidebarWidth = 0;
1128 + if ( SidebarWidth == 0 || !option(OPTSIDEBAR)) {
1129 + if (SidebarWidth > 0) {
1130 + saveSidebarWidth = SidebarWidth;
1133 + unset_option(OPTSIDEBAR);
1137 + /* get attributes for divider */
1138 + SETCOLOR(MT_COLOR_STATUS);
1139 +#ifndef USE_SLANG_CURSES
1140 + attr_get(&attrs, &color_pair, 0);
1142 + color_pair = attr_get();
1144 + SETCOLOR(MT_COLOR_NORMAL);
1146 + /* draw the divider */
1148 + for ( ; lines < LINES-1-(menu != MENU_PAGER || option(OPTSTATUSONTOP)); lines++ ) {
1149 + move(lines, SidebarWidth - delim_len);
1150 + addstr(NONULL(SidebarDelim));
1151 +#ifndef USE_SLANG_CURSES
1152 + mvchgat(lines, SidebarWidth - delim_len, delim_len, 0, color_pair, NULL);
1156 + if ( Incoming == 0 ) return 0;
1157 + lines = option(OPTHELP) ? 1 : 0; /* go back to the top */
1159 + if ( known_lines != LINES || TopBuffy == 0 || BottomBuffy == 0 )
1160 + calc_boundaries(menu);
1161 + if ( CurBuffy == 0 ) CurBuffy = Incoming;
1165 + SETCOLOR(MT_COLOR_NORMAL);
1167 + for ( ; tmp && lines < LINES-1 - (menu != MENU_PAGER || option(OPTSTATUSONTOP)); tmp = tmp->next ) {
1168 + if ( tmp == CurBuffy )
1169 + SETCOLOR(MT_COLOR_INDICATOR);
1170 + else if ( tmp->msg_unread > 0 )
1171 + SETCOLOR(MT_COLOR_NEW);
1172 + else if ( tmp->msg_flagged > 0 )
1173 + SETCOLOR(MT_COLOR_FLAGGED);
1175 + SETCOLOR(MT_COLOR_NORMAL);
1178 + if ( Context && !strcmp( tmp->path, Context->path ) ) {
1179 + tmp->msg_unread = Context->unread;
1180 + tmp->msgcount = Context->msgcount;
1181 + tmp->msg_flagged = Context->flagged;
1183 + // check whether Maildir is a prefix of the current folder's path
1184 + short maildir_is_prefix = 0;
1185 + if ( (strlen(tmp->path) > strlen(Maildir)) &&
1186 + (strncmp(Maildir, tmp->path, strlen(Maildir)) == 0) )
1187 + maildir_is_prefix = 1;
1188 + // calculate depth of current folder and generate its display name with indented spaces
1189 + int sidebar_folder_depth = 0;
1190 + char *sidebar_folder_name;
1191 + sidebar_folder_name = basename(tmp->path);
1192 + if ( maildir_is_prefix ) {
1193 + char *tmp_folder_name;
1195 + tmp_folder_name = tmp->path + strlen(Maildir);
1196 + for (i = 0; i < strlen(tmp->path) - strlen(Maildir); i++) {
1197 + if (tmp_folder_name[i] == '/') sidebar_folder_depth++;
1199 + if (sidebar_folder_depth > 0) {
1200 + sidebar_folder_name = malloc(strlen(basename(tmp->path)) + sidebar_folder_depth + 1);
1201 + for (i=0; i < sidebar_folder_depth; i++)
1202 + sidebar_folder_name[i]=' ';
1203 + sidebar_folder_name[i]=0;
1204 + strncat(sidebar_folder_name, basename(tmp->path), strlen(basename(tmp->path)) + sidebar_folder_depth);
1207 + printw( "%.*s", SidebarWidth - delim_len + 1,
1208 + make_sidebar_entry(sidebar_folder_name, tmp->msgcount,
1209 + tmp->msg_unread, tmp->msg_flagged));
1210 + if (sidebar_folder_depth > 0)
1211 + free(sidebar_folder_name);
1214 + SETCOLOR(MT_COLOR_NORMAL);
1215 + for ( ; lines < LINES-1 - (menu != MENU_PAGER || option(OPTSTATUSONTOP)); lines++ ) {
1218 + for ( ; i < SidebarWidth - delim_len; i++ )
1225 +void set_buffystats(CONTEXT* Context)
1227 + BUFFY *tmp = Incoming;
1229 + if(Context && !strcmp(tmp->path, Context->path)) {
1230 + tmp->msg_unread = Context->unread;
1231 + tmp->msgcount = Context->msgcount;
1238 +void scroll_sidebar(int op, int menu)
1240 + if(!SidebarWidth) return;
1241 + if(!CurBuffy) return;
1244 + case OP_SIDEBAR_NEXT:
1245 + if ( CurBuffy->next == NULL ) return;
1246 + CurBuffy = CurBuffy->next;
1248 + case OP_SIDEBAR_PREV:
1249 + if ( CurBuffy->prev == NULL ) return;
1250 + CurBuffy = CurBuffy->prev;
1252 + case OP_SIDEBAR_SCROLL_UP:
1253 + CurBuffy = TopBuffy;
1254 + if ( CurBuffy != Incoming ) {
1255 + calc_boundaries(menu);
1256 + CurBuffy = CurBuffy->prev;
1259 + case OP_SIDEBAR_SCROLL_DOWN:
1260 + CurBuffy = BottomBuffy;
1261 + if ( CurBuffy->next ) {
1262 + calc_boundaries(menu);
1263 + CurBuffy = CurBuffy->next;
1269 + calc_boundaries(menu);
1270 + draw_sidebar(menu);
1277 + * Copyright (C) ????-2004 Justin Hibbits <jrh29@po.cwru.edu>
1278 + * Copyright (C) 2004 Thomer M. Gil <mutt@thomer.com>
1280 + * This program is free software; you can redistribute it and/or modify
1281 + * it under the terms of the GNU General Public License as published by
1282 + * the Free Software Foundation; either version 2 of the License, or
1283 + * (at your option) any later version.
1285 + * This program is distributed in the hope that it will be useful,
1286 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1287 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1288 + * GNU General Public License for more details.
1290 + * You should have received a copy of the GNU General Public License
1291 + * along with this program; if not, write to the Free Software
1292 + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
1304 +/* parameter is whether or not to go to the status line */
1305 +/* used for omitting the last | that covers up the status bar in the index */
1306 +int draw_sidebar(int);
1307 +void scroll_sidebar(int, int);
1308 +void set_curbuffy(char*);
1309 +void set_buffystats(CONTEXT*);
1311 +#endif /* SIDEBAR_H */
1314 @@ -2167,6 +2167,26 @@
1318 +# set sidebar_visible=no
1320 +# Name: sidebar_visible
1325 +# This specifies whether or not to show sidebar (left-side list of folders).
1328 +# set sidebar_width=0
1330 +# Name: sidebar_width
1335 +# The width of the sidebar.
1338 # set crypt_autosign=no
1340 # Name: crypt_autosign
1343 @@ -1513,7 +1513,7 @@
1345 imap_munge_mbox_name (munged, sizeof (munged), name);
1346 snprintf (command, sizeof (command),
1347 - "STATUS %s (UIDNEXT UIDVALIDITY UNSEEN RECENT)", munged);
1348 + "STATUS %s (UIDNEXT UIDVALIDITY UNSEEN RECENT MESSAGES)", munged);
1350 if (imap_exec (idata, command, IMAP_CMD_QUEUE) < 0)
1352 --- a/imap/command.c
1353 +++ b/imap/command.c
1354 @@ -1009,6 +1009,13 @@
1356 status->uidnext = oldun;
1358 + /* Added to make the sidebar show the correct numbers */
1359 + if (status->messages)
1361 + inc->msgcount = status->messages;
1362 + inc->msg_unread = status->unseen;
1371 +patch-1.5.19.sidebar.20090522.txt