Andreas Krennmair:
[apps/madmutt.git] / pager.c
diff --git a/pager.c b/pager.c
index cc852a4..cb281de 100644 (file)
--- a/pager.c
+++ b/pager.c
@@ -26,6 +26,7 @@
 #include "pager.h"
 #include "attach.h"
 #include "mbyte.h"
+#include "sidebar.h"
 
 #include "mx.h"
 
@@ -970,7 +971,7 @@ fill_buffer (FILE *f, long *last_pos, long offset, unsigned char *buf,
             unsigned char *fmt, size_t blen, int *buf_ready)
 {
   unsigned char *p;
-  static int b_read;
+  static int b_read = 0;
 
   if (*buf_ready == 0)
   {
@@ -1037,7 +1038,7 @@ static int format_line (struct line_t **lineInfo, int n, unsigned char *buf,
   wchar_t wc;
   mbstate_t mbstate;
 
-  int wrap_cols = COLS - WrapMargin;
+  int wrap_cols = COLS - WrapMargin - SidebarWidth;
   
   if (wrap_cols <= 0)
     wrap_cols = COLS;
@@ -1676,19 +1677,21 @@ mutt_pager (const char *banner, const char *fname, int flags, pager_t *extra)
       j = -1;
       while (display_line (fp, &last_pos, &lineInfo, ++i, &lastLine, &maxLine,
             has_types | SearchFlag, &QuoteList, &q_level, &force_redraw,
-            &SearchRE) == 0)
-       if (!lineInfo[i].continuation && ++j == lines)
-       {
-         topline = i;
-         if (!SearchFlag)
-           break;
-       }
+            &SearchRE) == 0) {
+        if (!lineInfo[i].continuation && ++j == lines)
+        {
+          topline = i;
+          if (!SearchFlag)
+            break;
+        }
+        redraw |= REDRAW_SIDEBAR;
+      } /* while */
     }
 
     if ((redraw & REDRAW_BODY) || topline != oldtopline)
     {
       do {
-       move (bodyoffset, 0);
+       move (bodyoffset, SidebarWidth);
        curline = oldtopline = topline;
        lines = 0;
        force_redraw = 0;
@@ -1701,6 +1704,8 @@ mutt_pager (const char *banner, const char *fname, int flags, pager_t *extra)
                            &QuoteList, &q_level, &force_redraw, &SearchRE) > 0)
            lines++;
          curline++;
+               move(lines + bodyoffset, SidebarWidth);
+          redraw |= REDRAW_SIDEBAR;
        }
        last_offset = lineInfo[curline].offset;
       } while (force_redraw);
@@ -1714,6 +1719,7 @@ mutt_pager (const char *banner, const char *fname, int flags, pager_t *extra)
          addch ('~');
        addch ('\n');
        lines++;
+       move(lines + bodyoffset, SidebarWidth);
       }
       /* We are going to update the pager status bar, so it isn't
        * necessary to reset to normal color now. */
@@ -1726,20 +1732,22 @@ mutt_pager (const char *banner, const char *fname, int flags, pager_t *extra)
       /* print out the pager status bar */
       SETCOLOR (MT_COLOR_STATUS);
       BKGDSET (MT_COLOR_STATUS);
-      CLEARLINE (statusoffset);
+      CLEARLINE_WIN(statusoffset);
       if (IsHeader (extra))
       {
        _mutt_make_string (buffer,
-                          COLS-9 < sizeof (buffer) ? COLS-9 : sizeof (buffer),
+                          COLS-9-SidebarWidth < sizeof (buffer) ?
+                          COLS-9-SidebarWidth : sizeof (buffer),
                           NONULL (PagerFmt), Context, extra->hdr, M_FORMAT_MAKEPRINT);
       }
       else if (IsMsgAttach (extra))
       {
        _mutt_make_string (buffer,
-                          COLS - 9 < sizeof (buffer) ? COLS - 9: sizeof (buffer),
+                          COLS - 9 - SidebarWidth < sizeof (buffer) ?
+                          COLS - 9 - SidebarWidth : sizeof (buffer),
                           NONULL (PagerFmt), Context, extra->bdy->hdr, M_FORMAT_MAKEPRINT);
       }
-      mutt_paddstr (COLS-10, IsHeader (extra) || IsMsgAttach (extra) ?
+      mutt_paddstr (COLS-10-SidebarWidth, IsHeader (extra) || IsMsgAttach (extra) ?
                    buffer : banner);
       addstr (" -- (");
       if (last_pos < sb.st_size - 1)
@@ -1750,20 +1758,26 @@ mutt_pager (const char *banner, const char *fname, int flags, pager_t *extra)
       SETCOLOR (MT_COLOR_NORMAL);
     }
 
+    if (redraw & REDRAW_SIDEBAR)
+      draw_sidebar(MENU_PAGER);
+
     if ((redraw & REDRAW_INDEX) && index)
     {
       /* redraw the pager_index indicator, because the
        * flags for this message might have changed. */
       menu_redraw_current (index);
-
+         draw_sidebar(MENU_PAGER);
       /* print out the index status bar */
       menu_status_line (buffer, sizeof (buffer), index, NONULL(Status));
-      move (indexoffset + (option (OPTSTATUSONTOP) ? 0 : (indexlen - 1)), 0);
+      move (indexoffset + (option (OPTSTATUSONTOP) ? 0 : (indexlen - 1)),
+                 SidebarWidth);
       SETCOLOR (MT_COLOR_STATUS);
-      mutt_paddstr (COLS, buffer);
+      mutt_paddstr (COLS-SidebarWidth, buffer);
       SETCOLOR (MT_COLOR_NORMAL);
     }
+       /* if we're not using the index, update every time */
+       if ( index == 0 )
+               draw_sidebar(MENU_PAGER);
 
     redraw = 0;
 
@@ -2038,8 +2052,10 @@ search_next:
          while (display_line (fp, &last_pos, &lineInfo, i, &lastLine, 
                                &maxLine, M_SEARCH | (flags & M_PAGER_NSKIP),
                                &QuoteList, &q_level,
-                               &force_redraw, &SearchRE) == 0)
+                               &force_redraw, &SearchRE) == 0) {
            i++;
+            redraw |= REDRAW_SIDEBAR;
+          }
 
          if (!SearchBack)
          {
@@ -2119,8 +2135,10 @@ search_next:
                  (0 == (dretval = display_line (fp, &last_pos, &lineInfo,
                         new_topline, &lastLine, &maxLine, M_TYPES,
                         &QuoteList, &q_level, &force_redraw, &SearchRE))))
-                && lineInfo[new_topline].type != MT_COLOR_QUOTED)
+                && lineInfo[new_topline].type != MT_COLOR_QUOTED) {
+            redraw |= REDRAW_SIDEBAR;
            new_topline++;
+          }
 
          if (dretval < 0)
          {
@@ -2132,8 +2150,10 @@ search_next:
                  (0 == (dretval = display_line (fp, &last_pos, &lineInfo,
                         new_topline, &lastLine, &maxLine, M_TYPES,
                         &QuoteList, &q_level, &force_redraw, &SearchRE))))
-                && lineInfo[new_topline].type == MT_COLOR_QUOTED)
+                && lineInfo[new_topline].type == MT_COLOR_QUOTED) {
            new_topline++;
+            redraw |= REDRAW_SIDEBAR;
+          }
 
          if (dretval < 0)
          {
@@ -2152,8 +2172,10 @@ search_next:
          while (display_line (fp, &last_pos, &lineInfo, i, &lastLine, 
                                &maxLine, has_types, 
                                &QuoteList, &q_level, &force_redraw,
-                               &SearchRE) == 0)
+                               &SearchRE) == 0) {
            i++;
+            redraw |= REDRAW_SIDEBAR;
+          }
          topline = upNLines (bodylen, lineInfo, lastLine, hideQuoted);
        }
        else
@@ -2196,6 +2218,17 @@ search_next:
          mutt_resend_message (NULL, extra->ctx, extra->hdr);
         redraw = REDRAW_FULL;
         break;
+
+      case OP_CHECK_TRADITIONAL:
+        CHECK_MODE (IsHeader (extra));
+        if (!(WithCrypto & APPLICATION_PGP))
+         break;
+        if (!(extra->hdr->security & PGP_TRADITIONAL_CHECKED)) 
+        {
+         ch = -1;
+         rc = OP_CHECK_TRADITIONAL;
+       }
+        break;
       
       case OP_CREATE_ALIAS:
        CHECK_MODE(IsHeader (extra) || IsMsgAttach (extra));
@@ -2337,6 +2370,7 @@ CHECK_IMAP_ACL(IMAP_ACL_DELETE);
                                        &QuoteList, &q_level, &force_redraw,
                                        &SearchRE) == 0)
          {
+            redraw |= REDRAW_SIDEBAR;
            if (! lineInfo[topline].continuation)
              j--;
            if (j > 0)
@@ -2407,7 +2441,7 @@ CHECK_IMAP_ACL(IMAP_ACL_WRITE);
       case OP_MAIL:
        CHECK_MODE(IsHeader (extra) && !IsAttach (extra));
         CHECK_ATTACH;      
-       ci_send_message (0, NULL, NULL, extra->ctx, extra->hdr);
+       ci_send_message (0, NULL, NULL, extra->ctx, NULL);
        redraw = REDRAW_FULL;
        break;
 
@@ -2478,7 +2512,7 @@ CHECK_IMAP_ACL(IMAP_ACL_WRITE);
        break;
 
       case OP_RECALL_MESSAGE:
-       CHECK_MODE(IsHeader (extra));
+       CHECK_MODE(IsHeader (extra) && !IsAttach(extra));
         CHECK_ATTACH;
        ci_send_message (SENDPOSTPONED, NULL, NULL, extra->ctx, extra->hdr);
        redraw = REDRAW_FULL;
@@ -2570,6 +2604,11 @@ CHECK_IMAP_ACL(IMAP_ACL_WRITE);
       case OP_TAG:
        CHECK_MODE(IsHeader (extra));
        mutt_set_flag (Context, extra->hdr, M_TAG, !extra->hdr->tagged);
+
+       Context->last_tag = extra->hdr->tagged ? extra->hdr :
+         ((Context->last_tag == extra->hdr && !extra->hdr->tagged)
+          ? NULL : Context->last_tag);
+
        redraw = REDRAW_STATUS | REDRAW_INDEX;
        if (option (OPTRESOLVE))
        {
@@ -2699,6 +2738,12 @@ CHECK_IMAP_ACL(IMAP_ACL_DELETE);
         redraw = REDRAW_FULL;
         break;
 
+         case OP_SIDEBAR_SCROLL_UP:
+         case OP_SIDEBAR_SCROLL_DOWN:
+         case OP_SIDEBAR_NEXT:
+         case OP_SIDEBAR_PREV:
+           scroll_sidebar(ch, MENU_PAGER);
+               break;
       default:
        ch = -1;
        break;