]> granicus.if.org Git - neomutt/commitdiff
Change sidebar to consistently use realpath for context and buffy comparison.
authorKevin McCarthy <kevin@8t8.us>
Thu, 23 Jun 2016 19:38:07 +0000 (12:38 -0700)
committerRichard Russon <rich@flatcap.org>
Sun, 3 Jul 2016 13:39:17 +0000 (14:39 +0100)
The original sidebar patch contained a half-implemented attempt to use
realpath() mailbox paths for comparison.  (Presumably so the open mailbox
remains highlighted despite symlink issues).

Add realpath to the Context, and set it when opening a mailbox.
Remove sidebar ifdef for the buffy member, and always set it there too.

Change the sidebar to use the realpath for comparison everywhere.

mutt_buffy_check() is using stat device and inode for comparison.
Perhaps this can be changed to use realpath instead, but that's beyond
the scope of this patch.

buffy.c
buffy.h
curs_main.c
imap/imap.c
main.c
mutt.h
mx.c
pop.c
sidebar.c
sidebar.h

diff --git a/buffy.c b/buffy.c
index c9397e8108faa91bbe29772fa396dcbd251231d9..4ae879e013e71414103ee2006313b7a03bb5d18c 100644 (file)
--- a/buffy.c
+++ b/buffy.c
@@ -201,17 +201,13 @@ 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;
 
