summarylogtreecommitdiffstats
path: root/sidebar-newonly.patch
blob: d206848026b6b3200cdfd4d3dcae680c71fde081 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
From: Steve Kemp <steve@steve.org.uk>
Date: Tue, 4 Mar 2014 22:07:06 +0100
Subject: sidebar-newonly

patches written by Steve Kemp, it adds two new functionalities to the sidebar,
so only the mailbox with new messages will be shown (and/or) selected
See Debian bug http://bugs.debian.org/532510

Gbp-Pq: Topic mutt-patched
---
 OPS         |  2 ++
 curs_main.c |  2 ++
 functions.h |  4 ++++
 init.h      |  5 +++++
 mutt.h      |  2 ++
 pager.c     |  2 ++
 sidebar.c   | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++--
 7 files changed, 70 insertions(+), 2 deletions(-)

diff --git a/OPS b/OPS
index b036db9..1ed9c96 100644
--- a/OPS
+++ b/OPS
@@ -185,3 +185,5 @@ OP_SIDEBAR_SCROLL_DOWN "scroll the mailbox pane down 1 page"
 OP_SIDEBAR_NEXT "go down to next mailbox"
 OP_SIDEBAR_PREV "go to previous mailbox"
 OP_SIDEBAR_OPEN "open hilighted mailbox"
+OP_SIDEBAR_NEXT_NEW "go down to next mailbox with new mail"
+OP_SIDEBAR_PREV_NEW "go to previous mailbox with new mail"
diff --git a/curs_main.c b/curs_main.c
index ea530a6..acb106d 100644
--- a/curs_main.c
+++ b/curs_main.c
@@ -2326,6 +2326,8 @@ int mutt_index_menu (void)
       case OP_SIDEBAR_SCROLL_DOWN:
       case OP_SIDEBAR_NEXT:
       case OP_SIDEBAR_PREV:
+      case OP_SIDEBAR_NEXT_NEW:
+      case OP_SIDEBAR_PREV_NEW:
         scroll_sidebar(op, menu->menu);
         break;
       default:
diff --git a/functions.h b/functions.h
index ef8937a..363b4d5 100644
--- a/functions.h
+++ b/functions.h
@@ -174,6 +174,8 @@ const struct binding_t OpMain[] = { /* map: index */
  { "sidebar-scroll-down",	OP_SIDEBAR_SCROLL_DOWN, NULL },
  { "sidebar-next",		OP_SIDEBAR_NEXT, NULL },
  { "sidebar-prev",		OP_SIDEBAR_PREV, NULL },
+ { "sidebar-next-new", OP_SIDEBAR_NEXT_NEW, NULL},
+ { "sidebar-prev-new", OP_SIDEBAR_PREV_NEW, NULL},
  { "sidebar-open",		OP_SIDEBAR_OPEN, NULL },
   { NULL,			0,				NULL }
 };
@@ -283,6 +285,8 @@ const struct binding_t OpPager[] = { /* map: pager */
   { "sidebar-scroll-down",	OP_SIDEBAR_SCROLL_DOWN, NULL },
   { "sidebar-next",	OP_SIDEBAR_NEXT, NULL },
   { "sidebar-prev",	OP_SIDEBAR_PREV, NULL },
+  { "sidebar-next-new", OP_SIDEBAR_NEXT_NEW, NULL},
+  { "sidebar-prev-new", OP_SIDEBAR_PREV_NEW, NULL},
   { "sidebar-open", OP_SIDEBAR_OPEN, NULL },
   { NULL,		0,				NULL }
 };
diff --git a/init.h b/init.h
index 166671b..a5d4238 100644
--- a/init.h
+++ b/init.h
@@ -2059,6 +2059,11 @@ struct option_t MuttVars[] = {
   ** you're not using IMAP folders, you probably prefer setting this to "/"
   ** alone.
   */
+  {"sidebar_newmail_only", DT_BOOL, R_BOTH, OPTSIDEBARNEWMAILONLY, 0 },
+  /*
+  ** .pp
+  ** Show only new mail in the sidebar.
+  */
   { "pgp_use_gpg_agent", DT_BOOL, R_NONE, OPTUSEGPGAGENT, 0},
   /*
   ** .pp
diff --git a/mutt.h b/mutt.h
index 5f25406..d73e514 100644
--- a/mutt.h
+++ b/mutt.h
@@ -529,6 +529,8 @@ enum
   OPTDONTHANDLEPGPKEYS,	/* (pseudo) used to extract PGP keys */
   OPTUNBUFFEREDINPUT,   /* (pseudo) don't use key buffer */
 
+  OPTSIDEBARNEWMAILONLY,
+
   OPTMAX
 };
 
