- static char *entry = 0;
- char *c;
- int i = 0;
-
- c = realloc(entry, SidebarWidth + 1);
- if ( c ) entry = c;
- entry[SidebarWidth] = 0;
- for (; i < SidebarWidth; entry[i++] = ' ' );
- i = strlen(box);
- strncpy( entry, box, i < SidebarWidth ? i :SidebarWidth );
-
- if ( new )
- sprintf(
- entry + SidebarWidth - 5 - quick_log10(size) - quick_log10(new),
- "% d(%d)", size, new);
- else
- sprintf( entry + SidebarWidth - 3 - quick_log10(size), "% d", size);
- return entry;
+ int i = 0, dlen, max, shortened = 0;
+ int offset;
+
+ if (SidebarWidth > COLS)
+ SidebarWidth = COLS;
+
+ dlen = mutt_strlen(SidebarDelim);
+ max = SidebarWidth - dlen - 1;
+
+ safe_realloc(&entry, SidebarWidth + 1);
+ entry[SidebarWidth] = 0;
+ for (; i < SidebarWidth; entry[i++] = ' ' );
+#if USE_IMAP
+ if (ImapHomeNamespace && strlen(ImapHomeNamespace)>0) {
+ if (strncmp(box,ImapHomeNamespace,strlen(ImapHomeNamespace))==0 && strcmp(box,ImapHomeNamespace)!=0) {
+ box+=strlen(ImapHomeNamespace)+1;
+ }
+ }
+#endif
+ max -= quick_log10(size);
+ if (new)
+ max -= quick_log10(new) + 2;
+ if (flagged > 0)
+ max -= quick_log10(flagged) + 2;
+ if (option(OPTSHORTENHIERARCHY) && mutt_strlen(box) > max) {
+ box = shortened_hierarchy(box);
+ shortened = 1;
+ }
+ i = strlen(box);
+ strncpy( entry, box, i < SidebarWidth - dlen ? i :SidebarWidth - dlen);
+
+ if ( new ) {
+ if (flagged>0) {
+ offset = SidebarWidth - 5 - quick_log10(size) - dlen - quick_log10(new) - quick_log10(flagged);
+ if (offset<0) offset = 0;
+ snprintf(entry + offset, SidebarWidth - dlen - offset + 1,
+ "% d(%d)[%d]", size, new, flagged);
+ } else {
+ offset = SidebarWidth - 3 - quick_log10(size) - dlen - quick_log10(new);
+ if (offset<0) offset = 0;
+ snprintf(entry + offset, SidebarWidth - dlen - offset + 1,
+ "% d(%d)", size, new);
+ }
+ } else {
+ if (flagged>0) {
+ offset = SidebarWidth - 3 - quick_log10(size) - dlen - quick_log10(flagged);
+ if (offset<0) offset = 0;
+ snprintf( entry + offset, SidebarWidth - dlen - offset + 1,
+ "% d[%d]", size,flagged);
+ } else {
+ offset = SidebarWidth - 1 - quick_log10(size) - dlen;
+ if (offset<0) offset = 0;
+ snprintf( entry + offset, SidebarWidth - dlen - offset + 1,
+ "% d", size);
+ }
+ }
+
+ if (option(OPTSHORTENHIERARCHY) && shortened) {
+ free(box);
+ }
+ return entry;