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++;
95 if (option (OPTCHECKMBOXSIZE))
96 statcheck = sb->st_size > mailbox->size;
98 statcheck = sb->st_mtime > sb->st_atime
99 || (mailbox->newly_created && sb->st_ctime == sb->st_mtime && sb->st_ctime == sb->st_atime);
101 + if (statcheck || mailbox->msgcount == 0)
103 + BUFFY b = *mailbox;
105 + int msg_unread = 0;
106 + /* parse the mailbox, to see how much mail there is */
107 + ctx = mx_open_mailbox( mailbox->path, M_READONLY | M_QUIET | M_NOSORT | M_PEEK, NULL);
110 + msgcount = ctx->msgcount;
111 + msg_unread = ctx->unread;
112 + mx_close_mailbox(ctx, 0);
115 + mailbox->msgcount = msgcount;
116 + mailbox->msg_unread = msg_unread;
119 + mailbox->has_new = mailbox->new = 1;
121 if (!option(OPTMAILCHECKRECENT) || sb->st_mtime > mailbox->last_visited)
125 int mutt_buffy_check (int force)
128 + struct dirent *de, *dp;
130 struct stat contex_sb;
138 if ((tmp->new = mh_buffy (tmp->path)) > 0)
141 + if ((dp = opendir (tmp->path)) == NULL)
144 + while ((de = readdir (dp)))
146 + if (mh_valid_message (de->d_name))
149 + tmp->has_new = tmp->new = 1;
160 char path[_POSIX_PATH_MAX];
162 struct buffy_t *next;
163 + struct buffy_t *prev;
164 short new; /* mailbox has new mail */
165 + short has_new; /* set it new if new and not read */
166 + int msgcount; /* total number of messages */
167 + int msg_unread; /* number of unread messages */
168 + int msg_flagged; /* number of flagged messages */
169 short notified; /* user has been notified */
170 short magic; /* mailbox type */
171 short newly_created; /* mbox or mmdf just popped into existence */
175 { "bold", MT_COLOR_BOLD },
176 { "underline", MT_COLOR_UNDERLINE },
177 { "index", MT_COLOR_INDEX },
178 + { "sidebar_new", MT_COLOR_NEW },
179 + { "sidebar_flagged", MT_COLOR_FLAGGED },
187 #define HDR_XOFFSET 10
188 #define TITLE_FMT "%10s" /* Used for Prompts, which are ASCII */
189 -#define W (COLS - HDR_XOFFSET)
190 +#define W (COLS - HDR_XOFFSET - SidebarWidth)
192 static char *Prompts[] =
198 - mvaddstr (HDR_CRYPT, 0, "Security: ");
199 + mvaddstr (HDR_CRYPT, SidebarWidth, "Security: ");
201 if ((WithCrypto & (APPLICATION_PGP | APPLICATION_SMIME)) == 0)
207 - move (HDR_CRYPTINFO, 0);
208 + move (HDR_CRYPTINFO, SidebarWidth);
211 if ((WithCrypto & APPLICATION_PGP)
213 && (msg->security & ENCRYPT)
216 - mvprintw (HDR_CRYPTINFO, 40, "%s%s", _("Encrypt with: "),
217 + mvprintw (HDR_CRYPTINFO, SidebarWidth + 40, "%s%s", _("Encrypt with: "),
218 NONULL(SmimeCryptAlg));
225 - mvaddstr (HDR_MIX, 0, " Mix: ");
226 + mvaddstr (HDR_MIX, SidebarWidth, " Mix: ");
231 if (t && t[0] == '0' && t[1] == '\0')
234 - if (c + mutt_strlen (t) + 2 >= COLS)
235 + if (c + mutt_strlen (t) + 2 >= COLS - SidebarWidth)
242 rfc822_write_address (buf, sizeof (buf), addr, 1);
243 - mvprintw (line, 0, TITLE_FMT, Prompts[line - 1]);
244 + mvprintw (line, SidebarWidth, TITLE_FMT, Prompts[line - 1]);
245 mutt_paddstr (W, buf);
248 @@ -252,10 +252,10 @@
249 draw_envelope_addr (HDR_TO, msg->env->to);
250 draw_envelope_addr (HDR_CC, msg->env->cc);
251 draw_envelope_addr (HDR_BCC, msg->env->bcc);
252 - mvprintw (HDR_SUBJECT, 0, TITLE_FMT, Prompts[HDR_SUBJECT - 1]);
253 + mvprintw (HDR_SUBJECT, SidebarWidth, TITLE_FMT, Prompts[HDR_SUBJECT - 1]);
254 mutt_paddstr (W, NONULL (msg->env->subject));
255 draw_envelope_addr (HDR_REPLYTO, msg->env->reply_to);
256 - mvprintw (HDR_FCC, 0, TITLE_FMT, Prompts[HDR_FCC - 1]);
257 + mvprintw (HDR_FCC, SidebarWidth, TITLE_FMT, Prompts[HDR_FCC - 1]);
258 mutt_paddstr (W, fcc);
264 SETCOLOR (MT_COLOR_STATUS);
265 - mvaddstr (HDR_ATTACH - 1, 0, _("-- Attachments"));
266 + mvaddstr (HDR_ATTACH - 1, SidebarWidth, _("-- Attachments"));
267 BKGDSET (MT_COLOR_STATUS);
271 /* redraw the expanded list so the user can see the result */
273 rfc822_write_address (buf, sizeof (buf), *addr, 1);
274 - move (line, HDR_XOFFSET);
275 + move (line, HDR_XOFFSET+SidebarWidth);
276 mutt_paddstr (W, buf);
280 if (mutt_get_field ("Subject: ", buf, sizeof (buf), 0) == 0)
282 mutt_str_replace (&msg->env->subject, buf);
283 - move (HDR_SUBJECT, HDR_XOFFSET);
284 + move (HDR_SUBJECT, HDR_XOFFSET + SidebarWidth);
286 if (msg->env->subject)
287 mutt_paddstr (W, msg->env->subject);
290 strfcpy (fcc, buf, fcclen);
291 mutt_pretty_mailbox (fcc, fcclen);
292 - move (HDR_FCC, HDR_XOFFSET);
293 + move (HDR_FCC, HDR_XOFFSET + SidebarWidth);
294 mutt_paddstr (W, fcc);
305 +#include "sidebar.h"
310 menu->redraw |= REDRAW_STATUS;
313 - if (mutt_buffy_notify () && option (OPTBEEPNEW))
315 + if (mutt_buffy_notify ())
317 + menu->redraw |= REDRAW_FULL;
318 + if (option (OPTBEEPNEW))
325 if (menu->redraw & REDRAW_FULL)
327 menu_redraw_full (menu);
328 + draw_sidebar(menu->menu);
332 @@ -567,10 +574,13 @@
334 if (menu->redraw & REDRAW_STATUS)
337 menu_status_line (buf, sizeof (buf), menu, NONULL (Status));
339 CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES-2);
340 SETCOLOR (MT_COLOR_STATUS);
341 BKGDSET (MT_COLOR_STATUS);
342 + set_buffystats(Context);
343 mutt_paddstr (COLS, buf);
344 SETCOLOR (MT_COLOR_NORMAL);
345 BKGDSET (MT_COLOR_NORMAL);
347 menu->oldcurrent = -1;
349 if (option (OPTARROWCURSOR))
350 - move (menu->current - menu->top + menu->offset, 2);
351 + move (menu->current - menu->top + menu->offset, SidebarWidth + 2);
352 else if (option (OPTBRAILLEFRIENDLY))
353 move (menu->current - menu->top + menu->offset, 0);
355 @@ -1089,6 +1099,7 @@
356 menu->redraw = REDRAW_FULL;
359 + case OP_SIDEBAR_OPEN:
360 case OP_MAIN_CHANGE_FOLDER:
361 case OP_MAIN_NEXT_UNREAD_MAILBOX:
363 @@ -1120,7 +1131,11 @@
365 mutt_buffy (buf, sizeof (buf));
367 - if (mutt_enter_fname (cp, buf, sizeof (buf), &menu->redraw, 1) == -1)
368 + if ( op == OP_SIDEBAR_OPEN ) {
371 + strncpy( buf, CurBuffy->path, sizeof(buf) );
372 + } else if (mutt_enter_fname (cp, buf, sizeof (buf), &menu->redraw, 1) == -1)
374 if (menu->menu == MENU_PAGER)
376 @@ -1138,6 +1153,7 @@
379 mutt_expand_path (buf, sizeof (buf));
381 if (mx_get_magic (buf) <= 0)
383 mutt_error (_("%s is not a mailbox."), buf);
384 @@ -2241,6 +2257,12 @@
388 + case OP_SIDEBAR_SCROLL_UP:
389 + case OP_SIDEBAR_SCROLL_DOWN:
390 + case OP_SIDEBAR_NEXT:
391 + case OP_SIDEBAR_PREV:
392 + scroll_sidebar(op, menu->menu);
395 if (menu->menu == MENU_MAIN)
396 km_error_key (MENU_MAIN);
402 #include "mutt_curses.h"
403 +#include "mutt_menu.h"
406 +#include "sidebar.h"
408 void _mutt_set_flag (CONTEXT *ctx, HEADER *h, int flag, int bf, int upd_ctx)
412 if (h->searched && (changed != h->changed || deleted != ctx->deleted || tagged != ctx->tagged || flagged != ctx->flagged))
417 void mutt_tag_set_flag (int flag, int bf)
421 { "decrypt-save", OP_DECRYPT_SAVE, NULL },
424 + { "sidebar-scroll-up", OP_SIDEBAR_SCROLL_UP, NULL },
425 + { "sidebar-scroll-down", OP_SIDEBAR_SCROLL_DOWN, NULL },
426 + { "sidebar-next", OP_SIDEBAR_NEXT, NULL },
427 + { "sidebar-prev", OP_SIDEBAR_PREV, NULL },
428 + { "sidebar-open", OP_SIDEBAR_OPEN, NULL },
434 { "what-key", OP_WHAT_KEY, NULL },
436 + { "sidebar-scroll-up", OP_SIDEBAR_SCROLL_UP, NULL },
437 + { "sidebar-scroll-down", OP_SIDEBAR_SCROLL_DOWN, NULL },
438 + { "sidebar-next", OP_SIDEBAR_NEXT, NULL },
439 + { "sidebar-prev", OP_SIDEBAR_PREV, NULL },
440 + { "sidebar-open", OP_SIDEBAR_OPEN, NULL },
447 WHERE char *SendCharset;
448 WHERE char *Sendmail;
450 +WHERE char *SidebarDelim;
451 WHERE char *Signature;
452 WHERE char *SimpleSearch;
455 WHERE short ScoreThresholdRead;
456 WHERE short ScoreThresholdFlag;
458 +WHERE struct buffy_t *CurBuffy INITVAL(0);
459 +WHERE short DrawFullLine INITVAL(0);
460 +WHERE short SidebarWidth;
462 WHERE short ImapKeepalive;
463 WHERE short ImapPipelineDepth;
466 @@ -1965,6 +1965,22 @@
470 + {"sidebar_delim", DT_STR, R_BOTH, UL &SidebarDelim, "|"},
473 + ** This specifies the delimiter between the sidebar (if visible) and
476 + { "sidebar_visible", DT_BOOL, R_BOTH, OPTSIDEBAR, 0 },
479 + ** This specifies whether or not to show sidebar (left-side list of folders).
481 + { "sidebar_width", DT_NUM, R_BOTH, UL &SidebarWidth, 0 },
484 + ** The width of the sidebar.
486 { "pgp_use_gpg_agent", DT_BOOL, R_NONE, OPTUSEGPGAGENT, 0},
492 #define M_NEWFOLDER (1<<4) /* create a new folder - same as M_APPEND, but uses
493 * safe_fopen() for mbox-style folders.
495 +#define M_PEEK (1<<5) /* revert atime back after taking a look (if applicable) */
497 /* mx_open_new_message() */
498 #define M_ADD_FROM 1 /* add a From_ line */
502 score.c send.c sendlib.c signal.c sort.c \
503 status.c system.c thread.c charset.c history.c lib.c \
504 muttlib.c editmsg.c mbyte.c \
505 - url.c ascii.c crypt-mod.c crypt-mod.h safe_asprintf.c
506 + url.c ascii.c crypt-mod.c crypt-mod.h safe_asprintf.c \
509 nodist_mutt_SOURCES = $(BUILT_SOURCES)
514 mutt_perror (ctx->path);
517 + ctx->atime = sb.st_atime;
518 ctx->mtime = sb.st_mtime;
519 ctx->size = sb.st_size;
523 ctx->size = sb.st_size;
524 ctx->mtime = sb.st_mtime;
525 + ctx->atime = sb.st_atime;
527 #ifdef NFS_ATTRIBUTE_HACK
528 if (sb.st_mtime > sb.st_atime)
532 #include "mutt_curses.h"
533 #include "mutt_menu.h"
535 +#include "sidebar.h"
541 char *scratch = safe_strdup (s);
542 int shift = option (OPTARROWCURSOR) ? 3 : 0;
543 - int cols = COLS - shift;
544 + int cols = COLS - shift - SidebarWidth;
546 mutt_format_string (s, n, cols, cols, FMT_LEFT, ' ', scratch, mutt_strlen (scratch), 1);
549 char buf[LONG_STRING];
553 for (i = menu->top; i < menu->top + menu->pagelen; i++)
557 if (option (OPTARROWCURSOR))
559 attrset (menu->color (i));
560 - CLEARLINE (i - menu->top + menu->offset);
561 + CLEARLINE_WIN (i - menu->top + menu->offset);
563 if (i == menu->current)
565 @@ -246,14 +248,14 @@
566 BKGDSET (MT_COLOR_INDICATOR);
569 - CLEARLINE (i - menu->top + menu->offset);
570 + CLEARLINE_WIN (i - menu->top + menu->offset);
571 print_enriched_string (menu->color(i), (unsigned char *) buf, i != menu->current);
572 SETCOLOR (MT_COLOR_NORMAL);
573 BKGDSET (MT_COLOR_NORMAL);
577 - CLEARLINE (i - menu->top + menu->offset);
578 + CLEARLINE_WIN (i - menu->top + menu->offset);
586 - move (menu->oldcurrent + menu->offset - menu->top, 0);
587 + move (menu->oldcurrent + menu->offset - menu->top, SidebarWidth);
588 SETCOLOR (MT_COLOR_NORMAL);
589 BKGDSET (MT_COLOR_NORMAL);
591 @@ -283,13 +285,13 @@
593 menu_make_entry (buf, sizeof (buf), menu, menu->oldcurrent);
594 menu_pad_string (buf, sizeof (buf));
595 - move (menu->oldcurrent + menu->offset - menu->top, 3);
596 + move (menu->oldcurrent + menu->offset - menu->top, SidebarWidth + 3);
597 print_enriched_string (menu->color(menu->oldcurrent), (unsigned char *) buf, 1);
598 SETCOLOR (MT_COLOR_NORMAL);
601 /* now draw it in the new location */
602 - move (menu->current + menu->offset - menu->top, 0);
603 + move (menu->current + menu->offset - menu->top, SidebarWidth);
604 attrset (menu->color (menu->current));
605 ADDCOLOR (MT_COLOR_INDICATOR);
608 attrset (menu->color (menu->current));
609 ADDCOLOR (MT_COLOR_INDICATOR);
610 BKGDSET (MT_COLOR_INDICATOR);
611 - CLEARLINE (menu->current - menu->top + menu->offset);
612 + CLEARLINE_WIN (menu->current - menu->top + menu->offset);
613 print_enriched_string (menu->color(menu->current), (unsigned char *) buf, 0);
614 SETCOLOR (MT_COLOR_NORMAL);
615 BKGDSET (MT_COLOR_NORMAL);
618 char buf[LONG_STRING];
620 - move (menu->current + menu->offset - menu->top, 0);
621 + move (menu->current + menu->offset - menu->top, SidebarWidth);
622 menu_make_entry (buf, sizeof (buf), menu, menu->current);
623 menu_pad_string (buf, sizeof (buf));
628 if (option (OPTARROWCURSOR))
629 - move (menu->current - menu->top + menu->offset, 2);
630 + move (menu->current - menu->top + menu->offset, SidebarWidth + 2);
631 else if (option (OPTBRAILLEFRIENDLY))
632 move (menu->current - menu->top + menu->offset, 0);
640 +#define CLEARLINE_WIN(x) move(x,SidebarWidth), clrtoeol()
641 #define CLEARLINE(x) move(x,0), clrtoeol()
642 #define CENTERLINE(x,y) move(y, (COLS-strlen(x))/2), addstr(x)
643 #define BEEP() do { if (option (OPTBEEP)) beep(); } while (0)
672 unsigned int quiet : 1; /* inhibit status messages? */
673 unsigned int collapsed : 1; /* are all threads collapsed? */
674 unsigned int closing : 1; /* mailbox is being closed */
675 + unsigned int peekonly : 1; /* just taking a glance, revert atime */
678 void *data; /* driver specific data */
681 @@ -1286,6 +1286,8 @@
684 /* see if there's room to add content, else ignore */
685 + if ( DrawFullLine )
687 if ((col < COLS && wlen < destlen) || soft)
690 @@ -1329,6 +1331,52 @@
697 + if ((col < COLS-SidebarWidth && wlen < destlen) || soft)
701 + /* get contents after padding */
702 + mutt_FormatString (buf, sizeof (buf), 0, src + pl, callback, data, flags);
703 + len = mutt_strlen (buf);
704 + wid = mutt_strwidth (buf);
706 + /* try to consume as many columns as we can, if we don't have
707 + * memory for that, use as much memory as possible */
708 + pad = (COLS - SidebarWidth - col - wid) / pw;
709 + if (pad > 0 && wlen + (pad * pl) + len > destlen)
710 + pad = ((signed)(destlen - wlen - len)) / pl;
715 + memcpy (wptr, src, pl);
721 + else if (soft && pad < 0)
723 + /* \0-terminate dest for length computation in mutt_wstr_trunc() */
725 + /* make sure right part is at most as wide as display */
726 + len = mutt_wstr_trunc (buf, destlen, COLS, &wid);
727 + /* truncate left so that right part fits completely in */
728 + wlen = mutt_wstr_trunc (dest, destlen - len, col + pad, &col);
729 + wptr = dest + wlen;
731 + if (len + wlen > destlen)
732 + len = mutt_wstr_trunc (buf, destlen - wlen, COLS - SidebarWidth - col, NULL);
733 + memcpy (wptr, buf, len);
740 break; /* skip rest of input */
746 * M_APPEND open mailbox for appending
747 * M_READONLY open mailbox in read-only mode
748 * M_QUIET only print error messages
749 + * M_PEEK revert atime where applicable
750 * ctx if non-null, context struct to use
752 CONTEXT *mx_open_mailbox (const char *path, int flags, CONTEXT *pctx)
755 if (flags & M_READONLY)
757 + if (flags & M_PEEK)
760 if (flags & (M_APPEND|M_NEWFOLDER))
763 void mx_fastclose_mailbox (CONTEXT *ctx)
773 + /* fix up the times so buffy won't get confused */
774 + if (ctx->peekonly && ctx->path && ctx->mtime > ctx->atime)
776 + ut.actime = ctx->atime;
777 + ut.modtime = ctx->mtime;
778 + utime (ctx->path, &ut);
782 /* never announce that a mailbox we've just left has new mail. #3290
783 * XXX: really belongs in mx_close_mailbox, but this is a nice hook point */
787 OP_MAIN_SHOW_LIMIT "show currently active limit pattern"
788 OP_MAIN_COLLAPSE_THREAD "collapse/uncollapse current thread"
789 OP_MAIN_COLLAPSE_ALL "collapse/uncollapse all threads"
790 +OP_SIDEBAR_SCROLL_UP "scroll the mailbox pane up 1 page"
791 +OP_SIDEBAR_SCROLL_DOWN "scroll the mailbox pane down 1 page"
792 +OP_SIDEBAR_NEXT "go down to next mailbox"
793 +OP_SIDEBAR_PREV "go to previous mailbox"
794 +OP_SIDEBAR_OPEN "open hilighted mailbox"
801 +#include "sidebar.h"
803 #include "mutt_crypt.h"
805 @@ -1099,6 +1100,7 @@
806 if (check_attachment_marker ((char *)buf) == 0)
809 + wrap_cols -= SidebarWidth;
810 /* FIXME: this should come from lineInfo */
811 memset(&mbstate, 0, sizeof(mbstate));
813 @@ -1745,7 +1747,7 @@
814 if ((redraw & REDRAW_BODY) || topline != oldtopline)
817 - move (bodyoffset, 0);
818 + move (bodyoffset, SidebarWidth);
819 curline = oldtopline = topline;
822 @@ -1758,6 +1760,7 @@
823 &QuoteList, &q_level, &force_redraw, &SearchRE) > 0)
826 + move(lines + bodyoffset, SidebarWidth);
828 last_offset = lineInfo[curline].offset;
829 } while (force_redraw);
830 @@ -1771,6 +1774,7 @@
834 + move(lines + bodyoffset, SidebarWidth);
836 /* We are going to update the pager status bar, so it isn't
837 * necessary to reset to normal color now. */
838 @@ -1794,11 +1798,11 @@
839 /* print out the pager status bar */
840 SETCOLOR (MT_COLOR_STATUS);
841 BKGDSET (MT_COLOR_STATUS);
842 - CLEARLINE (statusoffset);
843 + CLEARLINE_WIN (statusoffset);
845 if (IsHeader (extra) || IsMsgAttach (extra))
847 - size_t l1 = COLS * MB_LEN_MAX;
848 + size_t l1 = (COLS-SidebarWidth) * MB_LEN_MAX;
849 size_t l2 = sizeof (buffer);
850 hfi.hdr = (IsHeader (extra)) ? extra->hdr : extra->bdy->hdr;
851 mutt_make_string_info (buffer, l1 < l2 ? l1 : l2, NONULL (PagerFmt), &hfi, M_FORMAT_MAKEPRINT);
852 @@ -1808,7 +1812,7 @@
855 snprintf (bn, sizeof (bn), "%s (%s)", banner, pager_progress_str);
856 - mutt_paddstr (COLS, bn);
857 + mutt_paddstr (COLS, IsHeader (extra) || IsMsgAttach (extra) ? buffer : banner);
859 BKGDSET (MT_COLOR_NORMAL);
860 SETCOLOR (MT_COLOR_NORMAL);
861 @@ -1826,18 +1830,23 @@
862 /* redraw the pager_index indicator, because the
863 * flags for this message might have changed. */
864 menu_redraw_current (index);
865 + draw_sidebar(MENU_PAGER);
867 /* print out the index status bar */
868 menu_status_line (buffer, sizeof (buffer), index, NONULL(Status));
870 - move (indexoffset + (option (OPTSTATUSONTOP) ? 0 : (indexlen - 1)), 0);
871 + move (indexoffset + (option (OPTSTATUSONTOP) ? 0 : (indexlen - 1)), SidebarWidth);
872 SETCOLOR (MT_COLOR_STATUS);
873 BKGDSET (MT_COLOR_STATUS);
874 - mutt_paddstr (COLS, buffer);
875 + mutt_paddstr (COLS-SidebarWidth, buffer);
876 SETCOLOR (MT_COLOR_NORMAL);
877 BKGDSET (MT_COLOR_NORMAL);
880 + /* if we're not using the index, update every time */
882 + draw_sidebar(MENU_PAGER);
886 if (option(OPTBRAILLEFRIENDLY)) {
887 @@ -2769,6 +2778,13 @@
891 + case OP_SIDEBAR_SCROLL_UP:
892 + case OP_SIDEBAR_SCROLL_DOWN:
893 + case OP_SIDEBAR_NEXT:
894 + case OP_SIDEBAR_PREV:
895 + scroll_sidebar(ch, MENU_PAGER);
905 + * Copyright (C) ????-2004 Justin Hibbits <jrh29@po.cwru.edu>
906 + * Copyright (C) 2004 Thomer M. Gil <mutt@thomer.com>
908 + * This program is free software; you can redistribute it and/or modify
909 + * it under the terms of the GNU General Public License as published by
910 + * the Free Software Foundation; either version 2 of the License, or
911 + * (at your option) any later version.
913 + * This program is distributed in the hope that it will be useful,
914 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
915 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
916 + * GNU General Public License for more details.
918 + * You should have received a copy of the GNU General Public License
919 + * along with this program; if not, write to the Free Software
920 + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
925 +# include "config.h"
929 +#include "mutt_menu.h"
930 +#include "mutt_curses.h"
931 +#include "sidebar.h"
935 +#include <stdbool.h>
937 +/*BUFFY *CurBuffy = 0;*/
938 +static BUFFY *TopBuffy = 0;
939 +static BUFFY *BottomBuffy = 0;
940 +static int known_lines = 0;
942 +static int quick_log10(int n)
945 + sprintf(string, "%d", n);
946 + return strlen(string);
949 +void calc_boundaries (int menu)
951 + BUFFY *tmp = Incoming;
953 + if ( known_lines != LINES ) {
954 + TopBuffy = BottomBuffy = 0;
955 + known_lines = LINES;
957 + for ( ; tmp->next != 0; tmp = tmp->next )
958 + tmp->next->prev = tmp;
960 + if ( TopBuffy == 0 && BottomBuffy == 0 )
961 + TopBuffy = Incoming;
962 + if ( BottomBuffy == 0 ) {
963 + int count = LINES - 2 - (menu != MENU_PAGER || option(OPTSTATUSONTOP));
964 + BottomBuffy = TopBuffy;
965 + while ( --count && BottomBuffy->next )
966 + BottomBuffy = BottomBuffy->next;
968 + else if ( TopBuffy == CurBuffy->next ) {
969 + int count = LINES - 2 - (menu != MENU_PAGER);
970 + BottomBuffy = CurBuffy;
972 + while ( --count && tmp->prev)
976 + else if ( BottomBuffy == CurBuffy->prev ) {
977 + int count = LINES - 2 - (menu != MENU_PAGER);
978 + TopBuffy = CurBuffy;
980 + while ( --count && tmp->next )
986 +char *make_sidebar_entry(char *box, int size, int new, int flagged)
988 + static char *entry = 0;
991 + int delim_len = strlen(SidebarDelim);
993 + c = realloc(entry, SidebarWidth - delim_len + 2);
994 + if ( c ) entry = c;
995 + entry[SidebarWidth - delim_len + 1] = 0;
996 + for (; i < SidebarWidth - delim_len + 1; entry[i++] = ' ' );
998 + strncpy( entry, box, i < (SidebarWidth - delim_len + 1) ? i : (SidebarWidth - delim_len + 1) );
1001 + sprintf(entry + SidebarWidth - delim_len - 3, "?");
1003 + if (flagged > 0) {
1005 + entry + SidebarWidth - delim_len - 5 - quick_log10(size) - quick_log10(new) - quick_log10(flagged),
1006 + "% d(%d)[%d]", size, new, flagged);
1009 + entry + SidebarWidth - delim_len - 3 - quick_log10(size) - quick_log10(new),
1010 + "% d(%d)", size, new);
1012 + } else if (flagged > 0) {
1013 + sprintf( entry + SidebarWidth - delim_len - 3 - quick_log10(size) - quick_log10(flagged), "% d[%d]", size, flagged);
1015 + sprintf( entry + SidebarWidth - delim_len - 1 - quick_log10(size), "% d", size);
1020 +void set_curbuffy(char buf[LONG_STRING])
1022 + BUFFY* tmp = CurBuffy = Incoming;
1028 + if(!strcmp(tmp->path, buf)) {
1040 +int draw_sidebar(int menu) {
1042 + int lines = option(OPTHELP) ? 1 : 0;
1044 +#ifndef USE_SLANG_CURSES
1047 + short delim_len = strlen(SidebarDelim);
1050 + static bool initialized = false;
1051 + static int prev_show_value;
1052 + static short saveSidebarWidth;
1054 + /* initialize first time */
1055 + if(!initialized) {
1056 + prev_show_value = option(OPTSIDEBAR);
1057 + saveSidebarWidth = SidebarWidth;
1058 + if(!option(OPTSIDEBAR)) SidebarWidth = 0;
1059 + initialized = true;
1062 + /* save or restore the value SidebarWidth */
1063 + if(prev_show_value != option(OPTSIDEBAR)) {
1064 + if(prev_show_value && !option(OPTSIDEBAR)) {
1065 + saveSidebarWidth = SidebarWidth;
1067 + } else if(!prev_show_value && option(OPTSIDEBAR)) {
1068 + SidebarWidth = saveSidebarWidth;
1070 + prev_show_value = option(OPTSIDEBAR);
1074 +// if ( SidebarWidth == 0 ) return 0;
1075 + if (SidebarWidth > 0 && option (OPTSIDEBAR)
1076 + && delim_len >= SidebarWidth) {
1077 + unset_option (OPTSIDEBAR);
1078 + /* saveSidebarWidth = SidebarWidth; */
1079 + if (saveSidebarWidth > delim_len) {
1080 + SidebarWidth = saveSidebarWidth;
1081 + mutt_error (_("Value for sidebar_delim is too long. Disabling sidebar."));
1085 + mutt_error (_("Value for sidebar_delim is too long. Disabling sidebar. Please set your sidebar_width to a sane value."));
1086 + sleep (4); /* the advise to set a sane value should be seen long enough */
1088 + saveSidebarWidth = 0;
1092 + if ( SidebarWidth == 0 || !option(OPTSIDEBAR)) {
1093 + if (SidebarWidth > 0) {
1094 + saveSidebarWidth = SidebarWidth;
1097 + unset_option(OPTSIDEBAR);
1101 + /* get attributes for divider */
1102 + SETCOLOR(MT_COLOR_STATUS);
1103 +#ifndef USE_SLANG_CURSES
1104 + attr_get(&attrs, &color_pair, 0);
1106 + color_pair = attr_get();
1108 + SETCOLOR(MT_COLOR_NORMAL);
1110 + /* draw the divider */
1112 + for ( ; lines < LINES-1-(menu != MENU_PAGER || option(OPTSTATUSONTOP)); lines++ ) {
1113 + move(lines, SidebarWidth - delim_len);
1114 + addstr(NONULL(SidebarDelim));
1115 +#ifndef USE_SLANG_CURSES
1116 + mvchgat(lines, SidebarWidth - delim_len, delim_len, 0, color_pair, NULL);
1120 + if ( Incoming == 0 ) return 0;
1121 + lines = option(OPTHELP) ? 1 : 0; /* go back to the top */
1123 + if ( known_lines != LINES || TopBuffy == 0 || BottomBuffy == 0 )
1124 + calc_boundaries(menu);
1125 + if ( CurBuffy == 0 ) CurBuffy = Incoming;
1129 + SETCOLOR(MT_COLOR_NORMAL);
1131 + for ( ; tmp && lines < LINES-1 - (menu != MENU_PAGER || option(OPTSTATUSONTOP)); tmp = tmp->next ) {
1132 + if ( tmp == CurBuffy )
1133 + SETCOLOR(MT_COLOR_INDICATOR);
1134 + else if ( tmp->msg_unread > 0 )
1135 + SETCOLOR(MT_COLOR_NEW);
1136 + else if ( tmp->msg_flagged > 0 )
1137 + SETCOLOR(MT_COLOR_FLAGGED);
1139 + SETCOLOR(MT_COLOR_NORMAL);
1142 + if ( Context && !strcmp( tmp->path, Context->path ) ) {
1143 + tmp->msg_unread = Context->unread;
1144 + tmp->msgcount = Context->msgcount;
1145 + tmp->msg_flagged = Context->flagged;
1147 + // check whether Maildir is a prefix of the current folder's path
1148 + short maildir_is_prefix = 0;
1149 + if ( (strlen(tmp->path) > strlen(Maildir)) &&
1150 + (strncmp(Maildir, tmp->path, strlen(Maildir)) == 0) )
1151 + maildir_is_prefix = 1;
1152 + // calculate depth of current folder and generate its display name with indented spaces
1153 + int sidebar_folder_depth = 0;
1154 + char *sidebar_folder_name;
1155 + sidebar_folder_name = basename(tmp->path);
1156 + if ( maildir_is_prefix ) {
1157 + char *tmp_folder_name;
1159 + tmp_folder_name = tmp->path + strlen(Maildir);
1160 + for (i = 0; i < strlen(tmp->path) - strlen(Maildir); i++) {
1161 + if (tmp_folder_name[i] == '/') sidebar_folder_depth++;
1163 + if (sidebar_folder_depth > 0) {
1164 + sidebar_folder_name = malloc(strlen(basename(tmp->path)) + sidebar_folder_depth + 1);
1165 + for (i=0; i < sidebar_folder_depth; i++)
1166 + sidebar_folder_name[i]=' ';
1167 + sidebar_folder_name[i]=0;
1168 + strncat(sidebar_folder_name, basename(tmp->path), strlen(basename(tmp->path)) + sidebar_folder_depth);
1171 + printw( "%.*s", SidebarWidth - delim_len + 1,
1172 + make_sidebar_entry(sidebar_folder_name, tmp->msgcount,
1173 + tmp->msg_unread, tmp->msg_flagged));
1174 + if (sidebar_folder_depth > 0)
1175 + free(sidebar_folder_name);
1178 + SETCOLOR(MT_COLOR_NORMAL);
1179 + for ( ; lines < LINES-1 - (menu != MENU_PAGER || option(OPTSTATUSONTOP)); lines++ ) {
1182 + for ( ; i < SidebarWidth - delim_len; i++ )
1189 +void set_buffystats(CONTEXT* Context)
1191 + BUFFY *tmp = Incoming;
1193 + if(Context && !strcmp(tmp->path, Context->path)) {
1194 + tmp->msg_unread = Context->unread;
1195 + tmp->msgcount = Context->msgcount;
1202 +void scroll_sidebar(int op, int menu)
1204 + if(!SidebarWidth) return;
1205 + if(!CurBuffy) return;
1208 + case OP_SIDEBAR_NEXT:
1209 + if ( CurBuffy->next == NULL ) return;
1210 + CurBuffy = CurBuffy->next;
1212 + case OP_SIDEBAR_PREV:
1213 + if ( CurBuffy->prev == NULL ) return;
1214 + CurBuffy = CurBuffy->prev;
1216 + case OP_SIDEBAR_SCROLL_UP:
1217 + CurBuffy = TopBuffy;
1218 + if ( CurBuffy != Incoming ) {
1219 + calc_boundaries(menu);
1220 + CurBuffy = CurBuffy->prev;
1223 + case OP_SIDEBAR_SCROLL_DOWN:
1224 + CurBuffy = BottomBuffy;
1225 + if ( CurBuffy->next ) {
1226 + calc_boundaries(menu);
1227 + CurBuffy = CurBuffy->next;
1233 + calc_boundaries(menu);
1234 + draw_sidebar(menu);
1241 + * Copyright (C) ????-2004 Justin Hibbits <jrh29@po.cwru.edu>
1242 + * Copyright (C) 2004 Thomer M. Gil <mutt@thomer.com>
1244 + * This program is free software; you can redistribute it and/or modify
1245 + * it under the terms of the GNU General Public License as published by
1246 + * the Free Software Foundation; either version 2 of the License, or
1247 + * (at your option) any later version.
1249 + * This program is distributed in the hope that it will be useful,
1250 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1251 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1252 + * GNU General Public License for more details.
1254 + * You should have received a copy of the GNU General Public License
1255 + * along with this program; if not, write to the Free Software
1256 + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
1268 +/* parameter is whether or not to go to the status line */
1269 +/* used for omitting the last | that covers up the status bar in the index */
1270 +int draw_sidebar(int);
1271 +void scroll_sidebar(int, int);
1272 +void set_curbuffy(char*);
1273 +void set_buffystats(CONTEXT*);
1275 +#endif /* SIDEBAR_H */
1278 @@ -657,6 +657,26 @@
1279 # $crypt_autosign, $crypt_replysign and $smime_is_default.
1282 +# set sidebar_visible=no
1284 +# Name: sidebar_visible
1289 +# This specifies whether or not to show sidebar (left-side list of folders).
1292 +# set sidebar_width=0
1294 +# Name: sidebar_width
1299 +# The width of the sidebar.
1302 # set crypt_autosign=no
1304 # Name: crypt_autosign
1307 @@ -1521,7 +1521,7 @@
1309 imap_munge_mbox_name (munged, sizeof (munged), name);
1310 snprintf (command, sizeof (command),
1311 - "STATUS %s (UIDNEXT UIDVALIDITY UNSEEN RECENT)", munged);
1312 + "STATUS %s (UIDNEXT UIDVALIDITY UNSEEN RECENT MESSAGES)", munged);
1314 if (imap_exec (idata, command, IMAP_CMD_QUEUE) < 0)
1316 --- a/imap/command.c
1317 +++ b/imap/command.c
1318 @@ -1011,6 +1011,13 @@
1320 status->uidnext = oldun;
1322 + /* Added to make the sidebar show the correct numbers */
1323 + if (status->messages)
1325 + inc->msgcount = status->messages;
1326 + inc->msg_unread = status->unseen;