diff --git a/pager.c b/pager.c
index 5cfcb75..8d64fe1 100644
--- a/pager.c
+++ b/pager.c
@@ -2789,6 +2789,8 @@ search_next:
       case OP_SIDEBAR_SCROLL_DOWN:
       case OP_SIDEBAR_NEXT:
       case OP_SIDEBAR_PREV:
+      case OP_SIDEBAR_NEXT_NEW:
+      case OP_SIDEBAR_PREV_NEW:
 	scroll_sidebar(ch, MENU_PAGER);
  	break;
 
diff --git a/sidebar.c b/sidebar.c
index 8f58f85..51a25ca 100644
--- a/sidebar.c
+++ b/sidebar.c
@@ -269,8 +269,21 @@ int draw_sidebar(int menu) {
 			SETCOLOR(MT_COLOR_NEW);
 		else if ( tmp->msg_flagged > 0 )
 		        SETCOLOR(MT_COLOR_FLAGGED);
-		else
-			SETCOLOR(MT_COLOR_NORMAL);
+		else {
+                  /* make sure the path is either:
+                     1.  Containing new mail.
+                     2.  The inbox.
+                     3.  The current box.
+                   */
+                  if ((option (OPTSIDEBARNEWMAILONLY)) &&
+                      ( (tmp->msg_unread <= 0)  &&
+                        ( tmp != Incoming ) &&
+                        Context &&
+                        ( strcmp( tmp->path, Context->path ) != 0 ) ) )
+                    continue;
+                  else
+                    SETCOLOR(MT_COLOR_NORMAL);
+                }
 
 		move( lines, 0 );
 		if ( Context && !strcmp( tmp->path, Context->path ) ) {
@@ -336,6 +349,29 @@ int draw_sidebar(int menu) {
 	return 0;
 }
 
+BUFFY * exist_next_new()
+{
+       BUFFY *tmp = CurBuffy;
+       if(tmp == NULL) return NULL;
+       while (tmp->next != NULL)
+       {
+              tmp = tmp->next;
+               if(tmp->msg_unread) return tmp;
+       }
+       return NULL;
+}
+
+BUFFY * exist_prev_new()
+{
+       BUFFY *tmp = CurBuffy;
+       if(tmp == NULL) return NULL;
+       while (tmp->prev != NULL)
+       {
+               tmp = tmp->prev;
+               if(tmp->msg_unread) return tmp;
+       }
+       return NULL;
+}
 
 void set_buffystats(CONTEXT* Context)
 {
@@ -352,18 +388,33 @@ void set_buffystats(CONTEXT* Context)
 
 void scroll_sidebar(int op, int menu)
 {
+        BUFFY *tmp;
         if(!SidebarWidth) return;
         if(!CurBuffy) return;
 
 	switch (op) {
 		case OP_SIDEBAR_NEXT:
+                if (!option (OPTSIDEBARNEWMAILONLY)) {
 			if ( CurBuffy->next == NULL ) return;
 			CurBuffy = CurBuffy->next;
 			break;
+                }
+                case OP_SIDEBAR_NEXT_NEW:
+                        if ( (tmp = exist_next_new()) == NULL)
+                                return;
+                        else CurBuffy = tmp;
+                        break;
 		case OP_SIDEBAR_PREV:
+                 if (!option (OPTSIDEBARNEWMAILONLY)) {
 			if ( CurBuffy->prev == NULL ) return;
 			CurBuffy = CurBuffy->prev;
 			break;
+                }
+                case OP_SIDEBAR_PREV_NEW:
+                       if ( (tmp = exist_prev_new()) == NULL)
+                               return;
+                       else CurBuffy = tmp;
+                       break;
 		case OP_SIDEBAR_SCROLL_UP:
 			CurBuffy = TopBuffy;
 			if ( CurBuffy != Incoming ) {