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 - 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,10 +355,27 @@ 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 @@ -366,17 +385,21 @@ int mutt_buffy_check (int force)
85 if (tmp->newly_created &&
86 (sb.st_ctime != sb.st_mtime || sb.st_ctime != sb.st_atime))
87 tmp->newly_created = 0;
94 + /* count new message */
95 snprintf (path, sizeof (path), "%s/new", tmp->path);
96 if ((dirp = opendir (path)) == NULL)
102 + tmp->msg_unread = 0;
103 + tmp->msg_flagged = 0;
104 while ((de = readdir (dirp)) != NULL)
107 @@ -385,12 +408,36 @@ int mutt_buffy_check (int force)
111 - /* one new and undeleted message is enough */
115 - if (! option (OPTMAILDIRMTIME)) /* prevent stat calls */
117 + tmp->has_new = tmp->new = 1;
122 + if(tmp->msg_unread)
128 + * count read messages (for folderlist (sidebar) we also need to count
129 + * messages in cur so that we the total number of messages
131 + snprintf (path, sizeof (path), "%s/cur", tmp->path);
132 + if ((dirp = opendir (path)) == NULL)
137 + while ((de = readdir (dirp)) != NULL)
140 + if (*de->d_name != '.' &&
141 + (!(p = strstr (de->d_name, ":2,")) || !strchr (p + 3, 'T')))
144 + if (p && strchr(p + 3, 'F')) {
145 + tmp->msg_flagged++;
148 snprintf (path, sizeof (path), "%s/new/%s", tmp->path, de->d_name);
149 if (!stat (path, &smd) && smd.st_mtime > tmp->mtime)
150 @@ -403,8 +450,25 @@ int mutt_buffy_check (int force)
154 - if ((tmp->new = mh_buffy (tmp->path)) > 0)
159 + if ((tmp->new = mh_buffy (tmp->path)) > 0)
162 + if ((dp = opendir (path)) == NULL)
165 + while ((de = readdir (dp)))
167 + if (mh_valid_message (de->d_name))
170 + tmp->has_new = tmp->new = 1;
180 @@ -25,8 +25,13 @@ typedef struct buffy_t
183 struct buffy_t *next;
184 + struct buffy_t *prev;
185 time_t mtime; /* for maildirs...time of newest entry */
186 short new; /* mailbox has new mail */
187 + short has_new; /* set it new if new and not read */
188 + int msgcount; /* total number of messages */
189 + int msg_unread; /* number of unread messages */
190 + int msg_flagged; /* number of flagged messages */
191 short notified; /* user has been notified */
192 short magic; /* mailbox type */
193 short newly_created; /* mbox or mmdf just popped into existence */
196 @@ -93,6 +93,8 @@ static struct mapping_t Fields[] =
197 { "bold", MT_COLOR_BOLD },
198 { "underline", MT_COLOR_UNDERLINE },
199 { "index", MT_COLOR_INDEX },
200 + { "sidebar_new", MT_COLOR_NEW },
201 + { "sidebar_flagged", MT_COLOR_FLAGGED },
207 @@ -72,7 +72,7 @@ enum
209 #define HDR_XOFFSET 10
210 #define TITLE_FMT "%10s" /* Used for Prompts, which are ASCII */
211 -#define W (COLS - HDR_XOFFSET)
212 +#define W (COLS - HDR_XOFFSET - SidebarWidth)
214 static char *Prompts[] =
216 @@ -115,16 +115,16 @@ static void redraw_crypt_lines (HEADER *
217 if ((WithCrypto & APPLICATION_PGP) && (WithCrypto & APPLICATION_SMIME))
220 - mvaddstr (HDR_CRYPT, 0, "Security: ");
221 + mvaddstr (HDR_CRYPT, SidebarWidth, "Security: ");
222 else if (msg->security & APPLICATION_SMIME)
223 - mvaddstr (HDR_CRYPT, 0, " S/MIME: ");
224 + mvaddstr (HDR_CRYPT, SidebarWidth, " S/MIME: ");
225 else if (msg->security & APPLICATION_PGP)
226 - mvaddstr (HDR_CRYPT, 0, " PGP: ");
227 + mvaddstr (HDR_CRYPT, SidebarWidth, " PGP: ");
229 else if ((WithCrypto & APPLICATION_SMIME))
230 - mvaddstr (HDR_CRYPT, 0, " S/MIME: ");
231 + mvaddstr (HDR_CRYPT, SidebarWidth, " S/MIME: ");
232 else if ((WithCrypto & APPLICATION_PGP))
233 - mvaddstr (HDR_CRYPT, 0, " PGP: ");
234 + mvaddstr (HDR_CRYPT, SidebarWidth, " PGP: ");
238 @@ -148,7 +148,7 @@ static void redraw_crypt_lines (HEADER *
242 - move (HDR_CRYPTINFO, 0);
243 + move (HDR_CRYPTINFO, SidebarWidth);
245 if ((WithCrypto & APPLICATION_PGP)
246 && msg->security & APPLICATION_PGP && msg->security & SIGN)
247 @@ -164,7 +164,7 @@ static void redraw_crypt_lines (HEADER *
248 && (msg->security & ENCRYPT)
251 - mvprintw (HDR_CRYPTINFO, 40, "%s%s", _("Encrypt with: "),
252 + mvprintw (HDR_CRYPTINFO, SidebarWidth + 40, "%s%s", _("Encrypt with: "),
253 NONULL(SmimeCryptAlg));
256 @@ -178,7 +178,7 @@ static void redraw_mix_line (LIST *chain
260 - mvaddstr (HDR_MIX, 0, " Mix: ");
261 + mvaddstr (HDR_MIX, SidebarWidth, " Mix: ");
265 @@ -193,7 +193,7 @@ static void redraw_mix_line (LIST *chain
266 if (t && t[0] == '0' && t[1] == '\0')
269 - if (c + mutt_strlen (t) + 2 >= COLS)
270 + if (c + mutt_strlen (t) + 2 >= COLS - SidebarWidth)
274 @@ -245,7 +245,7 @@ static void draw_envelope_addr (int line
277 rfc822_write_address (buf, sizeof (buf), addr, 1);
278 - mvprintw (line, 0, TITLE_FMT, Prompts[line - 1]);
279 + mvprintw (line, SidebarWidth, TITLE_FMT, Prompts[line - 1]);
280 mutt_paddstr (W, buf);
283 @@ -255,10 +255,10 @@ static void draw_envelope (HEADER *msg,
284 draw_envelope_addr (HDR_TO, msg->env->to);
285 draw_envelope_addr (HDR_CC, msg->env->cc);
286 draw_envelope_addr (HDR_BCC, msg->env->bcc);
287 - mvprintw (HDR_SUBJECT, 0, TITLE_FMT, Prompts[HDR_SUBJECT - 1]);
288 + mvprintw (HDR_SUBJECT, SidebarWidth, TITLE_FMT, Prompts[HDR_SUBJECT - 1]);
289 mutt_paddstr (W, NONULL (msg->env->subject));
290 draw_envelope_addr (HDR_REPLYTO, msg->env->reply_to);
291 - mvprintw (HDR_FCC, 0, TITLE_FMT, Prompts[HDR_FCC - 1]);
292 + mvprintw (HDR_FCC, SidebarWidth, TITLE_FMT, Prompts[HDR_FCC - 1]);
293 mutt_paddstr (W, fcc);
296 @@ -269,7 +269,7 @@ static void draw_envelope (HEADER *msg,
299 SETCOLOR (MT_COLOR_STATUS);
300 - mvaddstr (HDR_ATTACH - 1, 0, _("-- Attachments"));
301 + mvaddstr (HDR_ATTACH - 1, SidebarWidth, _("-- Attachments"));
302 BKGDSET (MT_COLOR_STATUS);
305 @@ -307,7 +307,7 @@ static int edit_address_list (int line,
306 /* redraw the expanded list so the user can see the result */
308 rfc822_write_address (buf, sizeof (buf), *addr, 1);
309 - move (line, HDR_XOFFSET);
310 + move (line, HDR_XOFFSET+SidebarWidth);
311 mutt_paddstr (W, buf);
314 @@ -553,7 +553,7 @@ int mutt_compose_menu (HEADER *msg, /*
315 if (mutt_get_field ("Subject: ", buf, sizeof (buf), 0) == 0)
317 mutt_str_replace (&msg->env->subject, buf);
318 - move (HDR_SUBJECT, HDR_XOFFSET);
319 + move (HDR_SUBJECT, HDR_XOFFSET + SidebarWidth);
321 if (msg->env->subject)
322 mutt_paddstr (W, msg->env->subject);
323 @@ -570,7 +570,7 @@ int mutt_compose_menu (HEADER *msg, /*
325 strfcpy (fcc, buf, _POSIX_PATH_MAX);
326 mutt_pretty_mailbox (fcc);
327 - move (HDR_FCC, HDR_XOFFSET);
328 + move (HDR_FCC, HDR_XOFFSET + SidebarWidth);
329 mutt_paddstr (W, fcc);
338 +#include "sidebar.h"
342 @@ -544,8 +545,12 @@ int mutt_index_menu (void)
343 menu->redraw |= REDRAW_STATUS;
346 - if (mutt_buffy_notify () && option (OPTBEEPNEW))
348 + if (mutt_buffy_notify ())
350 + menu->redraw |= REDRAW_FULL;
351 + if (option (OPTBEEPNEW))
357 @@ -557,6 +562,7 @@ int mutt_index_menu (void)
358 if (menu->redraw & REDRAW_FULL)
360 menu_redraw_full (menu);
361 + draw_sidebar(menu->menu);
365 @@ -579,10 +585,13 @@ int mutt_index_menu (void)
367 if (menu->redraw & REDRAW_STATUS)
370 menu_status_line (buf, sizeof (buf), menu, NONULL (Status));
372 CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES-2);
373 SETCOLOR (MT_COLOR_STATUS);
374 BKGDSET (MT_COLOR_STATUS);
375 + set_buffystats(Context);
376 mutt_paddstr (COLS, buf);
377 SETCOLOR (MT_COLOR_NORMAL);
378 BKGDSET (MT_COLOR_NORMAL);
379 @@ -603,7 +612,7 @@ int mutt_index_menu (void)
380 menu->oldcurrent = -1;
382 if (option (OPTARROWCURSOR))
383 - move (menu->current - menu->top + menu->offset, 2);
384 + move (menu->current - menu->top + menu->offset, SidebarWidth + 2);
385 else if (option (OPTBRAILLEFRIENDLY))
386 move (menu->current - menu->top + menu->offset, 0);
388 @@ -1072,6 +1081,7 @@ int mutt_index_menu (void)
389 menu->redraw = REDRAW_FULL;
392 + case OP_SIDEBAR_OPEN:
393 case OP_MAIN_CHANGE_FOLDER:
394 case OP_MAIN_NEXT_UNREAD_MAILBOX:
396 @@ -1103,7 +1113,11 @@ int mutt_index_menu (void)
398 mutt_buffy (buf, sizeof (buf));
400 - if (mutt_enter_fname (cp, buf, sizeof (buf), &menu->redraw, 1) == -1)
401 + if ( op == OP_SIDEBAR_OPEN ) {
404 + strncpy( buf, CurBuffy->path, sizeof(buf) );
405 + } else if (mutt_enter_fname (cp, buf, sizeof (buf), &menu->redraw, 1) == -1)
407 if (menu->menu == MENU_PAGER)
409 @@ -1121,6 +1135,7 @@ int mutt_index_menu (void)
412 mutt_expand_path (buf, sizeof (buf));
414 if (mx_get_magic (buf) <= 0)
416 mutt_error (_("%s is not a mailbox."), buf);
417 @@ -2213,6 +2228,12 @@ int mutt_index_menu (void)
421 + case OP_SIDEBAR_SCROLL_UP:
422 + case OP_SIDEBAR_SCROLL_DOWN:
423 + case OP_SIDEBAR_NEXT:
424 + case OP_SIDEBAR_PREV:
425 + scroll_sidebar(op, menu->menu);
428 if (menu->menu == MENU_MAIN)
429 km_error_key (MENU_MAIN);
435 #include "mutt_curses.h"
436 +#include "mutt_menu.h"
439 +#include "sidebar.h"
442 #include "imap_private.h"
443 @@ -294,6 +296,7 @@ void _mutt_set_flag (CONTEXT *ctx, HEADE
445 if (h->searched && (changed != h->changed || deleted != ctx->deleted || tagged != ctx->tagged || flagged != ctx->flagged))
450 void mutt_tag_set_flag (int flag, int bf)
453 @@ -169,6 +169,11 @@ struct binding_t OpMain[] = { /* map: in
454 { "decrypt-save", OP_DECRYPT_SAVE, NULL },
457 + { "sidebar-scroll-up", OP_SIDEBAR_SCROLL_UP, NULL },
458 + { "sidebar-scroll-down", OP_SIDEBAR_SCROLL_DOWN, NULL },
459 + { "sidebar-next", OP_SIDEBAR_NEXT, NULL },
460 + { "sidebar-prev", OP_SIDEBAR_PREV, NULL },
461 + { "sidebar-open", OP_SIDEBAR_OPEN, NULL },
465 @@ -267,6 +272,11 @@ struct binding_t OpPager[] = { /* map: p
466 { "decrypt-save", OP_DECRYPT_SAVE, NULL },
469 + { "sidebar-scroll-up", OP_SIDEBAR_SCROLL_UP, NULL },
470 + { "sidebar-scroll-down", OP_SIDEBAR_SCROLL_DOWN, NULL },
471 + { "sidebar-next", OP_SIDEBAR_NEXT, NULL },
472 + { "sidebar-prev", OP_SIDEBAR_PREV, NULL },
473 + { "sidebar-open", OP_SIDEBAR_OPEN, NULL },
479 @@ -116,6 +116,7 @@ WHERE char *Realname;
480 WHERE char *SendCharset;
481 WHERE char *Sendmail;
483 +WHERE char *SidebarDelim;
484 WHERE char *Signature;
485 WHERE char *SimpleSearch;
487 @@ -212,6 +213,9 @@ WHERE short ScoreThresholdDelete;
488 WHERE short ScoreThresholdRead;
489 WHERE short ScoreThresholdFlag;
491 +WHERE struct buffy_t *CurBuffy INITVAL(0);
492 +WHERE short DrawFullLine INITVAL(0);
493 +WHERE short SidebarWidth;
495 WHERE short ImapKeepalive;
499 @@ -1532,6 +1532,22 @@ struct option_t MuttVars[] = {
500 ** you may unset this setting.
503 + {"sidebar_delim", DT_STR, R_BOTH, UL &SidebarDelim, "|"},
506 + ** This specifies the delimiter between the sidebar (if visible) and
509 + { "sidebar_visible", DT_BOOL, R_BOTH, OPTSIDEBAR, 0 },
512 + ** This specifies whether or not to show sidebar (left-side list of folders).
514 + { "sidebar_width", DT_NUM, R_BOTH, UL &SidebarWidth, 0 },
517 + ** The width of the sidebar.
519 { "pgp_use_gpg_agent", DT_BOOL, R_NONE, OPTUSEGPGAGENT, 0},
525 #define M_NEWFOLDER (1<<4) /* create a new folder - same as M_APPEND, but uses
526 * safe_fopen() for mbox-style folders.
528 +#define M_PEEK (1<<5) /* revert atime back after taking a look (if applicable) */
530 /* mx_open_new_message() */
531 #define M_ADD_FROM 1 /* add a From_ line */
534 @@ -29,7 +29,8 @@ mutt_SOURCES = \
535 score.c send.c sendlib.c signal.c sort.c \
536 status.c system.c thread.c charset.c history.c lib.c \
537 muttlib.c editmsg.c mbyte.c \
538 - url.c ascii.c mutt_idna.c crypt-mod.c crypt-mod.h
539 + url.c ascii.c mutt_idna.c crypt-mod.c crypt-mod.h \
542 nodist_mutt_SOURCES = $(BUILT_SOURCES)
546 @@ -104,6 +104,7 @@ int mmdf_parse_mailbox (CONTEXT *ctx)
547 mutt_perror (ctx->path);
550 + ctx->atime = sb.st_atime;
551 ctx->mtime = sb.st_mtime;
552 ctx->size = sb.st_size;
554 @@ -259,6 +260,7 @@ int mbox_parse_mailbox (CONTEXT *ctx)
556 ctx->size = sb.st_size;
557 ctx->mtime = sb.st_mtime;
558 + ctx->atime = sb.st_atime;
560 #ifdef NFS_ATTRIBUTE_HACK
561 if (sb.st_mtime > sb.st_atime)
565 #include "mutt_curses.h"
566 #include "mutt_menu.h"
568 +#include "sidebar.h"
572 @@ -158,7 +159,7 @@ void menu_pad_string (char *s, size_t n)
574 char *scratch = safe_strdup (s);
575 int shift = option (OPTARROWCURSOR) ? 3 : 0;
576 - int cols = COLS - shift;
577 + int cols = COLS - shift - SidebarWidth;
579 mutt_format_string (s, n, cols, cols, FMT_LEFT, ' ', scratch, mutt_strlen (scratch), 1);
581 @@ -209,6 +210,7 @@ void menu_redraw_index (MUTTMENU *menu)
582 char buf[LONG_STRING];
586 for (i = menu->top; i < menu->top + menu->pagelen; i++)
589 @@ -219,7 +221,7 @@ void menu_redraw_index (MUTTMENU *menu)
590 if (option (OPTARROWCURSOR))
592 attrset (menu->color (i));
593 - CLEARLINE (i - menu->top + menu->offset);
594 + CLEARLINE_WIN (i - menu->top + menu->offset);
596 if (i == menu->current)
598 @@ -248,14 +250,14 @@ void menu_redraw_index (MUTTMENU *menu)
599 BKGDSET (MT_COLOR_INDICATOR);
602 - CLEARLINE (i - menu->top + menu->offset);
603 + CLEARLINE_WIN (i - menu->top + menu->offset);
604 print_enriched_string (menu->color(i), (unsigned char *) buf, i != menu->current);
605 SETCOLOR (MT_COLOR_NORMAL);
606 BKGDSET (MT_COLOR_NORMAL);
610 - CLEARLINE (i - menu->top + menu->offset);
611 + CLEARLINE_WIN (i - menu->top + menu->offset);
615 @@ -270,7 +272,7 @@ void menu_redraw_motion (MUTTMENU *menu)
619 - move (menu->oldcurrent + menu->offset - menu->top, 0);
620 + move (menu->oldcurrent + menu->offset - menu->top, SidebarWidth);
621 SETCOLOR (MT_COLOR_NORMAL);
622 BKGDSET (MT_COLOR_NORMAL);
624 @@ -285,13 +287,13 @@ void menu_redraw_motion (MUTTMENU *menu)
626 menu_make_entry (buf, sizeof (buf), menu, menu->oldcurrent);
627 menu_pad_string (buf, sizeof (buf));
628 - move (menu->oldcurrent + menu->offset - menu->top, 3);
629 + move (menu->oldcurrent + menu->offset - menu->top, SidebarWidth + 3);
630 print_enriched_string (menu->color(menu->oldcurrent), (unsigned char *) buf, 1);
631 SETCOLOR (MT_COLOR_NORMAL);
634 /* now draw it in the new location */
635 - move (menu->current + menu->offset - menu->top, 0);
636 + move (menu->current + menu->offset - menu->top, SidebarWidth);
637 attrset (menu->color (menu->current));
638 ADDCOLOR (MT_COLOR_INDICATOR);
640 @@ -312,7 +314,7 @@ void menu_redraw_motion (MUTTMENU *menu)
641 attrset (menu->color (menu->current));
642 ADDCOLOR (MT_COLOR_INDICATOR);
643 BKGDSET (MT_COLOR_INDICATOR);
644 - CLEARLINE (menu->current - menu->top + menu->offset);
645 + CLEARLINE_WIN (menu->current - menu->top + menu->offset);
646 print_enriched_string (menu->color(menu->current), (unsigned char *) buf, 0);
647 SETCOLOR (MT_COLOR_NORMAL);
648 BKGDSET (MT_COLOR_NORMAL);
649 @@ -324,7 +326,7 @@ void menu_redraw_current (MUTTMENU *menu
651 char buf[LONG_STRING];
653 - move (menu->current + menu->offset - menu->top, 0);
654 + move (menu->current + menu->offset - menu->top, SidebarWidth);
655 menu_make_entry (buf, sizeof (buf), menu, menu->current);
656 menu_pad_string (buf, sizeof (buf));
658 @@ -871,7 +873,7 @@ int mutt_menuLoop (MUTTMENU *menu)
661 if (option (OPTARROWCURSOR))
662 - move (menu->current - menu->top + menu->offset, 2);
663 + move (menu->current - menu->top + menu->offset, SidebarWidth + 2);
664 else if (option (OPTBRAILLEFRIENDLY))
665 move (menu->current - menu->top + menu->offset, 0);
673 +#define CLEARLINE_WIN(x) move(x,SidebarWidth), clrtoeol()
674 #define CLEARLINE(x) move(x,0), clrtoeol()
675 #define CENTERLINE(x,y) move(y, (COLS-strlen(x))/2), addstr(x)
676 #define BEEP() do { if (option (OPTBEEP)) beep(); } while (0)
677 @@ -126,6 +127,8 @@ enum
688 @@ -437,6 +437,7 @@ enum
696 @@ -874,6 +875,7 @@ typedef struct _context
704 @@ -914,6 +916,7 @@ typedef struct _context
705 unsigned int quiet : 1; /* inhibit status messages? */
706 unsigned int collapsed : 1; /* are all threads collapsed? */
707 unsigned int closing : 1; /* mailbox is being closed */
708 + unsigned int peekonly : 1; /* just taking a glance, revert atime */
711 void *data; /* driver specific data */
714 @@ -1205,6 +1205,8 @@ void mutt_FormatString (char *dest, /*
717 /* see if there's room to add content, else ignore */
718 + if ( DrawFullLine )
720 if ((col < COLS && wlen < destlen) || soft)
723 @@ -1247,6 +1249,52 @@ void mutt_FormatString (char *dest, /*
730 + if ((col < COLS-SidebarWidth && wlen < destlen) || soft)
734 + /* get contents after padding */
735 + mutt_FormatString (buf, sizeof (buf), 0, src + pl, callback, data, flags);
736 + len = mutt_strlen (buf);
737 + wid = mutt_strwidth (buf);
739 + /* try to consume as many columns as we can, if we don't have
740 + * memory for that, use as much memory as possible */
741 + pad = (COLS - SidebarWidth - col - wid) / pw;
742 + if (pad > 0 && wlen + (pad * pl) + len > destlen)
743 + pad = ((signed)(destlen - wlen - len)) / pl;
748 + memcpy (wptr, src, pl);
754 + else if (soft && pad < 0)
756 + /* \0-terminate dest for length computation in mutt_wstr_trunc() */
758 + /* make sure right part is at most as wide as display */
759 + len = mutt_wstr_trunc (buf, destlen, COLS, &wid);
760 + /* truncate left so that right part fits completely in */
761 + wlen = mutt_wstr_trunc (dest, destlen - len, col + pad, &col);
762 + wptr = dest + wlen;
764 + if (len + wlen > destlen)
765 + len = mutt_wstr_trunc (buf, destlen - wlen, COLS - SidebarWidth - col, NULL);
766 + memcpy (wptr, buf, len);
773 break; /* skip rest of input */
778 @@ -626,6 +626,7 @@ static int mx_open_mailbox_append (CONTE
779 * M_APPEND open mailbox for appending
780 * M_READONLY open mailbox in read-only mode
781 * M_QUIET only print error messages
782 + * M_PEEK revert atime where applicable
783 * ctx if non-null, context struct to use
785 CONTEXT *mx_open_mailbox (const char *path, int flags, CONTEXT *pctx)
786 @@ -648,6 +649,8 @@ CONTEXT *mx_open_mailbox (const char *pa
788 if (flags & M_READONLY)
790 + if (flags & M_PEEK)
793 if (flags & (M_APPEND|M_NEWFOLDER))
795 @@ -752,9 +755,21 @@ CONTEXT *mx_open_mailbox (const char *pa
796 void mx_fastclose_mailbox (CONTEXT *ctx)
806 + /* fix up the times so buffy won't get confused */
807 + if (ctx->peekonly && ctx->path && ctx->mtime > ctx->atime)
809 + ut.actime = ctx->atime;
810 + ut.modtime = ctx->mtime;
811 + utime (ctx->path, &ut);
819 @@ -179,3 +179,8 @@ OP_WHAT_KEY "display the keycode for a k
820 OP_MAIN_SHOW_LIMIT "show currently active limit pattern"
821 OP_MAIN_COLLAPSE_THREAD "collapse/uncollapse current thread"
822 OP_MAIN_COLLAPSE_ALL "collapse/uncollapse all threads"
823 +OP_SIDEBAR_SCROLL_UP "scroll the mailbox pane up 1 page"
824 +OP_SIDEBAR_SCROLL_DOWN "scroll the mailbox pane down 1 page"
825 +OP_SIDEBAR_NEXT "go down to next mailbox"
826 +OP_SIDEBAR_PREV "go to previous mailbox"
827 +OP_SIDEBAR_OPEN "open hilighted mailbox"
834 +#include "sidebar.h"
835 void set_xterm_title_bar(char *title);
836 void set_xterm_icon_name(char *name);
838 @@ -1069,6 +1070,8 @@ static int format_line (struct line_t **
841 int wrap_cols = mutt_term_width ((flags & M_PAGER_NOWRAP) ? 0 : Wrap);
843 + wrap_cols -= SidebarWidth;
845 /* FIXME: this should come from lineInfo */
846 memset(&mbstate, 0, sizeof(mbstate));
847 @@ -1702,7 +1705,7 @@ mutt_pager (const char *banner, const ch
848 if ((redraw & REDRAW_BODY) || topline != oldtopline)
851 - move (bodyoffset, 0);
852 + move (bodyoffset, SidebarWidth);
853 curline = oldtopline = topline;
856 @@ -1715,6 +1718,7 @@ mutt_pager (const char *banner, const ch
857 &QuoteList, &q_level, &force_redraw, &SearchRE) > 0)
860 + move(lines + bodyoffset, SidebarWidth);
862 last_offset = lineInfo[curline].offset;
863 } while (force_redraw);
864 @@ -1728,6 +1732,7 @@ mutt_pager (const char *banner, const ch
868 + move(lines + bodyoffset, SidebarWidth);
870 /* We are going to update the pager status bar, so it isn't
871 * necessary to reset to normal color now. */
872 @@ -1751,22 +1756,22 @@ mutt_pager (const char *banner, const ch
873 /* print out the pager status bar */
874 SETCOLOR (MT_COLOR_STATUS);
875 BKGDSET (MT_COLOR_STATUS);
876 - CLEARLINE (statusoffset);
877 + CLEARLINE_WIN (statusoffset);
878 if (IsHeader (extra))
880 - size_t l1 = COLS * MB_LEN_MAX;
881 + size_t l1 = (COLS-SidebarWidth) * MB_LEN_MAX;
882 size_t l2 = sizeof (buffer);
883 hfi.hdr = extra->hdr;
884 mutt_make_string_info (buffer, l1 < l2 ? l1 : l2, NONULL (PagerFmt), &hfi, M_FORMAT_MAKEPRINT);
886 else if (IsMsgAttach (extra))
888 - size_t l1 = COLS * MB_LEN_MAX;
889 + size_t l1 = (COLS-SidebarWidth) * MB_LEN_MAX;
890 size_t l2 = sizeof (buffer);
891 hfi.hdr = extra->bdy->hdr;
892 mutt_make_string_info (buffer, l1 < l2 ? l1 : l2, NONULL (PagerFmt), &hfi, M_FORMAT_MAKEPRINT);
894 - mutt_paddstr (COLS, IsHeader (extra) || IsMsgAttach (extra) ? buffer : banner);
895 + mutt_paddstr (COLS-SidebarWidth, IsHeader (extra) || IsMsgAttach (extra) ? buffer : banner);
896 BKGDSET (MT_COLOR_NORMAL);
897 SETCOLOR (MT_COLOR_NORMAL);
898 if (option(OPTXTERMSETTITLES))
899 @@ -1783,18 +1788,23 @@ mutt_pager (const char *banner, const ch
900 /* redraw the pager_index indicator, because the
901 * flags for this message might have changed. */
902 menu_redraw_current (index);
903 + draw_sidebar(MENU_PAGER);
905 /* print out the index status bar */
906 menu_status_line (buffer, sizeof (buffer), index, NONULL(Status));
908 - move (indexoffset + (option (OPTSTATUSONTOP) ? 0 : (indexlen - 1)), 0);
909 + move (indexoffset + (option (OPTSTATUSONTOP) ? 0 : (indexlen - 1)), SidebarWidth);
910 SETCOLOR (MT_COLOR_STATUS);
911 BKGDSET (MT_COLOR_STATUS);
912 - mutt_paddstr (COLS, buffer);
913 + mutt_paddstr (COLS-SidebarWidth, buffer);
914 SETCOLOR (MT_COLOR_NORMAL);
915 BKGDSET (MT_COLOR_NORMAL);
918 + /* if we're not using the index, update every time */
920 + draw_sidebar(MENU_PAGER);
924 if (option(OPTBRAILLEFRIENDLY)) {
925 @@ -2673,6 +2683,13 @@ search_next:
926 redraw = REDRAW_FULL;
929 + case OP_SIDEBAR_SCROLL_UP:
930 + case OP_SIDEBAR_SCROLL_DOWN:
931 + case OP_SIDEBAR_NEXT:
932 + case OP_SIDEBAR_PREV:
933 + scroll_sidebar(ch, MENU_PAGER);
943 + * Copyright (C) ????-2004 Justin Hibbits <jrh29@po.cwru.edu>
944 + * Copyright (C) 2004 Thomer M. Gil <mutt@thomer.com>
946 + * This program is free software; you can redistribute it and/or modify
947 + * it under the terms of the GNU General Public License as published by
948 + * the Free Software Foundation; either version 2 of the License, or
949 + * (at your option) any later version.
951 + * This program is distributed in the hope that it will be useful,
952 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
953 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
954 + * GNU General Public License for more details.
956 + * You should have received a copy of the GNU General Public License
957 + * along with this program; if not, write to the Free Software
958 + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
963 +# include "config.h"
967 +#include "mutt_menu.h"
968 +#include "mutt_curses.h"
969 +#include "sidebar.h"
973 +#include <stdbool.h>
975 +/*BUFFY *CurBuffy = 0;*/
976 +static BUFFY *TopBuffy = 0;
977 +static BUFFY *BottomBuffy = 0;
978 +static int known_lines = 0;
980 +static int quick_log10(int n)
983 + sprintf(string, "%d", n);
984 + return strlen(string);
987 +void calc_boundaries (int menu)
989 + BUFFY *tmp = Incoming;
991 + if ( known_lines != LINES ) {
992 + TopBuffy = BottomBuffy = 0;
993 + known_lines = LINES;
995 + for ( ; tmp->next != 0; tmp = tmp->next )
996 + tmp->next->prev = tmp;
998 + if ( TopBuffy == 0 && BottomBuffy == 0 )
999 + TopBuffy = Incoming;
1000 + if ( BottomBuffy == 0 ) {
1001 + int count = LINES - 2 - (menu != MENU_PAGER || option(OPTSTATUSONTOP));
1002 + BottomBuffy = TopBuffy;
1003 + while ( --count && BottomBuffy->next )
1004 + BottomBuffy = BottomBuffy->next;
1006 + else if ( TopBuffy == CurBuffy->next ) {
1007 + int count = LINES - 2 - (menu != MENU_PAGER);
1008 + BottomBuffy = CurBuffy;
1009 + tmp = BottomBuffy;
1010 + while ( --count && tmp->prev)
1014 + else if ( BottomBuffy == CurBuffy->prev ) {
1015 + int count = LINES - 2 - (menu != MENU_PAGER);
1016 + TopBuffy = CurBuffy;
1018 + while ( --count && tmp->next )
1020 + BottomBuffy = tmp;
1024 +char *make_sidebar_entry(char *box, int size, int new, int flagged)
1026 + static char *entry = 0;
1029 + int delim_len = strlen(SidebarDelim);
1031 + c = realloc(entry, SidebarWidth - delim_len + 2);
1032 + if ( c ) entry = c;
1033 + entry[SidebarWidth - delim_len + 1] = 0;
1034 + for (; i < SidebarWidth - delim_len + 1; entry[i++] = ' ' );
1036 + strncpy( entry, box, i < (SidebarWidth - delim_len + 1) ? i : (SidebarWidth - delim_len + 1) );
1039 + sprintf(entry + SidebarWidth - delim_len - 3, "?");
1041 + if (flagged > 0) {
1043 + entry + SidebarWidth - delim_len - 5 - quick_log10(size) - quick_log10(new) - quick_log10(flagged),
1044 + "% d(%d)[%d]", size, new, flagged);
1047 + entry + SidebarWidth - delim_len - 3 - quick_log10(size) - quick_log10(new),
1048 + "% d(%d)", size, new);
1050 + } else if (flagged > 0) {
1051 + sprintf( entry + SidebarWidth - delim_len - 3 - quick_log10(size) - quick_log10(flagged), "% d[%d]", size, flagged);
1053 + sprintf( entry + SidebarWidth - delim_len - 1 - quick_log10(size), "% d", size);
1058 +void set_curbuffy(char buf[LONG_STRING])
1060 + BUFFY* tmp = CurBuffy = Incoming;
1066 + if(!strcmp(tmp->path, buf)) {
1078 +int draw_sidebar(int menu) {
1080 + int lines = option(OPTHELP) ? 1 : 0;
1082 +#ifndef USE_SLANG_CURSES
1085 + short delim_len = strlen(SidebarDelim);
1088 + static bool initialized = false;
1089 + static int prev_show_value;
1090 + static short saveSidebarWidth;
1092 + /* initialize first time */
1093 + if(!initialized) {
1094 + prev_show_value = option(OPTSIDEBAR);
1095 + saveSidebarWidth = SidebarWidth;
1096 + if(!option(OPTSIDEBAR)) SidebarWidth = 0;
1097 + initialized = true;
1100 + /* save or restore the value SidebarWidth */
1101 + if(prev_show_value != option(OPTSIDEBAR)) {
1102 + if(prev_show_value && !option(OPTSIDEBAR)) {
1103 + saveSidebarWidth = SidebarWidth;
1105 + } else if(!prev_show_value && option(OPTSIDEBAR)) {
1106 + SidebarWidth = saveSidebarWidth;
1108 + prev_show_value = option(OPTSIDEBAR);
1112 +// if ( SidebarWidth == 0 ) return 0;
1113 + if (SidebarWidth > 0 && option (OPTSIDEBAR)
1114 + && delim_len >= SidebarWidth) {
1115 + unset_option (OPTSIDEBAR);
1116 + /* saveSidebarWidth = SidebarWidth; */
1117 + if (saveSidebarWidth > delim_len) {
1118 + SidebarWidth = saveSidebarWidth;
1119 + mutt_error (_("Value for sidebar_delim is too long. Disabling sidebar."));
1123 + mutt_error (_("Value for sidebar_delim is too long. Disabling sidebar. Please set your sidebar_width to a sane value."));
1124 + sleep (4); /* the advise to set a sane value should be seen long enough */
1126 + saveSidebarWidth = 0;
1130 + if ( SidebarWidth == 0 || !option(OPTSIDEBAR)) {
1131 + if (SidebarWidth > 0) {
1132 + saveSidebarWidth = SidebarWidth;
1135 + unset_option(OPTSIDEBAR);
1139 + /* get attributes for divider */
1140 + SETCOLOR(MT_COLOR_STATUS);
1141 +#ifndef USE_SLANG_CURSES
1142 + attr_get(&attrs, &color_pair, 0);
1144 + color_pair = attr_get();
1146 + SETCOLOR(MT_COLOR_NORMAL);
1148 + /* draw the divider */
1150 + for ( ; lines < LINES-1-(menu != MENU_PAGER || option(OPTSTATUSONTOP)); lines++ ) {
1151 + move(lines, SidebarWidth - delim_len);
1152 + addstr(NONULL(SidebarDelim));
1153 +#ifndef USE_SLANG_CURSES
1154 + mvchgat(lines, SidebarWidth - delim_len, delim_len, 0, color_pair, NULL);
1158 + if ( Incoming == 0 ) return 0;
1159 + lines = option(OPTHELP) ? 1 : 0; /* go back to the top */
1161 + if ( known_lines != LINES || TopBuffy == 0 || BottomBuffy == 0 )
1162 + calc_boundaries(menu);
1163 + if ( CurBuffy == 0 ) CurBuffy = Incoming;
1167 + SETCOLOR(MT_COLOR_NORMAL);
1169 + for ( ; tmp && lines < LINES-1 - (menu != MENU_PAGER || option(OPTSTATUSONTOP)); tmp = tmp->next ) {
1170 + if ( tmp == CurBuffy )
1171 + SETCOLOR(MT_COLOR_INDICATOR);
1172 + else if ( tmp->msg_unread > 0 )
1173 + SETCOLOR(MT_COLOR_NEW);
1174 + else if ( tmp->msg_flagged > 0 )
1175 + SETCOLOR(MT_COLOR_FLAGGED);
1177 + SETCOLOR(MT_COLOR_NORMAL);
1180 + if ( Context && !strcmp( tmp->path, Context->path ) ) {
1181 + tmp->msg_unread = Context->unread;
1182 + tmp->msgcount = Context->msgcount;
1183 + tmp->msg_flagged = Context->flagged;
1185 + // check whether Maildir is a prefix of the current folder's path
1186 + short maildir_is_prefix = 0;
1187 + if ( (strlen(tmp->path) > strlen(Maildir)) &&
1188 + (strncmp(Maildir, tmp->path, strlen(Maildir)) == 0) )
1189 + maildir_is_prefix = 1;
1190 + // calculate depth of current folder and generate its display name with indented spaces
1191 + int sidebar_folder_depth = 0;
1192 + char *sidebar_folder_name;
1193 + sidebar_folder_name = basename(tmp->path);
1194 + if ( maildir_is_prefix ) {
1195 + char *tmp_folder_name;
1197 + tmp_folder_name = tmp->path + strlen(Maildir);
1198 + for (i = 0; i < strlen(tmp->path) - strlen(Maildir); i++) {
1199 + if (tmp_folder_name[i] == '/') sidebar_folder_depth++;
1201 + if (sidebar_folder_depth > 0) {
1202 + sidebar_folder_name = malloc(strlen(basename(tmp->path)) + sidebar_folder_depth + 1);
1203 + for (i=0; i < sidebar_folder_depth; i++)
1204 + sidebar_folder_name[i]=' ';
1205 + sidebar_folder_name[i]=0;
1206 + strncat(sidebar_folder_name, basename(tmp->path), strlen(basename(tmp->path)) + sidebar_folder_depth);
1209 + printw( "%.*s", SidebarWidth - delim_len + 1,
1210 + make_sidebar_entry(sidebar_folder_name, tmp->msgcount,
1211 + tmp->msg_unread, tmp->msg_flagged));
1212 + if (sidebar_folder_depth > 0)
1213 + free(sidebar_folder_name);
1216 + SETCOLOR(MT_COLOR_NORMAL);
1217 + for ( ; lines < LINES-1 - (menu != MENU_PAGER || option(OPTSTATUSONTOP)); lines++ ) {
1220 + for ( ; i < SidebarWidth - delim_len; i++ )
1227 +void set_buffystats(CONTEXT* Context)
1229 + BUFFY *tmp = Incoming;
1231 + if(Context && !strcmp(tmp->path, Context->path)) {
1232 + tmp->msg_unread = Context->unread;
1233 + tmp->msgcount = Context->msgcount;
1240 +void scroll_sidebar(int op, int menu)
1242 + if(!SidebarWidth) return;
1243 + if(!CurBuffy) return;
1246 + case OP_SIDEBAR_NEXT:
1247 + if ( CurBuffy->next == NULL ) return;
1248 + CurBuffy = CurBuffy->next;
1250 + case OP_SIDEBAR_PREV:
1251 + if ( CurBuffy->prev == NULL ) return;
1252 + CurBuffy = CurBuffy->prev;
1254 + case OP_SIDEBAR_SCROLL_UP:
1255 + CurBuffy = TopBuffy;
1256 + if ( CurBuffy != Incoming ) {
1257 + calc_boundaries(menu);
1258 + CurBuffy = CurBuffy->prev;
1261 + case OP_SIDEBAR_SCROLL_DOWN:
1262 + CurBuffy = BottomBuffy;
1263 + if ( CurBuffy->next ) {
1264 + calc_boundaries(menu);
1265 + CurBuffy = CurBuffy->next;
1271 + calc_boundaries(menu);
1272 + draw_sidebar(menu);
1279 + * Copyright (C) ????-2004 Justin Hibbits <jrh29@po.cwru.edu>
1280 + * Copyright (C) 2004 Thomer M. Gil <mutt@thomer.com>
1282 + * This program is free software; you can redistribute it and/or modify
1283 + * it under the terms of the GNU General Public License as published by
1284 + * the Free Software Foundation; either version 2 of the License, or
1285 + * (at your option) any later version.
1287 + * This program is distributed in the hope that it will be useful,
1288 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1289 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1290 + * GNU General Public License for more details.
1292 + * You should have received a copy of the GNU General Public License
1293 + * along with this program; if not, write to the Free Software
1294 + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
1306 +/* parameter is whether or not to go to the status line */
1307 +/* used for omitting the last | that covers up the status bar in the index */
1308 +int draw_sidebar(int);
1309 +void scroll_sidebar(int, int);
1310 +void set_curbuffy(char*);
1311 +void set_buffystats(CONTEXT*);
1313 +#endif /* SIDEBAR_H */
1316 @@ -2090,6 +2090,26 @@ attachments -I message/external-body
1320 +# set sidebar_visible=no
1322 +# Name: sidebar_visible
1327 +# This specifies whether or not to show sidebar (left-side list of folders).
1330 +# set sidebar_width=0
1332 +# Name: sidebar_width
1337 +# The width of the sidebar.
1340 # set crypt_autosign=no
1342 # Name: crypt_autosign
1345 @@ -1484,7 +1484,7 @@ int imap_buffy_check (int force)
1347 imap_munge_mbox_name (munged, sizeof (munged), name);
1348 snprintf (command, sizeof (command),
1349 - "STATUS %s (UIDNEXT UIDVALIDITY UNSEEN RECENT)", munged);
1350 + "STATUS %s (UIDNEXT UIDVALIDITY UNSEEN RECENT MESSAGES)", munged);
1352 if (imap_cmd_queue (idata, command) < 0)
1354 --- a/imap/command.c
1355 +++ b/imap/command.c
1356 @@ -911,6 +911,13 @@ static void cmd_parse_status (IMAP_DATA*
1358 status->uidnext = oldun;
1360 + /* Added to make the sidebar show the correct numbers */
1361 + if (status->messages)
1363 + inc->msgcount = status->messages;
1364 + inc->msg_unread = status->unseen;
1373 +patch-1.5.18.sidebar.20080517.txt