From aef5a55dc7b9e5c8c94a499f2d95896eb6d797fc Mon Sep 17 00:00:00 2001 From: Rudi Chiarito Date: Mon, 9 Sep 2002 21:48:19 +0000 Subject: [PATCH] Add a buffy-list function, and display more information when new mail arrives. With some modifications from tlr. --- OPS | 1 + browser.c | 4 +++ buffy.c | 71 ++++++++++++++++++++++++++++++++++++++++------------- curs_main.c | 4 +++ functions.h | 3 +++ pager.c | 4 +++ protos.h | 1 + 7 files changed, 71 insertions(+), 17 deletions(-) diff --git a/OPS b/OPS index a8cdba2e..17d45fc0 100644 --- a/OPS +++ b/OPS @@ -10,6 +10,7 @@ OP_BROWSER_TELL "display the currently selected file's name" OP_BROWSER_SUBSCRIBE "subscribe to current mailbox (IMAP only)" OP_BROWSER_UNSUBSCRIBE "unsubscribe to current mailbox (IMAP only)" OP_BROWSER_TOGGLE_LSUB "toggle view all/subscribed mailboxes (IMAP only)" +OP_BUFFY_LIST "list mailboxes with new mail" OP_CHANGE_DIRECTORY "change directories" OP_CHECK_NEW "check mailboxes for new mail" OP_COMPOSE_ATTACH_FILE "attach a file(s) to this message" diff --git a/browser.c b/browser.c index 168c4d5f..34778ac2 100644 --- a/browser.c +++ b/browser.c @@ -1106,6 +1106,10 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files, int *num init_menu (&state, menu, title, sizeof (title), buffy); break; + case OP_BUFFY_LIST: + mutt_buffy_list (); + break; + case OP_BROWSER_NEW_FILE: snprintf (buf, sizeof (buf), "%s/", LastDir); diff --git a/buffy.c b/buffy.c index 660075d8..601c338b 100644 --- a/buffy.c +++ b/buffy.c @@ -21,6 +21,8 @@ #include "mailbox.h" #include "mx.h" +#include "mutt_curses.h" + #ifdef USE_IMAP #include "imap.h" #endif @@ -422,29 +424,64 @@ int mutt_buffy_check (int force) return (BuffyCount); } -int mutt_buffy_notify (void) +int mutt_buffy_list (void) { BUFFY *tmp; char path[_POSIX_PATH_MAX]; - - if (mutt_buffy_check (0) && BuffyNotify) + char buffylist[160]; + int pos; + int first; + + pos = 0; + first = 1; + buffylist[0] = 0; + pos += strlen (strncat (buffylist, _("New mail in "), sizeof (buffylist) - 1 - pos)); + for (tmp = Incoming; tmp; tmp = tmp->next) { - for (tmp = Incoming; tmp; tmp = tmp->next) + /* Is there new mail in this mailbox? */ + if (!tmp->new) + continue; + + strfcpy (path, tmp->path, sizeof (path)); + mutt_pretty_mailbox (path); + + if (!first && pos + strlen (path) >= COLS - 7) + break; + + if (!first) + pos += strlen (strncat(buffylist + pos, ", ", sizeof(buffylist)-1-pos)); + + /* Prepend an asterisk to mailboxes not already notified */ + if (!tmp->notified) { - if (tmp->new && !tmp->notified) - { - strfcpy (path, tmp->path, sizeof (path)); - mutt_pretty_mailbox (path); - mutt_message (_("New mail in %s."), path); - tmp->notified = 1; - BuffyNotify--; - return (1); - } + pos += strlen (strncat(buffylist + pos, "*", sizeof(buffylist)-1-pos)); + tmp->notified = 1; + BuffyNotify--; } - /* there were no mailboxes needing to be notified, so clean up since - * BuffyNotify has somehow gottten out of sync - */ - BuffyNotify = 0; + pos += strlen (strncat(buffylist + pos, path, sizeof(buffylist)-1-pos)); + first = 0; + } + if (!first && tmp) + { + strncat (buffylist + pos, ", ...", sizeof (buffylist) - 1 - pos); + } + if (!first) + { + mutt_message ("%s", buffylist); + return (1); + } + /* there were no mailboxes needing to be notified, so clean up since + * BuffyNotify has somehow gotten out of sync + */ + BuffyNotify = 0; + return (0); +} + +int mutt_buffy_notify (void) +{ + if (mutt_buffy_check (0) && BuffyNotify) + { + return (mutt_buffy_list ()); } return (0); } diff --git a/curs_main.c b/curs_main.c index c08bac3d..61fd0d2f 100644 --- a/curs_main.c +++ b/curs_main.c @@ -1969,6 +1969,10 @@ int mutt_index_menu (void) mutt_version (); break; + case OP_BUFFY_LIST: + mutt_buffy_list (); + break; + case OP_VIEW_ATTACHMENTS: CHECK_MSGCOUNT; CHECK_VISIBLE; diff --git a/functions.h b/functions.h index d38ce8d8..eae16756 100644 --- a/functions.h +++ b/functions.h @@ -125,6 +125,7 @@ struct binding_t OpMain[] = { { "set-flag", OP_MAIN_SET_FLAG, "w" }, { "clear-flag", OP_MAIN_CLEAR_FLAG, "W" }, { "display-message", OP_DISPLAY_MESSAGE, M_ENTER_S }, + { "buffy-list", OP_BUFFY_LIST, "." }, { "sync-mailbox", OP_MAIN_SYNC_FOLDER, "$" }, { "display-address", OP_DISPLAY_ADDRESS, "@" }, { "pipe-message", OP_PIPE, "|" }, @@ -212,6 +213,7 @@ struct binding_t OpPager[] = { { "sync-mailbox", OP_MAIN_SYNC_FOLDER, "$" }, { "shell-escape", OP_SHELL_ESCAPE, "!" }, { "enter-command", OP_ENTER_COMMAND, ":" }, + { "buffy-list", OP_BUFFY_LIST, "." }, { "search", OP_SEARCH, "/" }, { "search-reverse", OP_SEARCH_REVERSE, "\033/" }, { "search-opposite", OP_SEARCH_OPPOSITE, NULL }, @@ -359,6 +361,7 @@ struct binding_t OpBrowser[] = { { "check-new", OP_CHECK_NEW, NULL }, { "toggle-mailboxes", OP_TOGGLE_MAILBOXES, "\t" }, { "view-file", OP_BROWSER_VIEW_FILE, " " }, + { "buffy-list", OP_BUFFY_LIST, "." }, #ifdef USE_IMAP { "create-mailbox", OP_CREATE_MAILBOX, "C" }, { "delete-mailbox", OP_DELETE_MAILBOX, "d" }, diff --git a/pager.c b/pager.c index d3a74cdb..75f06597 100644 --- a/pager.c +++ b/pager.c @@ -2504,6 +2504,10 @@ mutt_pager (const char *banner, const char *fname, int flags, pager_t *extra) mutt_version (); break; + case OP_BUFFY_LIST: + mutt_buffy_list (); + break; + case OP_VIEW_ATTACHMENTS: if (flags & M_PAGER_ATTACHMENT) { diff --git a/protos.h b/protos.h index 25dc1863..54e008bb 100644 --- a/protos.h +++ b/protos.h @@ -149,6 +149,7 @@ void mutt_block_signals_system (void); void mutt_body_handler (BODY *, STATE *); void mutt_bounce_message (FILE *fp, HEADER *, ADDRESS *); void mutt_buffy (char *, size_t); +int mutt_buffy_list (void); void mutt_canonical_charset (char *, size_t, const char *); void mutt_check_rescore (CONTEXT *); void mutt_clear_error (void); -- 2.40.0