mutt stable branch with some hacks
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Make extended buffy independent of the sidebar.

Add new boolean option $mail_check_stats (default off) and
$mail_check_stats_interval. The first turns extended buffy on. The
second sets the amount of time in between extended buffy checks
(defaulting to 60 seconds).

Remove the option $sidebar_refresh_time.

Change mutt_buffy_check() to only notify the sidebar to redraw if a
mailbox buffy value changes.

Remove the #ifdefs around the extended buffy functions. The next
patch will merge these functions with the basic functions and pass a
parameter instead.

Imap is a special case, because it sends out the status in one batch.
Change this to perform the comparisons inside cmd_parse_status() and
flag the sidebar there. It was previously directly assigning the
status counters (unsigned int) to the buffy->new (short). Change this
to assign 1/0.

+89 -141
+35 -35
buffy.c
··· 45 45 #include <stdio.h> 46 46 47 47 static time_t BuffyTime = 0; /* last time we started checking for mail */ 48 + static time_t BuffyStatsTime = 0; /* last time we check performed mail_check_stats */ 48 49 time_t BuffyDoneTime = 0; /* last time we knew for sure how much mail there was. */ 49 50 static short BuffyCount = 0; /* how many boxes with new mail */ 50 51 static short BuffyNotify = 0; /* # of unnotified new boxes */ ··· 388 389 return 0; 389 390 } 390 391 391 - #ifdef USE_SIDEBAR 392 392 /** 393 393 * buffy_maildir_update_dir - Update counts for one directory 394 394 * @mailbox: BUFFY representing a maildir mailbox ··· 451 451 void 452 452 buffy_maildir_update (BUFFY *mailbox) 453 453 { 454 - if (!option (OPTSIDEBAR)) 455 - return; 456 - 457 454 mailbox->msg_count = 0; 458 455 mailbox->msg_unread = 0; 459 456 mailbox->msg_flagged = 0; ··· 463 460 mailbox->new = 1; 464 461 } 465 462 buffy_maildir_update_dir (mailbox, "cur"); 466 - 467 - mailbox->sb_last_checked = time (NULL); 468 463 } 469 - 470 - #endif 471 464 472 465 /* returns 1 if mailbox has new mail */ 473 466 static int buffy_mbox_hasnew (BUFFY* mailbox, struct stat *sb) ··· 500 493 return rc; 501 494 } 502 495 503 - #ifdef USE_SIDEBAR 504 496 /** 505 497 * buffy_mbox_update - Update messages counts for an mbox mailbox 506 498 * @mailbox: BUFFY representing an mbox mailbox ··· 515 507 { 516 508 CONTEXT *ctx = NULL; 517 509 518 - if (!option (OPTSIDEBAR)) 519 - return; 520 - if ((mailbox->sb_last_checked > sb->st_mtime) && (mailbox->msg_count != 0)) 510 + if ((mailbox->stats_last_checked > sb->st_mtime) && (mailbox->msg_count != 0)) 521 511 return; /* no check necessary */ 522 512 523 513 ctx = mx_open_mailbox (mailbox->path, MUTT_READONLY | MUTT_QUIET | MUTT_NOSORT | MUTT_PEEK, NULL); ··· 526 516 mailbox->msg_count = ctx->msgcount; 527 517 mailbox->msg_unread = ctx->unread; 528 518 mailbox->msg_flagged = ctx->flagged; 529 - mailbox->sb_last_checked = time (NULL); 519 + mailbox->stats_last_checked = time (NULL); 530 520 mx_close_mailbox (ctx, 0); 531 521 } 532 522 } 533 - #endif 534 523 535 524 int mutt_buffy_check (int force) 536 525 { ··· 538 527 struct stat sb; 539 528 struct stat contex_sb; 540 529 time_t t; 530 + int check_stats = 0; 531 + #ifdef USE_SIDEBAR 532 + short orig_new; 533 + int orig_count, orig_unread, orig_flagged; 534 + #endif 541 535 542 536 sb.st_size=0; 543 537 contex_sb.st_dev=0; ··· 555 549 t = time (NULL); 556 550 if (!force && (t - BuffyTime < BuffyTimeout)) 557 551 return BuffyCount; 558 - 552 + 553 + if (option (OPTMAILCHECKSTATS) && 554 + (t - BuffyStatsTime >= BuffyCheckStatsInterval)) 555 + { 556 + check_stats = 1; 557 + BuffyStatsTime = t; 558 + } 559 + 559 560 BuffyTime = t; 560 561 BuffyCount = 0; 561 562 BuffyNotify = 0; 562 563 563 564 #ifdef USE_IMAP 564 - BuffyCount += imap_buffy_check (force); 565 + BuffyCount += imap_buffy_check (force, check_stats); 565 566 #endif 566 567 567 568 /* check device ID and serial number instead of comparing paths */ ··· 572 573 contex_sb.st_ino=0; 573 574 } 574 575 575 - #ifdef USE_SIDEBAR 576 - int should_refresh = mutt_sb_should_refresh(); 577 - #endif 578 576 for (tmp = Incoming; tmp; tmp = tmp->next) 579 577 { 580 578 if (tmp->magic != MUTT_IMAP) ··· 597 595 } 598 596 } 599 597 598 + #ifdef USE_SIDEBAR 599 + orig_new = tmp->new; 600 + orig_count = tmp->msg_count; 601 + orig_unread = tmp->msg_unread; 602 + orig_flagged = tmp->msg_flagged; 603 + #endif 604 + 600 605 /* check to see if the folder is the currently selected folder 601 606 * before polling */ 602 607 if (!Context || !Context->path || ··· 608 613 { 609 614 case MUTT_MBOX: 610 615 case MUTT_MMDF: 611 - #ifdef USE_SIDEBAR 612 - if (should_refresh) 616 + if (check_stats) 613 617 buffy_mbox_update (tmp, &sb); 614 - #endif 615 618 if (buffy_mbox_hasnew (tmp, &sb) > 0) 616 619 BuffyCount++; 617 620 break; 618 621 619 622 case MUTT_MAILDIR: 620 - #ifdef USE_SIDEBAR 621 - if (should_refresh) 623 + if (check_stats) 622 624 buffy_maildir_update (tmp); 623 - #endif 624 625 if (buffy_maildir_hasnew (tmp) > 0) 625 626 BuffyCount++; 626 627 break; 627 628 628 629 case MUTT_MH: 629 - #ifdef USE_SIDEBAR 630 - if (should_refresh) 630 + if (check_stats) 631 631 mh_buffy_update (tmp); 632 - #endif 633 632 mh_buffy(tmp); 634 633 if (tmp->new) 635 634 BuffyCount++; ··· 639 638 else if (option(OPTCHECKMBOXSIZE) && Context && Context->path) 640 639 tmp->size = (off_t) sb.st_size; /* update the size of current folder */ 641 640 641 + #ifdef USE_SIDEBAR 642 + if ((orig_new != tmp->new) || 643 + (orig_count != tmp->msg_count) || 644 + (orig_unread != tmp->msg_unread) || 645 + (orig_flagged != tmp->msg_flagged)) 646 + SidebarNeedsRedraw = 1; 647 + #endif 648 + 642 649 if (!tmp->new) 643 650 tmp->notified = 0; 644 651 else if (!tmp->notified) 645 652 BuffyNotify++; 646 653 } 647 - #ifdef USE_SIDEBAR 648 - if (should_refresh) 649 - { 650 - SidebarNeedsRedraw = 1; 651 - mutt_sb_set_update_time(); 652 - } 653 - #endif 654 654 655 655 BuffyDoneTime = BuffyTime; 656 656 return (BuffyCount);
+6 -4
buffy.h
··· 35 35 struct buffy_t *prev; 36 36 #endif 37 37 short new; /* mailbox has new mail */ 38 - #ifdef USE_SIDEBAR 38 + 39 + /* These next three are only set when OPTMAILCHECKSTATS is set */ 39 40 int msg_count; /* total number of messages */ 40 41 int msg_unread; /* number of unread messages */ 41 42 int msg_flagged; /* number of flagged messages */ 43 + 44 + #ifdef USE_SIDEBAR 42 45 short is_hidden; /* is hidden from the sidebar */ 43 46 #endif 44 47 short notified; /* user has been notified */ 45 48 short magic; /* mailbox type */ 46 49 short newly_created; /* mbox or mmdf just popped into existence */ 47 50 time_t last_visited; /* time of last exit from this mailbox */ 48 - #ifdef USE_SIDEBAR 49 - time_t sb_last_checked; /* time of last buffy check from sidebar */ 50 - #endif 51 + time_t stats_last_checked; /* time of last mail_check_stats calculation */ 51 52 } 52 53 BUFFY; 53 54 54 55 WHERE BUFFY *Incoming INITVAL (0); 55 56 WHERE short BuffyTimeout INITVAL (3); 57 + WHERE short BuffyCheckStatsInterval INITVAL (60); 56 58 57 59 extern time_t BuffyDoneTime; /* last time we knew for sure how much mail there was */ 58 60
+4
contrib/sample.muttrc-sidebar
··· 43 43 # Note: Only the first character of this string is used. 44 44 set sidebar_divider_char = '|' 45 45 46 + # Enable extended buffy mode to calculate total, new, and flagged 47 + # message counts for each mailbox. 48 + set mail_check_stats 49 + 46 50 # Display the Sidebar mailboxes using this format string. 47 51 set sidebar_format = '%B%?F? [%F]?%* %?N?%N/?%S' 48 52
-5
doc/manual.xml.head
··· 8165 8165 <entry><literal>no</literal></entry> 8166 8166 </row> 8167 8167 <row> 8168 - <entry><literal>sidebar_refresh_time</literal></entry> 8169 - <entry>number</entry> 8170 - <entry><literal>60</literal></entry> 8171 - </row> 8172 - <row> 8173 8168 <entry><literal>sidebar_short_path</literal></entry> 8174 8169 <entry>boolean</entry> 8175 8170 <entry><literal>no</literal></entry>
-1
globals.h
··· 222 222 223 223 #ifdef USE_SIDEBAR 224 224 WHERE short SidebarWidth; 225 - WHERE short SidebarRefreshTime; 226 225 WHERE LIST *SidebarWhitelist INITVAL(0); 227 226 WHERE int SidebarNeedsRedraw INITVAL (0); 228 227 #endif
+15 -12
imap/command.c
··· 900 900 IMAP_STATUS *status; 901 901 unsigned int olduv, oldun; 902 902 long litlen; 903 + short new = 0; 903 904 904 905 mailbox = imap_next_word (s); 905 906 ··· 1000 1001 if (olduv && olduv == status->uidvalidity) 1001 1002 { 1002 1003 if (oldun < status->uidnext) 1003 - inc->new = status->unseen; 1004 + new = (status->unseen > 0); 1004 1005 } 1005 1006 else if (!olduv && !oldun) 1006 1007 /* first check per session, use recent. might need a flag for this. */ 1007 - inc->new = status->recent; 1008 + new = (status->recent > 0); 1008 1009 else 1009 - inc->new = status->unseen; 1010 + new = (status->unseen > 0); 1010 1011 } 1011 1012 else 1012 - inc->new = status->unseen; 1013 + new = (status->unseen > 0); 1014 + 1015 + #ifdef USE_SIDEBAR 1016 + if ((inc->new != new) || 1017 + (inc->msg_count != status->messages) || 1018 + (inc->msg_unread != status->unseen)) 1019 + SidebarNeedsRedraw = 1; 1020 + #endif 1021 + inc->new = new; 1022 + inc->msg_count = status->messages; 1023 + inc->msg_unread = status->unseen; 1013 1024 1014 1025 if (inc->new) 1015 1026 /* force back to keep detecting new mail until the mailbox is 1016 1027 opened */ 1017 1028 status->uidnext = oldun; 1018 - 1019 - #ifdef USE_SIDEBAR 1020 - /* Make the sidebar show the correct numbers */ 1021 - if (status->messages) { 1022 - inc->msg_count = status->messages; 1023 - inc->msg_unread = status->unseen; 1024 - } 1025 - #endif 1026 1029 1027 1030 FREE (&value); 1028 1031 return;
+5 -7
imap/imap.c
··· 1503 1503 /* check for new mail in any subscribed mailboxes. Given a list of mailboxes 1504 1504 * rather than called once for each so that it can batch the commands and 1505 1505 * save on round trips. Returns number of mailboxes with new mail. */ 1506 - int imap_buffy_check (int force) 1506 + int imap_buffy_check (int force, int check_stats) 1507 1507 { 1508 1508 IMAP_DATA* idata; 1509 1509 IMAP_DATA* lastdata = NULL; ··· 1524 1524 1525 1525 if (mailbox->magic != MUTT_IMAP) 1526 1526 continue; 1527 - 1528 - mailbox->new = 0; 1529 1527 1530 1528 if (imap_get_mailbox (mailbox->path, &idata, name, sizeof (name)) < 0) 1531 1529 continue; ··· 1558 1556 lastdata = idata; 1559 1557 1560 1558 imap_munge_mbox_name (idata, munged, sizeof (munged), name); 1561 - snprintf (command, sizeof (command), 1562 - #ifdef USE_SIDEBAR 1559 + if (check_stats) 1560 + snprintf (command, sizeof (command), 1563 1561 "STATUS %s (UIDNEXT UIDVALIDITY UNSEEN RECENT MESSAGES)", munged); 1564 - #else 1562 + else 1563 + snprintf (command, sizeof (command), 1565 1564 "STATUS %s (UIDNEXT UIDVALIDITY UNSEEN RECENT)", munged); 1566 - #endif 1567 1565 1568 1566 if (imap_exec (idata, command, IMAP_CMD_QUEUE) < 0) 1569 1567 {
+1 -1
imap/imap.h
··· 38 38 int imap_open_mailbox_append (CONTEXT *ctx); 39 39 int imap_sync_mailbox (CONTEXT *ctx, int expunge, int *index_hint); 40 40 int imap_close_mailbox (CONTEXT *ctx); 41 - int imap_buffy_check (int force); 41 + int imap_buffy_check (int force, int check_stats); 42 42 int imap_status (char *path, int queue); 43 43 int imap_search (CONTEXT* ctx, const pattern_t* pat); 44 44 int imap_subscribe (char *path, int subscribe);
+19 -9
init.h
··· 1409 1409 ** When \fI$$mark_old\fP is set, Mutt does not consider the mailbox to contain new 1410 1410 ** mail if only old messages exist. 1411 1411 */ 1412 + { "mail_check_stats", DT_BOOL, R_NONE, OPTMAILCHECKSTATS, 0 }, 1413 + /* 1414 + ** .pp 1415 + ** When \fIset\fP, mutt will periodically calculate message 1416 + ** statistics of a mailbox while polling for new mail. It will 1417 + ** check for unread, flagged, and total message counts. Because 1418 + ** this operation is more performance intensive, it defaults to 1419 + ** \fIunset\fP, and has a separate option, $$mail_check_stats_interval, to 1420 + ** control how often to update these counts. 1421 + */ 1422 + { "mail_check_stats_interval", DT_NUM, R_NONE, UL &BuffyCheckStatsInterval, 60 }, 1423 + /* 1424 + ** .pp 1425 + ** When $$mail_check_stats is \fIset\fP, this variable configures 1426 + ** how often (in seconds) mutt will update message counts. 1427 + */ 1412 1428 { "mailcap_path", DT_STR, R_NONE, UL &MailcapPath, 0 }, 1413 1429 /* 1414 1430 ** .pp ··· 2727 2743 ** * = Can be optionally printed if nonzero 2728 2744 ** @ = Only applicable to the current folder 2729 2745 ** .pp 2730 - ** A useful value for this is "%B%?F? [%F]?%* %?N?%N/?%S". 2746 + ** In order to use %S, %N, %F, and %!, $$mail_check_stats must 2747 + ** be \fIset\fP. When set, a useful value for this setting is 2748 + ** "%B%?F? [%F]?%* %?N?%N/?%S". 2731 2749 */ 2732 2750 { "sidebar_indent_string", DT_STR, R_BOTH, UL &SidebarIndentString, UL " " }, 2733 2751 /* ··· 2752 2770 ** the list of mailboxes, but wrap around to the beginning. The 2753 2771 ** \fC<sidebar-prev-new>\fP command is similarly affected, wrapping around to 2754 2772 ** the end of the list. 2755 - */ 2756 - { "sidebar_refresh_time", DT_NUM, R_BOTH, UL &SidebarRefreshTime, 60 }, 2757 - /* 2758 - ** .pp 2759 - ** Set sidebar_refresh_time to the minimum number of seconds between refreshes. 2760 - ** This will reduced network traffic. 2761 - ** .pp 2762 - ** \fBNote:\fP Set to 0 to disable refreshing. 2763 2773 */ 2764 2774 { "sidebar_short_path", DT_BOOL, R_BOTH, OPTSIDEBARSHORTPATH, 0 }, 2765 2775 /*
+1 -4
mailbox.h
··· 25 25 #define MUTT_READONLY (1<<2) /* open in read-only mode */ 26 26 #define MUTT_QUIET (1<<3) /* do not print any messages */ 27 27 #define MUTT_NEWFOLDER (1<<4) /* create a new folder - same as MUTT_APPEND, but uses 28 - * safe_fopen() for mbox-style folders. 29 - */ 30 - #ifdef USE_SIDEBAR 28 + * safe_fopen() for mbox-style folders. */ 31 29 #define MUTT_PEEK (1<<5) /* revert atime back after taking a look (if applicable) */ 32 - #endif 33 30 34 31 /* mx_open_new_message() */ 35 32 #define MUTT_ADD_FROM (1<<0) /* add a From_ line */
-4
mbox.c
··· 100 100 mutt_perror (ctx->path); 101 101 return (-1); 102 102 } 103 - #ifdef USE_SIDEBAR 104 103 ctx->atime = sb.st_atime; 105 - #endif 106 104 ctx->mtime = sb.st_mtime; 107 105 ctx->size = sb.st_size; 108 106 ··· 254 252 255 253 ctx->size = sb.st_size; 256 254 ctx->mtime = sb.st_mtime; 257 - #ifdef USE_SIDEBAR 258 255 ctx->atime = sb.st_atime; 259 - #endif 260 256 261 257 #ifdef NFS_ATTRIBUTE_HACK 262 258 if (sb.st_mtime > sb.st_atime)
-6
mh.c
··· 298 298 mhs_free_sequences (&mhs); 299 299 } 300 300 301 - #ifdef USE_SIDEBAR 302 301 /** 303 302 * mh_buffy_update - Update messages counts for an mh mailbox 304 303 * @mailbox: BUFFY representing a maildir mailbox ··· 315 314 if (!mailbox) 316 315 return; 317 316 318 - if (!option (OPTSIDEBAR)) 319 - return; 320 - 321 317 memset (&mhs, 0, sizeof (mhs)); 322 318 323 319 if (mh_read_sequences (&mhs, mailbox->path) < 0) ··· 336 332 mailbox->msg_flagged++; 337 333 } 338 334 mhs_free_sequences (&mhs); 339 - mailbox->sb_last_checked = time (NULL); 340 335 } 341 - #endif 342 336 343 337 static int mh_mkstemp (CONTEXT * dest, FILE ** fp, char **tgt) 344 338 {
+1 -4
mutt.h
··· 388 388 OPTKEEPFLAGGED, 389 389 OPTMAILCAPSANITIZE, 390 390 OPTMAILCHECKRECENT, 391 + OPTMAILCHECKSTATS, 391 392 OPTMAILDIRTRASH, 392 393 OPTMAILDIRCHECKCUR, 393 394 OPTMARKERS, ··· 900 901 { 901 902 char *path; 902 903 FILE *fp; 903 - #ifdef USE_SIDEBAR 904 904 time_t atime; 905 - #endif 906 905 time_t mtime; 907 906 off_t size; 908 907 off_t vsize; ··· 937 936 unsigned int quiet : 1; /* inhibit status messages? */ 938 937 unsigned int collapsed : 1; /* are all threads collapsed? */ 939 938 unsigned int closing : 1; /* mailbox is being closed */ 940 - #ifdef USE_SIDEBAR 941 939 unsigned int peekonly : 1; /* just taking a glance, revert atime */ 942 - #endif 943 940 944 941 /* driver hooks */ 945 942 void *data; /* driver specific data */
+2 -8
mx.c
··· 639 639 ctx->quiet = 1; 640 640 if (flags & MUTT_READONLY) 641 641 ctx->readonly = 1; 642 - #ifdef USE_SIDEBAR 643 642 if (flags & MUTT_PEEK) 644 643 ctx->peekonly = 1; 645 - #endif 646 644 647 645 if (flags & (MUTT_APPEND|MUTT_NEWFOLDER)) 648 646 { ··· 712 710 void mx_fastclose_mailbox (CONTEXT *ctx) 713 711 { 714 712 int i; 713 + struct utimbuf ut; 715 714 716 715 if(!ctx) 717 716 return; 718 717 719 - #ifdef USE_SIDEBAR 720 718 /* fix up the times so buffy won't get confused */ 721 - struct utimbuf ut; 722 719 if (ctx->peekonly && ctx->path && (ctx->mtime > ctx->atime)) { 723 720 ut.actime = ctx->atime; 724 721 ut.modtime = ctx->mtime; 725 722 utime (ctx->path, &ut); 726 723 } 727 - #endif 728 724 729 725 /* never announce that a mailbox we've just left has new mail. #3290 730 726 * XXX: really belongs in mx_close_mailbox, but this is a nice hook point */ 731 - #ifdef USE_SIDEBAR 732 727 if (!ctx->peekonly) 733 - #endif 734 - mutt_buffy_setnotified(ctx->path); 728 + mutt_buffy_setnotified(ctx->path); 735 729 736 730 if (ctx->mx_ops) 737 731 ctx->mx_ops->close (ctx);
-2
mx.h
··· 53 53 void mbox_reset_atime (CONTEXT *, struct stat *); 54 54 55 55 int mh_sync_mailbox (CONTEXT *, int *); 56 - #ifdef USE_SIDEBAR 57 56 void mh_buffy_update (BUFFY *mailbox); 58 - #endif 59 57 int mh_check_empty (const char *); 60 58 61 59 int maildir_check_empty (const char *);
-37
sidebar.c
··· 30 30 31 31 /* Previous values for some sidebar config */ 32 32 static short PreviousSort; /* sidebar_sort_method */ 33 - static time_t LastRefresh; /* Time of last refresh */ 34 33 35 34 /* Keep track of various BUFFYs */ 36 35 static BUFFY *TopBuffy; /* First mailbox visible in sidebar */ ··· 759 758 } 760 759 761 760 /** 762 - * mutt_sb_should_refresh - Check if the sidebar is due to be refreshed 763 - * 764 - * The "sidebar_refresh_time" config option allows the user to limit the frequency 765 - * with which the sidebar is refreshed. 766 - * 767 - * Returns: 768 - * 1 Yes, refresh is due 769 - * 0 No, refresh happened recently 770 - */ 771 - int mutt_sb_should_refresh (void) 772 - { 773 - if (!option (OPTSIDEBAR)) 774 - return 0; 775 - 776 - if (SidebarRefreshTime == 0) 777 - return 0; 778 - 779 - time_t diff = (time (NULL) - LastRefresh); 780 - 781 - return (diff >= SidebarRefreshTime); 782 - } 783 - 784 - /** 785 761 * mutt_sb_change_mailbox - Change the selected mailbox 786 762 * @op: Operation code 787 763 * ··· 928 904 } 929 905 930 906 return OpnBuffy; 931 - } 932 - 933 - /** 934 - * mutt_sb_set_update_time - Note the time that the sidebar was updated 935 - * 936 - * Update the timestamp representing the last sidebar update. If the user 937 - * configures "sidebar_refresh_time", this will help to reduce traffic. 938 - */ 939 - void mutt_sb_set_update_time (void) 940 - { 941 - /* XXX - should this be public? */ 942 - 943 - LastRefresh = time (NULL); 944 907 } 945 908 946 909 /**
-2
sidebar.h
··· 29 29 void mutt_sb_notify_mailbox (BUFFY *b, int created); 30 30 void mutt_sb_set_buffystats (const CONTEXT *ctx); 31 31 BUFFY * mutt_sb_set_open_buffy (const char *path); 32 - void mutt_sb_set_update_time (void); 33 - int mutt_sb_should_refresh (void); 34 32 35 33 #endif /* SIDEBAR_H */