# HG changeset patch
# User Fabian Groffen <grobian@gentoo.org>
# Date 1378662684 -7200
#      Sun Sep 08 19:51:24 2013 +0200
# Branch gentoo-1.5.21
# Node ID bf325808c6f821d4be59d26c9c579d86e19683df
# Parent  14420f16477a4bf246d17a777e6a520162737747
Make path separators for sidebar folders configurable.

When using IMAP, a '.' is often used as path separator, hence make the
path separators configurable through sidebar_delim_chars variable.
It defaults to "/." to work for both mboxes as well as IMAP folders.  It
can be set to only "/" or "." or whichever character desired as needed.

Author: Fabian Groffen <grobian@gentoo.org>

diff -r 14420f16477a -r bf325808c6f8 PATCHES
--- a/PATCHES   Sun Sep 08 19:51:24 2013 +0200
+++ b/PATCHES   Sun Sep 08 19:51:24 2013 +0200
@@ -1,3 +1,4 @@
+fg.sidebar-dotpathsep
 ar.sidebar-utf8
 sidebar
 fg.gpg_smime_output
diff -r 14420f16477a -r bf325808c6f8 globals.h
--- a/globals.h Sun Sep 08 19:51:24 2013 +0200
+++ b/globals.h Sun Sep 08 19:51:24 2013 +0200
@@ -127,6 +127,7 @@ WHERE char *SendCharset;
 WHERE char *Sendmail;
 WHERE char *Shell;
 WHERE char *SidebarDelim;
+WHERE char *SidebarDelimChars INITVAL (NULL);
 WHERE char *Signature;
 WHERE char *SimpleSearch;
 #if USE_SMTP
diff -r 14420f16477a -r bf325808c6f8 init.h
--- a/init.h    Sun Sep 08 19:51:24 2013 +0200
+++ b/init.h    Sun Sep 08 19:51:24 2013 +0200
@@ -2138,6 +2138,14 @@ struct option_t MuttVars[] = {
   ** .pp
   ** The width of the sidebar.
   */
+  { "sidebar_delim_chars",             DT_STR, R_NONE, UL &SidebarDelimChars, UL "/." },
+  /*
+  ** .pp
+  ** This contains the list of characters which you would like to treat
+  ** as folder separators for displaying paths in the sidebar.  If
+  ** you're not using IMAP folders, you probably prefer setting this to "/"
+  ** alone.
+  */
   { "pgp_use_gpg_agent", DT_BOOL, R_NONE, OPTUSEGPGAGENT, 0},
   /*
   ** .pp
diff -r 14420f16477a -r bf325808c6f8 sidebar.c
--- a/sidebar.c Sun Sep 08 19:51:24 2013 +0200
+++ b/sidebar.c Sun Sep 08 19:51:24 2013 +0200
@@ -285,20 +285,37 @@ int draw_sidebar(int menu) {
                // calculate depth of current folder and generate its display name with indented spaces
                int sidebar_folder_depth = 0;
                char *sidebar_folder_name;
-               sidebar_folder_name = basename(tmp->path);
+               int i;
+               sidebar_folder_name = tmp->path;
+               /* disregard a trailing separator, so strlen() - 2
+                * https://bugs.gentoo.org/show_bug.cgi?id=373197#c16 */
+               for (i = strlen(sidebar_folder_name) - 2; i >= 0; i--) {
+                       if (SidebarDelimChars &&
+                                       strchr(SidebarDelimChars, sidebar_folder_name[i]))
+                       {
+                               sidebar_folder_name += i + 1;
+                               break;
+                       }
+               }
                if ( maildir_is_prefix ) {
                        char *tmp_folder_name;
-                       int i;
+                       int lastsep = 0;
                        tmp_folder_name = tmp->path + strlen(Maildir);
-                       for (i = 0; i < strlen(tmp->path) - strlen(Maildir); i++) {
-                               if (tmp_folder_name[i] == '/') sidebar_folder_depth++;
-                       }   
+                       for (i = 0; i < strlen(tmp_folder_name) - 1; i++) {
+                               if (SidebarDelimChars &&
+                                               strchr(SidebarDelimChars, tmp_folder_name[i]))
+                               {
+                                       sidebar_folder_depth++;
+                                       lastsep = i + 1;
+                               }
+                       }
                        if (sidebar_folder_depth > 0) {
-                               sidebar_folder_name = malloc(strlen(basename(tmp->path)) + sidebar_folder_depth + 1);
+                               tmp_folder_name += lastsep;  /* basename */
+                               sidebar_folder_name = malloc(strlen(tmp_folder_name) + sidebar_folder_depth + 1);
                                for (i=0; i < sidebar_folder_depth; i++)
                                        sidebar_folder_name[i]=' ';
                                sidebar_folder_name[i]=0;
-                               strncat(sidebar_folder_name, basename(tmp->path), strlen(basename(tmp->path)) + sidebar_folder_depth);
+                               strncat(sidebar_folder_name, tmp_folder_name, strlen(tmp_folder_name) + sidebar_folder_depth);
                        }
                }
                printw( "%.*s", SidebarWidth - delim_len + 1,