Advertisement
Guest User

mutt-sidebar-debian-1.5.21-5

a guest
Mar 11th, 2012
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 39.29 KB | None | 0 0
  1. This is the sidebar patch.
  2.  
  3. When enabled, mutt will show a list of mailboxes with (new) message counts in a
  4. separate column on the left side of the screen.
  5.  
  6. As this feature is still considered to be unstable, this patch is only applied
  7. in the "mutt-patched" package.
  8.  
  9. * Configuration variables:
  10.  
  11. sidebar_delim (string, default "|")
  12.  
  13. This specifies the delimiter between the sidebar (if visible) and
  14. other screens.
  15.  
  16. sidebar_visible (boolean, default no)
  17.  
  18. This specifies whether or not to show sidebar (left-side list of folders).
  19.  
  20. sidebar_width (integer, default 0)
  21. -
  22. The width of the sidebar.
  23.  
  24. * Patch source:
  25. - http://www.lunar-linux.org/index.php?page=mutt-sidebar
  26. - http://lunar-linux.org/~tchan/mutt/patch-1.5.19.sidebar.20090522.txt
  27.  
  28. * Changes made:
  29. - 2008-08-02 myon: Refreshed patch using quilt push -f to remove hunks we do
  30. not need (Makefile.in).
  31.  
  32. --- a/Makefile.in
  33. +++ b/Makefile.in
  34. @@ -85,7 +85,8 @@ am_mutt_OBJECTS = addrbook.$(OBJEXT) alias.$(OBJEXT) attach.$(OBJEXT) \
  35. system.$(OBJEXT) thread.$(OBJEXT) charset.$(OBJEXT) \
  36. history.$(OBJEXT) lib.$(OBJEXT) muttlib.$(OBJEXT) \
  37. editmsg.$(OBJEXT) mbyte.$(OBJEXT) url.$(OBJEXT) \
  38. - ascii.$(OBJEXT) crypt-mod.$(OBJEXT) safe_asprintf.$(OBJEXT)
  39. + ascii.$(OBJEXT) crypt-mod.$(OBJEXT) safe_asprintf.$(OBJEXT) \
  40. + sidebar.$(OBJEXT)
  41. am__objects_1 =
  42. am__objects_2 = patchlist.$(OBJEXT) $(am__objects_1)
  43. nodist_mutt_OBJECTS = $(am__objects_2)
  44. @@ -359,7 +360,8 @@ mutt_SOURCES = \
  45. score.c send.c sendlib.c signal.c sort.c \
  46. status.c system.c thread.c charset.c history.c lib.c \
  47. muttlib.c editmsg.c mbyte.c \
  48. - url.c ascii.c crypt-mod.c crypt-mod.h safe_asprintf.c
  49. + url.c ascii.c crypt-mod.c crypt-mod.h safe_asprintf.c \
  50. + sidebar.c
  51.  
  52. nodist_mutt_SOURCES = $(BUILT_SOURCES)
  53. mutt_LDADD = @MUTT_LIB_OBJECTS@ @LIBOBJS@ $(LIBIMAP) $(MUTTLIBS) \
  54. @@ -671,6 +673,7 @@ distclean-compile:
  55. @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/send.Po@am__quote@
  56. @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sendlib.Po@am__quote@
  57. @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sha1.Po@am__quote@
  58. +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sidebar.Po@am__quote@
  59. @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/signal.Po@am__quote@
  60. @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/smime.Po@am__quote@
  61. @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/smtp.Po@am__quote@
  62.  
  63. --- a/Makefile.am
  64. +++ b/Makefile.am
  65. @@ -32,6 +32,7 @@
  66. rfc822.c rfc1524.c rfc2047.c rfc2231.c rfc3676.c \
  67. score.c send.c sendlib.c signal.c sort.c \
  68. status.c system.c thread.c charset.c history.c lib.c \
  69. + sidebar.c \
  70. muttlib.c editmsg.c mbyte.c \
  71. url.c ascii.c crypt-mod.c crypt-mod.h safe_asprintf.c
  72.  
  73. --- a/OPS
  74. +++ b/OPS
  75. @@ -180,3 +180,8 @@
  76. OP_MAIN_SHOW_LIMIT "show currently active limit pattern"
  77. OP_MAIN_COLLAPSE_THREAD "collapse/uncollapse current thread"
  78. OP_MAIN_COLLAPSE_ALL "collapse/uncollapse all threads"
  79. +OP_SIDEBAR_SCROLL_UP "scroll the mailbox pane up 1 page"
  80. +OP_SIDEBAR_SCROLL_DOWN "scroll the mailbox pane down 1 page"
  81. +OP_SIDEBAR_NEXT "go down to next mailbox"
  82. +OP_SIDEBAR_PREV "go to previous mailbox"
  83. +OP_SIDEBAR_OPEN "open hilighted mailbox"
  84. --- a/buffy.c
  85. +++ b/buffy.c
  86. @@ -340,6 +340,68 @@
  87. return rc;
  88. }
  89.  
  90. +/* update message counts for the sidebar */
  91. +void buffy_maildir_update (BUFFY* mailbox)
  92. +{
  93. + char path[_POSIX_PATH_MAX];
  94. + DIR *dirp;
  95. + struct dirent *de;
  96. + char *p;
  97. +
  98. + mailbox->msgcount = 0;
  99. + mailbox->msg_unread = 0;
  100. + mailbox->msg_flagged = 0;
  101. +
  102. + snprintf (path, sizeof (path), "%s/new", mailbox->path);
  103. +
  104. + if ((dirp = opendir (path)) == NULL)
  105. + {
  106. + mailbox->magic = 0;
  107. + return;
  108. + }
  109. +
  110. + while ((de = readdir (dirp)) != NULL)
  111. + {
  112. + if (*de->d_name == '.')
  113. + continue;
  114. +
  115. + if (!(p = strstr (de->d_name, ":2,")) || !strchr (p + 3, 'T')) {
  116. + mailbox->new = 1;
  117. + mailbox->msgcount++;
  118. + mailbox->msg_unread++;
  119. + }
  120. + }
  121. +
  122. + closedir (dirp);
  123. + snprintf (path, sizeof (path), "%s/cur", mailbox->path);
  124. +
  125. + if ((dirp = opendir (path)) == NULL)
  126. + {
  127. + mailbox->magic = 0;
  128. + return;
  129. + }
  130. +
  131. + while ((de = readdir (dirp)) != NULL)
  132. + {
  133. + if (*de->d_name == '.')
  134. + continue;
  135. +
  136. + if (!(p = strstr (de->d_name, ":2,")) || !strchr (p + 3, 'T')) {
  137. + mailbox->msgcount++;
  138. + if ((p = strstr (de->d_name, ":2,"))) {
  139. + if (!strchr (p + 3, 'T')) {
  140. + if (!strchr (p + 3, 'S'))
  141. + mailbox->msg_unread++;
  142. + if (strchr(p + 3, 'F'))
  143. + mailbox->msg_flagged++;
  144. + }
  145. + }
  146. + }
  147. + }
  148. +
  149. + closedir (dirp);
  150. +}
  151. +
  152. /* returns 1 if mailbox has new mail */
  153. static int buffy_mbox_hasnew (BUFFY* mailbox, struct stat *sb)
  154. {
  155. @@ -371,6 +433,20 @@
  156. return rc;
  157. }
  158.  
  159. +/* update message counts for the sidebar */
  160. +void buffy_mbox_update (BUFFY* mailbox)
  161. +{
  162. + CONTEXT *ctx = NULL;
  163. +
  164. + ctx = mx_open_mailbox(mailbox->path, M_READONLY | M_QUIET | M_NOSORT | M_PEEK, NULL);
  165. + if(ctx)
  166. + {
  167. + mailbox->msgcount = ctx->msgcount;
  168. + mailbox->msg_unread = ctx->unread;
  169. + mx_close_mailbox(ctx, 0);
  170. + }
  171. +}
  172. +
  173. int mutt_buffy_check (int force)
  174. {
  175. BUFFY *tmp;
  176. @@ -444,16 +520,19 @@
  177. {
  178. case M_MBOX:
  179. case M_MMDF:
  180. + buffy_mbox_update (tmp);
  181. if (buffy_mbox_hasnew (tmp, &sb) > 0)
  182. BuffyCount++;
  183. break;
  184.  
  185. case M_MAILDIR:
  186. + buffy_maildir_update (tmp);
  187. if (buffy_maildir_hasnew (tmp) > 0)
  188. BuffyCount++;
  189. break;
  190.  
  191. case M_MH:
  192. + mh_buffy_update (tmp->path, &tmp->msgcount, &tmp->msg_unread, &tmp->msg_flagged);
  193. if ((tmp->new = mh_buffy (tmp->path)) > 0)
  194. BuffyCount++;
  195. break;
  196. --- a/buffy.h
  197. +++ b/buffy.h
  198. @@ -25,7 +25,11 @@
  199. char path[_POSIX_PATH_MAX];
  200. off_t size;
  201. struct buffy_t *next;
  202. + struct buffy_t *prev;
  203. short new; /* mailbox has new mail */
  204. + int msgcount; /* total number of messages */
  205. + int msg_unread; /* number of unread messages */
  206. + int msg_flagged; /* number of flagged messages */
  207. short notified; /* user has been notified */
  208. short magic; /* mailbox type */
  209. short newly_created; /* mbox or mmdf just popped into existence */
  210. --- a/color.c
  211. +++ b/color.c
  212. @@ -93,6 +93,8 @@
  213. { "bold", MT_COLOR_BOLD },
  214. { "underline", MT_COLOR_UNDERLINE },
  215. { "index", MT_COLOR_INDEX },
  216. + { "sidebar_new", MT_COLOR_NEW },
  217. + { "sidebar_flagged", MT_COLOR_FLAGGED },
  218. { NULL, 0 }
  219. };
  220.  
  221. --- a/compose.c
  222. +++ b/compose.c
  223. @@ -72,7 +72,7 @@
  224.  
  225. #define HDR_XOFFSET 10
  226. #define TITLE_FMT "%10s" /* Used for Prompts, which are ASCII */
  227. -#define W (COLS - HDR_XOFFSET)
  228. +#define W (COLS - HDR_XOFFSET - SidebarWidth)
  229.  
  230. static char *Prompts[] =
  231. {
  232. @@ -112,7 +112,7 @@
  233. {
  234. int off = 0;
  235.  
  236. - mvaddstr (HDR_CRYPT, 0, "Security: ");
  237. + mvaddstr (HDR_CRYPT, SidebarWidth, "Security: ");
  238.  
  239. if ((WithCrypto & (APPLICATION_PGP | APPLICATION_SMIME)) == 0)
  240. {
  241. @@ -144,7 +144,7 @@
  242. }
  243.  
  244. clrtoeol ();
  245. - move (HDR_CRYPTINFO, 0);
  246. + move (HDR_CRYPTINFO, SidebarWidth);
  247. clrtoeol ();
  248.  
  249. if ((WithCrypto & APPLICATION_PGP)
  250. @@ -161,7 +161,7 @@
  251. && (msg->security & ENCRYPT)
  252. && SmimeCryptAlg
  253. && *SmimeCryptAlg) {
  254. - mvprintw (HDR_CRYPTINFO, 40, "%s%s", _("Encrypt with: "),
  255. + mvprintw (HDR_CRYPTINFO, SidebarWidth + 40, "%s%s", _("Encrypt with: "),
  256. NONULL(SmimeCryptAlg));
  257. off = 20;
  258. }
  259. @@ -175,7 +175,7 @@
  260. int c;
  261. char *t;
  262.  
  263. - mvaddstr (HDR_MIX, 0, " Mix: ");
  264. + mvaddstr (HDR_MIX, SidebarWidth, " Mix: ");
  265.  
  266. if (!chain)
  267. {
  268. @@ -190,7 +190,7 @@
  269. if (t && t[0] == '0' && t[1] == '\0')
  270. t = "<random>";
  271.  
  272. - if (c + mutt_strlen (t) + 2 >= COLS)
  273. + if (c + mutt_strlen (t) + 2 >= COLS - SidebarWidth)
  274. break;
  275.  
  276. addstr (NONULL(t));
  277. @@ -242,7 +242,7 @@
  278.  
  279. buf[0] = 0;
  280. rfc822_write_address (buf, sizeof (buf), addr, 1);
  281. - mvprintw (line, 0, TITLE_FMT, Prompts[line - 1]);
  282. + mvprintw (line, SidebarWidth, TITLE_FMT, Prompts[line - 1]);
  283. mutt_paddstr (W, buf);
  284. }
  285.  
  286. @@ -252,10 +252,10 @@
  287. draw_envelope_addr (HDR_TO, msg->env->to);
  288. draw_envelope_addr (HDR_CC, msg->env->cc);
  289. draw_envelope_addr (HDR_BCC, msg->env->bcc);
  290. - mvprintw (HDR_SUBJECT, 0, TITLE_FMT, Prompts[HDR_SUBJECT - 1]);
  291. + mvprintw (HDR_SUBJECT, SidebarWidth, TITLE_FMT, Prompts[HDR_SUBJECT - 1]);
  292. mutt_paddstr (W, NONULL (msg->env->subject));
  293. draw_envelope_addr (HDR_REPLYTO, msg->env->reply_to);
  294. - mvprintw (HDR_FCC, 0, TITLE_FMT, Prompts[HDR_FCC - 1]);
  295. + mvprintw (HDR_FCC, SidebarWidth, TITLE_FMT, Prompts[HDR_FCC - 1]);
  296. mutt_paddstr (W, fcc);
  297.  
  298. if (WithCrypto)
  299. @@ -266,7 +266,7 @@
  300. #endif
  301.  
  302. SETCOLOR (MT_COLOR_STATUS);
  303. - mvaddstr (HDR_ATTACH - 1, 0, _("-- Attachments"));
  304. + mvaddstr (HDR_ATTACH - 1, SidebarWidth, _("-- Attachments"));
  305. BKGDSET (MT_COLOR_STATUS);
  306. clrtoeol ();
  307.  
  308. @@ -304,7 +304,7 @@
  309. /* redraw the expanded list so the user can see the result */
  310. buf[0] = 0;
  311. rfc822_write_address (buf, sizeof (buf), *addr, 1);
  312. - move (line, HDR_XOFFSET);
  313. + move (line, HDR_XOFFSET+SidebarWidth);
  314. mutt_paddstr (W, buf);
  315.  
  316. return 0;
  317. @@ -549,7 +549,7 @@
  318. if (mutt_get_field ("Subject: ", buf, sizeof (buf), 0) == 0)
  319. {
  320. mutt_str_replace (&msg->env->subject, buf);
  321. - move (HDR_SUBJECT, HDR_XOFFSET);
  322. + move (HDR_SUBJECT, HDR_XOFFSET + SidebarWidth);
  323. clrtoeol ();
  324. if (msg->env->subject)
  325. mutt_paddstr (W, msg->env->subject);
  326. @@ -566,7 +566,7 @@
  327. {
  328. strfcpy (fcc, buf, fcclen);
  329. mutt_pretty_mailbox (fcc, fcclen);
  330. - move (HDR_FCC, HDR_XOFFSET);
  331. + move (HDR_FCC, HDR_XOFFSET + SidebarWidth);
  332. mutt_paddstr (W, fcc);
  333. fccSet = 1;
  334. }
  335. --- a/curs_main.c
  336. +++ b/curs_main.c
  337. @@ -26,7 +26,9 @@
  338. #include "mailbox.h"
  339. #include "mapping.h"
  340. #include "sort.h"
  341. +#include "buffy.h"
  342. #include "mx.h"
  343. +#include "sidebar.h"
  344.  
  345. #ifdef USE_POP
  346. #include "pop.h"
  347. @@ -532,8 +534,12 @@
  348. menu->redraw |= REDRAW_STATUS;
  349. if (do_buffy_notify)
  350. {
  351. - if (mutt_buffy_notify () && option (OPTBEEPNEW))
  352. - beep ();
  353. + if (mutt_buffy_notify ())
  354. + {
  355. + menu->redraw |= REDRAW_FULL;
  356. + if (option (OPTBEEPNEW))
  357. + beep ();
  358. + }
  359. }
  360. else
  361. do_buffy_notify = 1;
  362. @@ -545,6 +551,7 @@
  363. if (menu->redraw & REDRAW_FULL)
  364. {
  365. menu_redraw_full (menu);
  366. + draw_sidebar(menu->menu);
  367. mutt_show_error ();
  368. }
  369.  
  370. @@ -567,10 +574,13 @@
  371.  
  372. if (menu->redraw & REDRAW_STATUS)
  373. {
  374. + DrawFullLine = 1;
  375. menu_status_line (buf, sizeof (buf), menu, NONULL (Status));
  376. + DrawFullLine = 0;
  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. @@ -591,7 +601,7 @@
  385. menu->oldcurrent = -1;
  386.  
  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);
  392. else
  393. @@ -1089,6 +1099,7 @@
  394. menu->redraw = REDRAW_FULL;
  395. break;
  396.  
  397. + case OP_SIDEBAR_OPEN:
  398. case OP_MAIN_CHANGE_FOLDER:
  399. case OP_MAIN_NEXT_UNREAD_MAILBOX:
  400.  
  401. @@ -1120,7 +1131,11 @@
  402. {
  403. mutt_buffy (buf, sizeof (buf));
  404.  
  405. - if (mutt_enter_fname (cp, buf, sizeof (buf), &menu->redraw, 1) == -1)
  406. + if ( op == OP_SIDEBAR_OPEN ) {
  407. + if(!CurBuffy)
  408. + break;
  409. + strncpy( buf, CurBuffy->path, sizeof(buf) );
  410. + } else if (mutt_enter_fname (cp, buf, sizeof (buf), &menu->redraw, 1) == -1)
  411. {
  412. if (menu->menu == MENU_PAGER)
  413. {
  414. @@ -1138,6 +1153,7 @@
  415. }
  416.  
  417. mutt_expand_path (buf, sizeof (buf));
  418. + set_curbuffy(buf);
  419. if (mx_get_magic (buf) <= 0)
  420. {
  421. mutt_error (_("%s is not a mailbox."), buf);
  422. @@ -2241,6 +2257,12 @@
  423. mutt_what_key();
  424. break;
  425.  
  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);
  431. + break;
  432. default:
  433. if (menu->menu == MENU_MAIN)
  434. km_error_key (MENU_MAIN);
  435. --- a/flags.c
  436. +++ b/flags.c
  437. @@ -22,8 +22,10 @@
  438.  
  439. #include "mutt.h"
  440. #include "mutt_curses.h"
  441. +#include "mutt_menu.h"
  442. #include "sort.h"
  443. #include "mx.h"
  444. +#include "sidebar.h"
  445.  
  446. void _mutt_set_flag (CONTEXT *ctx, HEADER *h, int flag, int bf, int upd_ctx)
  447. {
  448. @@ -290,6 +292,7 @@
  449. */
  450. if (h->searched && (changed != h->changed || deleted != ctx->deleted || tagged != ctx->tagged || flagged != ctx->flagged))
  451. h->searched = 0;
  452. + draw_sidebar(0);
  453. }
  454.  
  455. void mutt_tag_set_flag (int flag, int bf)
  456. --- a/functions.h
  457. +++ b/functions.h
  458. @@ -170,6 +170,11 @@
  459. { "decrypt-save", OP_DECRYPT_SAVE, NULL },
  460.  
  461.  
  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 },
  467. { NULL, 0, NULL }
  468. };
  469.  
  470. @@ -274,6 +279,11 @@
  471.  
  472. { "what-key", OP_WHAT_KEY, NULL },
  473.  
  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 },
  479. { NULL, 0, NULL }
  480. };
  481.  
  482. --- a/globals.h
  483. +++ b/globals.h
  484. @@ -117,6 +117,7 @@
  485. WHERE char *SendCharset;
  486. WHERE char *Sendmail;
  487. WHERE char *Shell;
  488. +WHERE char *SidebarDelim;
  489. WHERE char *Signature;
  490. WHERE char *SimpleSearch;
  491. #if USE_SMTP
  492. @@ -210,6 +211,9 @@
  493. WHERE short ScoreThresholdRead;
  494. WHERE short ScoreThresholdFlag;
  495.  
  496. +WHERE struct buffy_t *CurBuffy INITVAL(0);
  497. +WHERE short DrawFullLine INITVAL(0);
  498. +WHERE short SidebarWidth;
  499. #ifdef USE_IMAP
  500. WHERE short ImapKeepalive;
  501. WHERE short ImapPipelineDepth;
  502. --- a/imap/command.c
  503. +++ b/imap/command.c
  504. @@ -1011,6 +1011,13 @@
  505. opened */
  506. status->uidnext = oldun;
  507.  
  508. + /* Added to make the sidebar show the correct numbers */
  509. + if (status->messages)
  510. + {
  511. + inc->msgcount = status->messages;
  512. + inc->msg_unread = status->unseen;
  513. + }
  514. +
  515. FREE (&value);
  516. return;
  517. }
  518. --- a/imap/imap.c
  519. +++ b/imap/imap.c
  520. @@ -1527,7 +1527,7 @@
  521.  
  522. imap_munge_mbox_name (munged, sizeof (munged), name);
  523. snprintf (command, sizeof (command),
  524. - "STATUS %s (UIDNEXT UIDVALIDITY UNSEEN RECENT)", munged);
  525. + "STATUS %s (UIDNEXT UIDVALIDITY UNSEEN RECENT MESSAGES)", munged);
  526.  
  527. if (imap_exec (idata, command, IMAP_CMD_QUEUE) < 0)
  528. {
  529. --- a/init.h
  530. +++ b/init.h
  531. @@ -1965,6 +1965,22 @@
  532. ** not used.
  533. ** (PGP only)
  534. */
  535. + {"sidebar_delim", DT_STR, R_BOTH, UL &SidebarDelim, "|"},
  536. + /*
  537. + ** .pp
  538. + ** This specifies the delimiter between the sidebar (if visible) and
  539. + ** other screens.
  540. + */
  541. + { "sidebar_visible", DT_BOOL, R_BOTH, OPTSIDEBAR, 0 },
  542. + /*
  543. + ** .pp
  544. + ** This specifies whether or not to show sidebar (left-side list of folders).
  545. + */
  546. + { "sidebar_width", DT_NUM, R_BOTH, UL &SidebarWidth, 0 },
  547. + /*
  548. + ** .pp
  549. + ** The width of the sidebar.
  550. + */
  551. { "pgp_use_gpg_agent", DT_BOOL, R_NONE, OPTUSEGPGAGENT, 0},
  552. /*
  553. ** .pp
  554. --- a/mailbox.h
  555. +++ b/mailbox.h
  556. @@ -27,6 +27,7 @@
  557. #define M_NEWFOLDER (1<<4) /* create a new folder - same as M_APPEND, but uses
  558. * safe_fopen() for mbox-style folders.
  559. */
  560. +#define M_PEEK (1<<5) /* revert atime back after taking a look (if applicable) */
  561.  
  562. /* mx_open_new_message() */
  563. #define M_ADD_FROM 1 /* add a From_ line */
  564. --- a/mbox.c
  565. +++ b/mbox.c
  566. @@ -104,6 +104,7 @@
  567. mutt_perror (ctx->path);
  568. return (-1);
  569. }
  570. + ctx->atime = sb.st_atime;
  571. ctx->mtime = sb.st_mtime;
  572. ctx->size = sb.st_size;
  573.  
  574. @@ -255,6 +256,7 @@
  575.  
  576. ctx->size = sb.st_size;
  577. ctx->mtime = sb.st_mtime;
  578. + ctx->atime = sb.st_atime;
  579.  
  580. #ifdef NFS_ATTRIBUTE_HACK
  581. if (sb.st_mtime > sb.st_atime)
  582. --- a/menu.c
  583. +++ b/menu.c
  584. @@ -24,6 +24,7 @@
  585. #include "mutt_curses.h"
  586. #include "mutt_menu.h"
  587. #include "mbyte.h"
  588. +#include "sidebar.h"
  589.  
  590. #include <string.h>
  591. #include <stdlib.h>
  592. @@ -156,7 +157,7 @@
  593. {
  594. char *scratch = safe_strdup (s);
  595. int shift = option (OPTARROWCURSOR) ? 3 : 0;
  596. - int cols = COLS - shift;
  597. + int cols = COLS - shift - SidebarWidth;
  598.  
  599. mutt_format_string (s, n, cols, cols, FMT_LEFT, ' ', scratch, mutt_strlen (scratch), 1);
  600. s[n - 1] = 0;
  601. @@ -207,6 +208,7 @@
  602. char buf[LONG_STRING];
  603. int i;
  604.  
  605. + draw_sidebar(1);
  606. for (i = menu->top; i < menu->top + menu->pagelen; i++)
  607. {
  608. if (i < menu->max)
  609. @@ -217,7 +219,7 @@
  610. if (option (OPTARROWCURSOR))
  611. {
  612. attrset (menu->color (i));
  613. - CLEARLINE (i - menu->top + menu->offset);
  614. + CLEARLINE_WIN (i - menu->top + menu->offset);
  615.  
  616. if (i == menu->current)
  617. {
  618. @@ -246,14 +248,14 @@
  619. BKGDSET (MT_COLOR_INDICATOR);
  620. }
  621.  
  622. - CLEARLINE (i - menu->top + menu->offset);
  623. + CLEARLINE_WIN (i - menu->top + menu->offset);
  624. print_enriched_string (menu->color(i), (unsigned char *) buf, i != menu->current);
  625. SETCOLOR (MT_COLOR_NORMAL);
  626. BKGDSET (MT_COLOR_NORMAL);
  627. }
  628. }
  629. else
  630. - CLEARLINE (i - menu->top + menu->offset);
  631. + CLEARLINE_WIN (i - menu->top + menu->offset);
  632. }
  633. menu->redraw = 0;
  634. }
  635. @@ -268,7 +270,7 @@
  636. return;
  637. }
  638.  
  639. - move (menu->oldcurrent + menu->offset - menu->top, 0);
  640. + move (menu->oldcurrent + menu->offset - menu->top, SidebarWidth);
  641. SETCOLOR (MT_COLOR_NORMAL);
  642. BKGDSET (MT_COLOR_NORMAL);
  643.  
  644. @@ -283,13 +285,13 @@
  645. clrtoeol ();
  646. menu_make_entry (buf, sizeof (buf), menu, menu->oldcurrent);
  647. menu_pad_string (buf, sizeof (buf));
  648. - move (menu->oldcurrent + menu->offset - menu->top, 3);
  649. + move (menu->oldcurrent + menu->offset - menu->top, SidebarWidth + 3);
  650. print_enriched_string (menu->color(menu->oldcurrent), (unsigned char *) buf, 1);
  651. SETCOLOR (MT_COLOR_NORMAL);
  652. }
  653.  
  654. /* now draw it in the new location */
  655. - move (menu->current + menu->offset - menu->top, 0);
  656. + move (menu->current + menu->offset - menu->top, SidebarWidth);
  657. attrset (menu->color (menu->current));
  658. ADDCOLOR (MT_COLOR_INDICATOR);
  659. addstr ("->");
  660. @@ -310,7 +312,7 @@
  661. attrset (menu->color (menu->current));
  662. ADDCOLOR (MT_COLOR_INDICATOR);
  663. BKGDSET (MT_COLOR_INDICATOR);
  664. - CLEARLINE (menu->current - menu->top + menu->offset);
  665. + CLEARLINE_WIN (menu->current - menu->top + menu->offset);
  666. print_enriched_string (menu->color(menu->current), (unsigned char *) buf, 0);
  667. SETCOLOR (MT_COLOR_NORMAL);
  668. BKGDSET (MT_COLOR_NORMAL);
  669. @@ -322,7 +324,7 @@
  670. {
  671. char buf[LONG_STRING];
  672.  
  673. - move (menu->current + menu->offset - menu->top, 0);
  674. + move (menu->current + menu->offset - menu->top, SidebarWidth);
  675. menu_make_entry (buf, sizeof (buf), menu, menu->current);
  676. menu_pad_string (buf, sizeof (buf));
  677.  
  678. @@ -884,7 +886,7 @@
  679.  
  680.  
  681. if (option (OPTARROWCURSOR))
  682. - move (menu->current - menu->top + menu->offset, 2);
  683. + move (menu->current - menu->top + menu->offset, SidebarWidth + 2);
  684. else if (option (OPTBRAILLEFRIENDLY))
  685. move (menu->current - menu->top + menu->offset, 0);
  686. else
  687. --- a/mh.c
  688. +++ b/mh.c
  689. @@ -235,13 +235,37 @@
  690.  
  691. if (mh_read_sequences (&mhs, path) < 0)
  692. return 0;
  693. +
  694. for (i = 0; !r && i <= mhs.max; i++)
  695. - if (mhs_check (&mhs, i) & MH_SEQ_UNSEEN)
  696. + if (mhs_check (&mhs, i) & MH_SEQ_UNSEEN) {
  697. r = 1;
  698. + }
  699. mhs_free_sequences (&mhs);
  700. return r;
  701. }
  702.  
  703. +void mh_buffy_update (const char *path, int *msgcount, int *msg_unread, int *msg_flagged)
  704. +{
  705. + int i;
  706. + struct mh_sequences mhs;
  707. + memset (&mhs, 0, sizeof (mhs));
  708. +
  709. + if (mh_read_sequences (&mhs, path) < 0)
  710. + return;
  711. +
  712. + msgcount = 0;
  713. + msg_unread = 0;
  714. + msg_flagged = 0;
  715. + for (i = 0; i <= mhs.max; i++)
  716. + msgcount++;
  717. + if (mhs_check (&mhs, i) & MH_SEQ_UNSEEN) {
  718. + msg_unread++;
  719. + }
  720. + if (mhs_check (&mhs, i) & MH_SEQ_FLAGGED)
  721. + msg_flagged++;
  722. + mhs_free_sequences (&mhs);
  723. +}
  724. +
  725. static int mh_mkstemp (CONTEXT * dest, FILE ** fp, char **tgt)
  726. {
  727. int fd;
  728. --- a/mutt.h
  729. +++ b/mutt.h
  730. @@ -431,6 +431,7 @@
  731. OPTSAVEEMPTY,
  732. OPTSAVENAME,
  733. OPTSCORE,
  734. + OPTSIDEBAR,
  735. OPTSIGDASHES,
  736. OPTSIGONTOP,
  737. OPTSORTRE,
  738. @@ -874,6 +875,7 @@
  739. {
  740. char *path;
  741. FILE *fp;
  742. + time_t atime;
  743. time_t mtime;
  744. off_t size;
  745. off_t vsize;
  746. @@ -914,6 +916,7 @@
  747. unsigned int quiet : 1; /* inhibit status messages? */
  748. unsigned int collapsed : 1; /* are all threads collapsed? */
  749. unsigned int closing : 1; /* mailbox is being closed */
  750. + unsigned int peekonly : 1; /* just taking a glance, revert atime */
  751.  
  752. /* driver hooks */
  753. void *data; /* driver specific data */
  754. --- a/mutt_curses.h
  755. +++ b/mutt_curses.h
  756. @@ -64,6 +64,7 @@
  757. #undef lines
  758. #endif /* lines */
  759.  
  760. +#define CLEARLINE_WIN(x) move(x,SidebarWidth), clrtoeol()
  761. #define CLEARLINE(x) move(x,0), clrtoeol()
  762. #define CENTERLINE(x,y) move(y, (COLS-strlen(x))/2), addstr(x)
  763. #define BEEP() do { if (option (OPTBEEP)) beep(); } while (0)
  764. @@ -126,6 +127,8 @@
  765. MT_COLOR_BOLD,
  766. MT_COLOR_UNDERLINE,
  767. MT_COLOR_INDEX,
  768. + MT_COLOR_NEW,
  769. + MT_COLOR_FLAGGED,
  770. MT_COLOR_MAX
  771. };
  772.  
  773. --- a/muttlib.c
  774. +++ b/muttlib.c
  775. @@ -1286,6 +1286,8 @@
  776. pl = pw = 1;
  777.  
  778. /* see if there's room to add content, else ignore */
  779. + if ( DrawFullLine )
  780. + {
  781. if ((col < COLS && wlen < destlen) || soft)
  782. {
  783. int pad;
  784. @@ -1329,6 +1331,52 @@
  785. col += wid;
  786. src += pl;
  787. }
  788. + }
  789. + else
  790. + {
  791. + if ((col < COLS-SidebarWidth && wlen < destlen) || soft)
  792. + {
  793. + int pad;
  794. +
  795. + /* get contents after padding */
  796. + mutt_FormatString (buf, sizeof (buf), 0, src + pl, callback, data, flags);
  797. + len = mutt_strlen (buf);
  798. + wid = mutt_strwidth (buf);
  799. +
  800. + /* try to consume as many columns as we can, if we don't have
  801. + * memory for that, use as much memory as possible */
  802. + pad = (COLS - SidebarWidth - col - wid) / pw;
  803. + if (pad > 0 && wlen + (pad * pl) + len > destlen)
  804. + pad = ((signed)(destlen - wlen - len)) / pl;
  805. + if (pad > 0)
  806. + {
  807. + while (pad--)
  808. + {
  809. + memcpy (wptr, src, pl);
  810. + wptr += pl;
  811. + wlen += pl;
  812. + col += pw;
  813. + }
  814. + }
  815. + else if (soft && pad < 0)
  816. + {
  817. + /* \0-terminate dest for length computation in mutt_wstr_trunc() */
  818. + *wptr = 0;
  819. + /* make sure right part is at most as wide as display */
  820. + len = mutt_wstr_trunc (buf, destlen, COLS, &wid);
  821. + /* truncate left so that right part fits completely in */
  822. + wlen = mutt_wstr_trunc (dest, destlen - len, col + pad, &col);
  823. + wptr = dest + wlen;
  824. + }
  825. + if (len + wlen > destlen)
  826. + len = mutt_wstr_trunc (buf, destlen - wlen, COLS - SidebarWidth - col, NULL);
  827. + memcpy (wptr, buf, len);
  828. + wptr += len;
  829. + wlen += len;
  830. + col += wid;
  831. + src += pl;
  832. + }
  833. + }
  834. break; /* skip rest of input */
  835. }
  836. else if (ch == '|')
  837. --- a/mx.c
  838. +++ b/mx.c
  839. @@ -595,6 +595,7 @@
  840. * M_APPEND open mailbox for appending
  841. * M_READONLY open mailbox in read-only mode
  842. * M_QUIET only print error messages
  843. + * M_PEEK revert atime where applicable
  844. * ctx if non-null, context struct to use
  845. */
  846. CONTEXT *mx_open_mailbox (const char *path, int flags, CONTEXT *pctx)
  847. @@ -617,6 +618,8 @@
  848. ctx->quiet = 1;
  849. if (flags & M_READONLY)
  850. ctx->readonly = 1;
  851. + if (flags & M_PEEK)
  852. + ctx->peekonly = 1;
  853.  
  854. if (flags & (M_APPEND|M_NEWFOLDER))
  855. {
  856. @@ -721,9 +724,21 @@
  857. void mx_fastclose_mailbox (CONTEXT *ctx)
  858. {
  859. int i;
  860. +#ifndef BUFFY_SIZE
  861. + struct utimbuf ut;
  862. +#endif
  863.  
  864. if(!ctx)
  865. return;
  866. +#ifndef BUFFY_SIZE
  867. + /* fix up the times so buffy won't get confused */
  868. + if (ctx->peekonly && ctx->path && ctx->mtime > ctx->atime)
  869. + {
  870. + ut.actime = ctx->atime;
  871. + ut.modtime = ctx->mtime;
  872. + utime (ctx->path, &ut);
  873. + }
  874. +#endif
  875.  
  876. /* never announce that a mailbox we've just left has new mail. #3290
  877. * XXX: really belongs in mx_close_mailbox, but this is a nice hook point */
  878. --- a/mx.h
  879. +++ b/mx.h
  880. @@ -61,6 +61,7 @@
  881. int mh_sync_mailbox (CONTEXT *, int *);
  882. int mh_check_mailbox (CONTEXT *, int *);
  883. int mh_buffy (const char *);
  884. +void mh_buffy_update (const char *, int *, int *, int *);
  885. int mh_check_empty (const char *);
  886.  
  887. int maildir_read_dir (CONTEXT *);
  888. --- a/pager.c
  889. +++ b/pager.c
  890. @@ -29,6 +29,7 @@
  891. #include "pager.h"
  892. #include "attach.h"
  893. #include "mbyte.h"
  894. +#include "sidebar.h"
  895.  
  896. #include "mutt_crypt.h"
  897.  
  898. @@ -1095,6 +1096,7 @@
  899. wchar_t wc;
  900. mbstate_t mbstate;
  901. int wrap_cols = mutt_term_width ((flags & M_PAGER_NOWRAP) ? 0 : Wrap);
  902. + wrap_cols -= SidebarWidth;
  903.  
  904. if (check_attachment_marker ((char *)buf) == 0)
  905. wrap_cols = COLS;
  906. @@ -1745,7 +1747,7 @@
  907. if ((redraw & REDRAW_BODY) || topline != oldtopline)
  908. {
  909. do {
  910. - move (bodyoffset, 0);
  911. + move (bodyoffset, SidebarWidth);
  912. curline = oldtopline = topline;
  913. lines = 0;
  914. force_redraw = 0;
  915. @@ -1758,6 +1760,7 @@
  916. &QuoteList, &q_level, &force_redraw, &SearchRE) > 0)
  917. lines++;
  918. curline++;
  919. + move(lines + bodyoffset, SidebarWidth);
  920. }
  921. last_offset = lineInfo[curline].offset;
  922. } while (force_redraw);
  923. @@ -1771,6 +1774,7 @@
  924. addch ('~');
  925. addch ('\n');
  926. lines++;
  927. + move(lines + bodyoffset, SidebarWidth);
  928. }
  929. /* We are going to update the pager status bar, so it isn't
  930. * necessary to reset to normal color now. */
  931. @@ -1794,21 +1798,21 @@
  932. /* print out the pager status bar */
  933. SETCOLOR (MT_COLOR_STATUS);
  934. BKGDSET (MT_COLOR_STATUS);
  935. - CLEARLINE (statusoffset);
  936. + CLEARLINE_WIN (statusoffset);
  937.  
  938. if (IsHeader (extra) || IsMsgAttach (extra))
  939. {
  940. - size_t l1 = COLS * MB_LEN_MAX;
  941. + size_t l1 = (COLS-SidebarWidth) * MB_LEN_MAX;
  942. size_t l2 = sizeof (buffer);
  943. hfi.hdr = (IsHeader (extra)) ? extra->hdr : extra->bdy->hdr;
  944. mutt_make_string_info (buffer, l1 < l2 ? l1 : l2, NONULL (PagerFmt), &hfi, M_FORMAT_MAKEPRINT);
  945. - mutt_paddstr (COLS, buffer);
  946. + mutt_paddstr (COLS-SidebarWidth, buffer);
  947. }
  948. else
  949. {
  950. char bn[STRING];
  951. snprintf (bn, sizeof (bn), "%s (%s)", banner, pager_progress_str);
  952. - mutt_paddstr (COLS, bn);
  953. + mutt_paddstr (COLS-SidebarWidth, bn);
  954. }
  955. BKGDSET (MT_COLOR_NORMAL);
  956. SETCOLOR (MT_COLOR_NORMAL);
  957. @@ -1826,18 +1830,23 @@
  958. /* redraw the pager_index indicator, because the
  959. * flags for this message might have changed. */
  960. menu_redraw_current (index);
  961. + draw_sidebar(MENU_PAGER);
  962.  
  963. /* print out the index status bar */
  964. menu_status_line (buffer, sizeof (buffer), index, NONULL(Status));
  965.  
  966. - move (indexoffset + (option (OPTSTATUSONTOP) ? 0 : (indexlen - 1)), 0);
  967. + move (indexoffset + (option (OPTSTATUSONTOP) ? 0 : (indexlen - 1)), SidebarWidth);
  968. SETCOLOR (MT_COLOR_STATUS);
  969. BKGDSET (MT_COLOR_STATUS);
  970. - mutt_paddstr (COLS, buffer);
  971. + mutt_paddstr (COLS-SidebarWidth, buffer);
  972. SETCOLOR (MT_COLOR_NORMAL);
  973. BKGDSET (MT_COLOR_NORMAL);
  974. }
  975.  
  976. + /* if we're not using the index, update every time */
  977. + if ( index == 0 )
  978. + draw_sidebar(MENU_PAGER);
  979. +
  980. redraw = 0;
  981.  
  982. if (option(OPTBRAILLEFRIENDLY)) {
  983. @@ -2769,6 +2778,13 @@
  984. mutt_what_key ();
  985. break;
  986.  
  987. + case OP_SIDEBAR_SCROLL_UP:
  988. + case OP_SIDEBAR_SCROLL_DOWN:
  989. + case OP_SIDEBAR_NEXT:
  990. + case OP_SIDEBAR_PREV:
  991. + scroll_sidebar(ch, MENU_PAGER);
  992. + break;
  993. +
  994. default:
  995. ch = -1;
  996. break;
  997. --- /dev/null
  998. +++ b/sidebar.c
  999. @@ -0,0 +1,336 @@
  1000. +/*
  1001. + * Copyright (C) ????-2004 Justin Hibbits <jrh29@po.cwru.edu>
  1002. + * Copyright (C) 2004 Thomer M. Gil <mutt@thomer.com>
  1003. + *
  1004. + * This program is free software; you can redistribute it and/or modify
  1005. + * it under the terms of the GNU General Public License as published by
  1006. + * the Free Software Foundation; either version 2 of the License, or
  1007. + * (at your option) any later version.
  1008. + *
  1009. + * This program is distributed in the hope that it will be useful,
  1010. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  1011. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  1012. + * GNU General Public License for more details.
  1013. + *
  1014. + * You should have received a copy of the GNU General Public License
  1015. + * along with this program; if not, write to the Free Software
  1016. + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
  1017. + */
  1018. +
  1019. +
  1020. +#if HAVE_CONFIG_H
  1021. +# include "config.h"
  1022. +#endif
  1023. +
  1024. +#include "mutt.h"
  1025. +#include "mutt_menu.h"
  1026. +#include "mutt_curses.h"
  1027. +#include "sidebar.h"
  1028. +#include "buffy.h"
  1029. +#include <libgen.h>
  1030. +#include "keymap.h"
  1031. +#include <stdbool.h>
  1032. +
  1033. +/*BUFFY *CurBuffy = 0;*/
  1034. +static BUFFY *TopBuffy = 0;
  1035. +static BUFFY *BottomBuffy = 0;
  1036. +static int known_lines = 0;
  1037. +
  1038. +static int quick_log10(int n)
  1039. +{
  1040. + char string[32];
  1041. + sprintf(string, "%d", n);
  1042. + return strlen(string);
  1043. +}
  1044. +
  1045. +void calc_boundaries (int menu)
  1046. +{
  1047. + BUFFY *tmp = Incoming;
  1048. +
  1049. + if ( known_lines != LINES ) {
  1050. + TopBuffy = BottomBuffy = 0;
  1051. + known_lines = LINES;
  1052. + }
  1053. + for ( ; tmp->next != 0; tmp = tmp->next )
  1054. + tmp->next->prev = tmp;
  1055. +
  1056. + if ( TopBuffy == 0 && BottomBuffy == 0 )
  1057. + TopBuffy = Incoming;
  1058. + if ( BottomBuffy == 0 ) {
  1059. + int count = LINES - 2 - (menu != MENU_PAGER || option(OPTSTATUSONTOP));
  1060. + BottomBuffy = TopBuffy;
  1061. + while ( --count && BottomBuffy->next )
  1062. + BottomBuffy = BottomBuffy->next;
  1063. + }
  1064. + else if ( TopBuffy == CurBuffy->next ) {
  1065. + int count = LINES - 2 - (menu != MENU_PAGER);
  1066. + BottomBuffy = CurBuffy;
  1067. + tmp = BottomBuffy;
  1068. + while ( --count && tmp->prev)
  1069. + tmp = tmp->prev;
  1070. + TopBuffy = tmp;
  1071. + }
  1072. + else if ( BottomBuffy == CurBuffy->prev ) {
  1073. + int count = LINES - 2 - (menu != MENU_PAGER);
  1074. + TopBuffy = CurBuffy;
  1075. + tmp = TopBuffy;
  1076. + while ( --count && tmp->next )
  1077. + tmp = tmp->next;
  1078. + BottomBuffy = tmp;
  1079. + }
  1080. +}
  1081. +
  1082. +char *make_sidebar_entry(char *box, int size, int new, int flagged)
  1083. +{
  1084. + static char *entry = 0;
  1085. + char *c;
  1086. + int i = 0;
  1087. + int delim_len = strlen(SidebarDelim);
  1088. +
  1089. + c = realloc(entry, SidebarWidth - delim_len + 2);
  1090. + if ( c ) entry = c;
  1091. + entry[SidebarWidth - delim_len + 1] = 0;
  1092. + for (; i < SidebarWidth - delim_len + 1; entry[i++] = ' ' );
  1093. + i = strlen(box);
  1094. + strncpy( entry, box, i < (SidebarWidth - delim_len + 1) ? i : (SidebarWidth - delim_len + 1) );
  1095. +
  1096. + if (size == -1)
  1097. + sprintf(entry + SidebarWidth - delim_len - 3, "?");
  1098. + else if ( new ) {
  1099. + if (flagged > 0) {
  1100. + sprintf(
  1101. + entry + SidebarWidth - delim_len - 5 - quick_log10(size) - quick_log10(new) - quick_log10(flagged),
  1102. + "% d(%d)[%d]", size, new, flagged);
  1103. + } else {
  1104. + sprintf(
  1105. + entry + SidebarWidth - delim_len - 3 - quick_log10(size) - quick_log10(new),
  1106. + "% d(%d)", size, new);
  1107. + }
  1108. + } else if (flagged > 0) {
  1109. + sprintf( entry + SidebarWidth - delim_len - 3 - quick_log10(size) - quick_log10(flagged), "% d[%d]", size, flagged);
  1110. + } else {
  1111. + sprintf( entry + SidebarWidth - delim_len - 1 - quick_log10(size), "% d", size);
  1112. + }
  1113. + return entry;
  1114. +}
  1115. +
  1116. +void set_curbuffy(char buf[LONG_STRING])
  1117. +{
  1118. + BUFFY* tmp = CurBuffy = Incoming;
  1119. +
  1120. + if (!Incoming)
  1121. + return;
  1122. +
  1123. + while(1) {
  1124. + if(!strcmp(tmp->path, buf)) {
  1125. + CurBuffy = tmp;
  1126. + break;
  1127. + }
  1128. +
  1129. + if(tmp->next)
  1130. + tmp = tmp->next;
  1131. + else
  1132. + break;
  1133. + }
  1134. +}
  1135. +
  1136. +int draw_sidebar(int menu) {
  1137. +
  1138. + int lines = option(OPTHELP) ? 1 : 0;
  1139. + lines += option(OPTSTATUSONTOP) ? 1 : 0;
  1140. +
  1141. + BUFFY *tmp;
  1142. +#ifndef USE_SLANG_CURSES
  1143. + attr_t attrs;
  1144. +#endif
  1145. + short delim_len = strlen(SidebarDelim);
  1146. + short color_pair;
  1147. +
  1148. + static bool initialized = false;
  1149. + static int prev_show_value;
  1150. + static short saveSidebarWidth;
  1151. +
  1152. + /* initialize first time */
  1153. + if(!initialized) {
  1154. + prev_show_value = option(OPTSIDEBAR);
  1155. + saveSidebarWidth = SidebarWidth;
  1156. + if(!option(OPTSIDEBAR)) SidebarWidth = 0;
  1157. + initialized = true;
  1158. + }
  1159. +
  1160. + /* save or restore the value SidebarWidth */
  1161. + if(prev_show_value != option(OPTSIDEBAR)) {
  1162. + if(prev_show_value && !option(OPTSIDEBAR)) {
  1163. + saveSidebarWidth = SidebarWidth;
  1164. + SidebarWidth = 0;
  1165. + } else if(!prev_show_value && option(OPTSIDEBAR)) {
  1166. + SidebarWidth = saveSidebarWidth;
  1167. + }
  1168. + prev_show_value = option(OPTSIDEBAR);
  1169. + }
  1170. +
  1171. +
  1172. +// if ( SidebarWidth == 0 ) return 0;
  1173. + if (SidebarWidth > 0 && option (OPTSIDEBAR)
  1174. + && delim_len >= SidebarWidth) {
  1175. + unset_option (OPTSIDEBAR);
  1176. + /* saveSidebarWidth = SidebarWidth; */
  1177. + if (saveSidebarWidth > delim_len) {
  1178. + SidebarWidth = saveSidebarWidth;
  1179. + mutt_error (_("Value for sidebar_delim is too long. Disabling sidebar."));
  1180. + sleep (2);
  1181. + } else {
  1182. + SidebarWidth = 0;
  1183. + mutt_error (_("Value for sidebar_delim is too long. Disabling sidebar. Please set your sidebar_width to a sane value."));
  1184. + sleep (4); /* the advise to set a sane value should be seen long enough */
  1185. + }
  1186. + saveSidebarWidth = 0;
  1187. + return (0);
  1188. + }
  1189. +
  1190. + if ( SidebarWidth == 0 || !option(OPTSIDEBAR)) {
  1191. + if (SidebarWidth > 0) {
  1192. + saveSidebarWidth = SidebarWidth;
  1193. + SidebarWidth = 0;
  1194. + }
  1195. + unset_option(OPTSIDEBAR);
  1196. + return 0;
  1197. + }
  1198. +
  1199. + /* get attributes for divider */
  1200. + SETCOLOR(MT_COLOR_STATUS);
  1201. +#ifndef USE_SLANG_CURSES
  1202. + attr_get(&attrs, &color_pair, 0);
  1203. +#else
  1204. + color_pair = attr_get();
  1205. +#endif
  1206. + SETCOLOR(MT_COLOR_NORMAL);
  1207. +
  1208. + /* draw the divider */
  1209. +
  1210. + for ( ; lines < LINES-1-(menu != MENU_PAGER || option(OPTSTATUSONTOP)); lines++ ) {
  1211. + move(lines, SidebarWidth - delim_len);
  1212. + addstr(NONULL(SidebarDelim));
  1213. +#ifndef USE_SLANG_CURSES
  1214. + mvchgat(lines, SidebarWidth - delim_len, delim_len, 0, color_pair, NULL);
  1215. +#endif
  1216. + }
  1217. +
  1218. + if ( Incoming == 0 ) return 0;
  1219. + lines = option(OPTHELP) ? 1 : 0; /* go back to the top */
  1220. + lines += option(OPTSTATUSONTOP) ? 1 : 0;
  1221. +
  1222. + if ( known_lines != LINES || TopBuffy == 0 || BottomBuffy == 0 )
  1223. + calc_boundaries(menu);
  1224. + if ( CurBuffy == 0 ) CurBuffy = Incoming;
  1225. +
  1226. + tmp = TopBuffy;
  1227. +
  1228. + SETCOLOR(MT_COLOR_NORMAL);
  1229. +
  1230. + for ( ; tmp && lines < LINES-1 - (menu != MENU_PAGER || option(OPTSTATUSONTOP)); tmp = tmp->next ) {
  1231. + if ( tmp == CurBuffy )
  1232. + SETCOLOR(MT_COLOR_INDICATOR);
  1233. + else if ( tmp->msg_unread > 0 )
  1234. + SETCOLOR(MT_COLOR_NEW);
  1235. + else if ( tmp->msg_flagged > 0 )
  1236. + SETCOLOR(MT_COLOR_FLAGGED);
  1237. + else
  1238. + SETCOLOR(MT_COLOR_NORMAL);
  1239. +
  1240. + move( lines, 0 );
  1241. + if ( Context && !strcmp( tmp->path, Context->path ) ) {
  1242. + tmp->msg_unread = Context->unread;
  1243. + tmp->msgcount = Context->msgcount;
  1244. + tmp->msg_flagged = Context->flagged;
  1245. + }
  1246. + // check whether Maildir is a prefix of the current folder's path
  1247. + short maildir_is_prefix = 0;
  1248. + if ( (strlen(tmp->path) > strlen(Maildir)) &&
  1249. + (strncmp(Maildir, tmp->path, strlen(Maildir)) == 0) )
  1250. + maildir_is_prefix = 1;
  1251. + // calculate depth of current folder and generate its display name with indented spaces
  1252. + int sidebar_folder_depth = 0;
  1253. + char *sidebar_folder_name;
  1254. + sidebar_folder_name = basename(tmp->path);
  1255. + if ( maildir_is_prefix ) {
  1256. + char *tmp_folder_name;
  1257. + int i;
  1258. + tmp_folder_name = tmp->path + strlen(Maildir);
  1259. + for (i = 0; i < strlen(tmp->path) - strlen(Maildir); i++) {
  1260. + if (tmp_folder_name[i] == '/') sidebar_folder_depth++;
  1261. + }
  1262. + if (sidebar_folder_depth > 0) {
  1263. + sidebar_folder_name = malloc(strlen(basename(tmp->path)) + sidebar_folder_depth + 1);
  1264. + for (i=0; i < sidebar_folder_depth; i++)
  1265. + sidebar_folder_name[i]=' ';
  1266. + sidebar_folder_name[i]=0;
  1267. + strncat(sidebar_folder_name, basename(tmp->path), strlen(basename(tmp->path)) + sidebar_folder_depth);
  1268. + }
  1269. + }
  1270. + printw( "%.*s", SidebarWidth - delim_len + 1,
  1271. + make_sidebar_entry(sidebar_folder_name, tmp->msgcount,
  1272. + tmp->msg_unread, tmp->msg_flagged));
  1273. + if (sidebar_folder_depth > 0)
  1274. + free(sidebar_folder_name);
  1275. + lines++;
  1276. + }
  1277. + SETCOLOR(MT_COLOR_NORMAL);
  1278. + for ( ; lines < LINES-1 - (menu != MENU_PAGER || option(OPTSTATUSONTOP)); lines++ ) {
  1279. + int i = 0;
  1280. + move( lines, 0 );
  1281. + for ( ; i < SidebarWidth - delim_len; i++ )
  1282. + addch(' ');
  1283. + }
  1284. + return 0;
  1285. +}
  1286. +
  1287. +
  1288. +void set_buffystats(CONTEXT* Context)
  1289. +{
  1290. + BUFFY *tmp = Incoming;
  1291. + while(tmp) {
  1292. + if(Context && !strcmp(tmp->path, Context->path)) {
  1293. + tmp->msg_unread = Context->unread;
  1294. + tmp->msgcount = Context->msgcount;
  1295. + break;
  1296. + }
  1297. + tmp = tmp->next;
  1298. + }
  1299. +}
  1300. +
  1301. +void scroll_sidebar(int op, int menu)
  1302. +{
  1303. + if(!SidebarWidth) return;
  1304. + if(!CurBuffy) return;
  1305. +
  1306. + switch (op) {
  1307. + case OP_SIDEBAR_NEXT:
  1308. + if ( CurBuffy->next == NULL ) return;
  1309. + CurBuffy = CurBuffy->next;
  1310. + break;
  1311. + case OP_SIDEBAR_PREV:
  1312. + if ( CurBuffy->prev == NULL ) return;
  1313. + CurBuffy = CurBuffy->prev;
  1314. + break;
  1315. + case OP_SIDEBAR_SCROLL_UP:
  1316. + CurBuffy = TopBuffy;
  1317. + if ( CurBuffy != Incoming ) {
  1318. + calc_boundaries(menu);
  1319. + CurBuffy = CurBuffy->prev;
  1320. + }
  1321. + break;
  1322. + case OP_SIDEBAR_SCROLL_DOWN:
  1323. + CurBuffy = BottomBuffy;
  1324. + if ( CurBuffy->next ) {
  1325. + calc_boundaries(menu);
  1326. + CurBuffy = CurBuffy->next;
  1327. + }
  1328. + break;
  1329. + default:
  1330. + return;
  1331. + }
  1332. + calc_boundaries(menu);
  1333. + draw_sidebar(menu);
  1334. +}
  1335. +
  1336. --- /dev/null
  1337. +++ b/sidebar.h
  1338. @@ -0,0 +1,36 @@
  1339. +/*
  1340. + * Copyright (C) ????-2004 Justin Hibbits <jrh29@po.cwru.edu>
  1341. + * Copyright (C) 2004 Thomer M. Gil <mutt@thomer.com>
  1342. + *
  1343. + * This program is free software; you can redistribute it and/or modify
  1344. + * it under the terms of the GNU General Public License as published by
  1345. + * the Free Software Foundation; either version 2 of the License, or
  1346. + * (at your option) any later version.
  1347. + *
  1348. + * This program is distributed in the hope that it will be useful,
  1349. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  1350. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  1351. + * GNU General Public License for more details.
  1352. + *
  1353. + * You should have received a copy of the GNU General Public License
  1354. + * along with this program; if not, write to the Free Software
  1355. + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
  1356. + */
  1357. +
  1358. +#ifndef SIDEBAR_H
  1359. +#define SIDEBAR_H
  1360. +
  1361. +struct MBOX_LIST {
  1362. + char *path;
  1363. + int msgcount;
  1364. + int new;
  1365. +} MBLIST;
  1366. +
  1367. +/* parameter is whether or not to go to the status line */
  1368. +/* used for omitting the last | that covers up the status bar in the index */
  1369. +int draw_sidebar(int);
  1370. +void scroll_sidebar(int, int);
  1371. +void set_curbuffy(char*);
  1372. +void set_buffystats(CONTEXT*);
  1373. +
  1374. +#endif /* SIDEBAR_H */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement