- BUFFY *tmp = Incoming;
-
- if ( known_lines != LINES ) {
- TopBuffy = BottomBuffy = 0;
- known_lines = LINES;
- }
- for ( ; tmp->next != 0; tmp = tmp->next )
- tmp->next->prev = tmp;
-
- if ( TopBuffy == 0 && BottomBuffy == 0 )
- TopBuffy = Incoming;
- if ( BottomBuffy == 0 ) {
- int count = LINES - 2 - (menu != MENU_PAGER);
- BottomBuffy = TopBuffy;
- while ( --count && BottomBuffy->next )
- BottomBuffy = BottomBuffy->next;
- }
- else if ( TopBuffy == CurBuffy->next ) {
- int count = LINES - 2 - (menu != MENU_PAGER);
- BottomBuffy = CurBuffy;
- tmp = BottomBuffy;
- while ( --count && tmp->prev)
- tmp = tmp->prev;
- TopBuffy = tmp;
- }
- else if ( BottomBuffy == CurBuffy->prev ) {
- int count = LINES - 2 - (menu != MENU_PAGER);
- TopBuffy = CurBuffy;
- tmp = TopBuffy;
- while ( --count && tmp->next )
- tmp = tmp->next;
- BottomBuffy = tmp;
- }
+ int dots = 0;
+ char *last_dot = NULL;
+ int i, j, len = m_strlen(box);
+ char *new_box;
+
+ if (!SidebarBoundary || !*SidebarBoundary)
+ return (m_strdup(box));
+
+ for (i = 0; i < len; ++i) {
+ if (strchr (SidebarBoundary, box[i])) {
+ ++dots;
+ last_dot = &box[i];
+ }
+ }
+
+ if (last_dot) {
+ ++last_dot;
+ new_box = p_new(char, maxlen + 1);
+ new_box[0] = box[0];
+ for (i = 1, j = 1; j < maxlen && i < len; ++i) {
+ if (strchr (SidebarBoundary, box[i])) {
+ new_box[j++] = box[i];
+ new_box[j] = 0;
+ if (&box[i + 1] != last_dot || j + m_strlen(last_dot) > maxlen) {
+ new_box[j++] = box[i + 1];
+ new_box[j] = 0;
+ } else {
+ strcat (&new_box[j], last_dot);
+ break;
+ }
+ }
+ }
+ return new_box;
+ }
+ return m_strdup(box);
+}
+
+static const char* sidebar_number_format (char* dest, size_t destlen, char op,
+ const char* src, const char* fmt,
+ const char* ifstr, const char* elstr,
+ unsigned long data, format_flag flags) {
+ char tmp[SHORT_STRING];
+ BUFFY* b = (BUFFY*) Incoming->data[data];
+ int opt = flags & M_FORMAT_OPTIONAL;
+ int c = Context && str_eq (Context->path, b->path);
+
+ switch (op) {
+ /* deleted */
+ case 'd':
+ if (!opt) {
+ snprintf (tmp, sizeof (tmp), "%%%sd", fmt);
+ snprintf (dest, destlen, tmp, c ? Context->deleted : 0);
+ } else if ((c && Context->deleted == 0) || !c)
+ opt = 0;
+ break;
+ /* flagged */
+ case 'F':
+ case 'f': /* for compatibility */
+ if (!opt) {
+ snprintf (tmp, sizeof (tmp), "%%%sd", fmt);
+ snprintf (dest, destlen, tmp, c ? Context->flagged : b->msg_flagged);
+ } else if ((c && Context->flagged == 0) || (!c && b->msg_flagged == 0))
+ opt = 0;
+ break;
+ /* total */
+ case 'c': /* for compatibility */
+ case 'm':
+ if (!opt) {
+ snprintf (tmp, sizeof (tmp), "%%%sd", fmt);
+ snprintf (dest, destlen, tmp, c ? Context->msgcount : b->msgcount);
+ } else if ((c && Context->msgcount == 0) || (!c && b->msgcount == 0))
+ opt = 0;
+ break;
+ /* total shown, i.e. not hidden by limit */
+ case 'M':
+ if (!opt) {
+ snprintf (tmp, sizeof (tmp), "%%%sd", fmt);
+ snprintf (dest, destlen, tmp, c ? Context->vcount : 0);
+ } else if ((c && Context->vcount == 0) || !c)
+ opt = 0;
+ break;
+ /* new */
+ case 'n':
+ if (!opt) {
+ snprintf (tmp, sizeof (tmp), "%%%sd", fmt);
+ snprintf (dest, destlen, tmp, c ? Context->new : b->new);
+ } else if ((c && Context->new == 0) || (!c && b->new == 0))
+ opt = 0;
+ break;
+ /* unread */
+ case 'u':
+ if (!opt) {
+ snprintf (tmp, sizeof (tmp), "%%%sd", fmt);
+ snprintf (dest, destlen, tmp, c ? Context->unread : b->msg_unread);
+ } else if ((c && Context->unread == 0) || (!c && b->msg_unread == 0))
+ opt = 0;
+ break;
+ /* tagged */
+ case 't':
+ if (!opt) {
+ snprintf (tmp, sizeof (tmp), "%%%sd", fmt);
+ snprintf (dest, destlen, tmp, c ? Context->tagged : 0);
+ } else if ((c && Context->tagged == 0) || !c)
+ opt = 0;
+ break;
+ }
+
+ if (opt)
+ mutt_FormatString (dest, destlen, ifstr, sidebar_number_format,
+ data, M_FORMAT_OPTIONAL);
+ else if (flags & M_FORMAT_OPTIONAL)
+ mutt_FormatString (dest, destlen, elstr, sidebar_number_format,
+ data, M_FORMAT_OPTIONAL);
+ return (src);