From d879724559e9802820eb61b6378e29cfb921323b Mon Sep 17 00:00:00 2001 From: Richard Russon Date: Wed, 2 Dec 2015 03:58:44 +0000 Subject: [PATCH] build: conditional compilation Make sidebar compilation conditional on a configure option. Add --enable-sidebar option to configure Alter Makefile to honour configure Move our OPS into OPS.sidebar Surround all our code with #ifdef USE_SIDEBAR By using the unifdef program, all the sidebar code can be removed. The result is code that differs only slightly from the original mutt code. Run this on each source file: unifdef -Bm -UUSE_SIDEBAR -UHAVE_FMEMOPEN Then run sed using this script: s/ *- *SidebarWidth//g s/ *+ *SidebarWidth//g s/SidebarWidth *+ *//g s/SidebarWidth/0/g Compared to the original mutt code, there are some minor changes, such as whitespace, and minor refactoring of variables. Note: One sidebar global variable is left-behind: SidebarWidth. This is deeply embedded in the mutt code. This is because mutt hard-codes a lot of values: 0's for the left-hand side of the screen and COLS representing the width of the screen. --- Makefile.am | 11 ++++++++--- OPS | 7 ------- OPS.SIDEBAR | 7 +++++++ buffy.c | 34 ++++++++++++++++++++++++++++++++++ buffy.h | 8 ++++++++ color.c | 2 ++ compose.c | 4 ++++ configure.ac | 9 +++++++++ curs_main.c | 28 +++++++++++++++++++++++++++- flags.c | 5 +++++ functions.h | 4 ++++ globals.h | 8 +++++++- imap/command.c | 4 +++- imap/imap.c | 4 ++++ init.h | 4 ++++ mailbox.h | 2 ++ main.c | 16 ++++++++++++++++ mbox.c | 4 ++++ menu.c | 8 ++++++++ mh.c | 2 ++ mutt.h | 6 ++++++ mutt_curses.h | 4 ++++ mutt_menu.h | 2 ++ mx.c | 12 ++++++++++++ mx.h | 2 ++ pager.c | 21 ++++++++++++++++++++- 26 files changed, 204 insertions(+), 14 deletions(-) create mode 100644 OPS.SIDEBAR diff --git a/Makefile.am b/Makefile.am index 20ead5f04..e7c4f3e2d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -33,7 +33,6 @@ mutt_SOURCES = \ rfc822.c rfc1524.c rfc2047.c rfc2231.c rfc3676.c \ score.c send.c sendlib.c signal.c sort.c \ status.c system.c thread.c charset.c history.c lib.c \ - sidebar.c \ muttlib.c editmsg.c mbyte.c \ url.c ascii.c crypt-mod.c crypt-mod.h safe_asprintf.c @@ -78,6 +77,12 @@ EXTRA_DIST = COPYRIGHT GPL OPS OPS.PGP OPS.CRYPT OPS.SMIME TODO UPDATING \ EXTRA_SCRIPTS = smime_keys +if BUILD_SIDEBAR +mutt_SOURCES += sidebar.c sidebar.h +endif + +EXTRA_DIST += OPS.SIDEBAR + mutt_dotlock_SOURCES = mutt_dotlock.c mutt_dotlock_LDADD = $(LIBOBJS) mutt_dotlock_DEPENDENCIES = $(LIBOBJS) @@ -130,10 +135,10 @@ smime_keys: $(srcdir)/smime_keys.pl keymap_defs.h: $(OPS) $(srcdir)/gen_defs $(srcdir)/gen_defs $(OPS) > keymap_defs.h -keymap_alldefs.h: $(srcdir)/OPS $(srcdir)/OPS.PGP $(srcdir)/OPS.MIX $(srcdir)/OPS.CRYPT $(srcdir)/OPS.SMIME $(srcdir)/gen_defs +keymap_alldefs.h: $(srcdir)/OPS $(srcdir)/OPS.SIDEBAR $(srcdir)/OPS.PGP $(srcdir)/OPS.MIX $(srcdir)/OPS.CRYPT $(srcdir)/OPS.SMIME $(srcdir)/gen_defs rm -f $@ $(srcdir)/gen_defs $(srcdir)/OPS $(srcdir)/OPS.PGP \ - $(srcdir)/OPS.MIX $(srcdir)/OPS.CRYPT $(srcdir)/OPS.SMIME \ + $(srcdir)/OPS.SIDEBAR $(srcdir)/OPS.MIX $(srcdir)/OPS.CRYPT $(srcdir)/OPS.SMIME \ > keymap_alldefs.h reldate.h: $(srcdir)/ChangeLog diff --git a/OPS b/OPS index 9c8670a16..8414a8b33 100644 --- a/OPS +++ b/OPS @@ -179,10 +179,3 @@ OP_WHAT_KEY "display the keycode for a key press" OP_MAIN_SHOW_LIMIT "show currently active limit pattern" OP_MAIN_COLLAPSE_THREAD "collapse/uncollapse current thread" OP_MAIN_COLLAPSE_ALL "collapse/uncollapse all threads" -OP_SIDEBAR_SCROLL_UP "scroll the mailbox pane up 1 page" -OP_SIDEBAR_SCROLL_DOWN "scroll the mailbox pane down 1 page" -OP_SIDEBAR_NEXT "go down to next mailbox" -OP_SIDEBAR_PREV "go to previous mailbox" -OP_SIDEBAR_OPEN "open hilighted mailbox" -OP_SIDEBAR_NEXT_NEW "go down to next mailbox with new mail" -OP_SIDEBAR_PREV_NEW "go to previous mailbox with new mail" diff --git a/OPS.SIDEBAR b/OPS.SIDEBAR new file mode 100644 index 000000000..3f261c867 --- /dev/null +++ b/OPS.SIDEBAR @@ -0,0 +1,7 @@ +OP_SIDEBAR_NEXT "Move the highlight to next mailbox" +OP_SIDEBAR_NEXT_NEW "Move the highlight to next mailbox with new mail" +OP_SIDEBAR_OPEN "Open highlighted mailbox" +OP_SIDEBAR_PREV "Move the highlight to previous mailbox" +OP_SIDEBAR_PREV_NEW "Move the highlight to previous mailbox with new mail" +OP_SIDEBAR_SCROLL_DOWN "Scroll the Sidebar down 1 page" +OP_SIDEBAR_SCROLL_UP "Scroll the Sidebar up 1 page" diff --git a/buffy.c b/buffy.c index 2409a71a1..21c136b20 100644 --- a/buffy.c +++ b/buffy.c @@ -26,7 +26,10 @@ #include "mx.h" #include "mutt_curses.h" + +#ifdef USE_SIDEBAR #include "sidebar.h" +#endif #ifdef USE_IMAP #include "imap.h" @@ -162,6 +165,7 @@ void mutt_buffy_cleanup (const char *buf, struct stat *st) } } +#ifdef USE_SIDEBAR /** * buffy_compare_name - qsort callback to sort BUFFYs * @a: First BUFFY to compare @@ -232,6 +236,7 @@ buffy_sort (BUFFY *b) free (ary); return tmp; } +#endif BUFFY *mutt_find_mailbox (const char *path) { @@ -268,13 +273,17 @@ void mutt_update_mailbox (BUFFY * b) static BUFFY *buffy_new (const char *path) { BUFFY* buffy; +#ifdef USE_SIDEBAR char rp[PATH_MAX] = ""; char *r = NULL; +#endif buffy = (BUFFY *) safe_calloc (1, sizeof (BUFFY)); strfcpy (buffy->path, path, sizeof (buffy->path)); +#ifdef USE_SIDEBAR r = realpath (path, rp); strfcpy (buffy->realpath, r ? rp : path, sizeof (buffy->realpath)); +#endif buffy->next = NULL; buffy->magic = 0; @@ -292,7 +301,9 @@ int mutt_parse_mailboxes (BUFFER *path, BUFFER *s, unsigned long data, BUFFER *e char buf[_POSIX_PATH_MAX]; struct stat sb; char f1[PATH_MAX]; +#ifndef USE_SIDEBAR char f2[PATH_MAX]; +#endif char *p, *q; while (MoreArgs (s)) @@ -320,8 +331,13 @@ int mutt_parse_mailboxes (BUFFER *path, BUFFER *s, unsigned long data, BUFFER *e p = realpath (buf, f1); for (tmp = &Incoming; *tmp; tmp = &((*tmp)->next)) { +#ifdef USE_SIDEBAR q = (*tmp)->realpath; if (mutt_strcmp (p ? p : buf, q) == 0) +#else + q = realpath ((*tmp)->path, f2); + if (mutt_strcmp (p ? p : buf, q ? q : (*tmp)->path) == 0) +#endif { dprint(3,(debugfile,"mailbox '%s' already registered as '%s'\n", buf, (*tmp)->path)); break; @@ -359,7 +375,9 @@ int mutt_parse_mailboxes (BUFFER *path, BUFFER *s, unsigned long data, BUFFER *e else (*tmp)->size = 0; } +#ifdef USE_SIDEBAR Incoming = buffy_sort (Incoming); +#endif return 0; } @@ -384,10 +402,12 @@ static int buffy_maildir_dir_hasnew(BUFFY* mailbox, const char *dir_name) return 0; } +#ifdef USE_SIDEBAR if (option (OPTSIDEBAR) && mailbox->msg_unread > 0) { mailbox->new = 1; return 1; } +#endif if ((dirp = opendir (path)) == NULL) { @@ -441,6 +461,7 @@ static int buffy_maildir_hasnew (BUFFY* mailbox) return 0; } +#ifdef USE_SIDEBAR /** * buffy_maildir_update - Update messages counts for a maildir mailbox * @mailbox: BUFFY representing a maildir mailbox @@ -511,6 +532,7 @@ buffy_maildir_update (BUFFY *mailbox) mailbox->sb_last_checked = time (NULL); closedir (dirp); } +#endif /* returns 1 if mailbox has new mail */ static int buffy_mbox_hasnew (BUFFY* mailbox, struct stat *sb) @@ -523,7 +545,11 @@ static int buffy_mbox_hasnew (BUFFY* mailbox, struct stat *sb) else statcheck = sb->st_mtime > sb->st_atime || (mailbox->newly_created && sb->st_ctime == sb->st_mtime && sb->st_ctime == sb->st_atime); +#ifdef USE_SIDEBAR if ((!option (OPTSIDEBAR) && statcheck) || (option (OPTSIDEBAR) && mailbox->msg_unread > 0)) +#else + if (statcheck) +#endif { if (!option(OPTMAILCHECKRECENT) || sb->st_mtime > mailbox->last_visited) { @@ -543,6 +569,7 @@ static int buffy_mbox_hasnew (BUFFY* mailbox, struct stat *sb) return rc; } +#ifdef USE_SIDEBAR /** * buffy_mbox_update - Update messages counts for an mbox mailbox * @mailbox: BUFFY representing an mbox mailbox @@ -571,6 +598,7 @@ buffy_mbox_update (BUFFY *mailbox, struct stat *sb) mx_close_mailbox (ctx, 0); } } +#endif int mutt_buffy_check (int force) { @@ -645,28 +673,34 @@ int mutt_buffy_check (int force) { case M_MBOX: case M_MMDF: +#ifdef USE_SIDEBAR if (sb_should_refresh()) { buffy_mbox_update (tmp, &sb); sb_set_update_time(); } +#endif if (buffy_mbox_hasnew (tmp, &sb) > 0) BuffyCount++; break; case M_MAILDIR: +#ifdef USE_SIDEBAR if (sb_should_refresh()) { buffy_maildir_update (tmp); sb_set_update_time(); } +#endif if (buffy_maildir_hasnew (tmp) > 0) BuffyCount++; break; case M_MH: +#ifdef USE_SIDEBAR if (sb_should_refresh()) { mh_buffy_update (tmp->path, &tmp->msgcount, &tmp->msg_unread, &tmp->msg_flagged, &tmp->sb_last_checked); sb_set_update_time(); } +#endif mh_buffy(tmp); if (tmp->new) BuffyCount++; diff --git a/buffy.h b/buffy.h index cf51f02fa..1eaa92eda 100644 --- a/buffy.h +++ b/buffy.h @@ -23,19 +23,27 @@ typedef struct buffy_t { char path[_POSIX_PATH_MAX]; +#ifdef USE_SIDEBAR char realpath[_POSIX_PATH_MAX]; +#endif off_t size; struct buffy_t *next; +#ifdef USE_SIDEBAR struct buffy_t *prev; +#endif short new; /* mailbox has new mail */ +#ifdef USE_SIDEBAR int msgcount; /* total number of messages */ int msg_unread; /* number of unread messages */ int msg_flagged; /* number of flagged messages */ +#endif short notified; /* user has been notified */ short magic; /* mailbox type */ short newly_created; /* mbox or mmdf just popped into existence */ time_t last_visited; /* time of last exit from this mailbox */ +#ifdef USE_SIDEBAR time_t sb_last_checked; /* time of last buffy check from sidebar */ +#endif } BUFFY; diff --git a/color.c b/color.c index ea48453a6..582fa91ac 100644 --- a/color.c +++ b/color.c @@ -94,8 +94,10 @@ static const struct mapping_t Fields[] = { "underline", MT_COLOR_UNDERLINE }, { "index", MT_COLOR_INDEX }, { "prompt", MT_COLOR_PROMPT }, +#ifdef USE_SIDEBAR { "sidebar_flagged", MT_COLOR_FLAGGED }, { "sidebar_new", MT_COLOR_NEW }, +#endif { NULL, 0 } }; diff --git a/compose.c b/compose.c index dcc7423ba..5ec9f3ff4 100644 --- a/compose.c +++ b/compose.c @@ -32,7 +32,9 @@ #include "mailbox.h" #include "sort.h" #include "charset.h" +#ifdef USE_SIDEBAR #include "sidebar.h" +#endif #ifdef MIXMASTER #include "remailer.h" @@ -249,7 +251,9 @@ static void draw_envelope_addr (int line, ADDRESS *addr) static void draw_envelope (HEADER *msg, char *fcc) { +#ifdef USE_SIDEBAR sb_draw(); +#endif draw_envelope_addr (HDR_FROM, msg->env->from); draw_envelope_addr (HDR_TO, msg->env->to); draw_envelope_addr (HDR_CC, msg->env->cc); diff --git a/configure.ac b/configure.ac index 1a76cd751..2343e050d 100644 --- a/configure.ac +++ b/configure.ac @@ -175,6 +175,15 @@ if test x$have_smime != xno ; then SMIMEAUX_TARGET="smime_keys" fi +AC_ARG_ENABLE(sidebar, AC_HELP_STRING([--enable-sidebar], [Enable Sidebar support]), +[ if test x$enableval = xyes ; then + AC_DEFINE(USE_SIDEBAR,1,[ Define if you want support for the sidebar. ]) + OPS="$OPS \$(srcdir)/OPS.SIDEBAR" + need_sidebar="yes" + fi +]) +AM_CONDITIONAL(BUILD_SIDEBAR, test x$need_sidebar = xyes) + AC_ARG_WITH(mixmaster, AS_HELP_STRING([--with-mixmaster@<:@=PATH@:>@],[Include Mixmaster support]), [if test "$withval" != no then diff --git a/curs_main.c b/curs_main.c index d52a5d06f..325abec90 100644 --- a/curs_main.c +++ b/curs_main.c @@ -28,7 +28,10 @@ #include "sort.h" #include "buffy.h" #include "mx.h" + +#ifdef USE_SIDEBAR #include "sidebar.h" +#endif #ifdef USE_POP #include "pop.h" @@ -609,8 +612,10 @@ int mutt_index_menu (void) do_buffy_notify = 1; } +#ifdef USE_SIDEBAR if (option (OPTSIDEBAR)) menu->redraw |= REDRAW_SIDEBAR; +#endif if (op != -1) mutt_curs_set (0); @@ -618,12 +623,17 @@ int mutt_index_menu (void) if (menu->redraw & REDRAW_FULL) { menu_redraw_full (menu); +#ifdef USE_SIDEBAR sb_draw(); +#endif mutt_show_error (); - } else if (menu->redraw & REDRAW_SIDEBAR) { + } +#ifdef USE_SIDEBAR + else if (menu->redraw & REDRAW_SIDEBAR) { sb_draw(); menu->redraw &= ~REDRAW_SIDEBAR; } +#endif if (menu->menu == MENU_MAIN) { @@ -644,14 +654,20 @@ int mutt_index_menu (void) if (menu->redraw & REDRAW_STATUS) { +#ifdef USE_SIDEBAR /* Temporarily lie about the sidebar width */ short sw = SidebarWidth; SidebarWidth = 0; +#endif menu_status_line (buf, sizeof (buf), menu, NONULL (Status)); +#ifdef USE_SIDEBAR SidebarWidth = sw; /* Restore the sidebar width */ +#endif move (option (OPTSTATUSONTOP) ? 0 : LINES-2, 0); SETCOLOR (MT_COLOR_STATUS); +#ifdef USE_SIDEBAR sb_set_buffystats (Context); +#endif mutt_paddstr (COLS, buf); NORMAL_COLOR; menu->redraw &= ~REDRAW_STATUS; @@ -1113,7 +1129,9 @@ int mutt_index_menu (void) break; CHECK_MSGCOUNT; +#ifdef USE_SIDEBAR CHECK_VISIBLE; +#endif CHECK_READONLY; { int oldvcount = Context->vcount; @@ -1173,7 +1191,9 @@ int mutt_index_menu (void) menu->redraw = REDRAW_FULL; break; +#ifdef USE_SIDEBAR case OP_SIDEBAR_OPEN: +#endif case OP_MAIN_CHANGE_FOLDER: case OP_MAIN_NEXT_UNREAD_MAILBOX: @@ -1205,11 +1225,13 @@ int mutt_index_menu (void) { mutt_buffy (buf, sizeof (buf)); +#ifdef USE_SIDEBAR if (op == OP_SIDEBAR_OPEN) { if (!CurBuffy) break; strncpy (buf, CurBuffy->path, sizeof (buf)); } else +#endif if (mutt_enter_fname (cp, buf, sizeof (buf), &menu->redraw, 1) == -1) { if (menu->menu == MENU_PAGER) @@ -1228,7 +1250,9 @@ int mutt_index_menu (void) } mutt_expand_path (buf, sizeof (buf)); +#ifdef USE_SIDEBAR sb_set_open_buffy (buf); +#endif if (mx_get_magic (buf) <= 0) { mutt_error (_("%s is not a mailbox."), buf); @@ -2319,6 +2343,7 @@ int mutt_index_menu (void) mutt_what_key(); break; +#ifdef USE_SIDEBAR case OP_SIDEBAR_SCROLL_UP: case OP_SIDEBAR_SCROLL_DOWN: case OP_SIDEBAR_NEXT: @@ -2327,6 +2352,7 @@ int mutt_index_menu (void) case OP_SIDEBAR_PREV_NEW: sb_change_mailbox (op); break; +#endif default: if (menu->menu == MENU_MAIN) km_error_key (MENU_MAIN); diff --git a/flags.c b/flags.c index cd5fe4fa5..f58aa38cd 100644 --- a/flags.c +++ b/flags.c @@ -24,7 +24,10 @@ #include "mutt_curses.h" #include "sort.h" #include "mx.h" + +#ifdef USE_SIDEBAR #include "sidebar.h" +#endif void _mutt_set_flag (CONTEXT *ctx, HEADER *h, int flag, int bf, int upd_ctx) { @@ -264,7 +267,9 @@ void _mutt_set_flag (CONTEXT *ctx, HEADER *h, int flag, int bf, int upd_ctx) */ if (h->searched && (changed != h->changed || deleted != ctx->deleted || tagged != ctx->tagged || flagged != ctx->flagged)) h->searched = 0; +#ifdef USE_SIDEBAR sb_draw(); +#endif } void mutt_tag_set_flag (int flag, int bf) diff --git a/functions.h b/functions.h index 41f9fb896..805d8b4fb 100644 --- a/functions.h +++ b/functions.h @@ -168,6 +168,7 @@ const struct binding_t OpMain[] = { /* map: index */ { "decrypt-copy", OP_DECRYPT_COPY, NULL }, { "decrypt-save", OP_DECRYPT_SAVE, NULL }, +#ifdef USE_SIDEBAR { "sidebar-next", OP_SIDEBAR_NEXT, NULL }, { "sidebar-next-new", OP_SIDEBAR_NEXT_NEW, NULL }, { "sidebar-open", OP_SIDEBAR_OPEN, NULL }, @@ -175,6 +176,7 @@ const struct binding_t OpMain[] = { /* map: index */ { "sidebar-prev-new", OP_SIDEBAR_PREV_NEW, NULL }, { "sidebar-scroll-down", OP_SIDEBAR_SCROLL_DOWN, NULL }, { "sidebar-scroll-up", OP_SIDEBAR_SCROLL_UP, NULL }, +#endif { NULL, 0, NULL } }; @@ -279,6 +281,7 @@ const struct binding_t OpPager[] = { /* map: pager */ { "what-key", OP_WHAT_KEY, NULL }, +#ifdef USE_SIDEBAR { "sidebar-next", OP_SIDEBAR_NEXT, NULL }, { "sidebar-next-new", OP_SIDEBAR_NEXT_NEW, NULL }, { "sidebar-open", OP_SIDEBAR_OPEN, NULL }, @@ -286,6 +289,7 @@ const struct binding_t OpPager[] = { /* map: pager */ { "sidebar-prev-new", OP_SIDEBAR_PREV_NEW, NULL }, { "sidebar-scroll-down", OP_SIDEBAR_SCROLL_DOWN, NULL }, { "sidebar-scroll-up", OP_SIDEBAR_SCROLL_UP, NULL }, +#endif { NULL, 0, NULL } }; diff --git a/globals.h b/globals.h index 6339a99ce..9d50a5142 100644 --- a/globals.h +++ b/globals.h @@ -118,10 +118,12 @@ WHERE short SearchContext; WHERE char *SendCharset; WHERE char *Sendmail; WHERE char *Shell; +#ifdef USE_SIDEBAR WHERE char *SidebarDelim; WHERE char *SidebarDelimChars; WHERE char *SidebarFormat; WHERE char *SidebarIndentStr; +#endif WHERE char *Signature; WHERE char *SimpleSearch; #if USE_SMTP @@ -217,11 +219,15 @@ WHERE short ScoreThresholdDelete; WHERE short ScoreThresholdRead; WHERE short ScoreThresholdFlag; +/* This isn't excluded from the build because it's too entwined in the code. + * For now. */ +WHERE short SidebarWidth; +#ifdef USE_SIDEBAR WHERE struct buffy_t *CurBuffy INITVAL(0); WHERE short SidebarLastRefresh; WHERE short SidebarRefresh; WHERE LIST *SidebarWhitelist INITVAL(0); -WHERE short SidebarWidth; +#endif #ifdef USE_IMAP WHERE short ImapKeepalive; diff --git a/imap/command.c b/imap/command.c index 296820400..eeda540c3 100644 --- a/imap/command.c +++ b/imap/command.c @@ -1012,11 +1012,13 @@ static void cmd_parse_status (IMAP_DATA* idata, char* s) opened */ status->uidnext = oldun; - /* Added to make the sidebar show the correct numbers */ +#ifdef USE_SIDEBAR + /* Make the sidebar show the correct numbers */ if (status->messages) { inc->msgcount = status->messages; inc->msg_unread = status->unseen; } +#endif FREE (&value); return; diff --git a/imap/imap.c b/imap/imap.c index 6f4af883f..4c1f943a8 100644 --- a/imap/imap.c +++ b/imap/imap.c @@ -1523,7 +1523,11 @@ int imap_buffy_check (int force) imap_munge_mbox_name (munged, sizeof (munged), name); snprintf (command, sizeof (command), +#ifdef USE_SIDEBAR "STATUS %s (UIDNEXT UIDVALIDITY UNSEEN RECENT MESSAGES)", munged); +#else + "STATUS %s (UIDNEXT UIDVALIDITY UNSEEN RECENT)", munged); +#endif if (imap_exec (idata, command, IMAP_CMD_QUEUE) < 0) { diff --git a/init.h b/init.h index 3da371b1f..cc9d3743b 100644 --- a/init.h +++ b/init.h @@ -2595,6 +2595,7 @@ struct option_t MuttVars[] = { ** Command to use when spawning a subshell. By default, the user's login ** shell from \fC/etc/passwd\fP is used. */ +#ifdef USE_SIDEBAR { "sidebar_delim", DT_STR, R_BOTH, UL &SidebarDelim, UL "|" }, /* ** .pp @@ -2713,6 +2714,7 @@ struct option_t MuttVars[] = { ** For example: sidebar_width=20 could display 20 ASCII characters, or 10 ** Chinese characters. */ +#endif { "sig_dashes", DT_BOOL, R_NONE, OPTSIGDASHES, 1 }, /* ** .pp @@ -3788,7 +3790,9 @@ const struct command_t Commands[] = { { "send-hook", mutt_parse_hook, M_SENDHOOK }, { "send2-hook", mutt_parse_hook, M_SEND2HOOK }, { "set", parse_set, 0 }, +#ifdef USE_SIDEBAR { "sidebar_whitelist",parse_list, UL &SidebarWhitelist }, +#endif { "source", parse_source, 0 }, { "spam", parse_spam_list, M_SPAM }, { "nospam", parse_spam_list, M_NOSPAM }, diff --git a/mailbox.h b/mailbox.h index 000503d7f..224966136 100644 --- a/mailbox.h +++ b/mailbox.h @@ -27,7 +27,9 @@ #define M_NEWFOLDER (1<<4) /* create a new folder - same as M_APPEND, but uses * safe_fopen() for mbox-style folders. */ +#ifdef USE_SIDEBAR #define M_PEEK (1<<5) /* revert atime back after taking a look (if applicable) */ +#endif /* mx_open_new_message() */ #define M_ADD_FROM (1<<0) /* add a From_ line */ diff --git a/main.c b/main.c index 41136129a..7f5895af7 100644 --- a/main.c +++ b/main.c @@ -31,7 +31,9 @@ #include "url.h" #include "mutt_crypt.h" #include "mutt_idna.h" +#ifdef USE_SIDEBAR #include "sidebar.h" +#endif #ifdef USE_SASL #include "mutt_sasl.h" @@ -484,6 +486,12 @@ static void show_version (void) "-USE_HCACHE " #endif +#ifdef USE_SIDEBAR + "+USE_SIDEBAR " +#else + "-USE_SIDEBAR " +#endif + ); #ifdef ISPELL @@ -556,7 +564,11 @@ init_extended_keys(); int main (int argc, char **argv) { +#ifdef USE_SIDEBAR char folder[PATH_MAX] = ""; +#else + char folder[_POSIX_PATH_MAX] = ""; +#endif char *subject = NULL; char *includeFile = NULL; char *draftFile = NULL; @@ -1037,12 +1049,14 @@ int main (int argc, char **argv) strfcpy (folder, NONULL(Spoolfile), sizeof (folder)); mutt_expand_path (folder, sizeof (folder)); +#ifdef USE_SIDEBAR { char tmpfolder[PATH_MAX] = ""; strfcpy (tmpfolder, folder, sizeof (tmpfolder)); if (!realpath (tmpfolder, folder)) strfcpy (folder, tmpfolder, sizeof (tmpfolder)); } +#endif mutt_str_replace (&CurrentFolder, folder); mutt_str_replace (&LastFolder, folder); @@ -1066,7 +1080,9 @@ int main (int argc, char **argv) if((Context = mx_open_mailbox (folder, ((flags & M_RO) || option (OPTREADONLY)) ? M_READONLY : 0, NULL)) || !explicit_folder) { +#ifdef USE_SIDEBAR sb_set_open_buffy (folder); +#endif mutt_index_menu (); if (Context) FREE (&Context); diff --git a/mbox.c b/mbox.c index cd51e641e..1be1f34ae 100644 --- a/mbox.c +++ b/mbox.c @@ -100,7 +100,9 @@ int mmdf_parse_mailbox (CONTEXT *ctx) mutt_perror (ctx->path); return (-1); } +#ifdef USE_SIDEBAR ctx->atime = sb.st_atime; +#endif ctx->mtime = sb.st_mtime; ctx->size = sb.st_size; @@ -252,7 +254,9 @@ int mbox_parse_mailbox (CONTEXT *ctx) ctx->size = sb.st_size; ctx->mtime = sb.st_mtime; +#ifdef USE_SIDEBAR ctx->atime = sb.st_atime; +#endif #ifdef NFS_ATTRIBUTE_HACK if (sb.st_mtime > sb.st_atime) diff --git a/menu.c b/menu.c index b44d44b3d..72a870d03 100644 --- a/menu.c +++ b/menu.c @@ -24,7 +24,9 @@ #include "mutt_curses.h" #include "mutt_menu.h" #include "mbyte.h" +#ifdef USE_SIDEBAR #include "sidebar.h" +#endif extern size_t UngetCount; @@ -240,7 +242,9 @@ void menu_redraw_index (MUTTMENU *menu) int do_color; int attr; +#ifdef USE_SIDEBAR sb_draw(); +#endif for (i = menu->top; i < menu->top + menu->pagelen; i++) { if (i < menu->max) @@ -274,7 +278,11 @@ void menu_redraw_index (MUTTMENU *menu) else { NORMAL_COLOR; +#ifdef USE_SIDEBAR CLEARLINE_WIN(i - menu->top + menu->offset); +#else + CLEARLINE(i - menu->top + menu->offset); +#endif } } NORMAL_COLOR; diff --git a/mh.c b/mh.c index 51d490ff4..a1b4f4c69 100644 --- a/mh.c +++ b/mh.c @@ -295,6 +295,7 @@ void mh_buffy(BUFFY *b) mhs_free_sequences (&mhs); } +#ifdef USE_SIDEBAR /** * mh_buffy_update - Update messages counts for an mh mailbox * @path: Pathname of the mailbox @@ -335,6 +336,7 @@ mh_buffy_update (const char *path, int *msgcount, int *msg_unread, int *msg_flag mhs_free_sequences (&mhs); *sb_last_checked = time (NULL); } +#endif static int mh_mkstemp (CONTEXT * dest, FILE ** fp, char **tgt) { diff --git a/mutt.h b/mutt.h index 67b614a2d..411a7a60b 100644 --- a/mutt.h +++ b/mutt.h @@ -423,12 +423,14 @@ enum OPTSAVEEMPTY, OPTSAVENAME, OPTSCORE, +#ifdef USE_SIDEBAR OPTSIDEBAR, OPTSIDEBARFOLDERINDENT, OPTSIDEBARNEWMAILONLY, OPTSIDEBARNEXTNEWWRAP, OPTSIDEBARSHORTPATH, OPTSIDEBARSORT, +#endif OPTSIGDASHES, OPTSIGONTOP, OPTSORTRE, @@ -872,7 +874,9 @@ typedef struct _context { char *path; FILE *fp; +#ifdef USE_SIDEBAR time_t atime; +#endif time_t mtime; off_t size; off_t vsize; @@ -907,7 +911,9 @@ typedef struct _context unsigned int quiet : 1; /* inhibit status messages? */ unsigned int collapsed : 1; /* are all threads collapsed? */ unsigned int closing : 1; /* mailbox is being closed */ +#ifdef USE_SIDEBAR unsigned int peekonly : 1; /* just taking a glance, revert atime */ +#endif /* driver hooks */ void *data; /* driver specific data */ diff --git a/mutt_curses.h b/mutt_curses.h index a16096088..268aa3e1b 100644 --- a/mutt_curses.h +++ b/mutt_curses.h @@ -64,7 +64,9 @@ #undef lines #endif /* lines */ +#ifdef USE_SIDEBAR #define CLEARLINE_WIN(x) move (x,SidebarWidth), clrtoeol() +#endif #define CLEARLINE(x) move(x,0), clrtoeol() #define CENTERLINE(x,y) move(y, (COLS-strlen(x))/2), addstr(x) #define BEEP() do { if (option (OPTBEEP)) beep(); } while (0) @@ -122,8 +124,10 @@ enum MT_COLOR_UNDERLINE, MT_COLOR_INDEX, MT_COLOR_PROMPT, +#ifdef USE_SIDEBAR MT_COLOR_FLAGGED, MT_COLOR_NEW, +#endif MT_COLOR_MAX }; diff --git a/mutt_menu.h b/mutt_menu.h index aea89f14d..8cb49dbcc 100644 --- a/mutt_menu.h +++ b/mutt_menu.h @@ -34,7 +34,9 @@ #define REDRAW_FULL (1<<5) #define REDRAW_BODY (1<<6) #define REDRAW_SIGWINCH (1<<7) +#ifdef USE_SIDEBAR #define REDRAW_SIDEBAR (1<<8) +#endif #define M_MODEFMT "-- Mutt: %s" diff --git a/mx.c b/mx.c index bd46cd39e..a6eab0a78 100644 --- a/mx.c +++ b/mx.c @@ -29,7 +29,9 @@ #include "copy.h" #include "keymap.h" #include "url.h" +#ifdef USE_SIDEBAR #include "sidebar.h" +#endif #ifdef USE_IMAP #include "imap.h" @@ -604,8 +606,10 @@ CONTEXT *mx_open_mailbox (const char *path, int flags, CONTEXT *pctx) ctx->quiet = 1; if (flags & M_READONLY) ctx->readonly = 1; +#ifdef USE_SIDEBAR if (flags & M_PEEK) ctx->peekonly = 1; +#endif if (flags & (M_APPEND|M_NEWFOLDER)) { @@ -709,6 +713,7 @@ void mx_fastclose_mailbox (CONTEXT *ctx) if(!ctx) return; +#ifdef USE_SIDEBAR /* fix up the times so buffy won't get confused */ struct utimbuf ut; if (ctx->peekonly && ctx->path && (ctx->mtime > ctx->atime)) { @@ -716,10 +721,13 @@ void mx_fastclose_mailbox (CONTEXT *ctx) ut.modtime = ctx->mtime; utime (ctx->path, &ut); } +#endif /* never announce that a mailbox we've just left has new mail. #3290 * XXX: really belongs in mx_close_mailbox, but this is a nice hook point */ +#ifdef USE_SIDEBAR if (!ctx->peekonly) +#endif mutt_buffy_setnotified(ctx->path); if (ctx->mx_close) @@ -732,8 +740,10 @@ void mx_fastclose_mailbox (CONTEXT *ctx) mutt_clear_threads (ctx); for (i = 0; i < ctx->msgcount; i++) mutt_free_header (&ctx->hdrs[i]); +#ifdef USE_SIDEBAR ctx->msgcount -= ctx->deleted; sb_set_buffystats (ctx); +#endif FREE (&ctx->hdrs); FREE (&ctx->v2r); FREE (&ctx->path); @@ -827,10 +837,12 @@ int mx_close_mailbox (CONTEXT *ctx, int *index_hint) if (!ctx->hdrs[i]->deleted && ctx->hdrs[i]->read && !(ctx->hdrs[i]->flagged && option (OPTKEEPFLAGGED))) read_msgs++; +#ifdef USE_SIDEBAR if (ctx->hdrs[i]->deleted && !ctx->hdrs[i]->read) ctx->unread--; if (ctx->hdrs[i]->deleted && ctx->hdrs[i]->flagged) ctx->flagged--; +#endif } if (read_msgs && quadoption (OPT_MOVE) != M_NO) diff --git a/mx.h b/mx.h index 516508dfe..495667a3c 100644 --- a/mx.h +++ b/mx.h @@ -57,7 +57,9 @@ void mbox_reset_atime (CONTEXT *, struct stat *); int mh_read_dir (CONTEXT *, const char *); int mh_sync_mailbox (CONTEXT *, int *); int mh_check_mailbox (CONTEXT *, int *); +#ifdef USE_SIDEBAR void mh_buffy_update (const char *, int *, int *, int *, time_t *); +#endif int mh_check_empty (const char *); int maildir_read_dir (CONTEXT *); diff --git a/pager.c b/pager.c index c7ccdddaf..c3177d076 100644 --- a/pager.c +++ b/pager.c @@ -29,7 +29,9 @@ #include "pager.h" #include "attach.h" #include "mbyte.h" +#ifdef USE_SIDEBAR #include "sidebar.h" +#endif #include "mutt_crypt.h" @@ -1096,7 +1098,9 @@ static int format_line (struct line_t **lineInfo, int n, unsigned char *buf, wchar_t wc; mbstate_t mbstate; int wrap_cols = mutt_term_width ((flags & M_PAGER_NOWRAP) ? 0 : Wrap); +#ifdef USE_SIDEBAR wrap_cols -= SidebarWidth; +#endif if (check_attachment_marker ((char *)buf) == 0) wrap_cols = COLS; @@ -1762,7 +1766,9 @@ mutt_pager (const char *banner, const char *fname, int flags, pager_t *extra) &QuoteList, &q_level, &force_redraw, &SearchRE) > 0) lines++; curline++; +#ifdef USE_SIDEBAR move (lines + bodyoffset, SidebarWidth); +#endif } last_offset = lineInfo[curline].offset; } while (force_redraw); @@ -1775,7 +1781,9 @@ mutt_pager (const char *banner, const char *fname, int flags, pager_t *extra) addch ('~'); addch ('\n'); lines++; +#ifdef USE_SIDEBAR move (lines + bodyoffset, SidebarWidth); +#endif } NORMAL_COLOR; @@ -1793,9 +1801,11 @@ mutt_pager (const char *banner, const char *fname, int flags, pager_t *extra) hfi.ctx = Context; hfi.pager_progress = pager_progress_str; +#ifdef USE_SIDEBAR statuswidth = COLS; if (option (OPTSTATUSONTOP) && (PagerIndexLines > 0)) statuswidth -= SidebarWidth; +#endif if (last_pos < sb.st_size - 1) snprintf(pager_progress_str, sizeof(pager_progress_str), OFF_T_FMT "%%", (100 * last_offset / sb.st_size)); @@ -1805,6 +1815,7 @@ mutt_pager (const char *banner, const char *fname, int flags, pager_t *extra) /* print out the pager status bar */ move (statusoffset, SidebarWidth); SETCOLOR (MT_COLOR_STATUS); +#ifdef USE_SIDEBAR short sw = SidebarWidth; if (option (OPTSTATUSONTOP) && PagerIndexLines > 0) { CLEARLINE_WIN (statusoffset); @@ -1813,6 +1824,7 @@ mutt_pager (const char *banner, const char *fname, int flags, pager_t *extra) /* Temporarily lie about the sidebar width */ SidebarWidth = 0; } +#endif if (IsHeader (extra) || IsMsgAttach (extra)) { @@ -1828,9 +1840,10 @@ mutt_pager (const char *banner, const char *fname, int flags, pager_t *extra) snprintf (bn, sizeof (bn), "%s (%s)", banner, pager_progress_str); mutt_paddstr (statuswidth, bn); } +#ifdef USE_SIDEBAR if (!option (OPTSTATUSONTOP) || PagerIndexLines == 0) SidebarWidth = sw; /* Restore the sidebar width */ - +#endif NORMAL_COLOR; if (option(OPTTSENABLED) && TSSupported) { @@ -1846,7 +1859,9 @@ mutt_pager (const char *banner, const char *fname, int flags, pager_t *extra) /* redraw the pager_index indicator, because the * flags for this message might have changed. */ menu_redraw_current (index); +#ifdef USE_SIDEBAR sb_draw(); +#endif /* print out the index status bar */ menu_status_line (buffer, sizeof (buffer), index, NONULL(Status)); @@ -1858,9 +1873,11 @@ mutt_pager (const char *banner, const char *fname, int flags, pager_t *extra) NORMAL_COLOR; } +#ifdef USE_SIDEBAR /* if we're not using the index, update every time */ if (index == 0) sb_draw(); +#endif redraw = 0; @@ -2796,6 +2813,7 @@ search_next: mutt_what_key (); break; +#ifdef USE_SIDEBAR case OP_SIDEBAR_NEXT: case OP_SIDEBAR_NEXT_NEW: case OP_SIDEBAR_PREV: @@ -2804,6 +2822,7 @@ search_next: case OP_SIDEBAR_SCROLL_UP: sb_change_mailbox (ch); break; +#endif default: ch = -1; -- 2.50.0