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;
44 for (tmp = Incoming; tmp; tmp = tmp->next)
46 + if ( tmp->new == 1 )
49 if (tmp->magic != M_IMAP)
57 + if (STAT_CHECK || tmp->msgcount == 0)
64 + /* parse the mailbox, to see how much mail there is */
65 + ctx = mx_open_mailbox( tmp->path, M_READONLY | M_QUIET | M_NOSORT | M_PEEK, NULL);
68 + msgcount = ctx->msgcount;
69 + msg_unread = ctx->unread;
70 + mx_close_mailbox(ctx, 0);
73 + tmp->msgcount = msgcount;
74 + tmp->msg_unread = msg_unread;
76 + tmp->has_new = tmp->new = 1;
80 else if (option(OPTCHECKMBOXSIZE))
83 if (tmp->newly_created &&
84 (sb.st_ctime != sb.st_mtime || sb.st_ctime != sb.st_atime))
85 tmp->newly_created = 0;
92 + /* count new message */
93 snprintf (path, sizeof (path), "%s/new", tmp->path);
94 if ((dirp = opendir (path)) == NULL)
100 + tmp->msg_unread = 0;
101 + tmp->msg_flagged = 0;
102 while ((de = readdir (dirp)) != NULL)
105 if (*de->d_name != '.' &&
106 (!(p = strstr (de->d_name, ":2,")) || !strchr (p + 3, 'T')))
108 - /* one new and undeleted message is enough */
112 + tmp->has_new = tmp->new = 1;
117 + if(tmp->msg_unread)
123 + * count read messages (for folderlist (sidebar) we also need to count
124 + * messages in cur so that we the total number of messages
126 + snprintf (path, sizeof (path), "%s/cur", tmp->path);
127 + if ((dirp = opendir (path)) == NULL)
132 + while ((de = readdir (dirp)) != NULL)
135 + if (*de->d_name != '.') {
136 + if ((p = strstr (de->d_name, ":2,"))) {
137 + if (!strchr (p + 3, 'T')) {
139 + if ( !strchr (p + 3, 'S'))
141 + if (strchr(p + 3, 'F'))
142 + tmp->msg_flagged++;
155 if ((tmp->new = mh_buffy (tmp->path)) > 0)
158 + if ((dp = opendir (path)) == NULL)
161 + while ((de = readdir (dp)))
163 + if (mh_valid_message (de->d_name))
166 + tmp->has_new = tmp->new = 1;
177 char path[_POSIX_PATH_MAX];
179 struct buffy_t *next;
180 + struct buffy_t *prev;
181 short new; /* mailbox has new mail */
182 + short has_new; /* set it new if new and not read */
183 + int msgcount; /* total number of messages */
184 + int msg_unread; /* number of unread messages */
185 + int msg_flagged; /* number of flagged messages */
186 short notified; /* user has been notified */
187 short magic; /* mailbox type */
188 short newly_created; /* mbox or mmdf just popped into existence */
192 { "bold", MT_COLOR_BOLD },
193 { "underline", MT_COLOR_UNDERLINE },
194 { "index", MT_COLOR_INDEX },
195 + { "sidebar_new", MT_COLOR_NEW },
196 + { "sidebar_flagged", MT_COLOR_FLAGGED },
204 #define HDR_XOFFSET 10
205 #define TITLE_FMT "%10s" /* Used for Prompts, which are ASCII */
206 -#define W (COLS - HDR_XOFFSET)
207 +#define W (COLS - HDR_XOFFSET - SidebarWidth)
209 static char *Prompts[] =
211 @@ -115,16 +115,16 @@
212 if ((WithCrypto & APPLICATION_PGP) && (WithCrypto & APPLICATION_SMIME))
215 - mvaddstr (HDR_CRYPT, 0, "Security: ");
216 + mvaddstr (HDR_CRYPT, SidebarWidth, "Security: ");
217 else if (msg->security & APPLICATION_SMIME)
218 - mvaddstr (HDR_CRYPT, 0, " S/MIME: ");
219 + mvaddstr (HDR_CRYPT, SidebarWidth, " S/MIME: ");
220 else if (msg->security & APPLICATION_PGP)
221 - mvaddstr (HDR_CRYPT, 0, " PGP: ");
222 + mvaddstr (HDR_CRYPT, SidebarWidth, " PGP: ");
224 else if ((WithCrypto & APPLICATION_SMIME))
225 - mvaddstr (HDR_CRYPT, 0, " S/MIME: ");
226 + mvaddstr (HDR_CRYPT, SidebarWidth, " S/MIME: ");
227 else if ((WithCrypto & APPLICATION_PGP))
228 - mvaddstr (HDR_CRYPT, 0, " PGP: ");
229 + mvaddstr (HDR_CRYPT, SidebarWidth, " PGP: ");
237 - move (HDR_CRYPTINFO, 0);
238 + move (HDR_CRYPTINFO, SidebarWidth);
240 if ((WithCrypto & APPLICATION_PGP)
241 && msg->security & APPLICATION_PGP && msg->security & SIGN)
243 && (msg->security & ENCRYPT)
246 - mvprintw (HDR_CRYPTINFO, 40, "%s%s", _("Encrypt with: "),
247 + mvprintw (HDR_CRYPTINFO, SidebarWidth + 40, "%s%s", _("Encrypt with: "),
248 NONULL(SmimeCryptAlg));
255 - mvaddstr (HDR_MIX, 0, " Mix: ");
256 + mvaddstr (HDR_MIX, SidebarWidth, " Mix: ");
261 if (t && t[0] == '0' && t[1] == '\0')
264 - if (c + mutt_strlen (t) + 2 >= COLS)
265 + if (c + mutt_strlen (t) + 2 >= COLS - SidebarWidth)
272 rfc822_write_address (buf, sizeof (buf), addr, 1);
273 - mvprintw (line, 0, TITLE_FMT, Prompts[line - 1]);
274 + mvprintw (line, SidebarWidth, TITLE_FMT, Prompts[line - 1]);
275 mutt_paddstr (W, buf);
278 @@ -255,10 +255,10 @@
279 draw_envelope_addr (HDR_TO, msg->env->to);
280 draw_envelope_addr (HDR_CC, msg->env->cc);
281 draw_envelope_addr (HDR_BCC, msg->env->bcc);
282 - mvprintw (HDR_SUBJECT, 0, TITLE_FMT, Prompts[HDR_SUBJECT - 1]);
283 + mvprintw (HDR_SUBJECT, SidebarWidth, TITLE_FMT, Prompts[HDR_SUBJECT - 1]);
284 mutt_paddstr (W, NONULL (msg->env->subject));
285 draw_envelope_addr (HDR_REPLYTO, msg->env->reply_to);
286 - mvprintw (HDR_FCC, 0, TITLE_FMT, Prompts[HDR_FCC - 1]);
287 + mvprintw (HDR_FCC, SidebarWidth, TITLE_FMT, Prompts[HDR_FCC - 1]);
288 mutt_paddstr (W, fcc);
294 SETCOLOR (MT_COLOR_STATUS);
295 - mvaddstr (HDR_ATTACH - 1, 0, _("-- Attachments"));
296 + mvaddstr (HDR_ATTACH - 1, SidebarWidth, _("-- Attachments"));
297 BKGDSET (MT_COLOR_STATUS);
301 /* redraw the expanded list so the user can see the result */
303 rfc822_write_address (buf, sizeof (buf), *addr, 1);
304 - move (line, HDR_XOFFSET);
305 + move (line, HDR_XOFFSET+SidebarWidth);
306 mutt_paddstr (W, buf);
310 if (mutt_get_field ("Subject: ", buf, sizeof (buf), 0) == 0)
312 mutt_str_replace (&msg->env->subject, buf);
313 - move (HDR_SUBJECT, HDR_XOFFSET);
314 + move (HDR_SUBJECT, HDR_XOFFSET + SidebarWidth);
316 if (msg->env->subject)
317 mutt_paddstr (W, msg->env->subject);
320 strfcpy (fcc, buf, fcclen);
321 mutt_pretty_mailbox (fcc, fcclen);
322 - move (HDR_FCC, HDR_XOFFSET);
323 + move (HDR_FCC, HDR_XOFFSET + SidebarWidth);
324 mutt_paddstr (W, fcc);
335 +#include "sidebar.h"
340 menu->redraw |= REDRAW_STATUS;
343 - if (mutt_buffy_notify () && option (OPTBEEPNEW))
345 + if (mutt_buffy_notify ())
347 + menu->redraw |= REDRAW_FULL;
348 + if (option (OPTBEEPNEW))
355 if (menu->redraw & REDRAW_FULL)
357 menu_redraw_full (menu);
358 + draw_sidebar(menu->menu);
362 @@ -571,10 +578,13 @@
364 if (menu->redraw & REDRAW_STATUS)
367 menu_status_line (buf, sizeof (buf), menu, NONULL (Status));
369 CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES-2);
370 SETCOLOR (MT_COLOR_STATUS);
371 BKGDSET (MT_COLOR_STATUS);
372 + set_buffystats(Context);
373 mutt_paddstr (COLS, buf);
374 SETCOLOR (MT_COLOR_NORMAL);
375 BKGDSET (MT_COLOR_NORMAL);
377 menu->oldcurrent = -1;
379 if (option (OPTARROWCURSOR))
380 - move (menu->current - menu->top + menu->offset, 2);
381 + move (menu->current - menu->top + menu->offset, SidebarWidth + 2);
382 else if (option (OPTBRAILLEFRIENDLY))
383 move (menu->current - menu->top + menu->offset, 0);
385 @@ -1075,6 +1085,7 @@
386 menu->redraw = REDRAW_FULL;
389 + case OP_SIDEBAR_OPEN:
390 case OP_MAIN_CHANGE_FOLDER:
391 case OP_MAIN_NEXT_UNREAD_MAILBOX:
393 @@ -1106,7 +1117,11 @@
395 mutt_buffy (buf, sizeof (buf));
397 - if (mutt_enter_fname (cp, buf, sizeof (buf), &menu->redraw, 1) == -1)
398 + if ( op == OP_SIDEBAR_OPEN ) {
401 + strncpy( buf, CurBuffy->path, sizeof(buf) );
402 + } else if (mutt_enter_fname (cp, buf, sizeof (buf), &menu->redraw, 1) == -1)
404 if (menu->menu == MENU_PAGER)
406 @@ -1124,6 +1139,7 @@
409 mutt_expand_path (buf, sizeof (buf));
411 if (mx_get_magic (buf) <= 0)
413 mutt_error (_("%s is not a mailbox."), buf);
414 @@ -2216,6 +2232,12 @@
418 + case OP_SIDEBAR_SCROLL_UP:
419 + case OP_SIDEBAR_SCROLL_DOWN:
420 + case OP_SIDEBAR_NEXT:
421 + case OP_SIDEBAR_PREV:
422 + scroll_sidebar(op, menu->menu);
425 if (menu->menu == MENU_MAIN)
426 km_error_key (MENU_MAIN);
432 #include "mutt_curses.h"
433 +#include "mutt_menu.h"
436 +#include "sidebar.h"
438 void _mutt_set_flag (CONTEXT *ctx, HEADER *h, int flag, int bf, int upd_ctx)
442 if (h->searched && (changed != h->changed || deleted != ctx->deleted || tagged != ctx->tagged || flagged != ctx->flagged))
447 void mutt_tag_set_flag (int flag, int bf)
451 { "decrypt-save", OP_DECRYPT_SAVE, NULL },
454 + { "sidebar-scroll-up", OP_SIDEBAR_SCROLL_UP, NULL },
455 + { "sidebar-scroll-down", OP_SIDEBAR_SCROLL_DOWN, NULL },
456 + { "sidebar-next", OP_SIDEBAR_NEXT, NULL },
457 + { "sidebar-prev", OP_SIDEBAR_PREV, NULL },
458 + { "sidebar-open", OP_SIDEBAR_OPEN, NULL },
464 { "what-key", OP_WHAT_KEY, NULL },
466 + { "sidebar-scroll-up", OP_SIDEBAR_SCROLL_UP, NULL },
467 + { "sidebar-scroll-down", OP_SIDEBAR_SCROLL_DOWN, NULL },
468 + { "sidebar-next", OP_SIDEBAR_NEXT, NULL },
469 + { "sidebar-prev", OP_SIDEBAR_PREV, NULL },
470 + { "sidebar-open", OP_SIDEBAR_OPEN, NULL },
477 WHERE char *SendCharset;
478 WHERE char *Sendmail;
480 +WHERE char *SidebarDelim;
481 WHERE char *Signature;
482 WHERE char *SimpleSearch;
485 WHERE short ScoreThresholdRead;
486 WHERE short ScoreThresholdFlag;
488 +WHERE struct buffy_t *CurBuffy INITVAL(0);
489 +WHERE short DrawFullLine INITVAL(0);
490 +WHERE short SidebarWidth;
492 WHERE short ImapKeepalive;
493 WHERE short ImapPipelineDepth;
496 @@ -1963,6 +1963,22 @@
500 + {"sidebar_delim", DT_STR, R_BOTH, UL &SidebarDelim, "|"},
503 + ** This specifies the delimiter between the sidebar (if visible) and
506 + { "sidebar_visible", DT_BOOL, R_BOTH, OPTSIDEBAR, 0 },
509 + ** This specifies whether or not to show sidebar (left-side list of folders).
511 + { "sidebar_width", DT_NUM, R_BOTH, UL &SidebarWidth, 0 },
514 + ** The width of the sidebar.
516 { "pgp_use_gpg_agent", DT_BOOL, R_NONE, OPTUSEGPGAGENT, 0},
522 #define M_NEWFOLDER (1<<4) /* create a new folder - same as M_APPEND, but uses
523 * safe_fopen() for mbox-style folders.
525 +#define M_PEEK (1<<5) /* revert atime back after taking a look (if applicable) */
527 /* mx_open_new_message() */
528 #define M_ADD_FROM 1 /* add a From_ line */
532 score.c send.c sendlib.c signal.c sort.c \
533 status.c system.c thread.c charset.c history.c lib.c \
534 muttlib.c editmsg.c mbyte.c \
535 - url.c ascii.c crypt-mod.c crypt-mod.h
536 + url.c ascii.c crypt-mod.c crypt-mod.h \
539 nodist_mutt_SOURCES = $(BUILT_SOURCES)
544 mutt_perror (ctx->path);
547 + ctx->atime = sb.st_atime;
548 ctx->mtime = sb.st_mtime;
549 ctx->size = sb.st_size;
553 ctx->size = sb.st_size;
554 ctx->mtime = sb.st_mtime;
555 + ctx->atime = sb.st_atime;
557 #ifdef NFS_ATTRIBUTE_HACK
558 if (sb.st_mtime > sb.st_atime)
562 #include "mutt_curses.h"
563 #include "mutt_menu.h"
565 +#include "sidebar.h"
571 char *scratch = safe_strdup (s);
572 int shift = option (OPTARROWCURSOR) ? 3 : 0;
573 - int cols = COLS - shift;
574 + int cols = COLS - shift - SidebarWidth;
576 mutt_format_string (s, n, cols, cols, FMT_LEFT, ' ', scratch, mutt_strlen (scratch), 1);
579 char buf[LONG_STRING];
583 for (i = menu->top; i < menu->top + menu->pagelen; i++)
587 if (option (OPTARROWCURSOR))
589 attrset (menu->color (i));
590 - CLEARLINE (i - menu->top + menu->offset);
591 + CLEARLINE_WIN (i - menu->top + menu->offset);
593 if (i == menu->current)
595 @@ -246,14 +248,14 @@
596 BKGDSET (MT_COLOR_INDICATOR);
599 - CLEARLINE (i - menu->top + menu->offset);
600 + CLEARLINE_WIN (i - menu->top + menu->offset);
601 print_enriched_string (menu->color(i), (unsigned char *) buf, i != menu->current);
602 SETCOLOR (MT_COLOR_NORMAL);
603 BKGDSET (MT_COLOR_NORMAL);
607 - CLEARLINE (i - menu->top + menu->offset);
608 + CLEARLINE_WIN (i - menu->top + menu->offset);
616 - move (menu->oldcurrent + menu->offset - menu->top, 0);
617 + move (menu->oldcurrent + menu->offset - menu->top, SidebarWidth);
618 SETCOLOR (MT_COLOR_NORMAL);
619 BKGDSET (MT_COLOR_NORMAL);
621 @@ -283,13 +285,13 @@
623 menu_make_entry (buf, sizeof (buf), menu, menu->oldcurrent);
624 menu_pad_string (buf, sizeof (buf));
625 - move (menu->oldcurrent + menu->offset - menu->top, 3);
626 + move (menu->oldcurrent + menu->offset - menu->top, SidebarWidth + 3);
627 print_enriched_string (menu->color(menu->oldcurrent), (unsigned char *) buf, 1);
628 SETCOLOR (MT_COLOR_NORMAL);
631 /* now draw it in the new location */
632 - move (menu->current + menu->offset - menu->top, 0);
633 + move (menu->current + menu->offset - menu->top, SidebarWidth);
634 attrset (menu->color (menu->current));
635 ADDCOLOR (MT_COLOR_INDICATOR);
638 attrset (menu->color (menu->current));
639 ADDCOLOR (MT_COLOR_INDICATOR);
640 BKGDSET (MT_COLOR_INDICATOR);
641 - CLEARLINE (menu->current - menu->top + menu->offset);
642 + CLEARLINE_WIN (menu->current - menu->top + menu->offset);
643 print_enriched_string (menu->color(menu->current), (unsigned char *) buf, 0);
644 SETCOLOR (MT_COLOR_NORMAL);
645 BKGDSET (MT_COLOR_NORMAL);
648 char buf[LONG_STRING];
650 - move (menu->current + menu->offset - menu->top, 0);
651 + move (menu->current + menu->offset - menu->top, SidebarWidth);
652 menu_make_entry (buf, sizeof (buf), menu, menu->current);
653 menu_pad_string (buf, sizeof (buf));
658 if (option (OPTARROWCURSOR))
659 - move (menu->current - menu->top + menu->offset, 2);
660 + move (menu->current - menu->top + menu->offset, SidebarWidth + 2);
661 else if (option (OPTBRAILLEFRIENDLY))
662 move (menu->current - menu->top + menu->offset, 0);
670 +#define CLEARLINE_WIN(x) move(x,SidebarWidth), clrtoeol()
671 #define CLEARLINE(x) move(x,0), clrtoeol()
672 #define CENTERLINE(x,y) move(y, (COLS-strlen(x))/2), addstr(x)
673 #define BEEP() do { if (option (OPTBEEP)) beep(); } while (0)
702 unsigned int quiet : 1; /* inhibit status messages? */
703 unsigned int collapsed : 1; /* are all threads collapsed? */
704 unsigned int closing : 1; /* mailbox is being closed */
705 + unsigned int peekonly : 1; /* just taking a glance, revert atime */
708 void *data; /* driver specific data */
711 @@ -1232,6 +1232,8 @@
714 /* see if there's room to add content, else ignore */
715 + if ( DrawFullLine )
717 if ((col < COLS && wlen < destlen) || soft)
720 @@ -1274,6 +1276,52 @@
727 + if ((col < COLS-SidebarWidth && wlen < destlen) || soft)
731 + /* get contents after padding */
732 + mutt_FormatString (buf, sizeof (buf), 0, src + pl, callback, data, flags);
733 + len = mutt_strlen (buf);
734 + wid = mutt_strwidth (buf);
736 + /* try to consume as many columns as we can, if we don't have
737 + * memory for that, use as much memory as possible */
738 + pad = (COLS - SidebarWidth - col - wid) / pw;
739 + if (pad > 0 && wlen + (pad * pl) + len > destlen)
740 + pad = ((signed)(destlen - wlen - len)) / pl;
745 + memcpy (wptr, src, pl);
751 + else if (soft && pad < 0)
753 + /* \0-terminate dest for length computation in mutt_wstr_trunc() */
755 + /* make sure right part is at most as wide as display */
756 + len = mutt_wstr_trunc (buf, destlen, COLS, &wid);
757 + /* truncate left so that right part fits completely in */
758 + wlen = mutt_wstr_trunc (dest, destlen - len, col + pad, &col);
759 + wptr = dest + wlen;
761 + if (len + wlen > destlen)
762 + len = mutt_wstr_trunc (buf, destlen - wlen, COLS - SidebarWidth - col, NULL);
763 + memcpy (wptr, buf, len);
770 break; /* skip rest of input */
776 * M_APPEND open mailbox for appending
777 * M_READONLY open mailbox in read-only mode
778 * M_QUIET only print error messages
779 + * M_PEEK revert atime where applicable
780 * ctx if non-null, context struct to use
782 CONTEXT *mx_open_mailbox (const char *path, int flags, CONTEXT *pctx)
785 if (flags & M_READONLY)
787 + if (flags & M_PEEK)
790 if (flags & (M_APPEND|M_NEWFOLDER))
793 void mx_fastclose_mailbox (CONTEXT *ctx)
803 + /* fix up the times so buffy won't get confused */
804 + if (ctx->peekonly && ctx->path && ctx->mtime > ctx->atime)
806 + ut.actime = ctx->atime;
807 + ut.modtime = ctx->mtime;
808 + utime (ctx->path, &ut);
817 OP_MAIN_SHOW_LIMIT "show currently active limit pattern"
818 OP_MAIN_COLLAPSE_THREAD "collapse/uncollapse current thread"
819 OP_MAIN_COLLAPSE_ALL "collapse/uncollapse all threads"
820 +OP_SIDEBAR_SCROLL_UP "scroll the mailbox pane up 1 page"
821 +OP_SIDEBAR_SCROLL_DOWN "scroll the mailbox pane down 1 page"
822 +OP_SIDEBAR_NEXT "go down to next mailbox"
823 +OP_SIDEBAR_PREV "go to previous mailbox"
824 +OP_SIDEBAR_OPEN "open hilighted mailbox"
831 +#include "sidebar.h"
833 #include "mutt_crypt.h"
835 @@ -1071,6 +1072,8 @@
838 int wrap_cols = mutt_term_width ((flags & M_PAGER_NOWRAP) ? 0 : Wrap);
840 + wrap_cols -= SidebarWidth;
842 /* FIXME: this should come from lineInfo */
843 memset(&mbstate, 0, sizeof(mbstate));
844 @@ -1717,7 +1720,7 @@
845 if ((redraw & REDRAW_BODY) || topline != oldtopline)
848 - move (bodyoffset, 0);
849 + move (bodyoffset, SidebarWidth);
850 curline = oldtopline = topline;
853 @@ -1730,6 +1733,7 @@
854 &QuoteList, &q_level, &force_redraw, &SearchRE) > 0)
857 + move(lines + bodyoffset, SidebarWidth);
859 last_offset = lineInfo[curline].offset;
860 } while (force_redraw);
861 @@ -1743,6 +1747,7 @@
865 + move(lines + bodyoffset, SidebarWidth);
867 /* We are going to update the pager status bar, so it isn't
868 * necessary to reset to normal color now. */
869 @@ -1766,11 +1771,11 @@
870 /* print out the pager status bar */
871 SETCOLOR (MT_COLOR_STATUS);
872 BKGDSET (MT_COLOR_STATUS);
873 - CLEARLINE (statusoffset);
874 + CLEARLINE_WIN (statusoffset);
876 if (IsHeader (extra) || IsMsgAttach (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 = (IsHeader (extra)) ? extra->hdr : extra->bdy->hdr;
882 mutt_make_string_info (buffer, l1 < l2 ? l1 : l2, NONULL (PagerFmt), &hfi, M_FORMAT_MAKEPRINT);
883 @@ -1780,7 +1785,7 @@
886 snprintf (bn, sizeof (bn), "%s (%s)", banner, pager_progress_str);
887 - mutt_paddstr (COLS, bn);
888 + mutt_paddstr (COLS, IsHeader (extra) || IsMsgAttach (extra) ? buffer : banner);
890 BKGDSET (MT_COLOR_NORMAL);
891 SETCOLOR (MT_COLOR_NORMAL);
892 @@ -1798,18 +1803,23 @@
893 /* redraw the pager_index indicator, because the
894 * flags for this message might have changed. */
895 menu_redraw_current (index);
896 + draw_sidebar(MENU_PAGER);
898 /* print out the index status bar */
899 menu_status_line (buffer, sizeof (buffer), index, NONULL(Status));
901 - move (indexoffset + (option (OPTSTATUSONTOP) ? 0 : (indexlen - 1)), 0);
902 + move (indexoffset + (option (OPTSTATUSONTOP) ? 0 : (indexlen - 1)), SidebarWidth);
903 SETCOLOR (MT_COLOR_STATUS);
904 BKGDSET (MT_COLOR_STATUS);
905 - mutt_paddstr (COLS, buffer);
906 + mutt_paddstr (COLS-SidebarWidth, buffer);
907 SETCOLOR (MT_COLOR_NORMAL);
908 BKGDSET (MT_COLOR_NORMAL);
911 + /* if we're not using the index, update every time */
913 + draw_sidebar(MENU_PAGER);
917 if (option(OPTBRAILLEFRIENDLY)) {
918 @@ -2742,6 +2752,13 @@
922 + case OP_SIDEBAR_SCROLL_UP:
923 + case OP_SIDEBAR_SCROLL_DOWN:
924 + case OP_SIDEBAR_NEXT:
925 + case OP_SIDEBAR_PREV:
926 + scroll_sidebar(ch, MENU_PAGER);
936 + * Copyright (C) ????-2004 Justin Hibbits <jrh29@po.cwru.edu>
937 + * Copyright (C) 2004 Thomer M. Gil <mutt@thomer.com>
939 + * This program is free software; you can redistribute it and/or modify
940 + * it under the terms of the GNU General Public License as published by
941 + * the Free Software Foundation; either version 2 of the License, or
942 + * (at your option) any later version.
944 + * This program is distributed in the hope that it will be useful,
945 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
946 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
947 + * GNU General Public License for more details.
949 + * You should have received a copy of the GNU General Public License
950 + * along with this program; if not, write to the Free Software
951 + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
956 +# include "config.h"
960 +#include "mutt_menu.h"
961 +#include "mutt_curses.h"
962 +#include "sidebar.h"
966 +#include <stdbool.h>
968 +/*BUFFY *CurBuffy = 0;*/
969 +static BUFFY *TopBuffy = 0;
970 +static BUFFY *BottomBuffy = 0;
971 +static int known_lines = 0;
973 +static int quick_log10(int n)
976 + sprintf(string, "%d", n);
977 + return strlen(string);
980 +void calc_boundaries (int menu)
982 + BUFFY *tmp = Incoming;
984 + if ( known_lines != LINES ) {
985 + TopBuffy = BottomBuffy = 0;
986 + known_lines = LINES;
988 + for ( ; tmp->next != 0; tmp = tmp->next )
989 + tmp->next->prev = tmp;
991 + if ( TopBuffy == 0 && BottomBuffy == 0 )
992 + TopBuffy = Incoming;
993 + if ( BottomBuffy == 0 ) {
994 + int count = LINES - 2 - (menu != MENU_PAGER || option(OPTSTATUSONTOP));
995 + BottomBuffy = TopBuffy;
996 + while ( --count && BottomBuffy->next )
997 + BottomBuffy = BottomBuffy->next;
999 + else if ( TopBuffy == CurBuffy->next ) {
1000 + int count = LINES - 2 - (menu != MENU_PAGER);
1001 + BottomBuffy = CurBuffy;
1002 + tmp = BottomBuffy;
1003 + while ( --count && tmp->prev)
1007 + else if ( BottomBuffy == CurBuffy->prev ) {
1008 + int count = LINES - 2 - (menu != MENU_PAGER);
1009 + TopBuffy = CurBuffy;
1011 + while ( --count && tmp->next )
1013 + BottomBuffy = tmp;
1017 +char *make_sidebar_entry(char *box, int size, int new, int flagged)
1019 + static char *entry = 0;
1022 + int delim_len = strlen(SidebarDelim);
1024 + c = realloc(entry, SidebarWidth - delim_len + 2);
1025 + if ( c ) entry = c;
1026 + entry[SidebarWidth - delim_len + 1] = 0;
1027 + for (; i < SidebarWidth - delim_len + 1; entry[i++] = ' ' );
1029 + strncpy( entry, box, i < (SidebarWidth - delim_len + 1) ? i : (SidebarWidth - delim_len + 1) );
1032 + sprintf(entry + SidebarWidth - delim_len - 3, "?");
1034 + if (flagged > 0) {
1036 + entry + SidebarWidth - delim_len - 5 - quick_log10(size) - quick_log10(new) - quick_log10(flagged),
1037 + "% d(%d)[%d]", size, new, flagged);
1040 + entry + SidebarWidth - delim_len - 3 - quick_log10(size) - quick_log10(new),
1041 + "% d(%d)", size, new);
1043 + } else if (flagged > 0) {
1044 + sprintf( entry + SidebarWidth - delim_len - 3 - quick_log10(size) - quick_log10(flagged), "% d[%d]", size, flagged);
1046 + sprintf( entry + SidebarWidth - delim_len - 1 - quick_log10(size), "% d", size);
1051 +void set_curbuffy(char buf[LONG_STRING])
1053 + BUFFY* tmp = CurBuffy = Incoming;
1059 + if(!strcmp(tmp->path, buf)) {
1071 +int draw_sidebar(int menu) {
1073 + int lines = option(OPTHELP) ? 1 : 0;
1075 +#ifndef USE_SLANG_CURSES
1078 + short delim_len = strlen(SidebarDelim);
1081 + static bool initialized = false;
1082 + static int prev_show_value;
1083 + static short saveSidebarWidth;
1085 + /* initialize first time */
1086 + if(!initialized) {
1087 + prev_show_value = option(OPTSIDEBAR);
1088 + saveSidebarWidth = SidebarWidth;
1089 + if(!option(OPTSIDEBAR)) SidebarWidth = 0;
1090 + initialized = true;
1093 + /* save or restore the value SidebarWidth */
1094 + if(prev_show_value != option(OPTSIDEBAR)) {
1095 + if(prev_show_value && !option(OPTSIDEBAR)) {
1096 + saveSidebarWidth = SidebarWidth;
1098 + } else if(!prev_show_value && option(OPTSIDEBAR)) {
1099 + SidebarWidth = saveSidebarWidth;
1101 + prev_show_value = option(OPTSIDEBAR);
1105 +// if ( SidebarWidth == 0 ) return 0;
1106 + if (SidebarWidth > 0 && option (OPTSIDEBAR)
1107 + && delim_len >= SidebarWidth) {
1108 + unset_option (OPTSIDEBAR);
1109 + /* saveSidebarWidth = SidebarWidth; */
1110 + if (saveSidebarWidth > delim_len) {
1111 + SidebarWidth = saveSidebarWidth;
1112 + mutt_error (_("Value for sidebar_delim is too long. Disabling sidebar."));
1116 + mutt_error (_("Value for sidebar_delim is too long. Disabling sidebar. Please set your sidebar_width to a sane value."));
1117 + sleep (4); /* the advise to set a sane value should be seen long enough */
1119 + saveSidebarWidth = 0;
1123 + if ( SidebarWidth == 0 || !option(OPTSIDEBAR)) {
1124 + if (SidebarWidth > 0) {
1125 + saveSidebarWidth = SidebarWidth;
1128 + unset_option(OPTSIDEBAR);
1132 + /* get attributes for divider */
1133 + SETCOLOR(MT_COLOR_STATUS);
1134 +#ifndef USE_SLANG_CURSES
1135 + attr_get(&attrs, &color_pair, 0);
1137 + color_pair = attr_get();
1139 + SETCOLOR(MT_COLOR_NORMAL);
1141 + /* draw the divider */
1143 + for ( ; lines < LINES-1-(menu != MENU_PAGER || option(OPTSTATUSONTOP)); lines++ ) {
1144 + move(lines, SidebarWidth - delim_len);
1145 + addstr(NONULL(SidebarDelim));
1146 +#ifndef USE_SLANG_CURSES
1147 + mvchgat(lines, SidebarWidth - delim_len, delim_len, 0, color_pair, NULL);
1151 + if ( Incoming == 0 ) return 0;
1152 + lines = option(OPTHELP) ? 1 : 0; /* go back to the top */
1154 + if ( known_lines != LINES || TopBuffy == 0 || BottomBuffy == 0 )
1155 + calc_boundaries(menu);
1156 + if ( CurBuffy == 0 ) CurBuffy = Incoming;
1160 + SETCOLOR(MT_COLOR_NORMAL);
1162 + for ( ; tmp && lines < LINES-1 - (menu != MENU_PAGER || option(OPTSTATUSONTOP)); tmp = tmp->next ) {
1163 + if ( tmp == CurBuffy )
1164 + SETCOLOR(MT_COLOR_INDICATOR);
1165 + else if ( tmp->msg_unread > 0 )
1166 + SETCOLOR(MT_COLOR_NEW);
1167 + else if ( tmp->msg_flagged > 0 )
1168 + SETCOLOR(MT_COLOR_FLAGGED);
1170 + SETCOLOR(MT_COLOR_NORMAL);
1173 + if ( Context && !strcmp( tmp->path, Context->path ) ) {
1174 + tmp->msg_unread = Context->unread;
1175 + tmp->msgcount = Context->msgcount;
1176 + tmp->msg_flagged = Context->flagged;
1178 + // check whether Maildir is a prefix of the current folder's path
1179 + short maildir_is_prefix = 0;
1180 + if ( (strlen(tmp->path) > strlen(Maildir)) &&
1181 + (strncmp(Maildir, tmp->path, strlen(Maildir)) == 0) )
1182 + maildir_is_prefix = 1;
1183 + // calculate depth of current folder and generate its display name with indented spaces
1184 + int sidebar_folder_depth = 0;
1185 + char *sidebar_folder_name;
1186 + sidebar_folder_name = basename(tmp->path);
1187 + if ( maildir_is_prefix ) {
1188 + char *tmp_folder_name;
1190 + tmp_folder_name = tmp->path + strlen(Maildir);
1191 + for (i = 0; i < strlen(tmp->path) - strlen(Maildir); i++) {
1192 + if (tmp_folder_name[i] == '/') sidebar_folder_depth++;
1194 + if (sidebar_folder_depth > 0) {
1195 + sidebar_folder_name = malloc(strlen(basename(tmp->path)) + sidebar_folder_depth + 1);
1196 + for (i=0; i < sidebar_folder_depth; i++)
1197 + sidebar_folder_name[i]=' ';
1198 + sidebar_folder_name[i]=0;
1199 + strncat(sidebar_folder_name, basename(tmp->path), strlen(basename(tmp->path)) + sidebar_folder_depth);
1202 + printw( "%.*s", SidebarWidth - delim_len + 1,
1203 + make_sidebar_entry(sidebar_folder_name, tmp->msgcount,
1204 + tmp->msg_unread, tmp->msg_flagged));
1205 + if (sidebar_folder_depth > 0)
1206 + free(sidebar_folder_name);
1209 + SETCOLOR(MT_COLOR_NORMAL);
1210 + for ( ; lines < LINES-1 - (menu != MENU_PAGER || option(OPTSTATUSONTOP)); lines++ ) {
1213 + for ( ; i < SidebarWidth - delim_len; i++ )
1220 +void set_buffystats(CONTEXT* Context)
1222 + BUFFY *tmp = Incoming;
1224 + if(Context && !strcmp(tmp->path, Context->path)) {
1225 + tmp->msg_unread = Context->unread;
1226 + tmp->msgcount = Context->msgcount;
1233 +void scroll_sidebar(int op, int menu)
1235 + if(!SidebarWidth) return;
1236 + if(!CurBuffy) return;
1239 + case OP_SIDEBAR_NEXT:
1240 + if ( CurBuffy->next == NULL ) return;
1241 + CurBuffy = CurBuffy->next;
1243 + case OP_SIDEBAR_PREV:
1244 + if ( CurBuffy->prev == NULL ) return;
1245 + CurBuffy = CurBuffy->prev;
1247 + case OP_SIDEBAR_SCROLL_UP:
1248 + CurBuffy = TopBuffy;
1249 + if ( CurBuffy != Incoming ) {
1250 + calc_boundaries(menu);
1251 + CurBuffy = CurBuffy->prev;
1254 + case OP_SIDEBAR_SCROLL_DOWN:
1255 + CurBuffy = BottomBuffy;
1256 + if ( CurBuffy->next ) {
1257 + calc_boundaries(menu);
1258 + CurBuffy = CurBuffy->next;
1264 + calc_boundaries(menu);
1265 + draw_sidebar(menu);
1272 + * Copyright (C) ????-2004 Justin Hibbits <jrh29@po.cwru.edu>
1273 + * Copyright (C) 2004 Thomer M. Gil <mutt@thomer.com>
1275 + * This program is free software; you can redistribute it and/or modify
1276 + * it under the terms of the GNU General Public License as published by
1277 + * the Free Software Foundation; either version 2 of the License, or
1278 + * (at your option) any later version.
1280 + * This program is distributed in the hope that it will be useful,
1281 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1282 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1283 + * GNU General Public License for more details.
1285 + * You should have received a copy of the GNU General Public License
1286 + * along with this program; if not, write to the Free Software
1287 + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
1299 +/* parameter is whether or not to go to the status line */
1300 +/* used for omitting the last | that covers up the status bar in the index */
1301 +int draw_sidebar(int);
1302 +void scroll_sidebar(int, int);
1303 +void set_curbuffy(char*);
1304 +void set_buffystats(CONTEXT*);
1306 +#endif /* SIDEBAR_H */
1309 @@ -657,6 +657,26 @@
1310 # $crypt_autosign, $crypt_replysign and $smime_is_default.
1313 +# set sidebar_visible=no
1315 +# Name: sidebar_visible
1320 +# This specifies whether or not to show sidebar (left-side list of folders).
1323 +# set sidebar_width=0
1325 +# Name: sidebar_width
1330 +# The width of the sidebar.
1333 # set crypt_autosign=no
1335 # Name: crypt_autosign
1338 @@ -1521,7 +1521,7 @@
1340 imap_munge_mbox_name (munged, sizeof (munged), name);
1341 snprintf (command, sizeof (command),
1342 - "STATUS %s (UIDNEXT UIDVALIDITY UNSEEN RECENT)", munged);
1343 + "STATUS %s (UIDNEXT UIDVALIDITY UNSEEN RECENT MESSAGES)", munged);
1345 if (imap_exec (idata, command, IMAP_CMD_QUEUE) < 0)
1347 --- a/imap/command.c
1348 +++ b/imap/command.c
1349 @@ -1009,6 +1009,13 @@
1351 status->uidnext = oldun;
1353 + /* Added to make the sidebar show the correct numbers */
1354 + if (status->messages)
1356 + inc->msgcount = status->messages;
1357 + inc->msg_unread = status->unseen;