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).
38 + mailbox->msgcount = 0;
39 + mailbox->msg_unread = 0;
40 + mailbox->msg_flagged = 0;
42 while ((de = readdir (dirp)) != NULL)
44 if (*de->d_name == '.')
48 /* one new and undeleted message is enough */
50 + mailbox->has_new = mailbox->new = 1;
51 + mailbox->msgcount++;
52 + mailbox->msg_unread++;
61 + * count read messages (for folderlist (sidebar) we also need to count
62 + * messages in cur so that we the total number of messages
64 + snprintf (path, sizeof (path), "%s/cur", mailbox->path);
65 + if ((dirp = opendir (path)) == NULL)
69 + while ((de = readdir (dirp)) != NULL)
72 + if (*de->d_name != '.') {
73 + if ((p = strstr (de->d_name, ":2,"))) {
74 + if (!strchr (p + 3, 'T')) {
75 + mailbox->msgcount++;
76 + if ( !strchr (p + 3, 'S'))
77 + mailbox->msg_unread++;
78 + if (strchr(p + 3, 'F'))
79 + mailbox->msg_flagged++;
82 + mailbox->msgcount++;
97 if (option (OPTCHECKMBOXSIZE))
98 statcheck = sb->st_size > mailbox->size;
100 statcheck = sb->st_mtime > sb->st_atime
101 || (mailbox->newly_created && sb->st_ctime == sb->st_mtime && sb->st_ctime == sb->st_atime);
103 + if (statcheck || mailbox->msgcount == 0)
105 + BUFFY b = *mailbox;
107 + int msg_unread = 0;
108 + /* parse the mailbox, to see how much mail there is */
109 + ctx = mx_open_mailbox( mailbox->path, M_READONLY | M_QUIET | M_NOSORT | M_PEEK, NULL);
112 + msgcount = ctx->msgcount;
113 + msg_unread = ctx->unread;
114 + mx_close_mailbox(ctx, 0);
117 + mailbox->msgcount = msgcount;
118 + mailbox->msg_unread = msg_unread;
121 + mailbox->has_new = mailbox->new = 1;
123 if (!option(OPTMAILCHECKRECENT) || sb->st_mtime > mailbox->last_visited)
127 int mutt_buffy_check (int force)
130 + struct dirent *de, *dp;
132 struct stat contex_sb;
140 if ((tmp->new = mh_buffy (tmp->path)) > 0)
143 + if ((dp = opendir (tmp->path)) == NULL)
146 + while ((de = readdir (dp)))
148 + if (mh_valid_message (de->d_name))
151 + tmp->has_new = tmp->new = 1;
162 char path[_POSIX_PATH_MAX];
164 struct buffy_t *next;
165 + struct buffy_t *prev;
166 short new; /* mailbox has new mail */
167 + short has_new; /* set it new if new and not read */
168 + int msgcount; /* total number of messages */
169 + int msg_unread; /* number of unread messages */
170 + int msg_flagged; /* number of flagged messages */
171 short notified; /* user has been notified */
172 short magic; /* mailbox type */
173 short newly_created; /* mbox or mmdf just popped into existence */
177 { "bold", MT_COLOR_BOLD },
178 { "underline", MT_COLOR_UNDERLINE },
179 { "index", MT_COLOR_INDEX },
180 + { "sidebar_new", MT_COLOR_NEW },
181 + { "sidebar_flagged", MT_COLOR_FLAGGED },
189 #define HDR_XOFFSET 10
190 #define TITLE_FMT "%10s" /* Used for Prompts, which are ASCII */
191 -#define W (COLS - HDR_XOFFSET)
192 +#define W (COLS - HDR_XOFFSET - SidebarWidth)
194 static char *Prompts[] =
200 - mvaddstr (HDR_CRYPT, 0, "Security: ");
201 + mvaddstr (HDR_CRYPT, SidebarWidth, "Security: ");
203 if ((WithCrypto & (APPLICATION_PGP | APPLICATION_SMIME)) == 0)
209 - move (HDR_CRYPTINFO, 0);
210 + move (HDR_CRYPTINFO, SidebarWidth);
213 if ((WithCrypto & APPLICATION_PGP)
215 && (msg->security & ENCRYPT)
218 - mvprintw (HDR_CRYPTINFO, 40, "%s%s", _("Encrypt with: "),
219 + mvprintw (HDR_CRYPTINFO, SidebarWidth + 40, "%s%s", _("Encrypt with: "),
220 NONULL(SmimeCryptAlg));
227 - mvaddstr (HDR_MIX, 0, " Mix: ");
228 + mvaddstr (HDR_MIX, SidebarWidth, " Mix: ");
233 if (t && t[0] == '0' && t[1] == '\0')
236 - if (c + mutt_strlen (t) + 2 >= COLS)
237 + if (c + mutt_strlen (t) + 2 >= COLS - SidebarWidth)
244 rfc822_write_address (buf, sizeof (buf), addr, 1);
245 - mvprintw (line, 0, TITLE_FMT, Prompts[line - 1]);
246 + mvprintw (line, SidebarWidth, TITLE_FMT, Prompts[line - 1]);
247 mutt_paddstr (W, buf);
250 @@ -252,10 +252,10 @@
251 draw_envelope_addr (HDR_TO, msg->env->to);
252 draw_envelope_addr (HDR_CC, msg->env->cc);
253 draw_envelope_addr (HDR_BCC, msg->env->bcc);
254 - mvprintw (HDR_SUBJECT, 0, TITLE_FMT, Prompts[HDR_SUBJECT - 1]);
255 + mvprintw (HDR_SUBJECT, SidebarWidth, TITLE_FMT, Prompts[HDR_SUBJECT - 1]);
256 mutt_paddstr (W, NONULL (msg->env->subject));
257 draw_envelope_addr (HDR_REPLYTO, msg->env->reply_to);
258 - mvprintw (HDR_FCC, 0, TITLE_FMT, Prompts[HDR_FCC - 1]);
259 + mvprintw (HDR_FCC, SidebarWidth, TITLE_FMT, Prompts[HDR_FCC - 1]);
260 mutt_paddstr (W, fcc);
266 SETCOLOR (MT_COLOR_STATUS);
267 - mvaddstr (HDR_ATTACH - 1, 0, _("-- Attachments"));
268 + mvaddstr (HDR_ATTACH - 1, SidebarWidth, _("-- Attachments"));
269 BKGDSET (MT_COLOR_STATUS);
273 /* redraw the expanded list so the user can see the result */
275 rfc822_write_address (buf, sizeof (buf), *addr, 1);
276 - move (line, HDR_XOFFSET);
277 + move (line, HDR_XOFFSET+SidebarWidth);
278 mutt_paddstr (W, buf);
282 if (mutt_get_field ("Subject: ", buf, sizeof (buf), 0) == 0)
284 mutt_str_replace (&msg->env->subject, buf);
285 - move (HDR_SUBJECT, HDR_XOFFSET);
286 + move (HDR_SUBJECT, HDR_XOFFSET + SidebarWidth);
288 if (msg->env->subject)
289 mutt_paddstr (W, msg->env->subject);
292 strfcpy (fcc, buf, fcclen);
293 mutt_pretty_mailbox (fcc, fcclen);
294 - move (HDR_FCC, HDR_XOFFSET);
295 + move (HDR_FCC, HDR_XOFFSET + SidebarWidth);
296 mutt_paddstr (W, fcc);
307 +#include "sidebar.h"
312 menu->redraw |= REDRAW_STATUS;
315 - if (mutt_buffy_notify () && option (OPTBEEPNEW))
317 + if (mutt_buffy_notify ())
319 + menu->redraw |= REDRAW_FULL;
320 + if (option (OPTBEEPNEW))
327 if (menu->redraw & REDRAW_FULL)
329 menu_redraw_full (menu);
330 + draw_sidebar(menu->menu);
334 @@ -567,10 +574,13 @@
336 if (menu->redraw & REDRAW_STATUS)
339 menu_status_line (buf, sizeof (buf), menu, NONULL (Status));
341 CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES-2);
342 SETCOLOR (MT_COLOR_STATUS);
343 BKGDSET (MT_COLOR_STATUS);
344 + set_buffystats(Context);
345 mutt_paddstr (COLS, buf);
346 SETCOLOR (MT_COLOR_NORMAL);
347 BKGDSET (MT_COLOR_NORMAL);
349 menu->oldcurrent = -1;
351 if (option (OPTARROWCURSOR))
352 - move (menu->current - menu->top + menu->offset, 2);
353 + move (menu->current - menu->top + menu->offset, SidebarWidth + 2);
354 else if (option (OPTBRAILLEFRIENDLY))
355 move (menu->current - menu->top + menu->offset, 0);
357 @@ -1089,6 +1099,7 @@
358 menu->redraw = REDRAW_FULL;
361 + case OP_SIDEBAR_OPEN:
362 case OP_MAIN_CHANGE_FOLDER:
363 case OP_MAIN_NEXT_UNREAD_MAILBOX:
365 @@ -1120,7 +1131,11 @@
367 mutt_buffy (buf, sizeof (buf));
369 - if (mutt_enter_fname (cp, buf, sizeof (buf), &menu->redraw, 1) == -1)
370 + if ( op == OP_SIDEBAR_OPEN ) {
373 + strncpy( buf, CurBuffy->path, sizeof(buf) );
374 + } else if (mutt_enter_fname (cp, buf, sizeof (buf), &menu->redraw, 1) == -1)
376 if (menu->menu == MENU_PAGER)
378 @@ -1138,6 +1153,7 @@
381 mutt_expand_path (buf, sizeof (buf));
383 if (mx_get_magic (buf) <= 0)
385 mutt_error (_("%s is not a mailbox."), buf);
386 @@ -2241,6 +2257,12 @@
390 + case OP_SIDEBAR_SCROLL_UP:
391 + case OP_SIDEBAR_SCROLL_DOWN:
392 + case OP_SIDEBAR_NEXT:
393 + case OP_SIDEBAR_PREV:
394 + scroll_sidebar(op, menu->menu);
397 if (menu->menu == MENU_MAIN)
398 km_error_key (MENU_MAIN);
404 #include "mutt_curses.h"
405 +#include "mutt_menu.h"
408 +#include "sidebar.h"
410 void _mutt_set_flag (CONTEXT *ctx, HEADER *h, int flag, int bf, int upd_ctx)
414 if (h->searched && (changed != h->changed || deleted != ctx->deleted || tagged != ctx->tagged || flagged != ctx->flagged))
419 void mutt_tag_set_flag (int flag, int bf)
423 { "decrypt-save", OP_DECRYPT_SAVE, NULL },
426 + { "sidebar-scroll-up", OP_SIDEBAR_SCROLL_UP, NULL },
427 + { "sidebar-scroll-down", OP_SIDEBAR_SCROLL_DOWN, NULL },
428 + { "sidebar-next", OP_SIDEBAR_NEXT, NULL },
429 + { "sidebar-prev", OP_SIDEBAR_PREV, NULL },
430 + { "sidebar-open", OP_SIDEBAR_OPEN, NULL },
436 { "what-key", OP_WHAT_KEY, NULL },
438 + { "sidebar-scroll-up", OP_SIDEBAR_SCROLL_UP, NULL },
439 + { "sidebar-scroll-down", OP_SIDEBAR_SCROLL_DOWN, NULL },
440 + { "sidebar-next", OP_SIDEBAR_NEXT, NULL },
441 + { "sidebar-prev", OP_SIDEBAR_PREV, NULL },
442 + { "sidebar-open", OP_SIDEBAR_OPEN, NULL },
449 WHERE char *SendCharset;
450 WHERE char *Sendmail;
452 +WHERE char *SidebarDelim;
453 WHERE char *Signature;
454 WHERE char *SimpleSearch;
457 WHERE short ScoreThresholdRead;
458 WHERE short ScoreThresholdFlag;
460 +WHERE struct buffy_t *CurBuffy INITVAL(0);
461 +WHERE short DrawFullLine INITVAL(0);
462 +WHERE short SidebarWidth;
464 WHERE short ImapKeepalive;
465 WHERE short ImapPipelineDepth;
468 @@ -1965,6 +1965,22 @@
472 + {"sidebar_delim", DT_STR, R_BOTH, UL &SidebarDelim, "|"},
475 + ** This specifies the delimiter between the sidebar (if visible) and
478 + { "sidebar_visible", DT_BOOL, R_BOTH, OPTSIDEBAR, 0 },
481 + ** This specifies whether or not to show sidebar (left-side list of folders).
483 + { "sidebar_width", DT_NUM, R_BOTH, UL &SidebarWidth, 0 },
486 + ** The width of the sidebar.
488 { "pgp_use_gpg_agent", DT_BOOL, R_NONE, OPTUSEGPGAGENT, 0},
494 #define M_NEWFOLDER (1<<4) /* create a new folder - same as M_APPEND, but uses
495 * safe_fopen() for mbox-style folders.
497 +#define M_PEEK (1<<5) /* revert atime back after taking a look (if applicable) */
499 /* mx_open_new_message() */
500 #define M_ADD_FROM 1 /* add a From_ line */
504 score.c send.c sendlib.c signal.c sort.c \
505 status.c system.c thread.c charset.c history.c lib.c \
506 muttlib.c editmsg.c mbyte.c \
507 - url.c ascii.c crypt-mod.c crypt-mod.h safe_asprintf.c
508 + url.c ascii.c crypt-mod.c crypt-mod.h safe_asprintf.c \
511 nodist_mutt_SOURCES = $(BUILT_SOURCES)
516 mutt_perror (ctx->path);
519 + ctx->atime = sb.st_atime;
520 ctx->mtime = sb.st_mtime;
521 ctx->size = sb.st_size;
525 ctx->size = sb.st_size;
526 ctx->mtime = sb.st_mtime;
527 + ctx->atime = sb.st_atime;
529 #ifdef NFS_ATTRIBUTE_HACK
530 if (sb.st_mtime > sb.st_atime)
534 #include "mutt_curses.h"
535 #include "mutt_menu.h"
537 +#include "sidebar.h"
543 char *scratch = safe_strdup (s);
544 int shift = option (OPTARROWCURSOR) ? 3 : 0;
545 - int cols = COLS - shift;
546 + int cols = COLS - shift - SidebarWidth;
548 mutt_format_string (s, n, cols, cols, FMT_LEFT, ' ', scratch, mutt_strlen (scratch), 1);
551 char buf[LONG_STRING];
555 for (i = menu->top; i < menu->top + menu->pagelen; i++)
559 if (option (OPTARROWCURSOR))
561 attrset (menu->color (i));
562 - CLEARLINE (i - menu->top + menu->offset);
563 + CLEARLINE_WIN (i - menu->top + menu->offset);
565 if (i == menu->current)
567 @@ -246,14 +248,14 @@
568 BKGDSET (MT_COLOR_INDICATOR);
571 - CLEARLINE (i - menu->top + menu->offset);
572 + CLEARLINE_WIN (i - menu->top + menu->offset);
573 print_enriched_string (menu->color(i), (unsigned char *) buf, i != menu->current);
574 SETCOLOR (MT_COLOR_NORMAL);
575 BKGDSET (MT_COLOR_NORMAL);
579 - CLEARLINE (i - menu->top + menu->offset);
580 + CLEARLINE_WIN (i - menu->top + menu->offset);
588 - move (menu->oldcurrent + menu->offset - menu->top, 0);
589 + move (menu->oldcurrent + menu->offset - menu->top, SidebarWidth);
590 SETCOLOR (MT_COLOR_NORMAL);
591 BKGDSET (MT_COLOR_NORMAL);
593 @@ -283,13 +285,13 @@
595 menu_make_entry (buf, sizeof (buf), menu, menu->oldcurrent);
596 menu_pad_string (buf, sizeof (buf));
597 - move (menu->oldcurrent + menu->offset - menu->top, 3);
598 + move (menu->oldcurrent + menu->offset - menu->top, SidebarWidth + 3);
599 print_enriched_string (menu->color(menu->oldcurrent), (unsigned char *) buf, 1);
600 SETCOLOR (MT_COLOR_NORMAL);
603 /* now draw it in the new location */
604 - move (menu->current + menu->offset - menu->top, 0);
605 + move (menu->current + menu->offset - menu->top, SidebarWidth);
606 attrset (menu->color (menu->current));
607 ADDCOLOR (MT_COLOR_INDICATOR);
610 attrset (menu->color (menu->current));
611 ADDCOLOR (MT_COLOR_INDICATOR);
612 BKGDSET (MT_COLOR_INDICATOR);
613 - CLEARLINE (menu->current - menu->top + menu->offset);
614 + CLEARLINE_WIN (menu->current - menu->top + menu->offset);
615 print_enriched_string (menu->color(menu->current), (unsigned char *) buf, 0);
616 SETCOLOR (MT_COLOR_NORMAL);
617 BKGDSET (MT_COLOR_NORMAL);
620 char buf[LONG_STRING];
622 - move (menu->current + menu->offset - menu->top, 0);
623 + move (menu->current + menu->offset - menu->top, SidebarWidth);
624 menu_make_entry (buf, sizeof (buf), menu, menu->current);
625 menu_pad_string (buf, sizeof (buf));
630 if (option (OPTARROWCURSOR))
631 - move (menu->current - menu->top + menu->offset, 2);
632 + move (menu->current - menu->top + menu->offset, SidebarWidth + 2);
633 else if (option (OPTBRAILLEFRIENDLY))
634 move (menu->current - menu->top + menu->offset, 0);
642 +#define CLEARLINE_WIN(x) move(x,SidebarWidth), clrtoeol()
643 #define CLEARLINE(x) move(x,0), clrtoeol()
644 #define CENTERLINE(x,y) move(y, (COLS-strlen(x))/2), addstr(x)
645 #define BEEP() do { if (option (OPTBEEP)) beep(); } while (0)
674 unsigned int quiet : 1; /* inhibit status messages? */
675 unsigned int collapsed : 1; /* are all threads collapsed? */
676 unsigned int closing : 1; /* mailbox is being closed */
677 + unsigned int peekonly : 1; /* just taking a glance, revert atime */
680 void *data; /* driver specific data */
683 @@ -1286,6 +1286,8 @@
686 /* see if there's room to add content, else ignore */
687 + if ( DrawFullLine )
689 if ((col < COLS && wlen < destlen) || soft)
692 @@ -1329,6 +1331,52 @@
699 + if ((col < COLS-SidebarWidth && wlen < destlen) || soft)
703 + /* get contents after padding */
704 + mutt_FormatString (buf, sizeof (buf), 0, src + pl, callback, data, flags);
705 + len = mutt_strlen (buf);
706 + wid = mutt_strwidth (buf);
708 + /* try to consume as many columns as we can, if we don't have
709 + * memory for that, use as much memory as possible */
710 + pad = (COLS - SidebarWidth - col - wid) / pw;
711 + if (pad > 0 && wlen + (pad * pl) + len > destlen)
712 + pad = ((signed)(destlen - wlen - len)) / pl;
717 + memcpy (wptr, src, pl);
723 + else if (soft && pad < 0)
725 + /* \0-terminate dest for length computation in mutt_wstr_trunc() */
727 + /* make sure right part is at most as wide as display */
728 + len = mutt_wstr_trunc (buf, destlen, COLS, &wid);
729 + /* truncate left so that right part fits completely in */
730 + wlen = mutt_wstr_trunc (dest, destlen - len, col + pad, &col);
731 + wptr = dest + wlen;
733 + if (len + wlen > destlen)
734 + len = mutt_wstr_trunc (buf, destlen - wlen, COLS - SidebarWidth - col, NULL);
735 + memcpy (wptr, buf, len);
742 break; /* skip rest of input */
748 * M_APPEND open mailbox for appending
749 * M_READONLY open mailbox in read-only mode
750 * M_QUIET only print error messages
751 + * M_PEEK revert atime where applicable
752 * ctx if non-null, context struct to use
754 CONTEXT *mx_open_mailbox (const char *path, int flags, CONTEXT *pctx)
757 if (flags & M_READONLY)
759 + if (flags & M_PEEK)
762 if (flags & (M_APPEND|M_NEWFOLDER))
765 void mx_fastclose_mailbox (CONTEXT *ctx)
775 + /* fix up the times so buffy won't get confused */
776 + if (ctx->peekonly && ctx->path && ctx->mtime > ctx->atime)
778 + ut.actime = ctx->atime;
779 + ut.modtime = ctx->mtime;
780 + utime (ctx->path, &ut);
784 /* never announce that a mailbox we've just left has new mail. #3290
785 * XXX: really belongs in mx_close_mailbox, but this is a nice hook point */
789 OP_MAIN_SHOW_LIMIT "show currently active limit pattern"
790 OP_MAIN_COLLAPSE_THREAD "collapse/uncollapse current thread"
791 OP_MAIN_COLLAPSE_ALL "collapse/uncollapse all threads"
792 +OP_SIDEBAR_SCROLL_UP "scroll the mailbox pane up 1 page"
793 +OP_SIDEBAR_SCROLL_DOWN "scroll the mailbox pane down 1 page"
794 +OP_SIDEBAR_NEXT "go down to next mailbox"
795 +OP_SIDEBAR_PREV "go to previous mailbox"
796 +OP_SIDEBAR_OPEN "open hilighted mailbox"
803 +#include "sidebar.h"
805 #include "mutt_crypt.h"
807 @@ -1099,6 +1100,7 @@
808 if (check_attachment_marker ((char *)buf) == 0)
811 + wrap_cols -= SidebarWidth;
812 /* FIXME: this should come from lineInfo */
813 memset(&mbstate, 0, sizeof(mbstate));
815 @@ -1745,7 +1747,7 @@
816 if ((redraw & REDRAW_BODY) || topline != oldtopline)
819 - move (bodyoffset, 0);
820 + move (bodyoffset, SidebarWidth);
821 curline = oldtopline = topline;
824 @@ -1758,6 +1760,7 @@
825 &QuoteList, &q_level, &force_redraw, &SearchRE) > 0)
828 + move(lines + bodyoffset, SidebarWidth);
830 last_offset = lineInfo[curline].offset;
831 } while (force_redraw);
832 @@ -1771,6 +1774,7 @@
836 + move(lines + bodyoffset, SidebarWidth);
838 /* We are going to update the pager status bar, so it isn't
839 * necessary to reset to normal color now. */
840 @@ -1794,11 +1798,11 @@
841 /* print out the pager status bar */
842 SETCOLOR (MT_COLOR_STATUS);
843 BKGDSET (MT_COLOR_STATUS);
844 - CLEARLINE (statusoffset);
845 + CLEARLINE_WIN (statusoffset);
847 if (IsHeader (extra) || IsMsgAttach (extra))
849 - size_t l1 = COLS * MB_LEN_MAX;
850 + size_t l1 = (COLS-SidebarWidth) * MB_LEN_MAX;
851 size_t l2 = sizeof (buffer);
852 hfi.hdr = (IsHeader (extra)) ? extra->hdr : extra->bdy->hdr;
853 mutt_make_string_info (buffer, l1 < l2 ? l1 : l2, NONULL (PagerFmt), &hfi, M_FORMAT_MAKEPRINT);
854 @@ -1808,7 +1812,7 @@
857 snprintf (bn, sizeof (bn), "%s (%s)", banner, pager_progress_str);
858 - mutt_paddstr (COLS, bn);
859 + mutt_paddstr (COLS, IsHeader (extra) || IsMsgAttach (extra) ? buffer : banner);
861 BKGDSET (MT_COLOR_NORMAL);
862 SETCOLOR (MT_COLOR_NORMAL);
863 @@ -1826,18 +1830,23 @@
864 /* redraw the pager_index indicator, because the
865 * flags for this message might have changed. */
866 menu_redraw_current (index);
867 + draw_sidebar(MENU_PAGER);
869 /* print out the index status bar */
870 menu_status_line (buffer, sizeof (buffer), index, NONULL(Status));
872 - move (indexoffset + (option (OPTSTATUSONTOP) ? 0 : (indexlen - 1)), 0);
873 + move (indexoffset + (option (OPTSTATUSONTOP) ? 0 : (indexlen - 1)), SidebarWidth);
874 SETCOLOR (MT_COLOR_STATUS);
875 BKGDSET (MT_COLOR_STATUS);
876 - mutt_paddstr (COLS, buffer);
877 + mutt_paddstr (COLS-SidebarWidth, buffer);
878 SETCOLOR (MT_COLOR_NORMAL);
879 BKGDSET (MT_COLOR_NORMAL);
882 + /* if we're not using the index, update every time */
884 + draw_sidebar(MENU_PAGER);
888 if (option(OPTBRAILLEFRIENDLY)) {
889 @@ -2769,6 +2778,13 @@
893 + case OP_SIDEBAR_SCROLL_UP:
894 + case OP_SIDEBAR_SCROLL_DOWN:
895 + case OP_SIDEBAR_NEXT:
896 + case OP_SIDEBAR_PREV:
897 + scroll_sidebar(ch, MENU_PAGER);
907 + * Copyright (C) ????-2004 Justin Hibbits <jrh29@po.cwru.edu>
908 + * Copyright (C) 2004 Thomer M. Gil <mutt@thomer.com>
910 + * This program is free software; you can redistribute it and/or modify
911 + * it under the terms of the GNU General Public License as published by
912 + * the Free Software Foundation; either version 2 of the License, or
913 + * (at your option) any later version.
915 + * This program is distributed in the hope that it will be useful,
916 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
917 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
918 + * GNU General Public License for more details.
920 + * You should have received a copy of the GNU General Public License
921 + * along with this program; if not, write to the Free Software
922 + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
927 +# include "config.h"
931 +#include "mutt_menu.h"
932 +#include "mutt_curses.h"
933 +#include "sidebar.h"
937 +#include <stdbool.h>
939 +/*BUFFY *CurBuffy = 0;*/
940 +static BUFFY *TopBuffy = 0;
941 +static BUFFY *BottomBuffy = 0;
942 +static int known_lines = 0;
944 +static int quick_log10(int n)
947 + sprintf(string, "%d", n);
948 + return strlen(string);
951 +void calc_boundaries (int menu)
953 + BUFFY *tmp = Incoming;
955 + if ( known_lines != LINES ) {
956 + TopBuffy = BottomBuffy = 0;
957 + known_lines = LINES;
959 + for ( ; tmp->next != 0; tmp = tmp->next )
960 + tmp->next->prev = tmp;
962 + if ( TopBuffy == 0 && BottomBuffy == 0 )
963 + TopBuffy = Incoming;
964 + if ( BottomBuffy == 0 ) {
965 + int count = LINES - 2 - (menu != MENU_PAGER || option(OPTSTATUSONTOP));
966 + BottomBuffy = TopBuffy;
967 + while ( --count && BottomBuffy->next )
968 + BottomBuffy = BottomBuffy->next;
970 + else if ( TopBuffy == CurBuffy->next ) {
971 + int count = LINES - 2 - (menu != MENU_PAGER);
972 + BottomBuffy = CurBuffy;
974 + while ( --count && tmp->prev)
978 + else if ( BottomBuffy == CurBuffy->prev ) {
979 + int count = LINES - 2 - (menu != MENU_PAGER);
980 + TopBuffy = CurBuffy;
982 + while ( --count && tmp->next )
988 +char *make_sidebar_entry(char *box, int size, int new, int flagged)
990 + static char *entry = 0;
993 + int delim_len = strlen(SidebarDelim);
995 + c = realloc(entry, SidebarWidth - delim_len + 2);
996 + if ( c ) entry = c;
997 + entry[SidebarWidth - delim_len + 1] = 0;
998 + for (; i < SidebarWidth - delim_len + 1; entry[i++] = ' ' );
1000 + strncpy( entry, box, i < (SidebarWidth - delim_len + 1) ? i : (SidebarWidth - delim_len + 1) );
1003 + sprintf(entry + SidebarWidth - delim_len - 3, "?");
1005 + if (flagged > 0) {
1007 + entry + SidebarWidth - delim_len - 5 - quick_log10(size) - quick_log10(new) - quick_log10(flagged),
1008 + "% d(%d)[%d]", size, new, flagged);
1011 + entry + SidebarWidth - delim_len - 3 - quick_log10(size) - quick_log10(new),
1012 + "% d(%d)", size, new);
1014 + } else if (flagged > 0) {
1015 + sprintf( entry + SidebarWidth - delim_len - 3 - quick_log10(size) - quick_log10(flagged), "% d[%d]", size, flagged);
1017 + sprintf( entry + SidebarWidth - delim_len - 1 - quick_log10(size), "% d", size);
1022 +void set_curbuffy(char buf[LONG_STRING])
1024 + BUFFY* tmp = CurBuffy = Incoming;
1030 + if(!strcmp(tmp->path, buf)) {
1042 +int draw_sidebar(int menu) {
1044 + int lines = option(OPTHELP) ? 1 : 0;
1046 +#ifndef USE_SLANG_CURSES
1049 + short delim_len = strlen(SidebarDelim);
1052 + static bool initialized = false;
1053 + static int prev_show_value;
1054 + static short saveSidebarWidth;
1056 + /* initialize first time */
1057 + if(!initialized) {
1058 + prev_show_value = option(OPTSIDEBAR);
1059 + saveSidebarWidth = SidebarWidth;
1060 + if(!option(OPTSIDEBAR)) SidebarWidth = 0;
1061 + initialized = true;
1064 + /* save or restore the value SidebarWidth */
1065 + if(prev_show_value != option(OPTSIDEBAR)) {
1066 + if(prev_show_value && !option(OPTSIDEBAR)) {
1067 + saveSidebarWidth = SidebarWidth;
1069 + } else if(!prev_show_value && option(OPTSIDEBAR)) {
1070 + SidebarWidth = saveSidebarWidth;
1072 + prev_show_value = option(OPTSIDEBAR);
1076 +// if ( SidebarWidth == 0 ) return 0;
1077 + if (SidebarWidth > 0 && option (OPTSIDEBAR)
1078 + && delim_len >= SidebarWidth) {
1079 + unset_option (OPTSIDEBAR);
1080 + /* saveSidebarWidth = SidebarWidth; */
1081 + if (saveSidebarWidth > delim_len) {
1082 + SidebarWidth = saveSidebarWidth;
1083 + mutt_error (_("Value for sidebar_delim is too long. Disabling sidebar."));
1087 + mutt_error (_("Value for sidebar_delim is too long. Disabling sidebar. Please set your sidebar_width to a sane value."));
1088 + sleep (4); /* the advise to set a sane value should be seen long enough */
1090 + saveSidebarWidth = 0;
1094 + if ( SidebarWidth == 0 || !option(OPTSIDEBAR)) {
1095 + if (SidebarWidth > 0) {
1096 + saveSidebarWidth = SidebarWidth;
1099 + unset_option(OPTSIDEBAR);
1103 + /* get attributes for divider */
1104 + SETCOLOR(MT_COLOR_STATUS);
1105 +#ifndef USE_SLANG_CURSES
1106 + attr_get(&attrs, &color_pair, 0);
1108 + color_pair = attr_get();
1110 + SETCOLOR(MT_COLOR_NORMAL);
1112 + /* draw the divider */
1114 + for ( ; lines < LINES-1-(menu != MENU_PAGER || option(OPTSTATUSONTOP)); lines++ ) {
1115 + move(lines, SidebarWidth - delim_len);
1116 + addstr(NONULL(SidebarDelim));
1117 +#ifndef USE_SLANG_CURSES
1118 + mvchgat(lines, SidebarWidth - delim_len, delim_len, 0, color_pair, NULL);
1122 + if ( Incoming == 0 ) return 0;
1123 + lines = option(OPTHELP) ? 1 : 0; /* go back to the top */
1125 + if ( known_lines != LINES || TopBuffy == 0 || BottomBuffy == 0 )
1126 + calc_boundaries(menu);
1127 + if ( CurBuffy == 0 ) CurBuffy = Incoming;
1131 + SETCOLOR(MT_COLOR_NORMAL);
1133 + for ( ; tmp && lines < LINES-1 - (menu != MENU_PAGER || option(OPTSTATUSONTOP)); tmp = tmp->next ) {
1134 + if ( tmp == CurBuffy )
1135 + SETCOLOR(MT_COLOR_INDICATOR);
1136 + else if ( tmp->msg_unread > 0 )
1137 + SETCOLOR(MT_COLOR_NEW);
1138 + else if ( tmp->msg_flagged > 0 )
1139 + SETCOLOR(MT_COLOR_FLAGGED);
1141 + SETCOLOR(MT_COLOR_NORMAL);
1144 + if ( Context && !strcmp( tmp->path, Context->path ) ) {
1145 + tmp->msg_unread = Context->unread;
1146 + tmp->msgcount = Context->msgcount;
1147 + tmp->msg_flagged = Context->flagged;
1149 + // check whether Maildir is a prefix of the current folder's path
1150 + short maildir_is_prefix = 0;
1151 + if ( (strlen(tmp->path) > strlen(Maildir)) &&
1152 + (strncmp(Maildir, tmp->path, strlen(Maildir)) == 0) )
1153 + maildir_is_prefix = 1;
1154 + // calculate depth of current folder and generate its display name with indented spaces
1155 + int sidebar_folder_depth = 0;
1156 + char *sidebar_folder_name;
1157 + sidebar_folder_name = basename(tmp->path);
1158 + if ( maildir_is_prefix ) {
1159 + char *tmp_folder_name;
1161 + tmp_folder_name = tmp->path + strlen(Maildir);
1162 + for (i = 0; i < strlen(tmp->path) - strlen(Maildir); i++) {
1163 + if (tmp_folder_name[i] == '/') sidebar_folder_depth++;
1165 + if (sidebar_folder_depth > 0) {
1166 + sidebar_folder_name = malloc(strlen(basename(tmp->path)) + sidebar_folder_depth + 1);
1167 + for (i=0; i < sidebar_folder_depth; i++)
1168 + sidebar_folder_name[i]=' ';
1169 + sidebar_folder_name[i]=0;
1170 + strncat(sidebar_folder_name, basename(tmp->path), strlen(basename(tmp->path)) + sidebar_folder_depth);
1173 + printw( "%.*s", SidebarWidth - delim_len + 1,
1174 + make_sidebar_entry(sidebar_folder_name, tmp->msgcount,
1175 + tmp->msg_unread, tmp->msg_flagged));
1176 + if (sidebar_folder_depth > 0)
1177 + free(sidebar_folder_name);
1180 + SETCOLOR(MT_COLOR_NORMAL);
1181 + for ( ; lines < LINES-1 - (menu != MENU_PAGER || option(OPTSTATUSONTOP)); lines++ ) {
1184 + for ( ; i < SidebarWidth - delim_len; i++ )
1191 +void set_buffystats(CONTEXT* Context)
1193 + BUFFY *tmp = Incoming;
1195 + if(Context && !strcmp(tmp->path, Context->path)) {
1196 + tmp->msg_unread = Context->unread;
1197 + tmp->msgcount = Context->msgcount;
1204 +void scroll_sidebar(int op, int menu)
1206 + if(!SidebarWidth) return;
1207 + if(!CurBuffy) return;
1210 + case OP_SIDEBAR_NEXT:
1211 + if ( CurBuffy->next == NULL ) return;
1212 + CurBuffy = CurBuffy->next;
1214 + case OP_SIDEBAR_PREV:
1215 + if ( CurBuffy->prev == NULL ) return;
1216 + CurBuffy = CurBuffy->prev;
1218 + case OP_SIDEBAR_SCROLL_UP:
1219 + CurBuffy = TopBuffy;
1220 + if ( CurBuffy != Incoming ) {
1221 + calc_boundaries(menu);
1222 + CurBuffy = CurBuffy->prev;
1225 + case OP_SIDEBAR_SCROLL_DOWN:
1226 + CurBuffy = BottomBuffy;
1227 + if ( CurBuffy->next ) {
1228 + calc_boundaries(menu);
1229 + CurBuffy = CurBuffy->next;
1235 + calc_boundaries(menu);
1236 + draw_sidebar(menu);
1243 + * Copyright (C) ????-2004 Justin Hibbits <jrh29@po.cwru.edu>
1244 + * Copyright (C) 2004 Thomer M. Gil <mutt@thomer.com>
1246 + * This program is free software; you can redistribute it and/or modify
1247 + * it under the terms of the GNU General Public License as published by
1248 + * the Free Software Foundation; either version 2 of the License, or
1249 + * (at your option) any later version.
1251 + * This program is distributed in the hope that it will be useful,
1252 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1253 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1254 + * GNU General Public License for more details.
1256 + * You should have received a copy of the GNU General Public License
1257 + * along with this program; if not, write to the Free Software
1258 + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
1270 +/* parameter is whether or not to go to the status line */
1271 +/* used for omitting the last | that covers up the status bar in the index */
1272 +int draw_sidebar(int);
1273 +void scroll_sidebar(int, int);
1274 +void set_curbuffy(char*);
1275 +void set_buffystats(CONTEXT*);
1277 +#endif /* SIDEBAR_H */
1280 @@ -657,6 +657,26 @@
1281 # $crypt_autosign, $crypt_replysign and $smime_is_default.
1284 +# set sidebar_visible=no
1286 +# Name: sidebar_visible
1291 +# This specifies whether or not to show sidebar (left-side list of folders).
1294 +# set sidebar_width=0
1296 +# Name: sidebar_width
1301 +# The width of the sidebar.
1304 # set crypt_autosign=no
1306 # Name: crypt_autosign
1309 @@ -1527,7 +1527,7 @@
1311 imap_munge_mbox_name (munged, sizeof (munged), name);
1312 snprintf (command, sizeof (command),
1313 - "STATUS %s (UIDNEXT UIDVALIDITY UNSEEN RECENT)", munged);
1314 + "STATUS %s (UIDNEXT UIDVALIDITY UNSEEN RECENT MESSAGES)", munged);
1316 if (imap_exec (idata, command, IMAP_CMD_QUEUE) < 0)
1318 --- a/imap/command.c
1319 +++ b/imap/command.c
1320 @@ -1011,6 +1011,13 @@
1322 status->uidnext = oldun;
1324 + /* Added to make the sidebar show the correct numbers */
1325 + if (status->messages)
1327 + inc->msgcount = status->messages;
1328 + inc->msg_unread = status->unseen;