@@ -229,10 +225,7 @@ 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;
+  char *p;
 
   while (MoreArgs (s))
   {
@@ -262,13 +255,7 @@ 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
+      if (mutt_strcmp (p ? p : buf, (*tmp)->realpath) == 0)
       {
        dprint(3,(debugfile,"mailbox '%s' already registered as '%s'\n", buf, (*tmp)->path));
        break;
diff --git a/buffy.h b/buffy.h
index 76f1f588b738577299a0ec9e5148fb8c0804f354..292dbc0e47bbbd4f81ddb2758f23dccd9d68318f 100644 (file)
--- a/buffy.h
+++ b/buffy.h
@@ -26,9 +26,8 @@
 typedef struct buffy_t
 {
   char path[_POSIX_PATH_MAX];
-#ifdef USE_SIDEBAR
-  char realpath[_POSIX_PATH_MAX];
-#endif
+  char realpath[_POSIX_PATH_MAX]; /* used for duplicate detection, context comparison,
+                                     and the sidebar */
   off_t size;
   struct buffy_t *next;
 #ifdef USE_SIDEBAR
index 9fbb5898111d2510f880b8bf11f031f496a39b7d..9c077fda9c5a8031c4449a5c5d1732f788ff6f6a 100644 (file)
@@ -1235,9 +1235,6 @@ int mutt_index_menu (void)
        }
 
        mutt_expand_path (buf, sizeof (buf));
-#ifdef USE_SIDEBAR
-       mutt_sb_set_open_buffy (buf);
-#endif
        if (mx_get_magic (buf) <= 0)
        {
          mutt_error (_("%s is not a mailbox."), buf);
@@ -1287,6 +1284,10 @@ int mutt_index_menu (void)
        else
          menu->current = 0;
 
+#ifdef USE_SIDEBAR
+        mutt_sb_set_open_buffy ();
+#endif
+
        mutt_clear_error ();
        mutt_buffy_check(1); /* force the buffy check after we have changed
                              the folder */
index 5f5e83b37bbb3b89ab339f264dbf1a8b95b55828..2aaa14cd367877918b20e8859c87e5da60d7c68b 100644 (file)
@@ -589,7 +589,9 @@ int imap_open_mailbox (CONTEXT* ctx)
   imap_qualify_path (buf, sizeof (buf), &mx, idata->mailbox);
 
   FREE (&(ctx->path));
+  FREE (&(ctx->realpath));
   ctx->path = safe_strdup (buf);
+  ctx->realpath = safe_strdup (ctx->path);
 
   idata->ctx = ctx;
 
diff --git a/main.c b/main.c
index 65f518039e839203444d448eb7e11c021a0434d9..67859ee20fbf719bbc70fb749894d46ea4573c0a 100644 (file)
--- a/main.c
+++ b/main.c
@@ -566,11 +566,7 @@ 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;
@@ -1200,15 +1196,6 @@ 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);
 
@@ -1232,7 +1219,7 @@ int main (int argc, char **argv)
        || !explicit_folder)
     {
 #ifdef USE_SIDEBAR
-      mutt_sb_set_open_buffy (folder);
+      mutt_sb_set_open_buffy ();
 #endif
       mutt_index_menu ();
       if (Context)
diff --git a/mutt.h b/mutt.h
index 1d224ddcff8df7e2e7ef802ab68dbd13cf5e0c96..b68731f079bc946b866af15dfefe1ee431a0cb1c 100644 (file)
--- a/mutt.h
+++ b/mutt.h
@@ -879,6 +879,7 @@ enum
 typedef struct _context
 {
   char *path;
+  char *realpath;               /* used for buffy comparison and the sidebar */
   FILE *fp;
   time_t atime;
   time_t mtime;
diff --git a/mx.c b/mx.c
index 8641de1bbfe10afc7eaeccb990a778d8baacf49f..0a146e544846c93f00c2d95db24f4dd1d688e0f0 100644 (file)
--- a/mx.c
+++ b/mx.c
@@ -595,6 +595,8 @@ CONTEXT *mx_open_mailbox (const char *path, int flags, CONTEXT *pctx)
     ctx = safe_malloc (sizeof (CONTEXT));
   memset (ctx, 0, sizeof (CONTEXT));
   ctx->path = safe_strdup (path);
+  if (! (ctx->realpath = realpath (ctx->path, NULL)) )
+    ctx->realpath = safe_strdup (ctx->path);
 
   ctx->msgnotreadyet = -1;
   ctx->collapsed = 0;
@@ -737,6 +739,7 @@ void mx_fastclose_mailbox (CONTEXT *ctx)
   FREE (&ctx->hdrs);
   FREE (&ctx->v2r);
   FREE (&ctx->path);
+  FREE (&ctx->realpath);
   FREE (&ctx->pattern);
   if (ctx->limit_pattern) 
     mutt_pattern_free (&ctx->limit_pattern);
diff --git a/pop.c b/pop.c
index 11af0ab953374da34b24a5eacebc873c0732e6c6..4ef0e11bda80d8105f620dbdb95837b706424b88 100644 (file)
--- a/pop.c
+++ b/pop.c
@@ -421,7 +421,9 @@ int pop_open_mailbox (CONTEXT *ctx)
     return -1;
 
   FREE (&ctx->path);
+  FREE (&ctx->realpath);
   ctx->path = safe_strdup (buf);
+  ctx->realpath = safe_strdup (ctx->path);
 
   pop_data = safe_calloc (1, sizeof (POP_DATA));
   pop_data->conn = conn;
index 1a16ba16da0d11931a3aac012725470df5725255..9fde404fcdebd4989e040d91f2baf6dfd9057832 100644 (file)
--- a/sidebar.c
+++ b/sidebar.c
@@ -150,7 +150,7 @@ static const char *cb_format_str(char *dest, size_t destlen, size_t col, char op
   if (!b)
     return src;
 
-  int c = Context && (mutt_strcmp (Context->path, b->path) == 0);
+  int c = Context && (mutt_strcmp (Context->realpath, b->realpath) == 0);
 
   optional = flags & M_FORMAT_OPTIONAL;
 
@@ -415,7 +415,7 @@ static void update_buffy_visibility (BUFFY **arr, int arr_len)
         (b == HilBuffy) || (b->msg_flagged > 0))
       continue;
 
-    if (Context && (strcmp (b->path, Context->path) == 0))
+    if (Context && (mutt_strcmp (b->realpath, Context->realpath) == 0))
       /* Spool directory */
       continue;
 
@@ -718,9 +718,8 @@ static void draw_sidebar (int first_row, int num_rows, int div_width)
       SETCOLOR(MT_COLOR_NORMAL);
 
     move (first_row + row, 0);
-    if (Context && Context->path &&
-        (!strcmp (b->path, Context->path)||
-         !strcmp (b->realpath, Context->path)))
+    if (Context && Context->realpath &&
+        !mutt_strcmp (b->realpath, Context->realpath))
     {
       b->msg_unread  = Context->unread;
       b->msg_count   = Context->msgcount;
@@ -955,8 +954,7 @@ void mutt_sb_set_buffystats (const CONTEXT *ctx)
 
   for (; b; b = b->next)
   {
-    if (!strcmp (b->path,     ctx->path) ||
-        !strcmp (b->realpath, ctx->path))
+    if (!mutt_strcmp (b->realpath, ctx->realpath))
     {
       b->msg_unread  = ctx->unread;
       b->msg_count   = ctx->msgcount;
@@ -983,27 +981,25 @@ const char *mutt_sb_get_highlight (void)
 }
 
 /**
- * mutt_sb_set_open_buffy - Set the OpnBuffy based on a mailbox path
- * @path: Mailbox path
+ * mutt_sb_set_open_buffy - Set the OpnBuffy based on a the global Context
  *
  * Search through the list of mailboxes.  If a BUFFY has a matching path, set
  * OpnBuffy to it.
  */
-BUFFY *mutt_sb_set_open_buffy (const char *path)
+BUFFY *mutt_sb_set_open_buffy (void)
 {
   /* Even if the sidebar is hidden */
 
   BUFFY *b = Incoming;
 
-  if (!path || !b)
-    return NULL;
-
   OpnBuffy = NULL;
 
+  if (!Context || !b)
+    return NULL;
+
   for (; b; b = b->next)
   {
-    if (!strcmp (b->path,     path) ||
-        !strcmp (b->realpath, path))
+    if (!mutt_strcmp (b->realpath, Context->realpath))
     {
       OpnBuffy = b;
       HilBuffy = b;
@@ -1045,7 +1041,7 @@ void mutt_sb_notify_mailbox (BUFFY *b, int created)
     {
       /* This might happen if the user "unmailboxes *", then
        * "mailboxes" our current mailbox back again */
-      if (mutt_strcmp (b->path, Context->path) == 0)
+      if (mutt_strcmp (b->realpath, Context->realpath) == 0)
         OpnBuffy = b;
     }
   }
index 2b93accb3960dc6bf7134c5204eaae383286d799..f7875ea57f0be2f8b7baecee114dbaa14d26fad9 100644 (file)
--- a/sidebar.h
+++ b/sidebar.h
@@ -29,6 +29,6 @@ const char * mutt_sb_get_highlight (void);
 void         mutt_sb_init (void);
 void         mutt_sb_notify_mailbox (BUFFY *b, int created);
 void         mutt_sb_set_buffystats (const CONTEXT *ctx);
-BUFFY *      mutt_sb_set_open_buffy (const char *path);
+BUFFY *      mutt_sb_set_open_buffy (void);
 
 #endif /* SIDEBAR_H */