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.20080517.txt
30 - Fixed conflict with maildir-mtime patch [myon]
35 @@ -261,7 +261,7 @@ int mutt_buffy_check (int force)
36 char path[_POSIX_PATH_MAX];
37 struct stat contex_sb;
42 /* update postponed count as well, on force */
44 @@ -296,6 +296,8 @@ int mutt_buffy_check (int force)
46 for (tmp = Incoming; tmp; tmp = tmp->next)
48 + if ( tmp->new == 1 )
51 if (tmp->magic != M_IMAP)
53 @@ -353,30 +355,51 @@ int mutt_buffy_check (int force)
59 + if (STAT_CHECK || tmp->msgcount == 0)
66 + /* parse the mailbox, to see how much mail there is */
67 + ctx = mx_open_mailbox( tmp->path, M_READONLY | M_QUIET | M_NOSORT | M_PEEK, NULL);
70 + msgcount = ctx->msgcount;
71 + msg_unread = ctx->unread;
72 + mx_close_mailbox(ctx, 0);
75 + tmp->msgcount = msgcount;
76 + tmp->msg_unread = msg_unread;
78 + tmp->has_new = tmp->new = 1;
82 else if (option(OPTCHECKMBOXSIZE))
84 /* some other program has deleted mail from the folder */
85 tmp->size = (long) sb.st_size;
87 - if (tmp->newly_created &&
88 - (sb.st_ctime != sb.st_mtime || sb.st_ctime != sb.st_atime))
89 - tmp->newly_created = 0;
92 + if (tmp->newly_created &&
93 + (sb.st_ctime != sb.st_mtime || sb.st_ctime != sb.st_atime))
94 + tmp->newly_created = 0;
100 + /* count new message */
101 snprintf (path, sizeof (path), "%s/new", tmp->path);
102 if ((dirp = opendir (path)) == NULL)
108 + tmp->msg_unread = 0;
109 + tmp->msg_flagged = 0;
110 while ((de = readdir (dirp)) != NULL)
113 @@ -385,12 +408,36 @@ int mutt_buffy_check (int force)
117 - /* one new and undeleted message is enough */
121 - if (! option (OPTMAILDIRMTIME)) /* prevent stat calls */
123 + tmp->has_new = tmp->new = 1;
128 + if(tmp->msg_unread)
134 + * count read messages (for folderlist (sidebar) we also need to count
135 + * messages in cur so that we the total number of messages
137 + snprintf (path, sizeof (path), "%s/cur", tmp->path);
138 + if ((dirp = opendir (path)) == NULL)
143 + while ((de = readdir (dirp)) != NULL)
146 + if (*de->d_name != '.' &&
147 + (!(p = strstr (de->d_name, ":2,")) || !strchr (p + 3, 'T')))
150 + if (p && strchr(p + 3, 'F')) {
151 + tmp->msg_flagged++;
154 snprintf (path, sizeof (path), "%s/new/%s", tmp->path, de->d_name);
155 if (!stat (path, &smd) && smd.st_mtime > tmp->mtime)
156 @@ -403,8 +450,25 @@ int mutt_buffy_check (int force)
160 - if ((tmp->new = mh_buffy (tmp->path)) > 0)
165 + if ((tmp->new = mh_buffy (tmp->path)) > 0)
168 + if ((dp = opendir (path)) == NULL)
171 + while ((de = readdir (dp)))
173 + if (mh_valid_message (de->d_name))
176 + tmp->has_new = tmp->new = 1;
186 @@ -25,8 +25,13 @@ typedef struct buffy_t
189 struct buffy_t *next;
190 + struct buffy_t *prev;
191 time_t mtime; /* for maildirs...time of newest entry */
192 short new; /* mailbox has new mail */
193 + short has_new; /* set it new if new and not read */
194 + int msgcount; /* total number of messages */
195 + int msg_unread; /* number of unread messages */
196 + int msg_flagged; /* number of flagged messages */
197 short notified; /* user has been notified */
198 short magic; /* mailbox type */
199 short newly_created; /* mbox or mmdf just popped into existence */
202 @@ -93,6 +93,8 @@ static struct mapping_t Fields[] =
203 { "bold", MT_COLOR_BOLD },
204 { "underline", MT_COLOR_UNDERLINE },
205 { "index", MT_COLOR_INDEX },
206 + { "sidebar_new", MT_COLOR_NEW },
207 + { "sidebar_flagged", MT_COLOR_FLAGGED },
213 @@ -72,7 +72,7 @@ enum
215 #define HDR_XOFFSET 10
216 #define TITLE_FMT "%10s" /* Used for Prompts, which are ASCII */
217 -#define W (COLS - HDR_XOFFSET)
218 +#define W (COLS - HDR_XOFFSET - SidebarWidth)
220 static char *Prompts[] =
222 @@ -115,16 +115,16 @@ static void redraw_crypt_lines (HEADER *
223 if ((WithCrypto & APPLICATION_PGP) && (WithCrypto & APPLICATION_SMIME))
226 - mvaddstr (HDR_CRYPT, 0, "Security: ");
227 + mvaddstr (HDR_CRYPT, SidebarWidth, "Security: ");
228 else if (msg->security & APPLICATION_SMIME)
229 - mvaddstr (HDR_CRYPT, 0, " S/MIME: ");
230 + mvaddstr (HDR_CRYPT, SidebarWidth, " S/MIME: ");
231 else if (msg->security & APPLICATION_PGP)
232 - mvaddstr (HDR_CRYPT, 0, " PGP: ");
233 + mvaddstr (HDR_CRYPT, SidebarWidth, " PGP: ");
235 else if ((WithCrypto & APPLICATION_SMIME))
236 - mvaddstr (HDR_CRYPT, 0, " S/MIME: ");
237 + mvaddstr (HDR_CRYPT, SidebarWidth, " S/MIME: ");
238 else if ((WithCrypto & APPLICATION_PGP))
239 - mvaddstr (HDR_CRYPT, 0, " PGP: ");
240 + mvaddstr (HDR_CRYPT, SidebarWidth, " PGP: ");
244 @@ -148,7 +148,7 @@ static void redraw_crypt_lines (HEADER *
248 - move (HDR_CRYPTINFO, 0);
249 + move (HDR_CRYPTINFO, SidebarWidth);
251 if ((WithCrypto & APPLICATION_PGP)
252 && msg->security & APPLICATION_PGP && msg->security & SIGN)
253 @@ -164,7 +164,7 @@ static void redraw_crypt_lines (HEADER *
254 && (msg->security & ENCRYPT)
257 - mvprintw (HDR_CRYPTINFO, 40, "%s%s", _("Encrypt with: "),
258 + mvprintw (HDR_CRYPTINFO, SidebarWidth + 40, "%s%s", _("Encrypt with: "),
259 NONULL(SmimeCryptAlg));
262 @@ -178,7 +178,7 @@ static void redraw_mix_line (LIST *chain
266 - mvaddstr (HDR_MIX, 0, " Mix: ");
267 + mvaddstr (HDR_MIX, SidebarWidth, " Mix: ");
271 @@ -193,7 +193,7 @@ static void redraw_mix_line (LIST *chain
272 if (t && t[0] == '0' && t[1] == '\0')
275 - if (c + mutt_strlen (t) + 2 >= COLS)
276 + if (c + mutt_strlen (t) + 2 >= COLS - SidebarWidth)
280 @@ -245,7 +245,7 @@ static void draw_envelope_addr (int line
283 rfc822_write_address (buf, sizeof (buf), addr, 1);
284 - mvprintw (line, 0, TITLE_FMT, Prompts[line - 1]);
285 + mvprintw (line, SidebarWidth, TITLE_FMT, Prompts[line - 1]);
286 mutt_paddstr (W, buf);
289 @@ -255,10 +255,10 @@ static void draw_envelope (HEADER *msg,
290 draw_envelope_addr (HDR_TO, msg->env->to);
291 draw_envelope_addr (HDR_CC, msg->env->cc);
292 draw_envelope_addr (HDR_BCC, msg->env->bcc);
293 - mvprintw (HDR_SUBJECT, 0, TITLE_FMT, Prompts[HDR_SUBJECT - 1]);
294 + mvprintw (HDR_SUBJECT, SidebarWidth, TITLE_FMT, Prompts[HDR_SUBJECT - 1]);
295 mutt_paddstr (W, NONULL (msg->env->subject));
296 draw_envelope_addr (HDR_REPLYTO, msg->env->reply_to);
297 - mvprintw (HDR_FCC, 0, TITLE_FMT, Prompts[HDR_FCC - 1]);
298 + mvprintw (HDR_FCC, SidebarWidth, TITLE_FMT, Prompts[HDR_FCC - 1]);
299 mutt_paddstr (W, fcc);
302 @@ -269,7 +269,7 @@ static void draw_envelope (HEADER *msg,
305 SETCOLOR (MT_COLOR_STATUS);
306 - mvaddstr (HDR_ATTACH - 1, 0, _("-- Attachments"));
307 + mvaddstr (HDR_ATTACH - 1, SidebarWidth, _("-- Attachments"));
308 BKGDSET (MT_COLOR_STATUS);
311 @@ -307,7 +307,7 @@ static int edit_address_list (int line,
312 /* redraw the expanded list so the user can see the result */
314 rfc822_write_address (buf, sizeof (buf), *addr, 1);
315 - move (line, HDR_XOFFSET);
316 + move (line, HDR_XOFFSET+SidebarWidth);
317 mutt_paddstr (W, buf);
320 @@ -553,7 +553,7 @@ int mutt_compose_menu (HEADER *msg, /*
321 if (mutt_get_field ("Subject: ", buf, sizeof (buf), 0) == 0)
323 mutt_str_replace (&msg->env->subject, buf);
324 - move (HDR_SUBJECT, HDR_XOFFSET);
325 + move (HDR_SUBJECT, HDR_XOFFSET + SidebarWidth);
327 if (msg->env->subject)
328 mutt_paddstr (W, msg->env->subject);
329 @@ -570,7 +570,7 @@ int mutt_compose_menu (HEADER *msg, /*
331 strfcpy (fcc, buf, _POSIX_PATH_MAX);
332 mutt_pretty_mailbox (fcc);
333 - move (HDR_FCC, HDR_XOFFSET);
334 + move (HDR_FCC, HDR_XOFFSET + SidebarWidth);
335 mutt_paddstr (W, fcc);
344 +#include "sidebar.h"
348 @@ -544,8 +545,12 @@ int mutt_index_menu (void)
349 menu->redraw |= REDRAW_STATUS;
352 - if (mutt_buffy_notify () && option (OPTBEEPNEW))
354 + if (mutt_buffy_notify ())
356 + menu->redraw |= REDRAW_FULL;
357 + if (option (OPTBEEPNEW))
363 @@ -557,6 +562,7 @@ int mutt_index_menu (void)
364 if (menu->redraw & REDRAW_FULL)
366 menu_redraw_full (menu);
367 + draw_sidebar(menu->menu);
371 @@ -579,10 +585,13 @@ int mutt_index_menu (void)
373 if (menu->redraw & REDRAW_STATUS)
376 menu_status_line (buf, sizeof (buf), menu, NONULL (Status));
378 CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES-2);
379 SETCOLOR (MT_COLOR_STATUS);
380 BKGDSET (MT_COLOR_STATUS);
381 + set_buffystats(Context);
382 mutt_paddstr (COLS, buf);
383 SETCOLOR (MT_COLOR_NORMAL);
384 BKGDSET (MT_COLOR_NORMAL);
385 @@ -603,7 +612,7 @@ int mutt_index_menu (void)
386 menu->oldcurrent = -1;
388 if (option (OPTARROWCURSOR))
389 - move (menu->current - menu->top + menu->offset, 2);
390 + move (menu->current - menu->top + menu->offset, SidebarWidth + 2);
391 else if (option (OPTBRAILLEFRIENDLY))
392 move (menu->current - menu->top + menu->offset, 0);
394 @@ -1072,6 +1081,7 @@ int mutt_index_menu (void)
395 menu->redraw = REDRAW_FULL;
398 + case OP_SIDEBAR_OPEN:
399 case OP_MAIN_CHANGE_FOLDER:
400 case OP_MAIN_NEXT_UNREAD_MAILBOX:
402 @@ -1103,7 +1113,11 @@ int mutt_index_menu (void)
404 mutt_buffy (buf, sizeof (buf));
406 - if (mutt_enter_fname (cp, buf, sizeof (buf), &menu->redraw, 1) == -1)
407 + if ( op == OP_SIDEBAR_OPEN ) {
410 + strncpy( buf, CurBuffy->path, sizeof(buf) );
411 + } else if (mutt_enter_fname (cp, buf, sizeof (buf), &menu->redraw, 1) == -1)
413 if (menu->menu == MENU_PAGER)
415 @@ -1121,6 +1135,7 @@ int mutt_index_menu (void)
418 mutt_expand_path (buf, sizeof (buf));
420 if (mx_get_magic (buf) <= 0)
422 mutt_error (_("%s is not a mailbox."), buf);
423 @@ -2213,6 +2228,12 @@ int mutt_index_menu (void)
427 + case OP_SIDEBAR_SCROLL_UP:
428 + case OP_SIDEBAR_SCROLL_DOWN:
429 + case OP_SIDEBAR_NEXT:
430 + case OP_SIDEBAR_PREV:
431 + scroll_sidebar(op, menu->menu);
434 if (menu->menu == MENU_MAIN)
435 km_error_key (MENU_MAIN);
441 #include "mutt_curses.h"
442 +#include "mutt_menu.h"
445 +#include "sidebar.h"
448 #include "imap_private.h"
449 @@ -294,6 +296,7 @@ void _mutt_set_flag (CONTEXT *ctx, HEADE
451 if (h->searched && (changed != h->changed || deleted != ctx->deleted || tagged != ctx->tagged || flagged != ctx->flagged))
456 void mutt_tag_set_flag (int flag, int bf)
459 @@ -169,6 +169,11 @@ struct binding_t OpMain[] = { /* map: in
460 { "decrypt-save", OP_DECRYPT_SAVE, NULL },
463 + { "sidebar-scroll-up", OP_SIDEBAR_SCROLL_UP, NULL },
464 + { "sidebar-scroll-down", OP_SIDEBAR_SCROLL_DOWN, NULL },
465 + { "sidebar-next", OP_SIDEBAR_NEXT, NULL },
466 + { "sidebar-prev", OP_SIDEBAR_PREV, NULL },
467 + { "sidebar-open", OP_SIDEBAR_OPEN, NULL },
471 @@ -267,6 +272,11 @@ struct binding_t OpPager[] = { /* map: p
472 { "decrypt-save", OP_DECRYPT_SAVE, NULL },
475 + { "sidebar-scroll-up", OP_SIDEBAR_SCROLL_UP, NULL },
476 + { "sidebar-scroll-down", OP_SIDEBAR_SCROLL_DOWN, NULL },
477 + { "sidebar-next", OP_SIDEBAR_NEXT, NULL },
478 + { "sidebar-prev", OP_SIDEBAR_PREV, NULL },
479 + { "sidebar-open", OP_SIDEBAR_OPEN, NULL },
485 @@ -116,6 +116,7 @@ WHERE char *Realname;
486 WHERE char *SendCharset;
487 WHERE char *Sendmail;
489 +WHERE char *SidebarDelim;
490 WHERE char *Signature;
491 WHERE char *SimpleSearch;
493 @@ -212,6 +213,9 @@ WHERE short ScoreThresholdDelete;
494 WHERE short ScoreThresholdRead;
495 WHERE short ScoreThresholdFlag;
497 +WHERE struct buffy_t *CurBuffy INITVAL(0);
498 +WHERE short DrawFullLine INITVAL(0);
499 +WHERE short SidebarWidth;
501 WHERE short ImapKeepalive;
505 @@ -1532,6 +1532,22 @@ struct option_t MuttVars[] = {
506 ** you may unset this setting.
509 + {"sidebar_delim", DT_STR, R_BOTH, UL &SidebarDelim, "|"},
512 + ** This specifies the delimiter between the sidebar (if visible) and
515 + { "sidebar_visible", DT_BOOL, R_BOTH, OPTSIDEBAR, 0 },
518 + ** This specifies whether or not to show sidebar (left-side list of folders).
520 + { "sidebar_width", DT_NUM, R_BOTH, UL &SidebarWidth, 0 },
523 + ** The width of the sidebar.
525 { "pgp_use_gpg_agent", DT_BOOL, R_NONE, OPTUSEGPGAGENT, 0},
531 #define M_NEWFOLDER (1<<4) /* create a new folder - same as M_APPEND, but uses
532 * safe_fopen() for mbox-style folders.
534 +#define M_PEEK (1<<5) /* revert atime back after taking a look (if applicable) */
536 /* mx_open_new_message() */
537 #define M_ADD_FROM 1 /* add a From_ line */
540 @@ -29,7 +29,8 @@ mutt_SOURCES = \
541 score.c send.c sendlib.c signal.c sort.c \
542 status.c system.c thread.c charset.c history.c lib.c \
543 muttlib.c editmsg.c mbyte.c \
544 - url.c ascii.c mutt_idna.c crypt-mod.c crypt-mod.h
545 + url.c ascii.c mutt_idna.c crypt-mod.c crypt-mod.h \
548 nodist_mutt_SOURCES = $(BUILT_SOURCES)
552 @@ -104,6 +104,7 @@ int mmdf_parse_mailbox (CONTEXT *ctx)
553 mutt_perror (ctx->path);
556 + ctx->atime = sb.st_atime;
557 ctx->mtime = sb.st_mtime;
558 ctx->size = sb.st_size;
560 @@ -259,6 +260,7 @@ int mbox_parse_mailbox (CONTEXT *ctx)
562 ctx->size = sb.st_size;
563 ctx->mtime = sb.st_mtime;
564 + ctx->atime = sb.st_atime;
566 #ifdef NFS_ATTRIBUTE_HACK
567 if (sb.st_mtime > sb.st_atime)
571 #include "mutt_curses.h"
572 #include "mutt_menu.h"
574 +#include "sidebar.h"
578 @@ -158,7 +159,7 @@ void menu_pad_string (char *s, size_t n)
580 char *scratch = safe_strdup (s);
581 int shift = option (OPTARROWCURSOR) ? 3 : 0;
582 - int cols = COLS - shift;
583 + int cols = COLS - shift - SidebarWidth;
585 mutt_format_string (s, n, cols, cols, FMT_LEFT, ' ', scratch, mutt_strlen (scratch), 1);
587 @@ -209,6 +210,7 @@ void menu_redraw_index (MUTTMENU *menu)
588 char buf[LONG_STRING];
592 for (i = menu->top; i < menu->top + menu->pagelen; i++)
595 @@ -219,7 +221,7 @@ void menu_redraw_index (MUTTMENU *menu)
596 if (option (OPTARROWCURSOR))
598 attrset (menu->color (i));
599 - CLEARLINE (i - menu->top + menu->offset);
600 + CLEARLINE_WIN (i - menu->top + menu->offset);
602 if (i == menu->current)
604 @@ -248,14 +250,14 @@ void menu_redraw_index (MUTTMENU *menu)
605 BKGDSET (MT_COLOR_INDICATOR);
608 - CLEARLINE (i - menu->top + menu->offset);
609 + CLEARLINE_WIN (i - menu->top + menu->offset);
610 print_enriched_string (menu->color(i), (unsigned char *) buf, i != menu->current);
611 SETCOLOR (MT_COLOR_NORMAL);
612 BKGDSET (MT_COLOR_NORMAL);
616 - CLEARLINE (i - menu->top + menu->offset);
617 + CLEARLINE_WIN (i - menu->top + menu->offset);
621 @@ -270,7 +272,7 @@ void menu_redraw_motion (MUTTMENU *menu)
625 - move (menu->oldcurrent + menu->offset - menu->top, 0);
626 + move (menu->oldcurrent + menu->offset - menu->top, SidebarWidth);
627 SETCOLOR (MT_COLOR_NORMAL);
628 BKGDSET (MT_COLOR_NORMAL);
630 @@ -285,13 +287,13 @@ void menu_redraw_motion (MUTTMENU *menu)
632 menu_make_entry (buf, sizeof (buf), menu, menu->oldcurrent);
633 menu_pad_string (buf, sizeof (buf));
634 - move (menu->oldcurrent + menu->offset - menu->top, 3);
635 + move (menu->oldcurrent + menu->offset - menu->top, SidebarWidth + 3);
636 print_enriched_string (menu->color(menu->oldcurrent), (unsigned char *) buf, 1);
637 SETCOLOR (MT_COLOR_NORMAL);
640 /* now draw it in the new location */
641 - move (menu->current + menu->offset - menu->top, 0);
642 + move (menu->current + menu->offset - menu->top, SidebarWidth);
643 attrset (menu->color (menu->current));
644 ADDCOLOR (MT_COLOR_INDICATOR);
646 @@ -312,7 +314,7 @@ void menu_redraw_motion (MUTTMENU *menu)
647 attrset (menu->color (menu->current));
648 ADDCOLOR (MT_COLOR_INDICATOR);
649 BKGDSET (MT_COLOR_INDICATOR);
650 - CLEARLINE (menu->current - menu->top + menu->offset);
651 + CLEARLINE_WIN (menu->current - menu->top + menu->offset);
652 print_enriched_string (menu->color(menu->current), (unsigned char *) buf, 0);
653 SETCOLOR (MT_COLOR_NORMAL);
654 BKGDSET (MT_COLOR_NORMAL);
655 @@ -324,7 +326,7 @@ void menu_redraw_current (MUTTMENU *menu
657 char buf[LONG_STRING];
659 - move (menu->current + menu->offset - menu->top, 0);
660 + move (menu->current + menu->offset - menu->top, SidebarWidth);
661 menu_make_entry (buf, sizeof (buf), menu, menu->current);
662 menu_pad_string (buf, sizeof (buf));
664 @@ -871,7 +873,7 @@ int mutt_menuLoop (MUTTMENU *menu)
667 if (option (OPTARROWCURSOR))
668 - move (menu->current - menu->top + menu->offset, 2);
669 + move (menu->current - menu->top + menu->offset, SidebarWidth + 2);
670 else if (option (OPTBRAILLEFRIENDLY))
671 move (menu->current - menu->top + menu->offset, 0);
679 +#define CLEARLINE_WIN(x) move(x,SidebarWidth), clrtoeol()
680 #define CLEARLINE(x) move(x,0), clrtoeol()
681 #define CENTERLINE(x,y) move(y, (COLS-strlen(x))/2), addstr(x)
682 #define BEEP() do { if (option (OPTBEEP)) beep(); } while (0)
683 @@ -126,6 +127,8 @@ enum
694 @@ -437,6 +437,7 @@ enum
702 @@ -874,6 +875,7 @@ typedef struct _context
710 @@ -914,6 +916,7 @@ typedef struct _context
711 unsigned int quiet : 1; /* inhibit status messages? */
712 unsigned int collapsed : 1; /* are all threads collapsed? */
713 unsigned int closing : 1; /* mailbox is being closed */
714 + unsigned int peekonly : 1; /* just taking a glance, revert atime */
717 void *data; /* driver specific data */
720 @@ -1205,6 +1205,8 @@ void mutt_FormatString (char *dest, /*
723 /* see if there's room to add content, else ignore */
724 + if ( DrawFullLine )
726 if ((col < COLS && wlen < destlen) || soft)
729 @@ -1247,6 +1249,52 @@ void mutt_FormatString (char *dest, /*
736 + if ((col < COLS-SidebarWidth && wlen < destlen) || soft)
740 + /* get contents after padding */
741 + mutt_FormatString (buf, sizeof (buf), 0, src + pl, callback, data, flags);
742 + len = mutt_strlen (buf);
743 + wid = mutt_strwidth (buf);
745 + /* try to consume as many columns as we can, if we don't have
746 + * memory for that, use as much memory as possible */
747 + pad = (COLS - SidebarWidth - col - wid) / pw;
748 + if (pad > 0 && wlen + (pad * pl) + len > destlen)
749 + pad = ((signed)(destlen - wlen - len)) / pl;
754 + memcpy (wptr, src, pl);
760 + else if (soft && pad < 0)
762 + /* \0-terminate dest for length computation in mutt_wstr_trunc() */
764 + /* make sure right part is at most as wide as display */
765 + len = mutt_wstr_trunc (buf, destlen, COLS, &wid);
766 + /* truncate left so that right part fits completely in */
767 + wlen = mutt_wstr_trunc (dest, destlen - len, col + pad, &col);
768 + wptr = dest + wlen;
770 + if (len + wlen > destlen)
771 + len = mutt_wstr_trunc (buf, destlen - wlen, COLS - SidebarWidth - col, NULL);
772 + memcpy (wptr, buf, len);
779 break; /* skip rest of input */
784 @@ -626,6 +626,7 @@ static int mx_open_mailbox_append (CONTE
785 * M_APPEND open mailbox for appending
786 * M_READONLY open mailbox in read-only mode
787 * M_QUIET only print error messages
788 + * M_PEEK revert atime where applicable
789 * ctx if non-null, context struct to use
791 CONTEXT *mx_open_mailbox (const char *path, int flags, CONTEXT *pctx)
792 @@ -648,6 +649,8 @@ CONTEXT *mx_open_mailbox (const char *pa
794 if (flags & M_READONLY)
796 + if (flags & M_PEEK)
799 if (flags & (M_APPEND|M_NEWFOLDER))
801 @@ -752,9 +755,21 @@ CONTEXT *mx_open_mailbox (const char *pa
802 void mx_fastclose_mailbox (CONTEXT *ctx)
812 + /* fix up the times so buffy won't get confused */
813 + if (ctx->peekonly && ctx->path && ctx->mtime > ctx->atime)
815 + ut.actime = ctx->atime;
816 + ut.modtime = ctx->mtime;
817 + utime (ctx->path, &ut);
825 @@ -179,3 +179,8 @@ OP_WHAT_KEY "display the keycode for a k
826 OP_MAIN_SHOW_LIMIT "show currently active limit pattern"
827 OP_MAIN_COLLAPSE_THREAD "collapse/uncollapse current thread"
828 OP_MAIN_COLLAPSE_ALL "collapse/uncollapse all threads"
829 +OP_SIDEBAR_SCROLL_UP "scroll the mailbox pane up 1 page"
830 +OP_SIDEBAR_SCROLL_DOWN "scroll the mailbox pane down 1 page"
831 +OP_SIDEBAR_NEXT "go down to next mailbox"
832 +OP_SIDEBAR_PREV "go to previous mailbox"
833 +OP_SIDEBAR_OPEN "open hilighted mailbox"
840 +#include "sidebar.h"
841 void set_xterm_title_bar(char *title);
842 void set_xterm_icon_name(char *name);
844 @@ -1069,6 +1070,8 @@ static int format_line (struct line_t **
847 int wrap_cols = mutt_term_width ((flags & M_PAGER_NOWRAP) ? 0 : Wrap);
849 + wrap_cols -= SidebarWidth;
851 /* FIXME: this should come from lineInfo */
852 memset(&mbstate, 0, sizeof(mbstate));
853 @@ -1702,7 +1705,7 @@ mutt_pager (const char *banner, const ch
854 if ((redraw & REDRAW_BODY) || topline != oldtopline)
857 - move (bodyoffset, 0);
858 + move (bodyoffset, SidebarWidth);
859 curline = oldtopline = topline;
862 @@ -1715,6 +1718,7 @@ mutt_pager (const char *banner, const ch
863 &QuoteList, &q_level, &force_redraw, &SearchRE) > 0)
866 + move(lines + bodyoffset, SidebarWidth);
868 last_offset = lineInfo[curline].offset;
869 } while (force_redraw);
870 @@ -1728,6 +1732,7 @@ mutt_pager (const char *banner, const ch
874 + move(lines + bodyoffset, SidebarWidth);
876 /* We are going to update the pager status bar, so it isn't
877 * necessary to reset to normal color now. */
878 @@ -1751,22 +1756,22 @@ mutt_pager (const char *banner, const ch
879 /* print out the pager status bar */
880 SETCOLOR (MT_COLOR_STATUS);
881 BKGDSET (MT_COLOR_STATUS);
882 - CLEARLINE (statusoffset);
883 + CLEARLINE_WIN (statusoffset);
884 if (IsHeader (extra))
886 - size_t l1 = COLS * MB_LEN_MAX;
887 + size_t l1 = (COLS-SidebarWidth) * MB_LEN_MAX;
888 size_t l2 = sizeof (buffer);
889 hfi.hdr = extra->hdr;
890 mutt_make_string_info (buffer, l1 < l2 ? l1 : l2, NONULL (PagerFmt), &hfi, M_FORMAT_MAKEPRINT);
892 else if (IsMsgAttach (extra))
894 - size_t l1 = COLS * MB_LEN_MAX;
895 + size_t l1 = (COLS-SidebarWidth) * MB_LEN_MAX;
896 size_t l2 = sizeof (buffer);
897 hfi.hdr = extra->bdy->hdr;
898 mutt_make_string_info (buffer, l1 < l2 ? l1 : l2, NONULL (PagerFmt), &hfi, M_FORMAT_MAKEPRINT);
900 - mutt_paddstr (COLS, IsHeader (extra) || IsMsgAttach (extra) ? buffer : banner);
901 + mutt_paddstr (COLS-SidebarWidth, IsHeader (extra) || IsMsgAttach (extra) ? buffer : banner);
902 BKGDSET (MT_COLOR_NORMAL);
903 SETCOLOR (MT_COLOR_NORMAL);
904 if (option(OPTXTERMSETTITLES))
905 @@ -1783,18 +1788,23 @@ mutt_pager (const char *banner, const ch
906 /* redraw the pager_index indicator, because the
907 * flags for this message might have changed. */
908 menu_redraw_current (index);
909 + draw_sidebar(MENU_PAGER);
911 /* print out the index status bar */
912 menu_status_line (buffer, sizeof (buffer), index, NONULL(Status));
914 - move (indexoffset + (option (OPTSTATUSONTOP) ? 0 : (indexlen - 1)), 0);
915 + move (indexoffset + (option (OPTSTATUSONTOP) ? 0 : (indexlen - 1)), SidebarWidth);
916 SETCOLOR (MT_COLOR_STATUS);
917 BKGDSET (MT_COLOR_STATUS);
918 - mutt_paddstr (COLS, buffer);
919 + mutt_paddstr (COLS-SidebarWidth, buffer);
920 SETCOLOR (MT_COLOR_NORMAL);
921 BKGDSET (MT_COLOR_NORMAL);
924 + /* if we're not using the index, update every time */
926 + draw_sidebar(MENU_PAGER);
930 if (option(OPTBRAILLEFRIENDLY)) {
931 @@ -2673,6 +2683,13 @@ search_next:
932 redraw = REDRAW_FULL;
935 + case OP_SIDEBAR_SCROLL_UP:
936 + case OP_SIDEBAR_SCROLL_DOWN:
937 + case OP_SIDEBAR_NEXT:
938 + case OP_SIDEBAR_PREV:
939 + scroll_sidebar(ch, MENU_PAGER);
949 + * Copyright (C) ????-2004 Justin Hibbits <jrh29@po.cwru.edu>
950 + * Copyright (C) 2004 Thomer M. Gil <mutt@thomer.com>
952 + * This program is free software; you can redistribute it and/or modify
953 + * it under the terms of the GNU General Public License as published by
954 + * the Free Software Foundation; either version 2 of the License, or
955 + * (at your option) any later version.
957 + * This program is distributed in the hope that it will be useful,
958 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
959 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
960 + * GNU General Public License for more details.
962 + * You should have received a copy of the GNU General Public License
963 + * along with this program; if not, write to the Free Software
964 + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
969 +# include "config.h"
973 +#include "mutt_menu.h"
974 +#include "mutt_curses.h"
975 +#include "sidebar.h"
979 +#include <stdbool.h>
981 +/*BUFFY *CurBuffy = 0;*/
982 +static BUFFY *TopBuffy = 0;
983 +static BUFFY *BottomBuffy = 0;
984 +static int known_lines = 0;
986 +static int quick_log10(int n)
989 + sprintf(string, "%d", n);
990 + return strlen(string);
993 +void calc_boundaries (int menu)
995 + BUFFY *tmp = Incoming;
997 + if ( known_lines != LINES ) {
998 + TopBuffy = BottomBuffy = 0;
999 + known_lines = LINES;
1001 + for ( ; tmp->next != 0; tmp = tmp->next )
1002 + tmp->next->prev = tmp;
1004 + if ( TopBuffy == 0 && BottomBuffy == 0 )
1005 + TopBuffy = Incoming;
1006 + if ( BottomBuffy == 0 ) {
1007 + int count = LINES - 2 - (menu != MENU_PAGER || option(OPTSTATUSONTOP));
1008 + BottomBuffy = TopBuffy;
1009 + while ( --count && BottomBuffy->next )
1010 + BottomBuffy = BottomBuffy->next;
1012 + else if ( TopBuffy == CurBuffy->next ) {
1013 + int count = LINES - 2 - (menu != MENU_PAGER);
1014 + BottomBuffy = CurBuffy;
1015 + tmp = BottomBuffy;
1016 + while ( --count && tmp->prev)
1020 + else if ( BottomBuffy == CurBuffy->prev ) {
1021 + int count = LINES - 2 - (menu != MENU_PAGER);
1022 + TopBuffy = CurBuffy;
1024 + while ( --count && tmp->next )
1026 + BottomBuffy = tmp;
1030 +char *make_sidebar_entry(char *box, int size, int new, int flagged)
1032 + static char *entry = 0;
1035 + int delim_len = strlen(SidebarDelim);
1037 + c = realloc(entry, SidebarWidth - delim_len + 2);
1038 + if ( c ) entry = c;
1039 + entry[SidebarWidth - delim_len + 1] = 0;
1040 + for (; i < SidebarWidth - delim_len + 1; entry[i++] = ' ' );
1042 + strncpy( entry, box, i < (SidebarWidth - delim_len + 1) ? i : (SidebarWidth - delim_len + 1) );
1045 + sprintf(entry + SidebarWidth - delim_len - 3, "?");
1047 + if (flagged > 0) {
1049 + entry + SidebarWidth - delim_len - 5 - quick_log10(size) - quick_log10(new) - quick_log10(flagged),
1050 + "% d(%d)[%d]", size, new, flagged);
1053 + entry + SidebarWidth - delim_len - 3 - quick_log10(size) - quick_log10(new),
1054 + "% d(%d)", size, new);
1056 + } else if (flagged > 0) {
1057 + sprintf( entry + SidebarWidth - delim_len - 3 - quick_log10(size) - quick_log10(flagged), "% d[%d]", size, flagged);
1059 + sprintf( entry + SidebarWidth - delim_len - 1 - quick_log10(size), "% d", size);
1064 +void set_curbuffy(char buf[LONG_STRING])
1066 + BUFFY* tmp = CurBuffy = Incoming;
1072 + if(!strcmp(tmp->path, buf)) {
1084 +int draw_sidebar(int menu) {
1086 + int lines = option(OPTHELP) ? 1 : 0;
1087 + int sidebar_folder_depth;
1088 + char *sidebar_folder_name;
1090 +#ifndef USE_SLANG_CURSES
1093 + short delim_len = strlen(SidebarDelim);
1096 + static bool initialized = false;
1097 + static int prev_show_value;
1098 + static short saveSidebarWidth;
1100 + /* initialize first time */
1101 + if(!initialized) {
1102 + prev_show_value = option(OPTSIDEBAR);
1103 + saveSidebarWidth = SidebarWidth;
1104 + if(!option(OPTSIDEBAR)) SidebarWidth = 0;
1105 + initialized = true;
1108 + /* save or restore the value SidebarWidth */
1109 + if(prev_show_value != option(OPTSIDEBAR)) {
1110 + if(prev_show_value && !option(OPTSIDEBAR)) {
1111 + saveSidebarWidth = SidebarWidth;
1113 + } else if(!prev_show_value && option(OPTSIDEBAR)) {
1114 + SidebarWidth = saveSidebarWidth;
1116 + prev_show_value = option(OPTSIDEBAR);
1120 +// if ( SidebarWidth == 0 ) return 0;
1121 + if (SidebarWidth > 0 && option (OPTSIDEBAR)
1122 + && delim_len >= SidebarWidth) {
1123 + unset_option (OPTSIDEBAR);
1124 + /* saveSidebarWidth = SidebarWidth; */
1125 + if (saveSidebarWidth > delim_len) {
1126 + SidebarWidth = saveSidebarWidth;
1127 + mutt_error (_("Value for sidebar_delim is too long. Disabling sidebar."));
1131 + mutt_error (_("Value for sidebar_delim is too long. Disabling sidebar. Please set your sidebar_width to a sane value."));
1132 + sleep (4); /* the advise to set a sane value should be seen long enough */
1134 + saveSidebarWidth = 0;
1138 + if ( SidebarWidth == 0 || !option(OPTSIDEBAR)) {
1139 + if (SidebarWidth > 0) {
1140 + saveSidebarWidth = SidebarWidth;
1143 + unset_option(OPTSIDEBAR);
1147 + /* get attributes for divider */
1148 + SETCOLOR(MT_COLOR_STATUS);
1149 +#ifndef USE_SLANG_CURSES
1150 + attr_get(&attrs, &color_pair, 0);
1152 + color_pair = attr_get();
1154 + SETCOLOR(MT_COLOR_NORMAL);
1156 + /* draw the divider */
1158 + for ( ; lines < LINES-1-(menu != MENU_PAGER || option(OPTSTATUSONTOP)); lines++ ) {
1159 + move(lines, SidebarWidth - delim_len);
1160 + addstr(NONULL(SidebarDelim));
1161 +#ifndef USE_SLANG_CURSES
1162 + mvchgat(lines, SidebarWidth - delim_len, delim_len, 0, color_pair, NULL);
1166 + if ( Incoming == 0 ) return 0;
1167 + lines = option(OPTHELP) ? 1 : 0; /* go back to the top */
1169 + if ( known_lines != LINES || TopBuffy == 0 || BottomBuffy == 0 )
1170 + calc_boundaries(menu);
1171 + if ( CurBuffy == 0 ) CurBuffy = Incoming;
1175 + SETCOLOR(MT_COLOR_NORMAL);
1177 + for ( ; tmp && lines < LINES-1 - (menu != MENU_PAGER || option(OPTSTATUSONTOP)); tmp = tmp->next ) {
1178 + if ( tmp == CurBuffy )
1179 + SETCOLOR(MT_COLOR_INDICATOR);
1180 + else if ( tmp->msg_unread > 0 )
1181 + SETCOLOR(MT_COLOR_NEW);
1182 + else if ( tmp->msg_flagged > 0 )
1183 + SETCOLOR(MT_COLOR_FLAGGED);
1185 + SETCOLOR(MT_COLOR_NORMAL);
1188 + if ( Context && !strcmp( tmp->path, Context->path ) ) {
1189 + tmp->msg_unread = Context->unread;
1190 + tmp->msgcount = Context->msgcount;
1191 + tmp->msg_flagged = Context->flagged;
1193 + sidebar_folder_depth = 0;
1194 + sidebar_folder_name = "<null>"; // ... just in case
1195 + if ( strlen(tmp->path) > strlen(Maildir) ) {
1197 + char *tmp_folder_name;
1198 + tmp_folder_name = tmp->path + strlen(Maildir);
1199 + for (i = 0; i < strlen(tmp->path) - strlen(Maildir); i++) {
1200 + if (tmp_folder_name[i] == '/') sidebar_folder_depth++;
1202 + if (sidebar_folder_depth > 0) {
1203 + sidebar_folder_name = malloc(strlen(basename(tmp->path)) + sidebar_folder_depth + 1);
1204 + for (i=0; i < sidebar_folder_depth; i++)
1205 + sidebar_folder_name[i]=' ';
1206 + sidebar_folder_name[i]=0;
1207 + strncat(sidebar_folder_name, basename(tmp->path), strlen(basename(tmp->path)) + sidebar_folder_depth);
1209 + } else sidebar_folder_name = "INBOX";
1210 + printw( "%.*s", SidebarWidth - delim_len + 1,
1211 + make_sidebar_entry(sidebar_folder_name, tmp->msgcount,
1212 + tmp->msg_unread, tmp->msg_flagged));
1213 + if (sidebar_folder_depth > 0)
1214 + free(sidebar_folder_name);
1217 + SETCOLOR(MT_COLOR_NORMAL);
1218 + for ( ; lines < LINES-1 - (menu != MENU_PAGER || option(OPTSTATUSONTOP)); lines++ ) {
1221 + for ( ; i < SidebarWidth - delim_len; i++ )
1228 +void set_buffystats(CONTEXT* Context)
1230 + BUFFY *tmp = Incoming;
1232 + if(Context && !strcmp(tmp->path, Context->path)) {
1233 + tmp->msg_unread = Context->unread;
1234 + tmp->msgcount = Context->msgcount;
1241 +void scroll_sidebar(int op, int menu)
1243 + if(!SidebarWidth) return;
1244 + if(!CurBuffy) return;
1247 + case OP_SIDEBAR_NEXT:
1248 + if ( CurBuffy->next == NULL ) return;
1249 + CurBuffy = CurBuffy->next;
1251 + case OP_SIDEBAR_PREV:
1252 + if ( CurBuffy->prev == NULL ) return;
1253 + CurBuffy = CurBuffy->prev;
1255 + case OP_SIDEBAR_SCROLL_UP:
1256 + CurBuffy = TopBuffy;
1257 + if ( CurBuffy != Incoming ) {
1258 + calc_boundaries(menu);
1259 + CurBuffy = CurBuffy->prev;
1262 + case OP_SIDEBAR_SCROLL_DOWN:
1263 + CurBuffy = BottomBuffy;
1264 + if ( CurBuffy->next ) {
1265 + calc_boundaries(menu);
1266 + CurBuffy = CurBuffy->next;
1272 + calc_boundaries(menu);
1273 + draw_sidebar(menu);
1280 + * Copyright (C) ????-2004 Justin Hibbits <jrh29@po.cwru.edu>
1281 + * Copyright (C) 2004 Thomer M. Gil <mutt@thomer.com>
1283 + * This program is free software; you can redistribute it and/or modify
1284 + * it under the terms of the GNU General Public License as published by
1285 + * the Free Software Foundation; either version 2 of the License, or
1286 + * (at your option) any later version.
1288 + * This program is distributed in the hope that it will be useful,
1289 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1290 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1291 + * GNU General Public License for more details.
1293 + * You should have received a copy of the GNU General Public License
1294 + * along with this program; if not, write to the Free Software
1295 + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
1307 +/* parameter is whether or not to go to the status line */
1308 +/* used for omitting the last | that covers up the status bar in the index */
1309 +int draw_sidebar(int);
1310 +void scroll_sidebar(int, int);
1311 +void set_curbuffy(char*);
1312 +void set_buffystats(CONTEXT*);
1314 +#endif /* SIDEBAR_H */
1317 @@ -2085,6 +2085,26 @@ attachments -I message/external-body
1321 +# set sidebar_visible=no
1323 +# Name: sidebar_visible
1328 +# This specifies whether or not to show sidebar (left-side list of folders).
1331 +# set sidebar_width=0
1333 +# Name: sidebar_width
1338 +# The width of the sidebar.
1341 # set crypt_autosign=no
1343 # Name: crypt_autosign
1346 @@ -1484,7 +1484,7 @@ int imap_buffy_check (int force)
1348 imap_munge_mbox_name (munged, sizeof (munged), name);
1349 snprintf (command, sizeof (command),
1350 - "STATUS %s (UIDNEXT UIDVALIDITY UNSEEN RECENT)", munged);
1351 + "STATUS %s (UIDNEXT UIDVALIDITY UNSEEN RECENT MESSAGES)", munged);
1353 if (imap_cmd_queue (idata, command) < 0)
1355 --- a/imap/command.c
1356 +++ b/imap/command.c
1357 @@ -911,6 +911,13 @@ static void cmd_parse_status (IMAP_DATA*
1359 status->uidnext = oldun;
1361 + /* Added to make the sidebar show the correct numbers */
1362 + if (status->messages)
1364 + inc->msgcount = status->messages;
1365 + inc->msg_unread = status->unseen;
1374 +patch-1.5.18.sidebar.20080517.txt