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 - provided by dann frazier in #277637
29 - Fixed conflict with maildir-mtime patch [myon]
34 @@ -261,7 +261,7 @@ int mutt_buffy_check (int force)
35 char path[_POSIX_PATH_MAX];
36 struct stat contex_sb;
41 /* update postponed count as well, on force */
43 @@ -296,6 +296,8 @@ int mutt_buffy_check (int force)
45 for (tmp = Incoming; tmp; tmp = tmp->next)
47 + if ( tmp->new == 1 )
50 if (tmp->magic != M_IMAP)
52 @@ -353,30 +355,51 @@ int mutt_buffy_check (int force)
58 + if (STAT_CHECK || tmp->msgcount == 0)
65 + /* parse the mailbox, to see how much mail there is */
66 + ctx = mx_open_mailbox( tmp->path, M_READONLY | M_QUIET | M_NOSORT | M_PEEK, NULL);
69 + msgcount = ctx->msgcount;
70 + msg_unread = ctx->unread;
71 + mx_close_mailbox(ctx, 0);
74 + tmp->msgcount = msgcount;
75 + tmp->msg_unread = msg_unread;
77 + tmp->has_new = tmp->new = 1;
81 else if (option(OPTCHECKMBOXSIZE))
83 /* some other program has deleted mail from the folder */
84 tmp->size = (long) sb.st_size;
86 - if (tmp->newly_created &&
87 - (sb.st_ctime != sb.st_mtime || sb.st_ctime != sb.st_atime))
88 - tmp->newly_created = 0;
91 + if (tmp->newly_created &&
92 + (sb.st_ctime != sb.st_mtime || sb.st_ctime != sb.st_atime))
93 + tmp->newly_created = 0;
99 + /* count new message */
100 snprintf (path, sizeof (path), "%s/new", tmp->path);
101 if ((dirp = opendir (path)) == NULL)
107 + tmp->msg_unread = 0;
108 + tmp->msg_flagged = 0;
109 while ((de = readdir (dirp)) != NULL)
112 @@ -385,12 +408,36 @@ int mutt_buffy_check (int force)
116 - /* one new and undeleted message is enough */
120 - if (! option (OPTMAILDIRMTIME)) /* prevent stat calls */
122 + tmp->has_new = tmp->new = 1;
127 + if(tmp->msg_unread)
133 + * count read messages (for folderlist (sidebar) we also need to count
134 + * messages in cur so that we the total number of messages
136 + snprintf (path, sizeof (path), "%s/cur", tmp->path);
137 + if ((dirp = opendir (path)) == NULL)
142 + while ((de = readdir (dirp)) != NULL)
145 + if (*de->d_name != '.' &&
146 + (!(p = strstr (de->d_name, ":2,")) || !strchr (p + 3, 'T')))
149 + if (p && strchr(p + 3, 'F')) {
150 + tmp->msg_flagged++;
153 snprintf (path, sizeof (path), "%s/new/%s", tmp->path, de->d_name);
154 if (!stat (path, &smd) && smd.st_mtime > tmp->mtime)
155 @@ -403,8 +450,25 @@ int mutt_buffy_check (int force)
159 - if ((tmp->new = mh_buffy (tmp->path)) > 0)
164 + if ((tmp->new = mh_buffy (tmp->path)) > 0)
167 + if ((dp = opendir (path)) == NULL)
170 + while ((de = readdir (dp)))
172 + if (mh_valid_message (de->d_name))
175 + tmp->has_new = tmp->new = 1;
185 @@ -25,8 +25,13 @@ typedef struct buffy_t
188 struct buffy_t *next;
189 + struct buffy_t *prev;
190 time_t mtime; /* for maildirs...time of newest entry */
191 short new; /* mailbox has new mail */
192 + short has_new; /* set it new if new and not read */
193 + int msgcount; /* total number of messages */
194 + int msg_unread; /* number of unread messages */
195 + int msg_flagged; /* number of flagged messages */
196 short notified; /* user has been notified */
197 short magic; /* mailbox type */
198 short newly_created; /* mbox or mmdf just popped into existence */
201 @@ -93,6 +93,8 @@ static struct mapping_t Fields[] =
202 { "bold", MT_COLOR_BOLD },
203 { "underline", MT_COLOR_UNDERLINE },
204 { "index", MT_COLOR_INDEX },
205 + { "sidebar_new", MT_COLOR_NEW },
206 + { "sidebar_flagged", MT_COLOR_FLAGGED },
212 @@ -72,7 +72,7 @@ enum
214 #define HDR_XOFFSET 10
215 #define TITLE_FMT "%10s" /* Used for Prompts, which are ASCII */
216 -#define W (COLS - HDR_XOFFSET)
217 +#define W (COLS - HDR_XOFFSET - SidebarWidth)
219 static char *Prompts[] =
221 @@ -115,16 +115,16 @@ static void redraw_crypt_lines (HEADER *
222 if ((WithCrypto & APPLICATION_PGP) && (WithCrypto & APPLICATION_SMIME))
225 - mvaddstr (HDR_CRYPT, 0, "Security: ");
226 + mvaddstr (HDR_CRYPT, SidebarWidth, "Security: ");
227 else if (msg->security & APPLICATION_SMIME)
228 - mvaddstr (HDR_CRYPT, 0, " S/MIME: ");
229 + mvaddstr (HDR_CRYPT, SidebarWidth, " S/MIME: ");
230 else if (msg->security & APPLICATION_PGP)
231 - mvaddstr (HDR_CRYPT, 0, " PGP: ");
232 + mvaddstr (HDR_CRYPT, SidebarWidth, " PGP: ");
234 else if ((WithCrypto & APPLICATION_SMIME))
235 - mvaddstr (HDR_CRYPT, 0, " S/MIME: ");
236 + mvaddstr (HDR_CRYPT, SidebarWidth, " S/MIME: ");
237 else if ((WithCrypto & APPLICATION_PGP))
238 - mvaddstr (HDR_CRYPT, 0, " PGP: ");
239 + mvaddstr (HDR_CRYPT, SidebarWidth, " PGP: ");
243 @@ -148,7 +148,7 @@ static void redraw_crypt_lines (HEADER *
247 - move (HDR_CRYPTINFO, 0);
248 + move (HDR_CRYPTINFO, SidebarWidth);
250 if ((WithCrypto & APPLICATION_PGP)
251 && msg->security & APPLICATION_PGP && msg->security & SIGN)
252 @@ -164,7 +164,7 @@ static void redraw_crypt_lines (HEADER *
253 && (msg->security & ENCRYPT)
256 - mvprintw (HDR_CRYPTINFO, 40, "%s%s", _("Encrypt with: "),
257 + mvprintw (HDR_CRYPTINFO, SidebarWidth + 40, "%s%s", _("Encrypt with: "),
258 NONULL(SmimeCryptAlg));
261 @@ -178,7 +178,7 @@ static void redraw_mix_line (LIST *chain
265 - mvaddstr (HDR_MIX, 0, " Mix: ");
266 + mvaddstr (HDR_MIX, SidebarWidth, " Mix: ");
270 @@ -193,7 +193,7 @@ static void redraw_mix_line (LIST *chain
271 if (t && t[0] == '0' && t[1] == '\0')
274 - if (c + mutt_strlen (t) + 2 >= COLS)
275 + if (c + mutt_strlen (t) + 2 >= COLS - SidebarWidth)
279 @@ -245,7 +245,7 @@ static void draw_envelope_addr (int line
282 rfc822_write_address (buf, sizeof (buf), addr, 1);
283 - mvprintw (line, 0, TITLE_FMT, Prompts[line - 1]);
284 + mvprintw (line, SidebarWidth, TITLE_FMT, Prompts[line - 1]);
285 mutt_paddstr (W, buf);
288 @@ -255,10 +255,10 @@ static void draw_envelope (HEADER *msg,
289 draw_envelope_addr (HDR_TO, msg->env->to);
290 draw_envelope_addr (HDR_CC, msg->env->cc);
291 draw_envelope_addr (HDR_BCC, msg->env->bcc);
292 - mvprintw (HDR_SUBJECT, 0, TITLE_FMT, Prompts[HDR_SUBJECT - 1]);
293 + mvprintw (HDR_SUBJECT, SidebarWidth, TITLE_FMT, Prompts[HDR_SUBJECT - 1]);
294 mutt_paddstr (W, NONULL (msg->env->subject));
295 draw_envelope_addr (HDR_REPLYTO, msg->env->reply_to);
296 - mvprintw (HDR_FCC, 0, TITLE_FMT, Prompts[HDR_FCC - 1]);
297 + mvprintw (HDR_FCC, SidebarWidth, TITLE_FMT, Prompts[HDR_FCC - 1]);
298 mutt_paddstr (W, fcc);
301 @@ -269,7 +269,7 @@ static void draw_envelope (HEADER *msg,
304 SETCOLOR (MT_COLOR_STATUS);
305 - mvaddstr (HDR_ATTACH - 1, 0, _("-- Attachments"));
306 + mvaddstr (HDR_ATTACH - 1, SidebarWidth, _("-- Attachments"));
307 BKGDSET (MT_COLOR_STATUS);
310 @@ -307,7 +307,7 @@ static int edit_address_list (int line,
311 /* redraw the expanded list so the user can see the result */
313 rfc822_write_address (buf, sizeof (buf), *addr, 1);
314 - move (line, HDR_XOFFSET);
315 + move (line, HDR_XOFFSET+SidebarWidth);
316 mutt_paddstr (W, buf);
319 @@ -553,7 +553,7 @@ int mutt_compose_menu (HEADER *msg, /*
320 if (mutt_get_field ("Subject: ", buf, sizeof (buf), 0) == 0)
322 mutt_str_replace (&msg->env->subject, buf);
323 - move (HDR_SUBJECT, HDR_XOFFSET);
324 + move (HDR_SUBJECT, HDR_XOFFSET + SidebarWidth);
326 if (msg->env->subject)
327 mutt_paddstr (W, msg->env->subject);
328 @@ -570,7 +570,7 @@ int mutt_compose_menu (HEADER *msg, /*
330 strfcpy (fcc, buf, _POSIX_PATH_MAX);
331 mutt_pretty_mailbox (fcc);
332 - move (HDR_FCC, HDR_XOFFSET);
333 + move (HDR_FCC, HDR_XOFFSET + SidebarWidth);
334 mutt_paddstr (W, fcc);
343 +#include "sidebar.h"
347 @@ -544,8 +545,12 @@ int mutt_index_menu (void)
348 menu->redraw |= REDRAW_STATUS;
351 - if (mutt_buffy_notify () && option (OPTBEEPNEW))
353 + if (mutt_buffy_notify ())
355 + menu->redraw |= REDRAW_FULL;
356 + if (option (OPTBEEPNEW))
362 @@ -557,6 +562,7 @@ int mutt_index_menu (void)
363 if (menu->redraw & REDRAW_FULL)
365 menu_redraw_full (menu);
366 + draw_sidebar(menu->menu);
370 @@ -579,10 +585,13 @@ int mutt_index_menu (void)
372 if (menu->redraw & REDRAW_STATUS)
375 menu_status_line (buf, sizeof (buf), menu, NONULL (Status));
377 CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES-2);
378 SETCOLOR (MT_COLOR_STATUS);
379 BKGDSET (MT_COLOR_STATUS);
380 + set_buffystats(Context);
381 mutt_paddstr (COLS, buf);
382 SETCOLOR (MT_COLOR_NORMAL);
383 BKGDSET (MT_COLOR_NORMAL);
384 @@ -603,7 +612,7 @@ int mutt_index_menu (void)
385 menu->oldcurrent = -1;
387 if (option (OPTARROWCURSOR))
388 - move (menu->current - menu->top + menu->offset, 2);
389 + move (menu->current - menu->top + menu->offset, SidebarWidth + 2);
390 else if (option (OPTBRAILLEFRIENDLY))
391 move (menu->current - menu->top + menu->offset, 0);
393 @@ -1072,6 +1081,7 @@ int mutt_index_menu (void)
394 menu->redraw = REDRAW_FULL;
397 + case OP_SIDEBAR_OPEN:
398 case OP_MAIN_CHANGE_FOLDER:
399 case OP_MAIN_NEXT_UNREAD_MAILBOX:
401 @@ -1103,7 +1113,11 @@ int mutt_index_menu (void)
403 mutt_buffy (buf, sizeof (buf));
405 - if (mutt_enter_fname (cp, buf, sizeof (buf), &menu->redraw, 1) == -1)
406 + if ( op == OP_SIDEBAR_OPEN ) {
409 + strncpy( buf, CurBuffy->path, sizeof(buf) );
410 + } else if (mutt_enter_fname (cp, buf, sizeof (buf), &menu->redraw, 1) == -1)
412 if (menu->menu == MENU_PAGER)
414 @@ -1121,6 +1135,7 @@ int mutt_index_menu (void)
417 mutt_expand_path (buf, sizeof (buf));
419 if (mx_get_magic (buf) <= 0)
421 mutt_error (_("%s is not a mailbox."), buf);
422 @@ -2213,6 +2228,12 @@ int mutt_index_menu (void)
426 + case OP_SIDEBAR_SCROLL_UP:
427 + case OP_SIDEBAR_SCROLL_DOWN:
428 + case OP_SIDEBAR_NEXT:
429 + case OP_SIDEBAR_PREV:
430 + scroll_sidebar(op, menu->menu);
433 if (menu->menu == MENU_MAIN)
434 km_error_key (MENU_MAIN);
440 #include "mutt_curses.h"
441 +#include "mutt_menu.h"
444 +#include "sidebar.h"
447 #include "imap_private.h"
448 @@ -294,6 +296,7 @@ void _mutt_set_flag (CONTEXT *ctx, HEADE
450 if (h->searched && (changed != h->changed || deleted != ctx->deleted || tagged != ctx->tagged || flagged != ctx->flagged))
455 void mutt_tag_set_flag (int flag, int bf)
458 @@ -169,6 +169,11 @@ struct binding_t OpMain[] = { /* map: in
459 { "decrypt-save", OP_DECRYPT_SAVE, NULL },
462 + { "sidebar-scroll-up", OP_SIDEBAR_SCROLL_UP, NULL },
463 + { "sidebar-scroll-down", OP_SIDEBAR_SCROLL_DOWN, NULL },
464 + { "sidebar-next", OP_SIDEBAR_NEXT, NULL },
465 + { "sidebar-prev", OP_SIDEBAR_PREV, NULL },
466 + { "sidebar-open", OP_SIDEBAR_OPEN, NULL },
470 @@ -267,6 +272,11 @@ struct binding_t OpPager[] = { /* map: p
471 { "decrypt-save", OP_DECRYPT_SAVE, NULL },
474 + { "sidebar-scroll-up", OP_SIDEBAR_SCROLL_UP, NULL },
475 + { "sidebar-scroll-down", OP_SIDEBAR_SCROLL_DOWN, NULL },
476 + { "sidebar-next", OP_SIDEBAR_NEXT, NULL },
477 + { "sidebar-prev", OP_SIDEBAR_PREV, NULL },
478 + { "sidebar-open", OP_SIDEBAR_OPEN, NULL },
484 @@ -116,6 +116,7 @@ WHERE char *Realname;
485 WHERE char *SendCharset;
486 WHERE char *Sendmail;
488 +WHERE char *SidebarDelim;
489 WHERE char *Signature;
490 WHERE char *SimpleSearch;
492 @@ -212,6 +213,9 @@ WHERE short ScoreThresholdDelete;
493 WHERE short ScoreThresholdRead;
494 WHERE short ScoreThresholdFlag;
496 +WHERE struct buffy_t *CurBuffy INITVAL(0);
497 +WHERE short DrawFullLine INITVAL(0);
498 +WHERE short SidebarWidth;
500 WHERE short ImapKeepalive;
504 @@ -1532,6 +1532,22 @@ struct option_t MuttVars[] = {
505 ** you may unset this setting.
508 + {"sidebar_delim", DT_STR, R_BOTH, UL &SidebarDelim, "|"},
511 + ** This specifies the delimiter between the sidebar (if visible) and
514 + { "sidebar_visible", DT_BOOL, R_BOTH, OPTSIDEBAR, 0 },
517 + ** This specifies whether or not to show sidebar (left-side list of folders).
519 + { "sidebar_width", DT_NUM, R_BOTH, UL &SidebarWidth, 0 },
522 + ** The width of the sidebar.
524 { "pgp_use_gpg_agent", DT_BOOL, R_NONE, OPTUSEGPGAGENT, 0},
530 #define M_NEWFOLDER (1<<4) /* create a new folder - same as M_APPEND, but uses
531 * safe_fopen() for mbox-style folders.
533 +#define M_PEEK (1<<5) /* revert atime back after taking a look (if applicable) */
535 /* mx_open_new_message() */
536 #define M_ADD_FROM 1 /* add a From_ line */
539 @@ -29,7 +29,8 @@ mutt_SOURCES = \
540 score.c send.c sendlib.c signal.c sort.c \
541 status.c system.c thread.c charset.c history.c lib.c \
542 muttlib.c editmsg.c mbyte.c \
543 - url.c ascii.c mutt_idna.c crypt-mod.c crypt-mod.h
544 + url.c ascii.c mutt_idna.c crypt-mod.c crypt-mod.h \
547 nodist_mutt_SOURCES = $(BUILT_SOURCES)
551 @@ -104,6 +104,7 @@ int mmdf_parse_mailbox (CONTEXT *ctx)
552 mutt_perror (ctx->path);
555 + ctx->atime = sb.st_atime;
556 ctx->mtime = sb.st_mtime;
557 ctx->size = sb.st_size;
559 @@ -259,6 +260,7 @@ int mbox_parse_mailbox (CONTEXT *ctx)
561 ctx->size = sb.st_size;
562 ctx->mtime = sb.st_mtime;
563 + ctx->atime = sb.st_atime;
565 #ifdef NFS_ATTRIBUTE_HACK
566 if (sb.st_mtime > sb.st_atime)
570 #include "mutt_curses.h"
571 #include "mutt_menu.h"
573 +#include "sidebar.h"
577 @@ -158,7 +159,7 @@ void menu_pad_string (char *s, size_t n)
579 char *scratch = safe_strdup (s);
580 int shift = option (OPTARROWCURSOR) ? 3 : 0;
581 - int cols = COLS - shift;
582 + int cols = COLS - shift - SidebarWidth;
584 mutt_format_string (s, n, cols, cols, FMT_LEFT, ' ', scratch, mutt_strlen (scratch), 1);
586 @@ -209,6 +210,7 @@ void menu_redraw_index (MUTTMENU *menu)
587 char buf[LONG_STRING];
591 for (i = menu->top; i < menu->top + menu->pagelen; i++)
594 @@ -219,7 +221,7 @@ void menu_redraw_index (MUTTMENU *menu)
595 if (option (OPTARROWCURSOR))
597 attrset (menu->color (i));
598 - CLEARLINE (i - menu->top + menu->offset);
599 + CLEARLINE_WIN (i - menu->top + menu->offset);
601 if (i == menu->current)
603 @@ -248,14 +250,14 @@ void menu_redraw_index (MUTTMENU *menu)
604 BKGDSET (MT_COLOR_INDICATOR);
607 - CLEARLINE (i - menu->top + menu->offset);
608 + CLEARLINE_WIN (i - menu->top + menu->offset);
609 print_enriched_string (menu->color(i), (unsigned char *) buf, i != menu->current);
610 SETCOLOR (MT_COLOR_NORMAL);
611 BKGDSET (MT_COLOR_NORMAL);
615 - CLEARLINE (i - menu->top + menu->offset);
616 + CLEARLINE_WIN (i - menu->top + menu->offset);
620 @@ -270,7 +272,7 @@ void menu_redraw_motion (MUTTMENU *menu)
624 - move (menu->oldcurrent + menu->offset - menu->top, 0);
625 + move (menu->oldcurrent + menu->offset - menu->top, SidebarWidth);
626 SETCOLOR (MT_COLOR_NORMAL);
627 BKGDSET (MT_COLOR_NORMAL);
629 @@ -285,13 +287,13 @@ void menu_redraw_motion (MUTTMENU *menu)
631 menu_make_entry (buf, sizeof (buf), menu, menu->oldcurrent);
632 menu_pad_string (buf, sizeof (buf));
633 - move (menu->oldcurrent + menu->offset - menu->top, 3);
634 + move (menu->oldcurrent + menu->offset - menu->top, SidebarWidth + 3);
635 print_enriched_string (menu->color(menu->oldcurrent), (unsigned char *) buf, 1);
636 SETCOLOR (MT_COLOR_NORMAL);
639 /* now draw it in the new location */
640 - move (menu->current + menu->offset - menu->top, 0);
641 + move (menu->current + menu->offset - menu->top, SidebarWidth);
642 attrset (menu->color (menu->current));
643 ADDCOLOR (MT_COLOR_INDICATOR);
645 @@ -312,7 +314,7 @@ void menu_redraw_motion (MUTTMENU *menu)
646 attrset (menu->color (menu->current));
647 ADDCOLOR (MT_COLOR_INDICATOR);
648 BKGDSET (MT_COLOR_INDICATOR);
649 - CLEARLINE (menu->current - menu->top + menu->offset);
650 + CLEARLINE_WIN (menu->current - menu->top + menu->offset);
651 print_enriched_string (menu->color(menu->current), (unsigned char *) buf, 0);
652 SETCOLOR (MT_COLOR_NORMAL);
653 BKGDSET (MT_COLOR_NORMAL);
654 @@ -324,7 +326,7 @@ void menu_redraw_current (MUTTMENU *menu
656 char buf[LONG_STRING];
658 - move (menu->current + menu->offset - menu->top, 0);
659 + move (menu->current + menu->offset - menu->top, SidebarWidth);
660 menu_make_entry (buf, sizeof (buf), menu, menu->current);
661 menu_pad_string (buf, sizeof (buf));
663 @@ -871,7 +873,7 @@ int mutt_menuLoop (MUTTMENU *menu)
666 if (option (OPTARROWCURSOR))
667 - move (menu->current - menu->top + menu->offset, 2);
668 + move (menu->current - menu->top + menu->offset, SidebarWidth + 2);
669 else if (option (OPTBRAILLEFRIENDLY))
670 move (menu->current - menu->top + menu->offset, 0);
678 +#define CLEARLINE_WIN(x) move(x,SidebarWidth), clrtoeol()
679 #define CLEARLINE(x) move(x,0), clrtoeol()
680 #define CENTERLINE(x,y) move(y, (COLS-strlen(x))/2), addstr(x)
681 #define BEEP() do { if (option (OPTBEEP)) beep(); } while (0)
682 @@ -126,6 +127,8 @@ enum
693 @@ -437,6 +437,7 @@ enum
701 @@ -874,6 +875,7 @@ typedef struct _context
709 @@ -914,6 +916,7 @@ typedef struct _context
710 unsigned int quiet : 1; /* inhibit status messages? */
711 unsigned int collapsed : 1; /* are all threads collapsed? */
712 unsigned int closing : 1; /* mailbox is being closed */
713 + unsigned int peekonly : 1; /* just taking a glance, revert atime */
716 void *data; /* driver specific data */
719 @@ -1205,6 +1205,8 @@ void mutt_FormatString (char *dest, /*
722 /* see if there's room to add content, else ignore */
723 + if ( DrawFullLine )
725 if ((col < COLS && wlen < destlen) || soft)
728 @@ -1247,6 +1249,52 @@ void mutt_FormatString (char *dest, /*
735 + if ((col < COLS-SidebarWidth && wlen < destlen) || soft)
739 + /* get contents after padding */
740 + mutt_FormatString (buf, sizeof (buf), 0, src + pl, callback, data, flags);
741 + len = mutt_strlen (buf);
742 + wid = mutt_strwidth (buf);
744 + /* try to consume as many columns as we can, if we don't have
745 + * memory for that, use as much memory as possible */
746 + pad = (COLS - SidebarWidth - col - wid) / pw;
747 + if (pad > 0 && wlen + (pad * pl) + len > destlen)
748 + pad = ((signed)(destlen - wlen - len)) / pl;
753 + memcpy (wptr, src, pl);
759 + else if (soft && pad < 0)
761 + /* \0-terminate dest for length computation in mutt_wstr_trunc() */
763 + /* make sure right part is at most as wide as display */
764 + len = mutt_wstr_trunc (buf, destlen, COLS, &wid);
765 + /* truncate left so that right part fits completely in */
766 + wlen = mutt_wstr_trunc (dest, destlen - len, col + pad, &col);
767 + wptr = dest + wlen;
769 + if (len + wlen > destlen)
770 + len = mutt_wstr_trunc (buf, destlen - wlen, COLS - SidebarWidth - col, NULL);
771 + memcpy (wptr, buf, len);
778 break; /* skip rest of input */
783 @@ -626,6 +626,7 @@ static int mx_open_mailbox_append (CONTE
784 * M_APPEND open mailbox for appending
785 * M_READONLY open mailbox in read-only mode
786 * M_QUIET only print error messages
787 + * M_PEEK revert atime where applicable
788 * ctx if non-null, context struct to use
790 CONTEXT *mx_open_mailbox (const char *path, int flags, CONTEXT *pctx)
791 @@ -648,6 +649,8 @@ CONTEXT *mx_open_mailbox (const char *pa
793 if (flags & M_READONLY)
795 + if (flags & M_PEEK)
798 if (flags & (M_APPEND|M_NEWFOLDER))
800 @@ -752,9 +755,21 @@ CONTEXT *mx_open_mailbox (const char *pa
801 void mx_fastclose_mailbox (CONTEXT *ctx)
811 + /* fix up the times so buffy won't get confused */
812 + if (ctx->peekonly && ctx->path && ctx->mtime > ctx->atime)
814 + ut.actime = ctx->atime;
815 + ut.modtime = ctx->mtime;
816 + utime (ctx->path, &ut);
824 @@ -179,3 +179,8 @@ OP_WHAT_KEY "display the keycode for a k
825 OP_MAIN_SHOW_LIMIT "show currently active limit pattern"
826 OP_MAIN_COLLAPSE_THREAD "collapse/uncollapse current thread"
827 OP_MAIN_COLLAPSE_ALL "collapse/uncollapse all threads"
828 +OP_SIDEBAR_SCROLL_UP "scroll the mailbox pane up 1 page"
829 +OP_SIDEBAR_SCROLL_DOWN "scroll the mailbox pane down 1 page"
830 +OP_SIDEBAR_NEXT "go down to next mailbox"
831 +OP_SIDEBAR_PREV "go to previous mailbox"
832 +OP_SIDEBAR_OPEN "open hilighted mailbox"
839 +#include "sidebar.h"
840 void set_xterm_title_bar(char *title);
841 void set_xterm_icon_name(char *name);
843 @@ -1069,6 +1070,8 @@ static int format_line (struct line_t **
846 int wrap_cols = mutt_term_width ((flags & M_PAGER_NOWRAP) ? 0 : Wrap);
848 + wrap_cols -= SidebarWidth;
850 /* FIXME: this should come from lineInfo */
851 memset(&mbstate, 0, sizeof(mbstate));
852 @@ -1702,7 +1705,7 @@ mutt_pager (const char *banner, const ch
853 if ((redraw & REDRAW_BODY) || topline != oldtopline)
856 - move (bodyoffset, 0);
857 + move (bodyoffset, SidebarWidth);
858 curline = oldtopline = topline;
861 @@ -1715,6 +1718,7 @@ mutt_pager (const char *banner, const ch
862 &QuoteList, &q_level, &force_redraw, &SearchRE) > 0)
865 + move(lines + bodyoffset, SidebarWidth);
867 last_offset = lineInfo[curline].offset;
868 } while (force_redraw);
869 @@ -1728,6 +1732,7 @@ mutt_pager (const char *banner, const ch
873 + move(lines + bodyoffset, SidebarWidth);
875 /* We are going to update the pager status bar, so it isn't
876 * necessary to reset to normal color now. */
877 @@ -1751,22 +1756,22 @@ mutt_pager (const char *banner, const ch
878 /* print out the pager status bar */
879 SETCOLOR (MT_COLOR_STATUS);
880 BKGDSET (MT_COLOR_STATUS);
881 - CLEARLINE (statusoffset);
882 + CLEARLINE_WIN (statusoffset);
883 if (IsHeader (extra))
885 - size_t l1 = COLS * MB_LEN_MAX;
886 + size_t l1 = (COLS-SidebarWidth) * MB_LEN_MAX;
887 size_t l2 = sizeof (buffer);
888 hfi.hdr = extra->hdr;
889 mutt_make_string_info (buffer, l1 < l2 ? l1 : l2, NONULL (PagerFmt), &hfi, M_FORMAT_MAKEPRINT);
891 else if (IsMsgAttach (extra))
893 - size_t l1 = COLS * MB_LEN_MAX;
894 + size_t l1 = (COLS-SidebarWidth) * MB_LEN_MAX;
895 size_t l2 = sizeof (buffer);
896 hfi.hdr = extra->bdy->hdr;
897 mutt_make_string_info (buffer, l1 < l2 ? l1 : l2, NONULL (PagerFmt), &hfi, M_FORMAT_MAKEPRINT);
899 - mutt_paddstr (COLS, IsHeader (extra) || IsMsgAttach (extra) ? buffer : banner);
900 + mutt_paddstr (COLS-SidebarWidth, IsHeader (extra) || IsMsgAttach (extra) ? buffer : banner);
901 BKGDSET (MT_COLOR_NORMAL);
902 SETCOLOR (MT_COLOR_NORMAL);
903 if (option(OPTXTERMSETTITLES))
904 @@ -1783,18 +1788,23 @@ mutt_pager (const char *banner, const ch
905 /* redraw the pager_index indicator, because the
906 * flags for this message might have changed. */
907 menu_redraw_current (index);
908 + draw_sidebar(MENU_PAGER);
910 /* print out the index status bar */
911 menu_status_line (buffer, sizeof (buffer), index, NONULL(Status));
913 - move (indexoffset + (option (OPTSTATUSONTOP) ? 0 : (indexlen - 1)), 0);
914 + move (indexoffset + (option (OPTSTATUSONTOP) ? 0 : (indexlen - 1)), SidebarWidth);
915 SETCOLOR (MT_COLOR_STATUS);
916 BKGDSET (MT_COLOR_STATUS);
917 - mutt_paddstr (COLS, buffer);
918 + mutt_paddstr (COLS-SidebarWidth, buffer);
919 SETCOLOR (MT_COLOR_NORMAL);
920 BKGDSET (MT_COLOR_NORMAL);
923 + /* if we're not using the index, update every time */
925 + draw_sidebar(MENU_PAGER);
929 if (option(OPTBRAILLEFRIENDLY)) {
930 @@ -2673,6 +2683,13 @@ search_next:
931 redraw = REDRAW_FULL;
934 + case OP_SIDEBAR_SCROLL_UP:
935 + case OP_SIDEBAR_SCROLL_DOWN:
936 + case OP_SIDEBAR_NEXT:
937 + case OP_SIDEBAR_PREV:
938 + scroll_sidebar(ch, MENU_PAGER);
948 + * Copyright (C) ????-2004 Justin Hibbits <jrh29@po.cwru.edu>
949 + * Copyright (C) 2004 Thomer M. Gil <mutt@thomer.com>
951 + * This program is free software; you can redistribute it and/or modify
952 + * it under the terms of the GNU General Public License as published by
953 + * the Free Software Foundation; either version 2 of the License, or
954 + * (at your option) any later version.
956 + * This program is distributed in the hope that it will be useful,
957 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
958 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
959 + * GNU General Public License for more details.
961 + * You should have received a copy of the GNU General Public License
962 + * along with this program; if not, write to the Free Software
963 + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
968 +# include "config.h"
972 +#include "mutt_menu.h"
973 +#include "mutt_curses.h"
974 +#include "sidebar.h"
978 +#include <stdbool.h>
980 +/*BUFFY *CurBuffy = 0;*/
981 +static BUFFY *TopBuffy = 0;
982 +static BUFFY *BottomBuffy = 0;
983 +static int known_lines = 0;
985 +static int quick_log10(int n)
988 + sprintf(string, "%d", n);
989 + return strlen(string);
992 +void calc_boundaries (int menu)
994 + BUFFY *tmp = Incoming;
996 + if ( known_lines != LINES ) {
997 + TopBuffy = BottomBuffy = 0;
998 + known_lines = LINES;
1000 + for ( ; tmp->next != 0; tmp = tmp->next )
1001 + tmp->next->prev = tmp;
1003 + if ( TopBuffy == 0 && BottomBuffy == 0 )
1004 + TopBuffy = Incoming;
1005 + if ( BottomBuffy == 0 ) {
1006 + int count = LINES - 2 - (menu != MENU_PAGER || option(OPTSTATUSONTOP));
1007 + BottomBuffy = TopBuffy;
1008 + while ( --count && BottomBuffy->next )
1009 + BottomBuffy = BottomBuffy->next;
1011 + else if ( TopBuffy == CurBuffy->next ) {
1012 + int count = LINES - 2 - (menu != MENU_PAGER);
1013 + BottomBuffy = CurBuffy;
1014 + tmp = BottomBuffy;
1015 + while ( --count && tmp->prev)
1019 + else if ( BottomBuffy == CurBuffy->prev ) {
1020 + int count = LINES - 2 - (menu != MENU_PAGER);
1021 + TopBuffy = CurBuffy;
1023 + while ( --count && tmp->next )
1025 + BottomBuffy = tmp;
1029 +char *make_sidebar_entry(char *box, int size, int new, int flagged)
1031 + static char *entry = 0;
1034 + int delim_len = strlen(SidebarDelim);
1036 + c = realloc(entry, SidebarWidth - delim_len + 2);
1037 + if ( c ) entry = c;
1038 + entry[SidebarWidth - delim_len + 1] = 0;
1039 + for (; i < SidebarWidth - delim_len + 1; entry[i++] = ' ' );
1041 + strncpy( entry, box, i < (SidebarWidth - delim_len + 1) ? i : (SidebarWidth - delim_len + 1) );
1044 + sprintf(entry + SidebarWidth - delim_len - 3, "?");
1046 + if (flagged > 0) {
1048 + entry + SidebarWidth - delim_len - 5 - quick_log10(size) - quick_log10(new) - quick_log10(flagged),
1049 + "% d(%d)[%d]", size, new, flagged);
1052 + entry + SidebarWidth - delim_len - 3 - quick_log10(size) - quick_log10(new),
1053 + "% d(%d)", size, new);
1055 + } else if (flagged > 0) {
1056 + sprintf( entry + SidebarWidth - delim_len - 3 - quick_log10(size) - quick_log10(flagged), "% d[%d]", size, flagged);
1058 + sprintf( entry + SidebarWidth - delim_len - 1 - quick_log10(size), "% d", size);
1063 +void set_curbuffy(char buf[LONG_STRING])
1065 + BUFFY* tmp = CurBuffy = Incoming;
1071 + if(!strcmp(tmp->path, buf)) {
1083 +int draw_sidebar(int menu) {
1085 + int lines = option(OPTHELP) ? 1 : 0;
1086 + int sidebar_folder_depth;
1087 + char *sidebar_folder_name;
1089 +#ifndef USE_SLANG_CURSES
1092 + short delim_len = strlen(SidebarDelim);
1095 + static bool initialized = false;
1096 + static int prev_show_value;
1097 + static short saveSidebarWidth;
1099 + /* initialize first time */
1100 + if(!initialized) {
1101 + prev_show_value = option(OPTSIDEBAR);
1102 + saveSidebarWidth = SidebarWidth;
1103 + if(!option(OPTSIDEBAR)) SidebarWidth = 0;
1104 + initialized = true;
1107 + /* save or restore the value SidebarWidth */
1108 + if(prev_show_value != option(OPTSIDEBAR)) {
1109 + if(prev_show_value && !option(OPTSIDEBAR)) {
1110 + saveSidebarWidth = SidebarWidth;
1112 + } else if(!prev_show_value && option(OPTSIDEBAR)) {
1113 + SidebarWidth = saveSidebarWidth;
1115 + prev_show_value = option(OPTSIDEBAR);
1119 +// if ( SidebarWidth == 0 ) return 0;
1120 + if (SidebarWidth > 0 && option (OPTSIDEBAR)
1121 + && delim_len >= SidebarWidth) {
1122 + unset_option (OPTSIDEBAR);
1123 + /* saveSidebarWidth = SidebarWidth; */
1124 + if (saveSidebarWidth > delim_len) {
1125 + SidebarWidth = saveSidebarWidth;
1126 + mutt_error (_("Value for sidebar_delim is too long. Disabling sidebar."));
1130 + mutt_error (_("Value for sidebar_delim is too long. Disabling sidebar. Please set your sidebar_width to a sane value."));
1131 + sleep (4); /* the advise to set a sane value should be seen long enough */
1133 + saveSidebarWidth = 0;
1137 + if ( SidebarWidth == 0 || !option(OPTSIDEBAR)) {
1138 + if (SidebarWidth > 0) {
1139 + saveSidebarWidth = SidebarWidth;
1142 + unset_option(OPTSIDEBAR);
1146 + /* get attributes for divider */
1147 + SETCOLOR(MT_COLOR_STATUS);
1148 +#ifndef USE_SLANG_CURSES
1149 + attr_get(&attrs, &color_pair, 0);
1151 + color_pair = attr_get();
1153 + SETCOLOR(MT_COLOR_NORMAL);
1155 + /* draw the divider */
1157 + for ( ; lines < LINES-1-(menu != MENU_PAGER || option(OPTSTATUSONTOP)); lines++ ) {
1158 + move(lines, SidebarWidth - delim_len);
1159 + addstr(NONULL(SidebarDelim));
1160 +#ifndef USE_SLANG_CURSES
1161 + mvchgat(lines, SidebarWidth - delim_len, delim_len, 0, color_pair, NULL);
1165 + if ( Incoming == 0 ) return 0;
1166 + lines = option(OPTHELP) ? 1 : 0; /* go back to the top */
1168 + if ( known_lines != LINES || TopBuffy == 0 || BottomBuffy == 0 )
1169 + calc_boundaries(menu);
1170 + if ( CurBuffy == 0 ) CurBuffy = Incoming;
1174 + SETCOLOR(MT_COLOR_NORMAL);
1176 + for ( ; tmp && lines < LINES-1 - (menu != MENU_PAGER || option(OPTSTATUSONTOP)); tmp = tmp->next ) {
1177 + if ( tmp == CurBuffy )
1178 + SETCOLOR(MT_COLOR_INDICATOR);
1179 + else if ( tmp->msg_unread > 0 )
1180 + SETCOLOR(MT_COLOR_NEW);
1181 + else if ( tmp->msg_flagged > 0 )
1182 + SETCOLOR(MT_COLOR_FLAGGED);
1184 + SETCOLOR(MT_COLOR_NORMAL);
1187 + if ( Context && !strcmp( tmp->path, Context->path ) ) {
1188 + tmp->msg_unread = Context->unread;
1189 + tmp->msgcount = Context->msgcount;
1190 + tmp->msg_flagged = Context->flagged;
1192 + sidebar_folder_depth = 0;
1193 + sidebar_folder_name = "<null>"; // ... just in case
1194 + if ( strlen(tmp->path) > strlen(Maildir) ) {
1196 + 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);
1208 + } else sidebar_folder_name = "INBOX";
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 @@ -2085,6 +2085,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