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 rfc822.c rfc1524.c rfc2047.c rfc2231.c rfc3676.c \
36 score.c send.c sendlib.c signal.c sort.c \
37 status.c system.c thread.c charset.c history.c lib.c \
39 muttlib.c editmsg.c mbyte.c \
40 url.c ascii.c crypt-mod.c crypt-mod.h safe_asprintf.c
45 OP_MAIN_SHOW_LIMIT "show currently active limit pattern"
46 OP_MAIN_COLLAPSE_THREAD "collapse/uncollapse current thread"
47 OP_MAIN_COLLAPSE_ALL "collapse/uncollapse all threads"
48 +OP_SIDEBAR_SCROLL_UP "scroll the mailbox pane up 1 page"
49 +OP_SIDEBAR_SCROLL_DOWN "scroll the mailbox pane down 1 page"
50 +OP_SIDEBAR_NEXT "go down to next mailbox"
51 +OP_SIDEBAR_PREV "go to previous mailbox"
52 +OP_SIDEBAR_OPEN "open hilighted mailbox"
59 +/* update message counts for the sidebar */
60 +void buffy_maildir_update (BUFFY* mailbox)
62 + char path[_POSIX_PATH_MAX];
67 + mailbox->msgcount = 0;
68 + mailbox->msg_unread = 0;
69 + mailbox->msg_flagged = 0;
71 + snprintf (path, sizeof (path), "%s/new", mailbox->path);
73 + if ((dirp = opendir (path)) == NULL)
79 + while ((de = readdir (dirp)) != NULL)
81 + if (*de->d_name == '.')
84 + if (!(p = strstr (de->d_name, ":2,")) || !strchr (p + 3, 'T')) {
86 + mailbox->msgcount++;
87 + mailbox->msg_unread++;
92 + snprintf (path, sizeof (path), "%s/cur", mailbox->path);
94 + if ((dirp = opendir (path)) == NULL)
100 + while ((de = readdir (dirp)) != NULL)
102 + if (*de->d_name == '.')
105 + if (!(p = strstr (de->d_name, ":2,")) || !strchr (p + 3, 'T')) {
106 + mailbox->msgcount++;
107 + if ((p = strstr (de->d_name, ":2,"))) {
108 + if (!strchr (p + 3, 'T')) {
109 + if (!strchr (p + 3, 'S'))
110 + mailbox->msg_unread++;
111 + if (strchr(p + 3, 'F'))
112 + mailbox->msg_flagged++;
121 /* returns 1 if mailbox has new mail */
122 static int buffy_mbox_hasnew (BUFFY* mailbox, struct stat *sb)
128 +/* update message counts for the sidebar */
129 +void buffy_mbox_update (BUFFY* mailbox)
131 + CONTEXT *ctx = NULL;
133 + ctx = mx_open_mailbox(mailbox->path, M_READONLY | M_QUIET | M_NOSORT | M_PEEK, NULL);
136 + mailbox->msgcount = ctx->msgcount;
137 + mailbox->msg_unread = ctx->unread;
138 + mx_close_mailbox(ctx, 0);
142 int mutt_buffy_check (int force)
145 @@ -444,16 +520,19 @@
149 + buffy_mbox_update (tmp);
150 if (buffy_mbox_hasnew (tmp, &sb) > 0)
155 + buffy_maildir_update (tmp);
156 if (buffy_maildir_hasnew (tmp) > 0)
161 + mh_buffy_update (tmp->path, &tmp->msgcount, &tmp->msg_unread, &tmp->msg_flagged);
162 if ((tmp->new = mh_buffy (tmp->path)) > 0)
168 char path[_POSIX_PATH_MAX];
170 struct buffy_t *next;
171 + struct buffy_t *prev;
172 short new; /* mailbox has new mail */
173 + int msgcount; /* total number of messages */
174 + int msg_unread; /* number of unread messages */
175 + int msg_flagged; /* number of flagged messages */
176 short notified; /* user has been notified */
177 short magic; /* mailbox type */
178 short newly_created; /* mbox or mmdf just popped into existence */
182 { "bold", MT_COLOR_BOLD },
183 { "underline", MT_COLOR_UNDERLINE },
184 { "index", MT_COLOR_INDEX },
185 + { "sidebar_new", MT_COLOR_NEW },
186 + { "sidebar_flagged", MT_COLOR_FLAGGED },
194 #define HDR_XOFFSET 10
195 #define TITLE_FMT "%10s" /* Used for Prompts, which are ASCII */
196 -#define W (COLS - HDR_XOFFSET)
197 +#define W (COLS - HDR_XOFFSET - SidebarWidth)
199 static char *Prompts[] =
205 - mvaddstr (HDR_CRYPT, 0, "Security: ");
206 + mvaddstr (HDR_CRYPT, SidebarWidth, "Security: ");
208 if ((WithCrypto & (APPLICATION_PGP | APPLICATION_SMIME)) == 0)
214 - move (HDR_CRYPTINFO, 0);
215 + move (HDR_CRYPTINFO, SidebarWidth);
218 if ((WithCrypto & APPLICATION_PGP)
220 && (msg->security & ENCRYPT)
223 - mvprintw (HDR_CRYPTINFO, 40, "%s%s", _("Encrypt with: "),
224 + mvprintw (HDR_CRYPTINFO, SidebarWidth + 40, "%s%s", _("Encrypt with: "),
225 NONULL(SmimeCryptAlg));
232 - mvaddstr (HDR_MIX, 0, " Mix: ");
233 + mvaddstr (HDR_MIX, SidebarWidth, " Mix: ");
238 if (t && t[0] == '0' && t[1] == '\0')
241 - if (c + mutt_strlen (t) + 2 >= COLS)
242 + if (c + mutt_strlen (t) + 2 >= COLS - SidebarWidth)
249 rfc822_write_address (buf, sizeof (buf), addr, 1);
250 - mvprintw (line, 0, TITLE_FMT, Prompts[line - 1]);
251 + mvprintw (line, SidebarWidth, TITLE_FMT, Prompts[line - 1]);
252 mutt_paddstr (W, buf);
255 @@ -252,10 +252,10 @@
256 draw_envelope_addr (HDR_TO, msg->env->to);
257 draw_envelope_addr (HDR_CC, msg->env->cc);
258 draw_envelope_addr (HDR_BCC, msg->env->bcc);
259 - mvprintw (HDR_SUBJECT, 0, TITLE_FMT, Prompts[HDR_SUBJECT - 1]);
260 + mvprintw (HDR_SUBJECT, SidebarWidth, TITLE_FMT, Prompts[HDR_SUBJECT - 1]);
261 mutt_paddstr (W, NONULL (msg->env->subject));
262 draw_envelope_addr (HDR_REPLYTO, msg->env->reply_to);
263 - mvprintw (HDR_FCC, 0, TITLE_FMT, Prompts[HDR_FCC - 1]);
264 + mvprintw (HDR_FCC, SidebarWidth, TITLE_FMT, Prompts[HDR_FCC - 1]);
265 mutt_paddstr (W, fcc);
271 SETCOLOR (MT_COLOR_STATUS);
272 - mvaddstr (HDR_ATTACH - 1, 0, _("-- Attachments"));
273 + mvaddstr (HDR_ATTACH - 1, SidebarWidth, _("-- Attachments"));
274 BKGDSET (MT_COLOR_STATUS);
278 /* redraw the expanded list so the user can see the result */
280 rfc822_write_address (buf, sizeof (buf), *addr, 1);
281 - move (line, HDR_XOFFSET);
282 + move (line, HDR_XOFFSET+SidebarWidth);
283 mutt_paddstr (W, buf);
287 if (mutt_get_field ("Subject: ", buf, sizeof (buf), 0) == 0)
289 mutt_str_replace (&msg->env->subject, buf);
290 - move (HDR_SUBJECT, HDR_XOFFSET);
291 + move (HDR_SUBJECT, HDR_XOFFSET + SidebarWidth);
293 if (msg->env->subject)
294 mutt_paddstr (W, msg->env->subject);
297 strfcpy (fcc, buf, fcclen);
298 mutt_pretty_mailbox (fcc, fcclen);
299 - move (HDR_FCC, HDR_XOFFSET);
300 + move (HDR_FCC, HDR_XOFFSET + SidebarWidth);
301 mutt_paddstr (W, fcc);
312 +#include "sidebar.h"
317 menu->redraw |= REDRAW_STATUS;
320 - if (mutt_buffy_notify () && option (OPTBEEPNEW))
322 + if (mutt_buffy_notify ())
324 + menu->redraw |= REDRAW_FULL;
325 + if (option (OPTBEEPNEW))
332 if (menu->redraw & REDRAW_FULL)
334 menu_redraw_full (menu);
335 + draw_sidebar(menu->menu);
339 @@ -567,10 +574,13 @@
341 if (menu->redraw & REDRAW_STATUS)
344 menu_status_line (buf, sizeof (buf), menu, NONULL (Status));
346 CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES-2);
347 SETCOLOR (MT_COLOR_STATUS);
348 BKGDSET (MT_COLOR_STATUS);
349 + set_buffystats(Context);
350 mutt_paddstr (COLS, buf);
351 SETCOLOR (MT_COLOR_NORMAL);
352 BKGDSET (MT_COLOR_NORMAL);
354 menu->oldcurrent = -1;
356 if (option (OPTARROWCURSOR))
357 - move (menu->current - menu->top + menu->offset, 2);
358 + move (menu->current - menu->top + menu->offset, SidebarWidth + 2);
359 else if (option (OPTBRAILLEFRIENDLY))
360 move (menu->current - menu->top + menu->offset, 0);
362 @@ -1089,6 +1099,7 @@
363 menu->redraw = REDRAW_FULL;
366 + case OP_SIDEBAR_OPEN:
367 case OP_MAIN_CHANGE_FOLDER:
368 case OP_MAIN_NEXT_UNREAD_MAILBOX:
370 @@ -1120,7 +1131,11 @@
372 mutt_buffy (buf, sizeof (buf));
374 - if (mutt_enter_fname (cp, buf, sizeof (buf), &menu->redraw, 1) == -1)
375 + if ( op == OP_SIDEBAR_OPEN ) {
378 + strncpy( buf, CurBuffy->path, sizeof(buf) );
379 + } else if (mutt_enter_fname (cp, buf, sizeof (buf), &menu->redraw, 1) == -1)
381 if (menu->menu == MENU_PAGER)
383 @@ -1138,6 +1153,7 @@
386 mutt_expand_path (buf, sizeof (buf));
388 if (mx_get_magic (buf) <= 0)
390 mutt_error (_("%s is not a mailbox."), buf);
391 @@ -2241,6 +2257,12 @@
395 + case OP_SIDEBAR_SCROLL_UP:
396 + case OP_SIDEBAR_SCROLL_DOWN:
397 + case OP_SIDEBAR_NEXT:
398 + case OP_SIDEBAR_PREV:
399 + scroll_sidebar(op, menu->menu);
402 if (menu->menu == MENU_MAIN)
403 km_error_key (MENU_MAIN);
409 #include "mutt_curses.h"
410 +#include "mutt_menu.h"
413 +#include "sidebar.h"
415 void _mutt_set_flag (CONTEXT *ctx, HEADER *h, int flag, int bf, int upd_ctx)
419 if (h->searched && (changed != h->changed || deleted != ctx->deleted || tagged != ctx->tagged || flagged != ctx->flagged))
424 void mutt_tag_set_flag (int flag, int bf)
428 { "decrypt-save", OP_DECRYPT_SAVE, NULL },
431 + { "sidebar-scroll-up", OP_SIDEBAR_SCROLL_UP, NULL },
432 + { "sidebar-scroll-down", OP_SIDEBAR_SCROLL_DOWN, NULL },
433 + { "sidebar-next", OP_SIDEBAR_NEXT, NULL },
434 + { "sidebar-prev", OP_SIDEBAR_PREV, NULL },
435 + { "sidebar-open", OP_SIDEBAR_OPEN, NULL },
441 { "what-key", OP_WHAT_KEY, NULL },
443 + { "sidebar-scroll-up", OP_SIDEBAR_SCROLL_UP, NULL },
444 + { "sidebar-scroll-down", OP_SIDEBAR_SCROLL_DOWN, NULL },
445 + { "sidebar-next", OP_SIDEBAR_NEXT, NULL },
446 + { "sidebar-prev", OP_SIDEBAR_PREV, NULL },
447 + { "sidebar-open", OP_SIDEBAR_OPEN, NULL },
454 WHERE char *SendCharset;
455 WHERE char *Sendmail;
457 +WHERE char *SidebarDelim;
458 WHERE char *Signature;
459 WHERE char *SimpleSearch;
462 WHERE short ScoreThresholdRead;
463 WHERE short ScoreThresholdFlag;
465 +WHERE struct buffy_t *CurBuffy INITVAL(0);
466 +WHERE short DrawFullLine INITVAL(0);
467 +WHERE short SidebarWidth;
469 WHERE short ImapKeepalive;
470 WHERE short ImapPipelineDepth;
473 @@ -1011,6 +1011,13 @@
475 status->uidnext = oldun;
477 + /* Added to make the sidebar show the correct numbers */
478 + if (status->messages)
480 + inc->msgcount = status->messages;
481 + inc->msg_unread = status->unseen;
489 @@ -1527,7 +1527,7 @@
491 imap_munge_mbox_name (munged, sizeof (munged), name);
492 snprintf (command, sizeof (command),
493 - "STATUS %s (UIDNEXT UIDVALIDITY UNSEEN RECENT)", munged);
494 + "STATUS %s (UIDNEXT UIDVALIDITY UNSEEN RECENT MESSAGES)", munged);
496 if (imap_exec (idata, command, IMAP_CMD_QUEUE) < 0)
500 @@ -1965,6 +1965,22 @@
504 + {"sidebar_delim", DT_STR, R_BOTH, UL &SidebarDelim, "|"},
507 + ** This specifies the delimiter between the sidebar (if visible) and
510 + { "sidebar_visible", DT_BOOL, R_BOTH, OPTSIDEBAR, 0 },
513 + ** This specifies whether or not to show sidebar (left-side list of folders).
515 + { "sidebar_width", DT_NUM, R_BOTH, UL &SidebarWidth, 0 },
518 + ** The width of the sidebar.
520 { "pgp_use_gpg_agent", DT_BOOL, R_NONE, OPTUSEGPGAGENT, 0},
526 #define M_NEWFOLDER (1<<4) /* create a new folder - same as M_APPEND, but uses
527 * safe_fopen() for mbox-style folders.
529 +#define M_PEEK (1<<5) /* revert atime back after taking a look (if applicable) */
531 /* mx_open_new_message() */
532 #define M_ADD_FROM 1 /* add a From_ line */
536 mutt_perror (ctx->path);
539 + ctx->atime = sb.st_atime;
540 ctx->mtime = sb.st_mtime;
541 ctx->size = sb.st_size;
545 ctx->size = sb.st_size;
546 ctx->mtime = sb.st_mtime;
547 + ctx->atime = sb.st_atime;
549 #ifdef NFS_ATTRIBUTE_HACK
550 if (sb.st_mtime > sb.st_atime)
554 #include "mutt_curses.h"
555 #include "mutt_menu.h"
557 +#include "sidebar.h"
563 char *scratch = safe_strdup (s);
564 int shift = option (OPTARROWCURSOR) ? 3 : 0;
565 - int cols = COLS - shift;
566 + int cols = COLS - shift - SidebarWidth;
568 mutt_format_string (s, n, cols, cols, FMT_LEFT, ' ', scratch, mutt_strlen (scratch), 1);
571 char buf[LONG_STRING];
575 for (i = menu->top; i < menu->top + menu->pagelen; i++)
579 if (option (OPTARROWCURSOR))
581 attrset (menu->color (i));
582 - CLEARLINE (i - menu->top + menu->offset);
583 + CLEARLINE_WIN (i - menu->top + menu->offset);
585 if (i == menu->current)
587 @@ -246,14 +248,14 @@
588 BKGDSET (MT_COLOR_INDICATOR);
591 - CLEARLINE (i - menu->top + menu->offset);
592 + CLEARLINE_WIN (i - menu->top + menu->offset);
593 print_enriched_string (menu->color(i), (unsigned char *) buf, i != menu->current);
594 SETCOLOR (MT_COLOR_NORMAL);
595 BKGDSET (MT_COLOR_NORMAL);
599 - CLEARLINE (i - menu->top + menu->offset);
600 + CLEARLINE_WIN (i - menu->top + menu->offset);
608 - move (menu->oldcurrent + menu->offset - menu->top, 0);
609 + move (menu->oldcurrent + menu->offset - menu->top, SidebarWidth);
610 SETCOLOR (MT_COLOR_NORMAL);
611 BKGDSET (MT_COLOR_NORMAL);
613 @@ -283,13 +285,13 @@
615 menu_make_entry (buf, sizeof (buf), menu, menu->oldcurrent);
616 menu_pad_string (buf, sizeof (buf));
617 - move (menu->oldcurrent + menu->offset - menu->top, 3);
618 + move (menu->oldcurrent + menu->offset - menu->top, SidebarWidth + 3);
619 print_enriched_string (menu->color(menu->oldcurrent), (unsigned char *) buf, 1);
620 SETCOLOR (MT_COLOR_NORMAL);
623 /* now draw it in the new location */
624 - move (menu->current + menu->offset - menu->top, 0);
625 + move (menu->current + menu->offset - menu->top, SidebarWidth);
626 attrset (menu->color (menu->current));
627 ADDCOLOR (MT_COLOR_INDICATOR);
630 attrset (menu->color (menu->current));
631 ADDCOLOR (MT_COLOR_INDICATOR);
632 BKGDSET (MT_COLOR_INDICATOR);
633 - CLEARLINE (menu->current - menu->top + menu->offset);
634 + CLEARLINE_WIN (menu->current - menu->top + menu->offset);
635 print_enriched_string (menu->color(menu->current), (unsigned char *) buf, 0);
636 SETCOLOR (MT_COLOR_NORMAL);
637 BKGDSET (MT_COLOR_NORMAL);
640 char buf[LONG_STRING];
642 - move (menu->current + menu->offset - menu->top, 0);
643 + move (menu->current + menu->offset - menu->top, SidebarWidth);
644 menu_make_entry (buf, sizeof (buf), menu, menu->current);
645 menu_pad_string (buf, sizeof (buf));
650 if (option (OPTARROWCURSOR))
651 - move (menu->current - menu->top + menu->offset, 2);
652 + move (menu->current - menu->top + menu->offset, SidebarWidth + 2);
653 else if (option (OPTBRAILLEFRIENDLY))
654 move (menu->current - menu->top + menu->offset, 0);
658 @@ -235,13 +235,37 @@
660 if (mh_read_sequences (&mhs, path) < 0)
663 for (i = 0; !r && i <= mhs.max; i++)
664 - if (mhs_check (&mhs, i) & MH_SEQ_UNSEEN)
665 + if (mhs_check (&mhs, i) & MH_SEQ_UNSEEN) {
668 mhs_free_sequences (&mhs);
672 +void mh_buffy_update (const char *path, int *msgcount, int *msg_unread, int *msg_flagged)
675 + struct mh_sequences mhs;
676 + memset (&mhs, 0, sizeof (mhs));
678 + if (mh_read_sequences (&mhs, path) < 0)
684 + for (i = 0; i <= mhs.max; i++)
686 + if (mhs_check (&mhs, i) & MH_SEQ_UNSEEN) {
689 + if (mhs_check (&mhs, i) & MH_SEQ_FLAGGED)
691 + mhs_free_sequences (&mhs);
694 static int mh_mkstemp (CONTEXT * dest, FILE ** fp, char **tgt)
716 unsigned int quiet : 1; /* inhibit status messages? */
717 unsigned int collapsed : 1; /* are all threads collapsed? */
718 unsigned int closing : 1; /* mailbox is being closed */
719 + unsigned int peekonly : 1; /* just taking a glance, revert atime */
722 void *data; /* driver specific data */
729 +#define CLEARLINE_WIN(x) move(x,SidebarWidth), clrtoeol()
730 #define CLEARLINE(x) move(x,0), clrtoeol()
731 #define CENTERLINE(x,y) move(y, (COLS-strlen(x))/2), addstr(x)
732 #define BEEP() do { if (option (OPTBEEP)) beep(); } while (0)
744 @@ -1286,6 +1286,8 @@
747 /* see if there's room to add content, else ignore */
748 + if ( DrawFullLine )
750 if ((col < COLS && wlen < destlen) || soft)
753 @@ -1329,6 +1331,52 @@
760 + if ((col < COLS-SidebarWidth && wlen < destlen) || soft)
764 + /* get contents after padding */
765 + mutt_FormatString (buf, sizeof (buf), 0, src + pl, callback, data, flags);
766 + len = mutt_strlen (buf);
767 + wid = mutt_strwidth (buf);
769 + /* try to consume as many columns as we can, if we don't have
770 + * memory for that, use as much memory as possible */
771 + pad = (COLS - SidebarWidth - col - wid) / pw;
772 + if (pad > 0 && wlen + (pad * pl) + len > destlen)
773 + pad = ((signed)(destlen - wlen - len)) / pl;
778 + memcpy (wptr, src, pl);
784 + else if (soft && pad < 0)
786 + /* \0-terminate dest for length computation in mutt_wstr_trunc() */
788 + /* make sure right part is at most as wide as display */
789 + len = mutt_wstr_trunc (buf, destlen, COLS, &wid);
790 + /* truncate left so that right part fits completely in */
791 + wlen = mutt_wstr_trunc (dest, destlen - len, col + pad, &col);
792 + wptr = dest + wlen;
794 + if (len + wlen > destlen)
795 + len = mutt_wstr_trunc (buf, destlen - wlen, COLS - SidebarWidth - col, NULL);
796 + memcpy (wptr, buf, len);
803 break; /* skip rest of input */
809 * M_APPEND open mailbox for appending
810 * M_READONLY open mailbox in read-only mode
811 * M_QUIET only print error messages
812 + * M_PEEK revert atime where applicable
813 * ctx if non-null, context struct to use
815 CONTEXT *mx_open_mailbox (const char *path, int flags, CONTEXT *pctx)
818 if (flags & M_READONLY)
820 + if (flags & M_PEEK)
823 if (flags & (M_APPEND|M_NEWFOLDER))
826 void mx_fastclose_mailbox (CONTEXT *ctx)
836 + /* fix up the times so buffy won't get confused */
837 + if (ctx->peekonly && ctx->path && ctx->mtime > ctx->atime)
839 + ut.actime = ctx->atime;
840 + ut.modtime = ctx->mtime;
841 + utime (ctx->path, &ut);
845 /* never announce that a mailbox we've just left has new mail. #3290
846 * XXX: really belongs in mx_close_mailbox, but this is a nice hook point */
850 int mh_sync_mailbox (CONTEXT *, int *);
851 int mh_check_mailbox (CONTEXT *, int *);
852 int mh_buffy (const char *);
853 +void mh_buffy_update (const char *, int *, int *, int *);
854 int mh_check_empty (const char *);
856 int maildir_read_dir (CONTEXT *);
863 +#include "sidebar.h"
865 #include "mutt_crypt.h"
867 @@ -1095,6 +1096,7 @@
870 int wrap_cols = mutt_term_width ((flags & M_PAGER_NOWRAP) ? 0 : Wrap);
871 + wrap_cols -= SidebarWidth;
873 if (check_attachment_marker ((char *)buf) == 0)
875 @@ -1745,7 +1747,7 @@
876 if ((redraw & REDRAW_BODY) || topline != oldtopline)
879 - move (bodyoffset, 0);
880 + move (bodyoffset, SidebarWidth);
881 curline = oldtopline = topline;
884 @@ -1758,6 +1760,7 @@
885 &QuoteList, &q_level, &force_redraw, &SearchRE) > 0)
888 + move(lines + bodyoffset, SidebarWidth);
890 last_offset = lineInfo[curline].offset;
891 } while (force_redraw);
892 @@ -1771,6 +1774,7 @@
896 + move(lines + bodyoffset, SidebarWidth);
898 /* We are going to update the pager status bar, so it isn't
899 * necessary to reset to normal color now. */
900 @@ -1794,21 +1798,21 @@
901 /* print out the pager status bar */
902 SETCOLOR (MT_COLOR_STATUS);
903 BKGDSET (MT_COLOR_STATUS);
904 - CLEARLINE (statusoffset);
905 + CLEARLINE_WIN (statusoffset);
907 if (IsHeader (extra) || IsMsgAttach (extra))
909 - size_t l1 = COLS * MB_LEN_MAX;
910 + size_t l1 = (COLS-SidebarWidth) * MB_LEN_MAX;
911 size_t l2 = sizeof (buffer);
912 hfi.hdr = (IsHeader (extra)) ? extra->hdr : extra->bdy->hdr;
913 mutt_make_string_info (buffer, l1 < l2 ? l1 : l2, NONULL (PagerFmt), &hfi, M_FORMAT_MAKEPRINT);
914 - mutt_paddstr (COLS, buffer);
915 + mutt_paddstr (COLS-SidebarWidth, buffer);
920 snprintf (bn, sizeof (bn), "%s (%s)", banner, pager_progress_str);
921 - mutt_paddstr (COLS, bn);
922 + mutt_paddstr (COLS-SidebarWidth, bn);
924 BKGDSET (MT_COLOR_NORMAL);
925 SETCOLOR (MT_COLOR_NORMAL);
926 @@ -1826,18 +1830,23 @@
927 /* redraw the pager_index indicator, because the
928 * flags for this message might have changed. */
929 menu_redraw_current (index);
930 + draw_sidebar(MENU_PAGER);
932 /* print out the index status bar */
933 menu_status_line (buffer, sizeof (buffer), index, NONULL(Status));
935 - move (indexoffset + (option (OPTSTATUSONTOP) ? 0 : (indexlen - 1)), 0);
936 + move (indexoffset + (option (OPTSTATUSONTOP) ? 0 : (indexlen - 1)), SidebarWidth);
937 SETCOLOR (MT_COLOR_STATUS);
938 BKGDSET (MT_COLOR_STATUS);
939 - mutt_paddstr (COLS, buffer);
940 + mutt_paddstr (COLS-SidebarWidth, buffer);
941 SETCOLOR (MT_COLOR_NORMAL);
942 BKGDSET (MT_COLOR_NORMAL);
945 + /* if we're not using the index, update every time */
947 + draw_sidebar(MENU_PAGER);
951 if (option(OPTBRAILLEFRIENDLY)) {
952 @@ -2769,6 +2778,13 @@
956 + case OP_SIDEBAR_SCROLL_UP:
957 + case OP_SIDEBAR_SCROLL_DOWN:
958 + case OP_SIDEBAR_NEXT:
959 + case OP_SIDEBAR_PREV:
960 + scroll_sidebar(ch, MENU_PAGER);
970 + * Copyright (C) ????-2004 Justin Hibbits <jrh29@po.cwru.edu>
971 + * Copyright (C) 2004 Thomer M. Gil <mutt@thomer.com>
973 + * This program is free software; you can redistribute it and/or modify
974 + * it under the terms of the GNU General Public License as published by
975 + * the Free Software Foundation; either version 2 of the License, or
976 + * (at your option) any later version.
978 + * This program is distributed in the hope that it will be useful,
979 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
980 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
981 + * GNU General Public License for more details.
983 + * You should have received a copy of the GNU General Public License
984 + * along with this program; if not, write to the Free Software
985 + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
990 +# include "config.h"
994 +#include "mutt_menu.h"
995 +#include "mutt_curses.h"
996 +#include "sidebar.h"
1000 +#include <stdbool.h>
1002 +/*BUFFY *CurBuffy = 0;*/
1003 +static BUFFY *TopBuffy = 0;
1004 +static BUFFY *BottomBuffy = 0;
1005 +static int known_lines = 0;
1007 +static int quick_log10(int n)
1010 + sprintf(string, "%d", n);
1011 + return strlen(string);
1014 +void calc_boundaries (int menu)
1016 + BUFFY *tmp = Incoming;
1018 + if ( known_lines != LINES ) {
1019 + TopBuffy = BottomBuffy = 0;
1020 + known_lines = LINES;
1022 + for ( ; tmp->next != 0; tmp = tmp->next )
1023 + tmp->next->prev = tmp;
1025 + if ( TopBuffy == 0 && BottomBuffy == 0 )
1026 + TopBuffy = Incoming;
1027 + if ( BottomBuffy == 0 ) {
1028 + int count = LINES - 2 - (menu != MENU_PAGER || option(OPTSTATUSONTOP));
1029 + BottomBuffy = TopBuffy;
1030 + while ( --count && BottomBuffy->next )
1031 + BottomBuffy = BottomBuffy->next;
1033 + else if ( TopBuffy == CurBuffy->next ) {
1034 + int count = LINES - 2 - (menu != MENU_PAGER);
1035 + BottomBuffy = CurBuffy;
1036 + tmp = BottomBuffy;
1037 + while ( --count && tmp->prev)
1041 + else if ( BottomBuffy == CurBuffy->prev ) {
1042 + int count = LINES - 2 - (menu != MENU_PAGER);
1043 + TopBuffy = CurBuffy;
1045 + while ( --count && tmp->next )
1047 + BottomBuffy = tmp;
1051 +char *make_sidebar_entry(char *box, int size, int new, int flagged)
1053 + static char *entry = 0;
1056 + int delim_len = strlen(SidebarDelim);
1058 + c = realloc(entry, SidebarWidth - delim_len + 2);
1059 + if ( c ) entry = c;
1060 + entry[SidebarWidth - delim_len + 1] = 0;
1061 + for (; i < SidebarWidth - delim_len + 1; entry[i++] = ' ' );
1063 + strncpy( entry, box, i < (SidebarWidth - delim_len + 1) ? i : (SidebarWidth - delim_len + 1) );
1066 + sprintf(entry + SidebarWidth - delim_len - 3, "?");
1068 + if (flagged > 0) {
1070 + entry + SidebarWidth - delim_len - 5 - quick_log10(size) - quick_log10(new) - quick_log10(flagged),
1071 + "% d(%d)[%d]", size, new, flagged);
1074 + entry + SidebarWidth - delim_len - 3 - quick_log10(size) - quick_log10(new),
1075 + "% d(%d)", size, new);
1077 + } else if (flagged > 0) {
1078 + sprintf( entry + SidebarWidth - delim_len - 3 - quick_log10(size) - quick_log10(flagged), "% d[%d]", size, flagged);
1080 + sprintf( entry + SidebarWidth - delim_len - 1 - quick_log10(size), "% d", size);
1085 +void set_curbuffy(char buf[LONG_STRING])
1087 + BUFFY* tmp = CurBuffy = Incoming;
1093 + if(!strcmp(tmp->path, buf)) {
1105 +int draw_sidebar(int menu) {
1107 + int lines = option(OPTHELP) ? 1 : 0;
1108 + lines += option(OPTSTATUSONTOP) ? 1 : 0;
1111 +#ifndef USE_SLANG_CURSES
1114 + short delim_len = strlen(SidebarDelim);
1117 + static bool initialized = false;
1118 + static int prev_show_value;
1119 + static short saveSidebarWidth;
1121 + /* initialize first time */
1122 + if(!initialized) {
1123 + prev_show_value = option(OPTSIDEBAR);
1124 + saveSidebarWidth = SidebarWidth;
1125 + if(!option(OPTSIDEBAR)) SidebarWidth = 0;
1126 + initialized = true;
1129 + /* save or restore the value SidebarWidth */
1130 + if(prev_show_value != option(OPTSIDEBAR)) {
1131 + if(prev_show_value && !option(OPTSIDEBAR)) {
1132 + saveSidebarWidth = SidebarWidth;
1134 + } else if(!prev_show_value && option(OPTSIDEBAR)) {
1135 + SidebarWidth = saveSidebarWidth;
1137 + prev_show_value = option(OPTSIDEBAR);
1141 +// if ( SidebarWidth == 0 ) return 0;
1142 + if (SidebarWidth > 0 && option (OPTSIDEBAR)
1143 + && delim_len >= SidebarWidth) {
1144 + unset_option (OPTSIDEBAR);
1145 + /* saveSidebarWidth = SidebarWidth; */
1146 + if (saveSidebarWidth > delim_len) {
1147 + SidebarWidth = saveSidebarWidth;
1148 + mutt_error (_("Value for sidebar_delim is too long. Disabling sidebar."));
1152 + mutt_error (_("Value for sidebar_delim is too long. Disabling sidebar. Please set your sidebar_width to a sane value."));
1153 + sleep (4); /* the advise to set a sane value should be seen long enough */
1155 + saveSidebarWidth = 0;
1159 + if ( SidebarWidth == 0 || !option(OPTSIDEBAR)) {
1160 + if (SidebarWidth > 0) {
1161 + saveSidebarWidth = SidebarWidth;
1164 + unset_option(OPTSIDEBAR);
1168 + /* get attributes for divider */
1169 + SETCOLOR(MT_COLOR_STATUS);
1170 +#ifndef USE_SLANG_CURSES
1171 + attr_get(&attrs, &color_pair, 0);
1173 + color_pair = attr_get();
1175 + SETCOLOR(MT_COLOR_NORMAL);
1177 + /* draw the divider */
1179 + for ( ; lines < LINES-1-(menu != MENU_PAGER || option(OPTSTATUSONTOP)); lines++ ) {
1180 + move(lines, SidebarWidth - delim_len);
1181 + addstr(NONULL(SidebarDelim));
1182 +#ifndef USE_SLANG_CURSES
1183 + mvchgat(lines, SidebarWidth - delim_len, delim_len, 0, color_pair, NULL);
1187 + if ( Incoming == 0 ) return 0;
1188 + lines = option(OPTHELP) ? 1 : 0; /* go back to the top */
1189 + lines += option(OPTSTATUSONTOP) ? 1 : 0;
1191 + if ( known_lines != LINES || TopBuffy == 0 || BottomBuffy == 0 )
1192 + calc_boundaries(menu);
1193 + if ( CurBuffy == 0 ) CurBuffy = Incoming;
1197 + SETCOLOR(MT_COLOR_NORMAL);
1199 + for ( ; tmp && lines < LINES-1 - (menu != MENU_PAGER || option(OPTSTATUSONTOP)); tmp = tmp->next ) {
1200 + if ( tmp == CurBuffy )
1201 + SETCOLOR(MT_COLOR_INDICATOR);
1202 + else if ( tmp->msg_unread > 0 )
1203 + SETCOLOR(MT_COLOR_NEW);
1204 + else if ( tmp->msg_flagged > 0 )
1205 + SETCOLOR(MT_COLOR_FLAGGED);
1207 + SETCOLOR(MT_COLOR_NORMAL);
1210 + if ( Context && !strcmp( tmp->path, Context->path ) ) {
1211 + tmp->msg_unread = Context->unread;
1212 + tmp->msgcount = Context->msgcount;
1213 + tmp->msg_flagged = Context->flagged;
1215 + // check whether Maildir is a prefix of the current folder's path
1216 + short maildir_is_prefix = 0;
1217 + if ( (strlen(tmp->path) > strlen(Maildir)) &&
1218 + (strncmp(Maildir, tmp->path, strlen(Maildir)) == 0) )
1219 + maildir_is_prefix = 1;
1220 + // calculate depth of current folder and generate its display name with indented spaces
1221 + int sidebar_folder_depth = 0;
1222 + char *sidebar_folder_name;
1223 + sidebar_folder_name = basename(tmp->path);
1224 + if ( maildir_is_prefix ) {
1225 + char *tmp_folder_name;
1227 + tmp_folder_name = tmp->path + strlen(Maildir);
1228 + for (i = 0; i < strlen(tmp->path) - strlen(Maildir); i++) {
1229 + if (tmp_folder_name[i] == '/') sidebar_folder_depth++;
1231 + if (sidebar_folder_depth > 0) {
1232 + sidebar_folder_name = malloc(strlen(basename(tmp->path)) + sidebar_folder_depth + 1);
1233 + for (i=0; i < sidebar_folder_depth; i++)
1234 + sidebar_folder_name[i]=' ';
1235 + sidebar_folder_name[i]=0;
1236 + strncat(sidebar_folder_name, basename(tmp->path), strlen(basename(tmp->path)) + sidebar_folder_depth);
1239 + printw( "%.*s", SidebarWidth - delim_len + 1,
1240 + make_sidebar_entry(sidebar_folder_name, tmp->msgcount,
1241 + tmp->msg_unread, tmp->msg_flagged));
1242 + if (sidebar_folder_depth > 0)
1243 + free(sidebar_folder_name);
1246 + SETCOLOR(MT_COLOR_NORMAL);
1247 + for ( ; lines < LINES-1 - (menu != MENU_PAGER || option(OPTSTATUSONTOP)); lines++ ) {
1250 + for ( ; i < SidebarWidth - delim_len; i++ )
1257 +void set_buffystats(CONTEXT* Context)
1259 + BUFFY *tmp = Incoming;
1261 + if(Context && !strcmp(tmp->path, Context->path)) {
1262 + tmp->msg_unread = Context->unread;
1263 + tmp->msgcount = Context->msgcount;
1270 +void scroll_sidebar(int op, int menu)
1272 + if(!SidebarWidth) return;
1273 + if(!CurBuffy) return;
1276 + case OP_SIDEBAR_NEXT:
1277 + if ( CurBuffy->next == NULL ) return;
1278 + CurBuffy = CurBuffy->next;
1280 + case OP_SIDEBAR_PREV:
1281 + if ( CurBuffy->prev == NULL ) return;
1282 + CurBuffy = CurBuffy->prev;
1284 + case OP_SIDEBAR_SCROLL_UP:
1285 + CurBuffy = TopBuffy;
1286 + if ( CurBuffy != Incoming ) {
1287 + calc_boundaries(menu);
1288 + CurBuffy = CurBuffy->prev;
1291 + case OP_SIDEBAR_SCROLL_DOWN:
1292 + CurBuffy = BottomBuffy;
1293 + if ( CurBuffy->next ) {
1294 + calc_boundaries(menu);
1295 + CurBuffy = CurBuffy->next;
1301 + calc_boundaries(menu);
1302 + draw_sidebar(menu);
1309 + * Copyright (C) ????-2004 Justin Hibbits <jrh29@po.cwru.edu>
1310 + * Copyright (C) 2004 Thomer M. Gil <mutt@thomer.com>
1312 + * This program is free software; you can redistribute it and/or modify
1313 + * it under the terms of the GNU General Public License as published by
1314 + * the Free Software Foundation; either version 2 of the License, or
1315 + * (at your option) any later version.
1317 + * This program is distributed in the hope that it will be useful,
1318 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1319 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1320 + * GNU General Public License for more details.
1322 + * You should have received a copy of the GNU General Public License
1323 + * along with this program; if not, write to the Free Software
1324 + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
1336 +/* parameter is whether or not to go to the status line */
1337 +/* used for omitting the last | that covers up the status bar in the index */
1338 +int draw_sidebar(int);
1339 +void scroll_sidebar(int, int);
1340 +void set_curbuffy(char*);
1341 +void set_buffystats(CONTEXT*);
1343 +#endif /* SIDEBAR_H */