2 This is the sidebar patch.
4 When enabled, mutt will show a list of mailboxes with (new) message counts in a
5 separate column on the left side of the screen.
7 As this feature is still considered to be unstable, this patch is only applied
8 in the "mutt-patched" package.
10 * Configuration variables:
12 sidebar_delim (string, default "|")
14 This specifies the delimiter between the sidebar (if visible) and
17 sidebar_visible (boolean, default no)
19 This specifies whether or not to show sidebar (left-side list of folders).
21 sidebar_width (integer, default 0)
23 The width of the sidebar.
26 - http://www.lunar-linux.org/index.php?page=mutt-sidebar
27 - http://lunar-linux.org/~tchan/mutt/patch-1.5.18.sidebar.20080611.txt
30 - 2008-08-02 myon: Refreshed patch using quilt push -f to remove hunks we do
31 not need (Makefile.in).
36 @@ -261,7 +261,7 @@ int mutt_buffy_check (int force)
37 char path[_POSIX_PATH_MAX];
38 struct stat contex_sb;
43 /* update postponed count as well, on force */
45 @@ -296,6 +296,8 @@ int mutt_buffy_check (int force)
47 for (tmp = Incoming; tmp; tmp = tmp->next)
49 + if ( tmp->new == 1 )
52 if (tmp->magic != M_IMAP)
54 @@ -353,48 +355,112 @@ int mutt_buffy_check (int force)
60 + if (STAT_CHECK || tmp->msgcount == 0)
67 + /* parse the mailbox, to see how much mail there is */
68 + ctx = mx_open_mailbox( tmp->path, M_READONLY | M_QUIET | M_NOSORT | M_PEEK, NULL);
71 + msgcount = ctx->msgcount;
72 + msg_unread = ctx->unread;
73 + mx_close_mailbox(ctx, 0);
76 + tmp->msgcount = msgcount;
77 + tmp->msg_unread = msg_unread;
79 + tmp->has_new = tmp->new = 1;
83 else if (option(OPTCHECKMBOXSIZE))
85 /* some other program has deleted mail from the folder */
86 tmp->size = (long) sb.st_size;
88 - if (tmp->newly_created &&
89 - (sb.st_ctime != sb.st_mtime || sb.st_ctime != sb.st_atime))
90 - tmp->newly_created = 0;
93 + if (tmp->newly_created &&
94 + (sb.st_ctime != sb.st_mtime || sb.st_ctime != sb.st_atime))
95 + tmp->newly_created = 0;
101 + /* count new message */
102 snprintf (path, sizeof (path), "%s/new", tmp->path);
103 if ((dirp = opendir (path)) == NULL)
109 + tmp->msg_unread = 0;
110 + tmp->msg_flagged = 0;
111 while ((de = readdir (dirp)) != NULL)
114 if (*de->d_name != '.' &&
115 (!(p = strstr (de->d_name, ":2,")) || !strchr (p + 3, 'T')))
117 - /* one new and undeleted message is enough */
121 + tmp->has_new = tmp->new = 1;
126 + if(tmp->msg_unread)
132 + * count read messages (for folderlist (sidebar) we also need to count
133 + * messages in cur so that we the total number of messages
135 + snprintf (path, sizeof (path), "%s/cur", tmp->path);
136 + if ((dirp = opendir (path)) == NULL)
141 + while ((de = readdir (dirp)) != NULL)
144 + if (*de->d_name != '.' &&
145 + (!(p = strstr (de->d_name, ":2,")) || !strchr (p + 3, 'T')))
148 + if (p && strchr(p + 3, 'F')) {
149 + tmp->msg_flagged++;
157 - if ((tmp->new = mh_buffy (tmp->path)) > 0)
162 + if ((tmp->new = mh_buffy (tmp->path)) > 0)
165 + if ((dp = opendir (path)) == NULL)
168 + while ((de = readdir (dp)))
170 + if (mh_valid_message (de->d_name))
173 + tmp->has_new = tmp->new = 1;
183 @@ -25,7 +25,12 @@ typedef struct buffy_t
186 struct buffy_t *next;
187 + struct buffy_t *prev;
188 short new; /* mailbox has new mail */
189 + short has_new; /* set it new if new and not read */
190 + int msgcount; /* total number of messages */
191 + int msg_unread; /* number of unread messages */
192 + int msg_flagged; /* number of flagged messages */
193 short notified; /* user has been notified */
194 short magic; /* mailbox type */
195 short newly_created; /* mbox or mmdf just popped into existence */
198 @@ -93,6 +93,8 @@ static struct mapping_t Fields[] =
199 { "bold", MT_COLOR_BOLD },
200 { "underline", MT_COLOR_UNDERLINE },
201 { "index", MT_COLOR_INDEX },
202 + { "sidebar_new", MT_COLOR_NEW },
203 + { "sidebar_flagged", MT_COLOR_FLAGGED },
209 @@ -72,7 +72,7 @@ enum
211 #define HDR_XOFFSET 10
212 #define TITLE_FMT "%10s" /* Used for Prompts, which are ASCII */
213 -#define W (COLS - HDR_XOFFSET)
214 +#define W (COLS - HDR_XOFFSET - SidebarWidth)
216 static char *Prompts[] =
218 @@ -115,16 +115,16 @@ static void redraw_crypt_lines (HEADER *
219 if ((WithCrypto & APPLICATION_PGP) && (WithCrypto & APPLICATION_SMIME))
222 - mvaddstr (HDR_CRYPT, 0, "Security: ");
223 + mvaddstr (HDR_CRYPT, SidebarWidth, "Security: ");
224 else if (msg->security & APPLICATION_SMIME)
225 - mvaddstr (HDR_CRYPT, 0, " S/MIME: ");
226 + mvaddstr (HDR_CRYPT, SidebarWidth, " S/MIME: ");
227 else if (msg->security & APPLICATION_PGP)
228 - mvaddstr (HDR_CRYPT, 0, " PGP: ");
229 + mvaddstr (HDR_CRYPT, SidebarWidth, " PGP: ");
231 else if ((WithCrypto & APPLICATION_SMIME))
232 - mvaddstr (HDR_CRYPT, 0, " S/MIME: ");
233 + mvaddstr (HDR_CRYPT, SidebarWidth, " S/MIME: ");
234 else if ((WithCrypto & APPLICATION_PGP))
235 - mvaddstr (HDR_CRYPT, 0, " PGP: ");
236 + mvaddstr (HDR_CRYPT, SidebarWidth, " PGP: ");
240 @@ -148,7 +148,7 @@ static void redraw_crypt_lines (HEADER *
244 - move (HDR_CRYPTINFO, 0);
245 + move (HDR_CRYPTINFO, SidebarWidth);
247 if ((WithCrypto & APPLICATION_PGP)
248 && msg->security & APPLICATION_PGP && msg->security & SIGN)
249 @@ -164,7 +164,7 @@ static void redraw_crypt_lines (HEADER *
250 && (msg->security & ENCRYPT)
253 - mvprintw (HDR_CRYPTINFO, 40, "%s%s", _("Encrypt with: "),
254 + mvprintw (HDR_CRYPTINFO, SidebarWidth + 40, "%s%s", _("Encrypt with: "),
255 NONULL(SmimeCryptAlg));
258 @@ -178,7 +178,7 @@ static void redraw_mix_line (LIST *chain
262 - mvaddstr (HDR_MIX, 0, " Mix: ");
263 + mvaddstr (HDR_MIX, SidebarWidth, " Mix: ");
267 @@ -193,7 +193,7 @@ static void redraw_mix_line (LIST *chain
268 if (t && t[0] == '0' && t[1] == '\0')
271 - if (c + mutt_strlen (t) + 2 >= COLS)
272 + if (c + mutt_strlen (t) + 2 >= COLS - SidebarWidth)
276 @@ -245,7 +245,7 @@ static void draw_envelope_addr (int line
279 rfc822_write_address (buf, sizeof (buf), addr, 1);
280 - mvprintw (line, 0, TITLE_FMT, Prompts[line - 1]);
281 + mvprintw (line, SidebarWidth, TITLE_FMT, Prompts[line - 1]);
282 mutt_paddstr (W, buf);
285 @@ -255,10 +255,10 @@ static void draw_envelope (HEADER *msg,
286 draw_envelope_addr (HDR_TO, msg->env->to);
287 draw_envelope_addr (HDR_CC, msg->env->cc);
288 draw_envelope_addr (HDR_BCC, msg->env->bcc);
289 - mvprintw (HDR_SUBJECT, 0, TITLE_FMT, Prompts[HDR_SUBJECT - 1]);
290 + mvprintw (HDR_SUBJECT, SidebarWidth, TITLE_FMT, Prompts[HDR_SUBJECT - 1]);
291 mutt_paddstr (W, NONULL (msg->env->subject));
292 draw_envelope_addr (HDR_REPLYTO, msg->env->reply_to);
293 - mvprintw (HDR_FCC, 0, TITLE_FMT, Prompts[HDR_FCC - 1]);
294 + mvprintw (HDR_FCC, SidebarWidth, TITLE_FMT, Prompts[HDR_FCC - 1]);
295 mutt_paddstr (W, fcc);
298 @@ -269,7 +269,7 @@ static void draw_envelope (HEADER *msg,
301 SETCOLOR (MT_COLOR_STATUS);
302 - mvaddstr (HDR_ATTACH - 1, 0, _("-- Attachments"));
303 + mvaddstr (HDR_ATTACH - 1, SidebarWidth, _("-- Attachments"));
304 BKGDSET (MT_COLOR_STATUS);
307 @@ -307,7 +307,7 @@ static int edit_address_list (int line,
308 /* redraw the expanded list so the user can see the result */
310 rfc822_write_address (buf, sizeof (buf), *addr, 1);
311 - move (line, HDR_XOFFSET);
312 + move (line, HDR_XOFFSET+SidebarWidth);
313 mutt_paddstr (W, buf);
316 @@ -553,7 +553,7 @@ int mutt_compose_menu (HEADER *msg, /*
317 if (mutt_get_field ("Subject: ", buf, sizeof (buf), 0) == 0)
319 mutt_str_replace (&msg->env->subject, buf);
320 - move (HDR_SUBJECT, HDR_XOFFSET);
321 + move (HDR_SUBJECT, HDR_XOFFSET + SidebarWidth);
323 if (msg->env->subject)
324 mutt_paddstr (W, msg->env->subject);
325 @@ -570,7 +570,7 @@ int mutt_compose_menu (HEADER *msg, /*
327 strfcpy (fcc, buf, _POSIX_PATH_MAX);
328 mutt_pretty_mailbox (fcc);
329 - move (HDR_FCC, HDR_XOFFSET);
330 + move (HDR_FCC, HDR_XOFFSET + SidebarWidth);
331 mutt_paddstr (W, fcc);
340 +#include "sidebar.h"
344 @@ -544,8 +545,12 @@ int mutt_index_menu (void)
345 menu->redraw |= REDRAW_STATUS;
348 - if (mutt_buffy_notify () && option (OPTBEEPNEW))
350 + if (mutt_buffy_notify ())
352 + menu->redraw |= REDRAW_FULL;
353 + if (option (OPTBEEPNEW))
359 @@ -557,6 +562,7 @@ int mutt_index_menu (void)
360 if (menu->redraw & REDRAW_FULL)
362 menu_redraw_full (menu);
363 + draw_sidebar(menu->menu);
367 @@ -579,10 +585,13 @@ int mutt_index_menu (void)
369 if (menu->redraw & REDRAW_STATUS)
372 menu_status_line (buf, sizeof (buf), menu, NONULL (Status));
374 CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES-2);
375 SETCOLOR (MT_COLOR_STATUS);
376 BKGDSET (MT_COLOR_STATUS);
377 + set_buffystats(Context);
378 mutt_paddstr (COLS, buf);
379 SETCOLOR (MT_COLOR_NORMAL);
380 BKGDSET (MT_COLOR_NORMAL);
381 @@ -603,7 +612,7 @@ int mutt_index_menu (void)
382 menu->oldcurrent = -1;
384 if (option (OPTARROWCURSOR))
385 - move (menu->current - menu->top + menu->offset, 2);
386 + move (menu->current - menu->top + menu->offset, SidebarWidth + 2);
387 else if (option (OPTBRAILLEFRIENDLY))
388 move (menu->current - menu->top + menu->offset, 0);
390 @@ -1072,6 +1081,7 @@ int mutt_index_menu (void)
391 menu->redraw = REDRAW_FULL;
394 + case OP_SIDEBAR_OPEN:
395 case OP_MAIN_CHANGE_FOLDER:
396 case OP_MAIN_NEXT_UNREAD_MAILBOX:
398 @@ -1103,7 +1113,11 @@ int mutt_index_menu (void)
400 mutt_buffy (buf, sizeof (buf));
402 - if (mutt_enter_fname (cp, buf, sizeof (buf), &menu->redraw, 1) == -1)
403 + if ( op == OP_SIDEBAR_OPEN ) {
406 + strncpy( buf, CurBuffy->path, sizeof(buf) );
407 + } else if (mutt_enter_fname (cp, buf, sizeof (buf), &menu->redraw, 1) == -1)
409 if (menu->menu == MENU_PAGER)
411 @@ -1121,6 +1135,7 @@ int mutt_index_menu (void)
414 mutt_expand_path (buf, sizeof (buf));
416 if (mx_get_magic (buf) <= 0)
418 mutt_error (_("%s is not a mailbox."), buf);
419 @@ -2213,6 +2228,12 @@ int mutt_index_menu (void)
423 + case OP_SIDEBAR_SCROLL_UP:
424 + case OP_SIDEBAR_SCROLL_DOWN:
425 + case OP_SIDEBAR_NEXT:
426 + case OP_SIDEBAR_PREV:
427 + scroll_sidebar(op, menu->menu);
430 if (menu->menu == MENU_MAIN)
431 km_error_key (MENU_MAIN);
437 #include "mutt_curses.h"
438 +#include "mutt_menu.h"
441 +#include "sidebar.h"
444 #include "imap_private.h"
445 @@ -294,6 +296,7 @@ void _mutt_set_flag (CONTEXT *ctx, HEADE
447 if (h->searched && (changed != h->changed || deleted != ctx->deleted || tagged != ctx->tagged || flagged != ctx->flagged))
452 void mutt_tag_set_flag (int flag, int bf)
455 @@ -169,6 +169,11 @@ struct binding_t OpMain[] = { /* map: in
456 { "decrypt-save", OP_DECRYPT_SAVE, NULL },
459 + { "sidebar-scroll-up", OP_SIDEBAR_SCROLL_UP, NULL },
460 + { "sidebar-scroll-down", OP_SIDEBAR_SCROLL_DOWN, NULL },
461 + { "sidebar-next", OP_SIDEBAR_NEXT, NULL },
462 + { "sidebar-prev", OP_SIDEBAR_PREV, NULL },
463 + { "sidebar-open", OP_SIDEBAR_OPEN, NULL },
467 @@ -267,6 +272,11 @@ struct binding_t OpPager[] = { /* map: p
468 { "decrypt-save", OP_DECRYPT_SAVE, NULL },
471 + { "sidebar-scroll-up", OP_SIDEBAR_SCROLL_UP, NULL },
472 + { "sidebar-scroll-down", OP_SIDEBAR_SCROLL_DOWN, NULL },
473 + { "sidebar-next", OP_SIDEBAR_NEXT, NULL },
474 + { "sidebar-prev", OP_SIDEBAR_PREV, NULL },
475 + { "sidebar-open", OP_SIDEBAR_OPEN, NULL },
481 @@ -116,6 +116,7 @@ WHERE char *Realname;
482 WHERE char *SendCharset;
483 WHERE char *Sendmail;
485 +WHERE char *SidebarDelim;
486 WHERE char *Signature;
487 WHERE char *SimpleSearch;
489 @@ -212,6 +213,9 @@ WHERE short ScoreThresholdDelete;
490 WHERE short ScoreThresholdRead;
491 WHERE short ScoreThresholdFlag;
493 +WHERE struct buffy_t *CurBuffy INITVAL(0);
494 +WHERE short DrawFullLine INITVAL(0);
495 +WHERE short SidebarWidth;
497 WHERE short ImapKeepalive;
501 @@ -1532,6 +1532,22 @@ struct option_t MuttVars[] = {
502 ** you may unset this setting.
505 + {"sidebar_delim", DT_STR, R_BOTH, UL &SidebarDelim, "|"},
508 + ** This specifies the delimiter between the sidebar (if visible) and
511 + { "sidebar_visible", DT_BOOL, R_BOTH, OPTSIDEBAR, 0 },
514 + ** This specifies whether or not to show sidebar (left-side list of folders).
516 + { "sidebar_width", DT_NUM, R_BOTH, UL &SidebarWidth, 0 },
519 + ** The width of the sidebar.
521 { "pgp_use_gpg_agent", DT_BOOL, R_NONE, OPTUSEGPGAGENT, 0},
527 #define M_NEWFOLDER (1<<4) /* create a new folder - same as M_APPEND, but uses
528 * safe_fopen() for mbox-style folders.
530 +#define M_PEEK (1<<5) /* revert atime back after taking a look (if applicable) */
532 /* mx_open_new_message() */
533 #define M_ADD_FROM 1 /* add a From_ line */
536 @@ -29,7 +29,8 @@ mutt_SOURCES = \
537 score.c send.c sendlib.c signal.c sort.c \
538 status.c system.c thread.c charset.c history.c lib.c \
539 muttlib.c editmsg.c mbyte.c \
540 - url.c ascii.c mutt_idna.c crypt-mod.c crypt-mod.h
541 + url.c ascii.c mutt_idna.c crypt-mod.c crypt-mod.h \
544 nodist_mutt_SOURCES = $(BUILT_SOURCES)
548 @@ -104,6 +104,7 @@ int mmdf_parse_mailbox (CONTEXT *ctx)
549 mutt_perror (ctx->path);
552 + ctx->atime = sb.st_atime;
553 ctx->mtime = sb.st_mtime;
554 ctx->size = sb.st_size;
556 @@ -259,6 +260,7 @@ int mbox_parse_mailbox (CONTEXT *ctx)
558 ctx->size = sb.st_size;
559 ctx->mtime = sb.st_mtime;
560 + ctx->atime = sb.st_atime;
562 #ifdef NFS_ATTRIBUTE_HACK
563 if (sb.st_mtime > sb.st_atime)
567 #include "mutt_curses.h"
568 #include "mutt_menu.h"
570 +#include "sidebar.h"
574 @@ -158,7 +159,7 @@ void menu_pad_string (char *s, size_t n)
576 char *scratch = safe_strdup (s);
577 int shift = option (OPTARROWCURSOR) ? 3 : 0;
578 - int cols = COLS - shift;
579 + int cols = COLS - shift - SidebarWidth;
581 mutt_format_string (s, n, cols, cols, FMT_LEFT, ' ', scratch, mutt_strlen (scratch), 1);
583 @@ -209,6 +210,7 @@ void menu_redraw_index (MUTTMENU *menu)
584 char buf[LONG_STRING];
588 for (i = menu->top; i < menu->top + menu->pagelen; i++)
591 @@ -219,7 +221,7 @@ void menu_redraw_index (MUTTMENU *menu)
592 if (option (OPTARROWCURSOR))
594 attrset (menu->color (i));
595 - CLEARLINE (i - menu->top + menu->offset);
596 + CLEARLINE_WIN (i - menu->top + menu->offset);
598 if (i == menu->current)
600 @@ -248,14 +250,14 @@ void menu_redraw_index (MUTTMENU *menu)
601 BKGDSET (MT_COLOR_INDICATOR);
604 - CLEARLINE (i - menu->top + menu->offset);
605 + CLEARLINE_WIN (i - menu->top + menu->offset);
606 print_enriched_string (menu->color(i), (unsigned char *) buf, i != menu->current);
607 SETCOLOR (MT_COLOR_NORMAL);
608 BKGDSET (MT_COLOR_NORMAL);
612 - CLEARLINE (i - menu->top + menu->offset);
613 + CLEARLINE_WIN (i - menu->top + menu->offset);
617 @@ -270,7 +272,7 @@ void menu_redraw_motion (MUTTMENU *menu)
621 - move (menu->oldcurrent + menu->offset - menu->top, 0);
622 + move (menu->oldcurrent + menu->offset - menu->top, SidebarWidth);
623 SETCOLOR (MT_COLOR_NORMAL);
624 BKGDSET (MT_COLOR_NORMAL);
626 @@ -285,13 +287,13 @@ void menu_redraw_motion (MUTTMENU *menu)
628 menu_make_entry (buf, sizeof (buf), menu, menu->oldcurrent);
629 menu_pad_string (buf, sizeof (buf));
630 - move (menu->oldcurrent + menu->offset - menu->top, 3);
631 + move (menu->oldcurrent + menu->offset - menu->top, SidebarWidth + 3);
632 print_enriched_string (menu->color(menu->oldcurrent), (unsigned char *) buf, 1);
633 SETCOLOR (MT_COLOR_NORMAL);
636 /* now draw it in the new location */
637 - move (menu->current + menu->offset - menu->top, 0);
638 + move (menu->current + menu->offset - menu->top, SidebarWidth);
639 attrset (menu->color (menu->current));
640 ADDCOLOR (MT_COLOR_INDICATOR);
642 @@ -312,7 +314,7 @@ void menu_redraw_motion (MUTTMENU *menu)
643 attrset (menu->color (menu->current));
644 ADDCOLOR (MT_COLOR_INDICATOR);
645 BKGDSET (MT_COLOR_INDICATOR);
646 - CLEARLINE (menu->current - menu->top + menu->offset);
647 + CLEARLINE_WIN (menu->current - menu->top + menu->offset);
648 print_enriched_string (menu->color(menu->current), (unsigned char *) buf, 0);
649 SETCOLOR (MT_COLOR_NORMAL);
650 BKGDSET (MT_COLOR_NORMAL);
651 @@ -324,7 +326,7 @@ void menu_redraw_current (MUTTMENU *menu
653 char buf[LONG_STRING];
655 - move (menu->current + menu->offset - menu->top, 0);
656 + move (menu->current + menu->offset - menu->top, SidebarWidth);
657 menu_make_entry (buf, sizeof (buf), menu, menu->current);
658 menu_pad_string (buf, sizeof (buf));
660 @@ -871,7 +873,7 @@ int mutt_menuLoop (MUTTMENU *menu)
663 if (option (OPTARROWCURSOR))
664 - move (menu->current - menu->top + menu->offset, 2);
665 + move (menu->current - menu->top + menu->offset, SidebarWidth + 2);
666 else if (option (OPTBRAILLEFRIENDLY))
667 move (menu->current - menu->top + menu->offset, 0);
675 +#define CLEARLINE_WIN(x) move(x,SidebarWidth), clrtoeol()
676 #define CLEARLINE(x) move(x,0), clrtoeol()
677 #define CENTERLINE(x,y) move(y, (COLS-strlen(x))/2), addstr(x)
678 #define BEEP() do { if (option (OPTBEEP)) beep(); } while (0)
679 @@ -126,6 +127,8 @@ enum
690 @@ -437,6 +437,7 @@ enum
698 @@ -874,6 +875,7 @@ typedef struct _context
706 @@ -914,6 +916,7 @@ typedef struct _context
707 unsigned int quiet : 1; /* inhibit status messages? */
708 unsigned int collapsed : 1; /* are all threads collapsed? */
709 unsigned int closing : 1; /* mailbox is being closed */
710 + unsigned int peekonly : 1; /* just taking a glance, revert atime */
713 void *data; /* driver specific data */
716 @@ -1205,6 +1205,8 @@ void mutt_FormatString (char *dest, /*
719 /* see if there's room to add content, else ignore */
720 + if ( DrawFullLine )
722 if ((col < COLS && wlen < destlen) || soft)
725 @@ -1247,6 +1249,52 @@ void mutt_FormatString (char *dest, /*
732 + if ((col < COLS-SidebarWidth && wlen < destlen) || soft)
736 + /* get contents after padding */
737 + mutt_FormatString (buf, sizeof (buf), 0, src + pl, callback, data, flags);
738 + len = mutt_strlen (buf);
739 + wid = mutt_strwidth (buf);
741 + /* try to consume as many columns as we can, if we don't have
742 + * memory for that, use as much memory as possible */
743 + pad = (COLS - SidebarWidth - col - wid) / pw;
744 + if (pad > 0 && wlen + (pad * pl) + len > destlen)
745 + pad = ((signed)(destlen - wlen - len)) / pl;
750 + memcpy (wptr, src, pl);
756 + else if (soft && pad < 0)
758 + /* \0-terminate dest for length computation in mutt_wstr_trunc() */
760 + /* make sure right part is at most as wide as display */
761 + len = mutt_wstr_trunc (buf, destlen, COLS, &wid);
762 + /* truncate left so that right part fits completely in */
763 + wlen = mutt_wstr_trunc (dest, destlen - len, col + pad, &col);
764 + wptr = dest + wlen;
766 + if (len + wlen > destlen)
767 + len = mutt_wstr_trunc (buf, destlen - wlen, COLS - SidebarWidth - col, NULL);
768 + memcpy (wptr, buf, len);
775 break; /* skip rest of input */
780 @@ -626,6 +626,7 @@ static int mx_open_mailbox_append (CONTE
781 * M_APPEND open mailbox for appending
782 * M_READONLY open mailbox in read-only mode
783 * M_QUIET only print error messages
784 + * M_PEEK revert atime where applicable
785 * ctx if non-null, context struct to use
787 CONTEXT *mx_open_mailbox (const char *path, int flags, CONTEXT *pctx)
788 @@ -648,6 +649,8 @@ CONTEXT *mx_open_mailbox (const char *pa
790 if (flags & M_READONLY)
792 + if (flags & M_PEEK)
795 if (flags & (M_APPEND|M_NEWFOLDER))
797 @@ -752,9 +755,21 @@ CONTEXT *mx_open_mailbox (const char *pa
798 void mx_fastclose_mailbox (CONTEXT *ctx)
808 + /* fix up the times so buffy won't get confused */
809 + if (ctx->peekonly && ctx->path && ctx->mtime > ctx->atime)
811 + ut.actime = ctx->atime;
812 + ut.modtime = ctx->mtime;
813 + utime (ctx->path, &ut);
821 @@ -179,3 +179,8 @@ OP_WHAT_KEY "display the keycode for a k
822 OP_MAIN_SHOW_LIMIT "show currently active limit pattern"
823 OP_MAIN_COLLAPSE_THREAD "collapse/uncollapse current thread"
824 OP_MAIN_COLLAPSE_ALL "collapse/uncollapse all threads"
825 +OP_SIDEBAR_SCROLL_UP "scroll the mailbox pane up 1 page"
826 +OP_SIDEBAR_SCROLL_DOWN "scroll the mailbox pane down 1 page"
827 +OP_SIDEBAR_NEXT "go down to next mailbox"
828 +OP_SIDEBAR_PREV "go to previous mailbox"
829 +OP_SIDEBAR_OPEN "open hilighted mailbox"
836 +#include "sidebar.h"
840 @@ -1067,6 +1068,8 @@ static int format_line (struct line_t **
843 int wrap_cols = mutt_term_width ((flags & M_PAGER_NOWRAP) ? 0 : Wrap);
845 + wrap_cols -= SidebarWidth;
847 /* FIXME: this should come from lineInfo */
848 memset(&mbstate, 0, sizeof(mbstate));
849 @@ -1700,7 +1703,7 @@ mutt_pager (const char *banner, const ch
850 if ((redraw & REDRAW_BODY) || topline != oldtopline)
853 - move (bodyoffset, 0);
854 + move (bodyoffset, SidebarWidth);
855 curline = oldtopline = topline;
858 @@ -1713,6 +1716,7 @@ mutt_pager (const char *banner, const ch
859 &QuoteList, &q_level, &force_redraw, &SearchRE) > 0)
862 + move(lines + bodyoffset, SidebarWidth);
864 last_offset = lineInfo[curline].offset;
865 } while (force_redraw);
866 @@ -1726,6 +1730,7 @@ mutt_pager (const char *banner, const ch
870 + move(lines + bodyoffset, SidebarWidth);
872 /* We are going to update the pager status bar, so it isn't
873 * necessary to reset to normal color now. */
874 @@ -1749,22 +1754,22 @@ mutt_pager (const char *banner, const ch
875 /* print out the pager status bar */
876 SETCOLOR (MT_COLOR_STATUS);
877 BKGDSET (MT_COLOR_STATUS);
878 - CLEARLINE (statusoffset);
879 + CLEARLINE_WIN (statusoffset);
880 if (IsHeader (extra))
882 - size_t l1 = COLS * MB_LEN_MAX;
883 + size_t l1 = (COLS-SidebarWidth) * MB_LEN_MAX;
884 size_t l2 = sizeof (buffer);
885 hfi.hdr = extra->hdr;
886 mutt_make_string_info (buffer, l1 < l2 ? l1 : l2, NONULL (PagerFmt), &hfi, M_FORMAT_MAKEPRINT);
888 else if (IsMsgAttach (extra))
890 - size_t l1 = COLS * MB_LEN_MAX;
891 + size_t l1 = (COLS-SidebarWidth) * MB_LEN_MAX;
892 size_t l2 = sizeof (buffer);
893 hfi.hdr = extra->bdy->hdr;
894 mutt_make_string_info (buffer, l1 < l2 ? l1 : l2, NONULL (PagerFmt), &hfi, M_FORMAT_MAKEPRINT);
896 - mutt_paddstr (COLS, IsHeader (extra) || IsMsgAttach (extra) ? buffer : banner);
897 + mutt_paddstr (COLS-SidebarWidth, IsHeader (extra) || IsMsgAttach (extra) ? buffer : banner);
898 BKGDSET (MT_COLOR_NORMAL);
899 SETCOLOR (MT_COLOR_NORMAL);
900 if (option(OPTXTERMSETTITLES))
901 @@ -1781,18 +1786,23 @@ mutt_pager (const char *banner, const ch
902 /* redraw the pager_index indicator, because the
903 * flags for this message might have changed. */
904 menu_redraw_current (index);
905 + draw_sidebar(MENU_PAGER);
907 /* print out the index status bar */
908 menu_status_line (buffer, sizeof (buffer), index, NONULL(Status));
910 - move (indexoffset + (option (OPTSTATUSONTOP) ? 0 : (indexlen - 1)), 0);
911 + move (indexoffset + (option (OPTSTATUSONTOP) ? 0 : (indexlen - 1)), SidebarWidth);
912 SETCOLOR (MT_COLOR_STATUS);
913 BKGDSET (MT_COLOR_STATUS);
914 - mutt_paddstr (COLS, buffer);
915 + mutt_paddstr (COLS-SidebarWidth, buffer);
916 SETCOLOR (MT_COLOR_NORMAL);
917 BKGDSET (MT_COLOR_NORMAL);
920 + /* if we're not using the index, update every time */
922 + draw_sidebar(MENU_PAGER);
926 if (option(OPTBRAILLEFRIENDLY)) {
927 @@ -2671,6 +2681,13 @@ search_next:
928 redraw = REDRAW_FULL;
931 + case OP_SIDEBAR_SCROLL_UP:
932 + case OP_SIDEBAR_SCROLL_DOWN:
933 + case OP_SIDEBAR_NEXT:
934 + case OP_SIDEBAR_PREV:
935 + scroll_sidebar(ch, MENU_PAGER);
945 + * Copyright (C) ????-2004 Justin Hibbits <jrh29@po.cwru.edu>
946 + * Copyright (C) 2004 Thomer M. Gil <mutt@thomer.com>
948 + * This program is free software; you can redistribute it and/or modify
949 + * it under the terms of the GNU General Public License as published by
950 + * the Free Software Foundation; either version 2 of the License, or
951 + * (at your option) any later version.
953 + * This program is distributed in the hope that it will be useful,
954 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
955 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
956 + * GNU General Public License for more details.
958 + * You should have received a copy of the GNU General Public License
959 + * along with this program; if not, write to the Free Software
960 + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
965 +# include "config.h"
969 +#include "mutt_menu.h"
970 +#include "mutt_curses.h"
971 +#include "sidebar.h"
975 +#include <stdbool.h>
977 +/*BUFFY *CurBuffy = 0;*/
978 +static BUFFY *TopBuffy = 0;
979 +static BUFFY *BottomBuffy = 0;
980 +static int known_lines = 0;
982 +static int quick_log10(int n)
985 + sprintf(string, "%d", n);
986 + return strlen(string);
989 +void calc_boundaries (int menu)
991 + BUFFY *tmp = Incoming;
993 + if ( known_lines != LINES ) {
994 + TopBuffy = BottomBuffy = 0;
995 + known_lines = LINES;
997 + for ( ; tmp->next != 0; tmp = tmp->next )
998 + tmp->next->prev = tmp;
1000 + if ( TopBuffy == 0 && BottomBuffy == 0 )
1001 + TopBuffy = Incoming;
1002 + if ( BottomBuffy == 0 ) {
1003 + int count = LINES - 2 - (menu != MENU_PAGER || option(OPTSTATUSONTOP));
1004 + BottomBuffy = TopBuffy;
1005 + while ( --count && BottomBuffy->next )
1006 + BottomBuffy = BottomBuffy->next;
1008 + else if ( TopBuffy == CurBuffy->next ) {
1009 + int count = LINES - 2 - (menu != MENU_PAGER);
1010 + BottomBuffy = CurBuffy;
1011 + tmp = BottomBuffy;
1012 + while ( --count && tmp->prev)
1016 + else if ( BottomBuffy == CurBuffy->prev ) {
1017 + int count = LINES - 2 - (menu != MENU_PAGER);
1018 + TopBuffy = CurBuffy;
1020 + while ( --count && tmp->next )
1022 + BottomBuffy = tmp;
1026 +char *make_sidebar_entry(char *box, int size, int new, int flagged)
1028 + static char *entry = 0;
1031 + int delim_len = strlen(SidebarDelim);
1033 + c = realloc(entry, SidebarWidth - delim_len + 2);
1034 + if ( c ) entry = c;
1035 + entry[SidebarWidth - delim_len + 1] = 0;
1036 + for (; i < SidebarWidth - delim_len + 1; entry[i++] = ' ' );
1038 + strncpy( entry, box, i < (SidebarWidth - delim_len + 1) ? i : (SidebarWidth - delim_len + 1) );
1041 + sprintf(entry + SidebarWidth - delim_len - 3, "?");
1043 + if (flagged > 0) {
1045 + entry + SidebarWidth - delim_len - 5 - quick_log10(size) - quick_log10(new) - quick_log10(flagged),
1046 + "% d(%d)[%d]", size, new, flagged);
1049 + entry + SidebarWidth - delim_len - 3 - quick_log10(size) - quick_log10(new),
1050 + "% d(%d)", size, new);
1052 + } else if (flagged > 0) {
1053 + sprintf( entry + SidebarWidth - delim_len - 3 - quick_log10(size) - quick_log10(flagged), "% d[%d]", size, flagged);
1055 + sprintf( entry + SidebarWidth - delim_len - 1 - quick_log10(size), "% d", size);
1060 +void set_curbuffy(char buf[LONG_STRING])
1062 + BUFFY* tmp = CurBuffy = Incoming;
1068 + if(!strcmp(tmp->path, buf)) {
1080 +int draw_sidebar(int menu) {
1082 + int lines = option(OPTHELP) ? 1 : 0;
1084 +#ifndef USE_SLANG_CURSES
1087 + short delim_len = strlen(SidebarDelim);
1090 + static bool initialized = false;
1091 + static int prev_show_value;
1092 + static short saveSidebarWidth;
1094 + /* initialize first time */
1095 + if(!initialized) {
1096 + prev_show_value = option(OPTSIDEBAR);
1097 + saveSidebarWidth = SidebarWidth;
1098 + if(!option(OPTSIDEBAR)) SidebarWidth = 0;
1099 + initialized = true;
1102 + /* save or restore the value SidebarWidth */
1103 + if(prev_show_value != option(OPTSIDEBAR)) {
1104 + if(prev_show_value && !option(OPTSIDEBAR)) {
1105 + saveSidebarWidth = SidebarWidth;
1107 + } else if(!prev_show_value && option(OPTSIDEBAR)) {
1108 + SidebarWidth = saveSidebarWidth;
1110 + prev_show_value = option(OPTSIDEBAR);
1114 +// if ( SidebarWidth == 0 ) return 0;
1115 + if (SidebarWidth > 0 && option (OPTSIDEBAR)
1116 + && delim_len >= SidebarWidth) {
1117 + unset_option (OPTSIDEBAR);
1118 + /* saveSidebarWidth = SidebarWidth; */
1119 + if (saveSidebarWidth > delim_len) {
1120 + SidebarWidth = saveSidebarWidth;
1121 + mutt_error (_("Value for sidebar_delim is too long. Disabling sidebar."));
1125 + mutt_error (_("Value for sidebar_delim is too long. Disabling sidebar. Please set your sidebar_width to a sane value."));
1126 + sleep (4); /* the advise to set a sane value should be seen long enough */
1128 + saveSidebarWidth = 0;
1132 + if ( SidebarWidth == 0 || !option(OPTSIDEBAR)) {
1133 + if (SidebarWidth > 0) {
1134 + saveSidebarWidth = SidebarWidth;
1137 + unset_option(OPTSIDEBAR);
1141 + /* get attributes for divider */
1142 + SETCOLOR(MT_COLOR_STATUS);
1143 +#ifndef USE_SLANG_CURSES
1144 + attr_get(&attrs, &color_pair, 0);
1146 + color_pair = attr_get();
1148 + SETCOLOR(MT_COLOR_NORMAL);
1150 + /* draw the divider */
1152 + for ( ; lines < LINES-1-(menu != MENU_PAGER || option(OPTSTATUSONTOP)); lines++ ) {
1153 + move(lines, SidebarWidth - delim_len);
1154 + addstr(NONULL(SidebarDelim));
1155 +#ifndef USE_SLANG_CURSES
1156 + mvchgat(lines, SidebarWidth - delim_len, delim_len, 0, color_pair, NULL);
1160 + if ( Incoming == 0 ) return 0;
1161 + lines = option(OPTHELP) ? 1 : 0; /* go back to the top */
1163 + if ( known_lines != LINES || TopBuffy == 0 || BottomBuffy == 0 )
1164 + calc_boundaries(menu);
1165 + if ( CurBuffy == 0 ) CurBuffy = Incoming;
1169 + SETCOLOR(MT_COLOR_NORMAL);
1171 + for ( ; tmp && lines < LINES-1 - (menu != MENU_PAGER || option(OPTSTATUSONTOP)); tmp = tmp->next ) {
1172 + if ( tmp == CurBuffy )
1173 + SETCOLOR(MT_COLOR_INDICATOR);
1174 + else if ( tmp->msg_unread > 0 )
1175 + SETCOLOR(MT_COLOR_NEW);
1176 + else if ( tmp->msg_flagged > 0 )
1177 + SETCOLOR(MT_COLOR_FLAGGED);
1179 + SETCOLOR(MT_COLOR_NORMAL);
1182 + if ( Context && !strcmp( tmp->path, Context->path ) ) {
1183 + tmp->msg_unread = Context->unread;
1184 + tmp->msgcount = Context->msgcount;
1185 + tmp->msg_flagged = Context->flagged;
1187 + // check whether Maildir is a prefix of the current folder's path
1188 + short maildir_is_prefix = 0;
1189 + if ( (strlen(tmp->path) > strlen(Maildir)) &&
1190 + (strncmp(Maildir, tmp->path, strlen(Maildir)) == 0) )
1191 + maildir_is_prefix = 1;
1192 + // calculate depth of current folder and generate its display name with indented spaces
1193 + int sidebar_folder_depth = 0;
1194 + char *sidebar_folder_name;
1195 + sidebar_folder_name = basename(tmp->path);
1196 + if ( maildir_is_prefix ) {
1197 + char *tmp_folder_name;
1199 + tmp_folder_name = tmp->path + strlen(Maildir);
1200 + for (i = 0; i < strlen(tmp->path) - strlen(Maildir); i++) {
1201 + if (tmp_folder_name[i] == '/') sidebar_folder_depth++;
1203 + if (sidebar_folder_depth > 0) {
1204 + sidebar_folder_name = malloc(strlen(basename(tmp->path)) + sidebar_folder_depth + 1);
1205 + for (i=0; i < sidebar_folder_depth; i++)
1206 + sidebar_folder_name[i]=' ';
1207 + sidebar_folder_name[i]=0;
1208 + strncat(sidebar_folder_name, basename(tmp->path), strlen(basename(tmp->path)) + sidebar_folder_depth);
1211 + printw( "%.*s", SidebarWidth - delim_len + 1,
1212 + make_sidebar_entry(sidebar_folder_name, tmp->msgcount,
1213 + tmp->msg_unread, tmp->msg_flagged));
1214 + if (sidebar_folder_depth > 0)
1215 + free(sidebar_folder_name);
1218 + SETCOLOR(MT_COLOR_NORMAL);
1219 + for ( ; lines < LINES-1 - (menu != MENU_PAGER || option(OPTSTATUSONTOP)); lines++ ) {
1222 + for ( ; i < SidebarWidth - delim_len; i++ )
1229 +void set_buffystats(CONTEXT* Context)
1231 + BUFFY *tmp = Incoming;
1233 + if(Context && !strcmp(tmp->path, Context->path)) {
1234 + tmp->msg_unread = Context->unread;
1235 + tmp->msgcount = Context->msgcount;
1242 +void scroll_sidebar(int op, int menu)
1244 + if(!SidebarWidth) return;
1245 + if(!CurBuffy) return;
1248 + case OP_SIDEBAR_NEXT:
1249 + if ( CurBuffy->next == NULL ) return;
1250 + CurBuffy = CurBuffy->next;
1252 + case OP_SIDEBAR_PREV:
1253 + if ( CurBuffy->prev == NULL ) return;
1254 + CurBuffy = CurBuffy->prev;
1256 + case OP_SIDEBAR_SCROLL_UP:
1257 + CurBuffy = TopBuffy;
1258 + if ( CurBuffy != Incoming ) {
1259 + calc_boundaries(menu);
1260 + CurBuffy = CurBuffy->prev;
1263 + case OP_SIDEBAR_SCROLL_DOWN:
1264 + CurBuffy = BottomBuffy;
1265 + if ( CurBuffy->next ) {
1266 + calc_boundaries(menu);
1267 + CurBuffy = CurBuffy->next;
1273 + calc_boundaries(menu);
1274 + draw_sidebar(menu);
1281 + * Copyright (C) ????-2004 Justin Hibbits <jrh29@po.cwru.edu>
1282 + * Copyright (C) 2004 Thomer M. Gil <mutt@thomer.com>
1284 + * This program is free software; you can redistribute it and/or modify
1285 + * it under the terms of the GNU General Public License as published by
1286 + * the Free Software Foundation; either version 2 of the License, or
1287 + * (at your option) any later version.
1289 + * This program is distributed in the hope that it will be useful,
1290 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1291 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1292 + * GNU General Public License for more details.
1294 + * You should have received a copy of the GNU General Public License
1295 + * along with this program; if not, write to the Free Software
1296 + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
1308 +/* parameter is whether or not to go to the status line */
1309 +/* used for omitting the last | that covers up the status bar in the index */
1310 +int draw_sidebar(int);
1311 +void scroll_sidebar(int, int);
1312 +void set_curbuffy(char*);
1313 +void set_buffystats(CONTEXT*);
1315 +#endif /* SIDEBAR_H */
1318 @@ -2090,6 +2090,26 @@ attachments -I message/external-body
1322 +# set sidebar_visible=no
1324 +# Name: sidebar_visible
1329 +# This specifies whether or not to show sidebar (left-side list of folders).
1332 +# set sidebar_width=0
1334 +# Name: sidebar_width
1339 +# The width of the sidebar.
1342 # set crypt_autosign=no
1344 # Name: crypt_autosign
1347 @@ -1484,7 +1484,7 @@ int imap_buffy_check (int force)
1349 imap_munge_mbox_name (munged, sizeof (munged), name);
1350 snprintf (command, sizeof (command),
1351 - "STATUS %s (UIDNEXT UIDVALIDITY UNSEEN RECENT)", munged);
1352 + "STATUS %s (UIDNEXT UIDVALIDITY UNSEEN RECENT MESSAGES)", munged);
1354 if (imap_cmd_queue (idata, command) < 0)
1356 --- a/imap/command.c
1357 +++ b/imap/command.c
1358 @@ -911,6 +911,13 @@ static void cmd_parse_status (IMAP_DATA*
1360 status->uidnext = oldun;
1362 + /* Added to make the sidebar show the correct numbers */
1363 + if (status->messages)
1365 + inc->msgcount = status->messages;
1366 + inc->msg_unread = status->unseen;
1375 +patch-1.5.18.sidebar.20080611.txt