about summary refs log tree commit diff
path: root/pkgs/applications/networking/mailreaders
diff options
context:
space:
mode:
authorRobin Gloster <mail@glob.in>2016-07-15 14:41:01 +0000
committerRobin Gloster <mail@glob.in>2016-07-15 14:41:01 +0000
commit5185bc177309c62e53dad1ad346d1220f0e77bd4 (patch)
tree52f5878b394abf2ef326765d46880ccbabd84903 /pkgs/applications/networking/mailreaders
parent07615735077db344539eb9131823600593f0eddf (diff)
parentf402c6321aa3c6e56f5e1f1e36c4ad459c881309 (diff)
Merge remote-tracking branch 'upstream/master' into hardened-stdenv
Diffstat (limited to 'pkgs/applications/networking/mailreaders')
-rw-r--r--pkgs/applications/networking/mailreaders/mutt/default.nix86
-rw-r--r--pkgs/applications/networking/mailreaders/mutt/sidebar-compose.patch40
-rw-r--r--pkgs/applications/networking/mailreaders/mutt/sidebar-delimnullwide.patch38
-rw-r--r--pkgs/applications/networking/mailreaders/mutt/sidebar-dotpathsep.patch98
-rw-r--r--pkgs/applications/networking/mailreaders/mutt/sidebar-new.patch97
-rw-r--r--pkgs/applications/networking/mailreaders/mutt/sidebar-newonly.patch198
-rw-r--r--pkgs/applications/networking/mailreaders/mutt/sidebar-utf8.patch132
-rw-r--r--pkgs/applications/networking/mailreaders/mutt/sidebar.patch4623
-rw-r--r--pkgs/applications/networking/mailreaders/mutt/trash-folder.patch316
-rw-r--r--pkgs/applications/networking/mailreaders/mutt/trash.patch797
-rw-r--r--pkgs/applications/networking/mailreaders/neomutt/default.nix8
-rw-r--r--pkgs/applications/networking/mailreaders/thunderbird-bin/generate_sources.rb2
-rw-r--r--pkgs/applications/networking/mailreaders/thunderbird-bin/sources.nix236
-rw-r--r--pkgs/applications/networking/mailreaders/thunderbird/default.nix4
-rw-r--r--pkgs/applications/networking/mailreaders/trojita/default.nix41
15 files changed, 4802 insertions, 1914 deletions
diff --git a/pkgs/applications/networking/mailreaders/mutt/default.nix b/pkgs/applications/networking/mailreaders/mutt/default.nix
index 1964faf2f5c84..31ead22e1fd68 100644
--- a/pkgs/applications/networking/mailreaders/mutt/default.nix
+++ b/pkgs/applications/networking/mailreaders/mutt/default.nix
@@ -1,43 +1,51 @@
 { stdenv, fetchurl, ncurses, which, perl, autoreconfHook
-, sslSupport ? true
-, imapSupport ? true
-, headerCache ? true
-, saslSupport ? true
-, gpgmeSupport ? true
 , gdbm ? null
 , openssl ? null
 , cyrus_sasl ? null
 , gpgme ? null
-, withSidebar ? false
+, aclocal ? null
+, headerCache  ? true
+, sslSupport   ? true
+, saslSupport  ? true
+, gpgmeSupport ? true
+, imapSupport  ? true
+, withSidebar  ? false
+, withTrash    ? false
 }:
 
-assert headerCache -> gdbm != null;
-assert sslSupport -> openssl != null;
-assert saslSupport -> cyrus_sasl != null;
-assert gpgmeSupport -> gpgme != null;
+assert headerCache  -> gdbm       != null;
+assert sslSupport   -> openssl    != null;
+assert saslSupport  -> cyrus_sasl != null;
+assert gpgmeSupport -> gpgme      != null;
+
+with stdenv.lib;
 
-let
-  version = "1.6.0";
-in
 stdenv.mkDerivation rec {
-  name = "mutt${stdenv.lib.optionalString withSidebar "-with-sidebar"}-${version}";
+  name = "mutt-${version}";
+  version = "1.6.2";
 
   src = fetchurl {
-    url = "http://ftp.mutt.org/pub/mutt/mutt-${version}.tar.gz";
-    sha256 = "06bc2drbgalkk68rzg7hq2v5m5qgjxff5357wg0419dpi8ivdbr9";
+    url = "http://ftp.mutt.org/pub/mutt/${name}.tar.gz";
+    sha256 = "13hxmji7v9m2agmvzrs7gzx8s3c9jiwrv7pbkr7z1kc6ckq2xl65";
   };
 
-  buildInputs = with stdenv.lib;
+  buildInputs =
     [ ncurses which perl ]
-    ++ optional headerCache gdbm
-    ++ optional sslSupport openssl
-    ++ optional saslSupport cyrus_sasl
-    ++ optional gpgmeSupport gpgme;
-
-  nativeBuildInputs = stdenv.lib.optional withSidebar autoreconfHook;
+    ++ optional headerCache  gdbm
+    ++ optional sslSupport   openssl
+    ++ optional saslSupport  cyrus_sasl
+    ++ optional gpgmeSupport gpgme
+    ++ optional withSidebar  autoreconfHook;
 
   configureFlags = [
-    "--with-mailpath=" "--enable-smtp"
+    (enableFeature headerCache  "hcache")
+    (enableFeature gpgmeSupport "gpgme")
+    (enableFeature imapSupport  "imap")
+    (enableFeature withSidebar  "sidebar")
+    "--enable-smtp"
+    "--enable-pop"
+    "--enable-imap"
+    "--with-mailpath="
 
     # Look in $PATH at runtime, instead of hardcoding /usr/bin/sendmail
     "ac_cv_path_SENDMAIL=sendmail"
@@ -45,36 +53,22 @@ stdenv.mkDerivation rec {
     # This allows calls with "-d N", that output debug info into ~/.muttdebug*
     "--enable-debug"
 
-    "--enable-pop" "--enable-imap"
-
     # The next allows building mutt without having anything setgid
     # set by the installer, and removing the need for the group 'mail'
     # I set the value 'mailbox' because it is a default in the configure script
     "--with-homespool=mailbox"
-    (if headerCache then "--enable-hcache" else "--disable-hcache")
-    (if sslSupport then "--with-ssl" else "--without-ssl")
-    (if imapSupport then "--enable-imap" else "--disable-imap")
-    (if saslSupport then "--with-sasl" else "--without-sasl")
-    (if gpgmeSupport then "--enable-gpgme" else "--disable-gpgme")
-  ];
+  ] ++ optional sslSupport  "--with-ssl"
+    ++ optional saslSupport "--with-sasl";
 
-  # Adding the sidebar
-  patches = stdenv.lib.optional withSidebar [
-    ./trash-folder.patch
-    ./sidebar.patch
-    ./sidebar-dotpathsep.patch
-    ./sidebar-utf8.patch
-    ./sidebar-newonly.patch
-    ./sidebar-delimnullwide.patch
-    ./sidebar-compose.patch
-    ./sidebar-new.patch
-  ];
+  patches =
+    optional withTrash ./trash.patch ++
+    optional withSidebar ./sidebar.patch;
 
-  meta = with stdenv.lib; {
+  meta = {
     description = "A small but very powerful text-based mail client";
     homepage = http://www.mutt.org;
-    license = stdenv.lib.licenses.gpl2Plus;
+    license = licenses.gpl2Plus;
     platforms = platforms.unix;
-    maintainers = with maintainers; [ the-kenny ];
+    maintainers = with maintainers; [ the-kenny rnhmjoj ];
   };
 }
diff --git a/pkgs/applications/networking/mailreaders/mutt/sidebar-compose.patch b/pkgs/applications/networking/mailreaders/mutt/sidebar-compose.patch
deleted file mode 100644
index 90d815b841d79..0000000000000
--- a/pkgs/applications/networking/mailreaders/mutt/sidebar-compose.patch
+++ /dev/null
@@ -1,40 +0,0 @@
-From: Evgeni Golov <evgeni@debian.org>
-Date: Fri, 14 Mar 2014 08:54:47 +0100
-Subject: sidebar-compose
-
-draw_sidebar sets SidebarWidth to 0 when sidebar_visible is false.
-However, if you start mutt in compose mode, draw_sidebar won't be
-called until the next redraw and your header lines will be off by
-the width of the sidebar, even when you did not want a sidebar at
-all.
-
-Can be tested with:
-  HOME=/ LC_ALL=C mutt -e 'unset sidebar_visible' -s test recipient
-
-Closes: #502627
-
-Gbp-Pq: Topic mutt-patched
----
- compose.c | 2 ++
- 1 file changed, 2 insertions(+)
-
-diff --git a/compose.c b/compose.c
-index b63695f..0fa6df2 100644
---- a/compose.c
-+++ b/compose.c
-@@ -32,6 +32,7 @@
- #include "mailbox.h"
- #include "sort.h"
- #include "charset.h"
-+#include "sidebar.h"
- 
- #ifdef MIXMASTER
- #include "remailer.h"
-@@ -248,6 +249,7 @@ static void draw_envelope_addr (int line, ADDRESS *addr)
- 
- static void draw_envelope (HEADER *msg, char *fcc)
- {
-+  draw_sidebar (MENU_COMPOSE);
-   draw_envelope_addr (HDR_FROM, msg->env->from);
-   draw_envelope_addr (HDR_TO, msg->env->to);
-   draw_envelope_addr (HDR_CC, msg->env->cc);
diff --git a/pkgs/applications/networking/mailreaders/mutt/sidebar-delimnullwide.patch b/pkgs/applications/networking/mailreaders/mutt/sidebar-delimnullwide.patch
deleted file mode 100644
index 11d2ced5a0c08..0000000000000
--- a/pkgs/applications/networking/mailreaders/mutt/sidebar-delimnullwide.patch
+++ /dev/null
@@ -1,38 +0,0 @@
-From: Evgeni Golov <sargentd@die-welt.net>
-Date: Wed, 5 Mar 2014 17:46:07 +0100
-Subject: sidebar-delimnullwide
-
-SidebarDelim can be NULL and strlen(NULL) is a bad idea, as it will segfault.
-Wrap it with NONULL().
-
-While at it, change strlen to mbstowcs for better utf8 support.
-
-Closes: #696145, #663883
-
-Gbp-Pq: Topic mutt-patched
----
- sidebar.c | 4 ++--
- 1 file changed, 2 insertions(+), 2 deletions(-)
-
-diff --git a/sidebar.c b/sidebar.c
-index 51a25ca..c3ea338 100644
---- a/sidebar.c
-+++ b/sidebar.c
-@@ -88,7 +88,7 @@ char *make_sidebar_entry(char *box, int size, int new, int flagged)
-     int box_len, box_bytes;
-     int int_len;
-     int right_offset = 0;
--    int delim_len = strlen(SidebarDelim);
-+    int delim_len = mbstowcs(NULL, NONULL(SidebarDelim), 0);
-     static char *entry;
- 
-     right_width = left_width = 0;
-@@ -178,7 +178,7 @@ int draw_sidebar(int menu) {
- #ifndef USE_SLANG_CURSES
-         attr_t attrs;
- #endif
--        short delim_len = strlen(SidebarDelim);
-+        short delim_len = mbstowcs(NULL, NONULL(SidebarDelim), 0);
-         short color_pair;
- 
-         static bool initialized = false;
diff --git a/pkgs/applications/networking/mailreaders/mutt/sidebar-dotpathsep.patch b/pkgs/applications/networking/mailreaders/mutt/sidebar-dotpathsep.patch
deleted file mode 100644
index 315fa1649bcf7..0000000000000
--- a/pkgs/applications/networking/mailreaders/mutt/sidebar-dotpathsep.patch
+++ /dev/null
@@ -1,98 +0,0 @@
-From: Fabian Groffen <grobian@gentoo.org>
-Date: Tue, 4 Mar 2014 21:12:15 +0100
-Subject: sidebar-dotpathsep
-
-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.
-
-Gbp-Pq: Topic mutt-patched
----
- globals.h |  1 +
- init.h    |  8 ++++++++
- sidebar.c | 31 ++++++++++++++++++++++++-------
- 3 files changed, 33 insertions(+), 7 deletions(-)
-
-diff --git a/globals.h b/globals.h
-index 004c795..602f932 100644
---- a/globals.h
-+++ b/globals.h
-@@ -119,6 +119,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 --git a/init.h b/init.h
-index c664e5f..166671b 100644
---- a/init.h
-+++ b/init.h
-@@ -2051,6 +2051,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 --git a/sidebar.c b/sidebar.c
-index 6098c2a..4356ffc 100644
---- a/sidebar.c
-+++ b/sidebar.c
-@@ -249,20 +249,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,
diff --git a/pkgs/applications/networking/mailreaders/mutt/sidebar-new.patch b/pkgs/applications/networking/mailreaders/mutt/sidebar-new.patch
deleted file mode 100644
index fb26534636115..0000000000000
--- a/pkgs/applications/networking/mailreaders/mutt/sidebar-new.patch
+++ /dev/null
@@ -1,97 +0,0 @@
-From 355399bde98203af59d20821f9e840fc056bd383 Mon Sep 17 00:00:00 2001
-From: Julius Haertl <jus@bitgrid.net>
-Date: Tue, 9 Sep 2014 22:31:49 +0200
-Subject: Patch for sidebar iteration functionality
-
-sidebar-new will move the selected folder to the next with new messages.
-If the end is reached, it will start at the top.
-
-Useful macros would be:
-
-	macro index <esc>a "<sidebar-new><sidebar-open>"
-	macro pager <esc>a "<exit><sidebar-new><sidebar-open>"
----
- OPS         |  1 +
- curs_main.c |  1 +
- functions.h |  2 ++
- pager.c     |  1 +
- sidebar.c   | 10 ++++++++++
- 5 files changed, 15 insertions(+)
-
-diff --git a/OPS b/OPS
-index 1ed9c96..3ffb82a 100644
---- a/OPS
-+++ b/OPS
-@@ -187,3 +187,4 @@ 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"
-+OP_SIDEBAR_NEW "iterate though mailboxes with new mail"
-diff --git a/curs_main.c b/curs_main.c
-index acb106d..2e35f90 100644
---- a/curs_main.c
-+++ b/curs_main.c
-@@ -2328,6 +2328,7 @@ int mutt_index_menu (void)
-       case OP_SIDEBAR_PREV:
-       case OP_SIDEBAR_NEXT_NEW:
-       case OP_SIDEBAR_PREV_NEW:
-+      case OP_SIDEBAR_NEW:
-         scroll_sidebar(op, menu->menu);
-         break;
-       default:
-diff --git a/functions.h b/functions.h
-index 363b4d5..1485080 100644
---- a/functions.h
-+++ b/functions.h
-@@ -176,6 +176,7 @@ const struct binding_t OpMain[] = { /* map: index */
-  { "sidebar-prev",		OP_SIDEBAR_PREV, NULL },
-  { "sidebar-next-new", OP_SIDEBAR_NEXT_NEW, NULL},
-  { "sidebar-prev-new", OP_SIDEBAR_PREV_NEW, NULL},
-+ { "sidebar-new",		OP_SIDEBAR_NEW, NULL },
-  { "sidebar-open",		OP_SIDEBAR_OPEN, NULL },
-   { NULL,			0,				NULL }
- };
-@@ -287,6 +288,7 @@ const struct binding_t OpPager[] = { /* map: pager */
-   { "sidebar-prev",	OP_SIDEBAR_PREV, NULL },
-   { "sidebar-next-new", OP_SIDEBAR_NEXT_NEW, NULL},
-   { "sidebar-prev-new", OP_SIDEBAR_PREV_NEW, NULL},
-+  { "sidebar-new",		OP_SIDEBAR_NEW, NULL },
-   { "sidebar-open", OP_SIDEBAR_OPEN, NULL },
-   { NULL,		0,				NULL }
- };
-diff --git a/pager.c b/pager.c
-index 8d64fe1..696e55c 100644
---- a/pager.c
-+++ b/pager.c
-@@ -2791,6 +2791,7 @@ search_next:
-       case OP_SIDEBAR_PREV:
-       case OP_SIDEBAR_NEXT_NEW:
-       case OP_SIDEBAR_PREV_NEW:
-+      case OP_SIDEBAR_NEW:
- 	scroll_sidebar(ch, MENU_PAGER);
-  	break;
- 
-diff --git a/sidebar.c b/sidebar.c
-index c3ea338..eb8ecd2 100644
---- a/sidebar.c
-+++ b/sidebar.c
-@@ -429,6 +429,16 @@ void scroll_sidebar(int op, int menu)
- 				CurBuffy = CurBuffy->next;
- 			}
- 			break;
-+                case OP_SIDEBAR_NEW:
-+                	if ( (tmp = exist_next_new()) == NULL)
-+				tmp = TopBuffy;
-+			if ( tmp->msg_unread == 0 ) {
-+				CurBuffy = tmp;
-+				tmp = exist_next_new();
-+			}
-+			if ( tmp != NULL )
-+				CurBuffy = tmp;
-+			break;
- 		default:
- 			return;
- 	}
--- 
-2.6.0.rc0.2.g7662973.dirty
-
diff --git a/pkgs/applications/networking/mailreaders/mutt/sidebar-newonly.patch b/pkgs/applications/networking/mailreaders/mutt/sidebar-newonly.patch
deleted file mode 100644
index d206848026b6b..0000000000000
--- a/pkgs/applications/networking/mailreaders/mutt/sidebar-newonly.patch
+++ /dev/null
@@ -1,198 +0,0 @@
-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 ) {
diff --git a/pkgs/applications/networking/mailreaders/mutt/sidebar-utf8.patch b/pkgs/applications/networking/mailreaders/mutt/sidebar-utf8.patch
deleted file mode 100644
index d67e43c24b6ed..0000000000000
--- a/pkgs/applications/networking/mailreaders/mutt/sidebar-utf8.patch
+++ /dev/null
@@ -1,132 +0,0 @@
-From: Antonio Radici <antonio@debian.org>
-Date: Tue, 4 Mar 2014 15:39:14 +0100
-Subject: sidebar-utf8
-
-This patch fixes a problem with utf-8 strings and the sidebar,
-it rewrites entirely make_sidebar_entry so it also fixes some
-segfaults due to misallocations and overflows.
-
-See:
- http://bugs.debian.org/584581
- http://bugs.debian.org/603287
-
-Gbp-Pq: Topic mutt-patched
----
- sidebar.c | 97 +++++++++++++++++++++++++++++++++++++++++++--------------------
- 1 file changed, 67 insertions(+), 30 deletions(-)
-
-diff --git a/sidebar.c b/sidebar.c
-index 4356ffc..8f58f85 100644
---- a/sidebar.c
-+++ b/sidebar.c
-@@ -30,6 +30,7 @@
- #include <libgen.h>
- #include "keymap.h"
- #include <stdbool.h>
-+#include <wchar.h>
- 
- /*BUFFY *CurBuffy = 0;*/
- static BUFFY *TopBuffy = 0;
-@@ -82,36 +83,72 @@ void calc_boundaries (int menu)
- 
- char *make_sidebar_entry(char *box, int size, int new, int flagged)
- {
--	static char *entry = 0;
--	char *c;
--	int i = 0;
--	int delim_len = strlen(SidebarDelim);
--
--	c = realloc(entry, SidebarWidth - delim_len + 2);
--	if ( c ) entry = c;
--	entry[SidebarWidth - delim_len + 1] = 0;
--	for (; i < SidebarWidth - delim_len + 1; entry[i++] = ' ' );
--	i = strlen(box);
--	strncpy( entry, box, i < (SidebarWidth - delim_len + 1) ? i : (SidebarWidth - delim_len + 1) );
--
--        if (size == -1)
--                sprintf(entry + SidebarWidth - delim_len - 3, "?");
--        else if ( new ) {
--          if (flagged > 0) {
--              sprintf(
--		        entry + SidebarWidth - delim_len - 5 - quick_log10(size) - quick_log10(new) - quick_log10(flagged),
--		        "% d(%d)[%d]", size, new, flagged);
--          } else {
--              sprintf(
--                      entry + SidebarWidth - delim_len - 3 - quick_log10(size) - quick_log10(new),
--                      "% d(%d)", size, new);
--          }
--        } else if (flagged > 0) {
--              sprintf( entry + SidebarWidth - delim_len - 3 - quick_log10(size) - quick_log10(flagged), "% d[%d]", size, flagged);
--        } else {
--              sprintf( entry + SidebarWidth - delim_len - 1 - quick_log10(size), "% d", size);
--        }
--	return entry;
-+    char int_store[20]; // up to 64 bits integers
-+    int right_width, left_width;
-+    int box_len, box_bytes;
-+    int int_len;
-+    int right_offset = 0;
-+    int delim_len = strlen(SidebarDelim);
-+    static char *entry;
-+
-+    right_width = left_width = 0;
-+    box_len = box_bytes = 0;
-+
-+    // allocate an entry big enough to contain SidebarWidth wide chars
-+    entry = malloc((SidebarWidth*4)+1); // TODO: error check
-+
-+    // determine the right space (i.e.: how big are the numbers that we want to print)
-+    if ( size > 0 ) {
-+        int_len = snprintf(int_store, sizeof(int_store), "%d", size);
-+        right_width += int_len;
-+    } else {
-+        right_width = 1; // to represent 0
-+    }
-+    if ( new > 0 ) {
-+        int_len = snprintf(int_store, sizeof(int_store), "%d", new);
-+        right_width += int_len + 2; // 2 is for ()
-+    }
-+    if ( flagged > 0 ) {
-+        int_len = snprintf(int_store, sizeof(int_store), "%d", flagged);
-+        right_width += int_len + 2; // 2 is for []
-+    }
-+
-+    // determine how much space we have for *box and its padding (if any)
-+    left_width = SidebarWidth - right_width - 1 - delim_len; // 1 is for the space
-+    //fprintf(stdout, "left_width: %d right_width: %d\n", left_width, right_width);
-+    // right side overflow case
-+    if ( left_width <= 0 ) {
-+        snprintf(entry, SidebarWidth*4, "%-*.*s ...", SidebarWidth-4-delim_len, SidebarWidth-4-delim_len, box);
-+        return entry;
-+    }
-+    right_width -= delim_len;
-+
-+    // to support utf-8 chars we need to add enough space padding in case there
-+    // are less chars than bytes in *box
-+    box_len = mbstowcs(NULL, box, 0);
-+    box_bytes = strlen(box);
-+    // debug
-+    //fprintf(stdout, "box_len: %d box_bytes: %d (diff: %d)\n", box_len, box_bytes, (box_bytes-box_len));
-+    // if there is less string than the space we allow, then we will add the
-+    // spaces
-+    if ( box_len != -1 && box_len < left_width ) {
-+        left_width += (box_bytes - box_len);
-+    }
-+    // otherwise sprintf will truncate the string for us (therefore, no else case)
-+
-+    // print the sidebar entry (without new and flagged messages, at the moment)
-+    //fprintf(stdout, "left_width: %d right_width: %d\n", left_width, right_width);
-+    right_offset = snprintf(entry, SidebarWidth*4, "%-*.*s %d", left_width, left_width, box, size);
-+
-+    // then pad new and flagged messages if any
-+    if ( new > 0 ) {
-+        right_offset += snprintf(entry+right_offset, SidebarWidth*4-right_offset, "(%d)", new);
-+    }
-+    if ( flagged > 0 ) {
-+        right_offset += snprintf(entry+right_offset, SidebarWidth*4-right_offset, "[%d]", flagged);
-+    }
-+
-+    return entry;
- }
- 
- void set_curbuffy(char buf[LONG_STRING])
diff --git a/pkgs/applications/networking/mailreaders/mutt/sidebar.patch b/pkgs/applications/networking/mailreaders/mutt/sidebar.patch
index bac1b4ab83b2c..218de7a0c46ff 100644
--- a/pkgs/applications/networking/mailreaders/mutt/sidebar.patch
+++ b/pkgs/applications/networking/mailreaders/mutt/sidebar.patch
@@ -1,306 +1,373 @@
-From: Antonio Radici <antonio@debian.org>
-Date: Tue, 4 Mar 2014 15:21:10 +0100
-Subject: sidebar
-
-When enabled, mutt will show a list of mailboxes with (new) message counts in a
-separate column on the left side of the screen.
-
-As this feature is still considered to be unstable, this patch is only applied
-in the "mutt-patched" package.
-
-* Configuration variables:
-
-  sidebar_delim (string, default "|")
-
-    This specifies the delimiter between the sidebar (if visible) and
-    other screens.
-
-  sidebar_visible (boolean, default no)
-
-    This specifies whether or not to show sidebar (left-side list of folders).
-
-  sidebar_width (integer, default 0)
--
-    The width of the sidebar.
-
-* Patch source:
-  - http://www.lunar-linux.org/index.php?page=mutt-sidebar
-  - http://lunar-linux.org/~tchan/mutt/patch-1.5.19.sidebar.20090522.txt
-
-* Changes made:
-  - 2008-08-02 myon: Refreshed patch using quilt push -f to remove hunks we do
-    not need (Makefile.in).
-
-  - 2014-03-04 evgeni: refresh sidebar patch with the version from OpenBSD
-    Source:
-      ftp://ftp.openbsd.org/pub/OpenBSD/distfiles/mutt/sidebar-1.5.22.diff1.gz
-
-Signed-off-by: Matteo F. Vescovi <mfvescovi@gmail.com>
-Signed-off-by: Evgeni Golov <evgeni@debian.org>
-
-Gbp-Pq: Topic mutt-patched
----
- Makefile.am    |   1 +
- OPS            |   5 +
- buffy.c        | 124 +++++++++++++++++++++
- buffy.h        |   4 +
- color.c        |   2 +
- compose.c      |  26 ++---
- curs_main.c    |  30 +++++-
- flags.c        |   3 +
- functions.h    |  10 ++
- globals.h      |   4 +
- imap/command.c |   7 ++
- imap/imap.c    |   2 +-
- init.h         |  21 ++++
- mailbox.h      |   1 +
- mbox.c         |   2 +
- menu.c         |  20 ++--
- mh.c           |  22 ++++
- mutt.h         |   4 +
- mutt_curses.h  |   3 +
- muttlib.c      |  48 +++++++++
- mx.c           |  15 +++
- mx.h           |   1 +
- pager.c        |  30 ++++--
- sidebar.c      | 333 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- sidebar.h      |  36 +++++++
- 25 files changed, 720 insertions(+), 34 deletions(-)
- create mode 100644 sidebar.c
- create mode 100644 sidebar.h
-
-diff --git a/Makefile.am b/Makefile.am
-index 5dfeff6..cf1ac98 100644
---- a/Makefile.am
-+++ b/Makefile.am
-@@ -33,6 +33,7 @@ mutt_SOURCES = \
- 	rfc822.c rfc1524.c rfc2047.c rfc2231.c rfc3676.c \
- 	score.c send.c sendlib.c signal.c sort.c \
- 	status.c system.c thread.c charset.c history.c lib.c \
-+	sidebar.c \
- 	muttlib.c editmsg.c mbyte.c mutt_idna.c \
- 	url.c ascii.c crypt-mod.c crypt-mod.h safe_asprintf.c
- 
-diff --git a/OPS b/OPS
-index 02cea8e..b036db9 100644
---- a/OPS
-+++ b/OPS
-@@ -180,3 +180,8 @@ OP_WHAT_KEY "display the keycode for a key press"
- OP_MAIN_SHOW_LIMIT "show currently active limit pattern"
- OP_MAIN_COLLAPSE_THREAD "collapse/uncollapse current thread"
- OP_MAIN_COLLAPSE_ALL "collapse/uncollapse all threads"
-+OP_SIDEBAR_SCROLL_UP "scroll the mailbox pane up 1 page"
-+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"
-diff --git a/buffy.c b/buffy.c
-index 12a16d1..90ca6db 100644
---- a/buffy.c
-+++ b/buffy.c
-@@ -161,6 +161,49 @@ void mutt_buffy_cleanup (const char *buf, struct stat *st)
-   }
- }
+diff -urN mutt-1.6.1/buffy.c mutt-1.6.1-sidebar/buffy.c
+--- mutt-1.6.1/buffy.c	2016-06-12 18:43:00.397447512 +0100
++++ mutt-1.6.1-sidebar/buffy.c	2016-06-12 18:43:03.951502935 +0100
+@@ -27,6 +27,10 @@
  
-+static int buffy_compare_name(const void *a, const void *b) {
-+  const BUFFY *b1 = * (BUFFY * const *) a;
-+  const BUFFY *b2 = * (BUFFY * const *) b;
-+
-+  return mutt_strcoll(b1->path, b2->path);
-+}
-+
-+static BUFFY *buffy_sort(BUFFY *b)
-+{
-+  BUFFY *tmp = b;
-+  int buffycount = 0;
-+  BUFFY **ary;
-+  int i;
-+
-+  if (!option(OPTSIDEBARSORT))
-+    return b;
-+
-+  for (; tmp != NULL; tmp = tmp->next)
-+    buffycount++;
-+
-+  ary = (BUFFY **) safe_calloc(buffycount, sizeof (*ary));
-+
-+  tmp = b;
-+  for (i = 0; tmp != NULL; tmp = tmp->next, i++) {
-+    ary[i] = tmp;
-+  }
-+
-+  qsort(ary, buffycount, sizeof(*ary), buffy_compare_name);
-+
-+  for (i = 0; i < buffycount - 1; i++) {
-+    ary[i]->next = ary[i+1];
-+  }
-+  ary[buffycount - 1]->next = NULL;
-+  for (i = 1; i < buffycount; i++) {
-+    ary[i]->prev = ary[i-1];
-+  }
-+  ary[0]->prev = NULL;
-+
-+  tmp = ary[0];
-+  free(ary);
-+  return tmp;
-+}
+ #include "mutt_curses.h"
+ 
++#ifdef USE_SIDEBAR
++#include "sidebar.h"
++#endif
 +
- BUFFY *mutt_find_mailbox (const char *path)
+ #ifdef USE_IMAP
+ #include "imap.h"
+ #endif
+@@ -196,9 +200,17 @@
+ static BUFFY *buffy_new (const char *path)
  {
-   BUFFY *tmp = NULL;
-@@ -282,6 +325,7 @@ int mutt_parse_mailboxes (BUFFER *path, BUFFER *s, unsigned long data, BUFFER *e
-     else
-       (*tmp)->size = 0;
+   BUFFY* buffy;
++#ifdef USE_SIDEBAR
++  char rp[PATH_MAX] = "";
++  char *r = NULL;
++#endif
+ 
+   buffy = (BUFFY *) safe_calloc (1, sizeof (BUFFY));
+   strfcpy (buffy->path, path, sizeof (buffy->path));
++#ifdef USE_SIDEBAR
++  r = realpath (path, rp);
++  strfcpy (buffy->realpath, r ? rp : path, sizeof (buffy->realpath));
++#endif
+   buffy->next = NULL;
+   buffy->magic = 0;
+ 
+@@ -215,7 +227,10 @@
+   BUFFY **tmp,*tmp1;
+   char buf[_POSIX_PATH_MAX];
+   struct stat sb;
+-  char f1[PATH_MAX], f2[PATH_MAX];
++  char f1[PATH_MAX];
++#ifndef USE_SIDEBAR
++  char f2[PATH_MAX];
++#endif
+   char *p, *q;
+ 
+   while (MoreArgs (s))
+@@ -228,6 +243,9 @@
+       for (tmp = &Incoming; *tmp;)
+       {
+         tmp1=(*tmp)->next;
++#ifdef USE_SIDEBAR
++	mutt_sb_notify_mailbox (*tmp, 0);
++#endif
+         buffy_free (tmp);
+         *tmp=tmp1;
+       }
+@@ -243,8 +261,13 @@
+     p = realpath (buf, f1);
+     for (tmp = &Incoming; *tmp; tmp = &((*tmp)->next))
+     {
++#ifdef USE_SIDEBAR
++      q = (*tmp)->realpath;
++      if (mutt_strcmp (p ? p : buf, q) == 0)
++#else
+       q = realpath ((*tmp)->path, f2);
+       if (mutt_strcmp (p ? p : buf, q ? q : (*tmp)->path) == 0)
++#endif
+       {
+ 	dprint(3,(debugfile,"mailbox '%s' already registered as '%s'\n", buf, (*tmp)->path));
+ 	break;
+@@ -256,14 +279,21 @@
+       if(*tmp)
+       {
+         tmp1=(*tmp)->next;
++#ifdef USE_SIDEBAR
++	mutt_sb_notify_mailbox (*tmp, 0);
++#endif
+         buffy_free (tmp);
+         *tmp=tmp1;
+       }
+       continue;
+     }
+ 
+-    if (!*tmp)
++    if (!*tmp) {
+       *tmp = buffy_new (buf);
++#ifdef USE_SIDEBAR
++      mutt_sb_notify_mailbox (*tmp, 1);
++#endif
++    }
+ 
+     (*tmp)->new = 0;
+     (*tmp)->notified = 1;
+@@ -306,6 +336,13 @@
+       return 0;
    }
-+  Incoming = buffy_sort(Incoming);
-   return 0;
- }
  
-@@ -357,6 +401,69 @@ static int buffy_maildir_hasnew (BUFFY* mailbox)
++#ifdef USE_SIDEBAR
++  if (option (OPTSIDEBAR) && mailbox->msg_unread > 0) {
++    mailbox->new = 1;
++    return 1;
++  }
++#endif
++
+   if ((dirp = opendir (path)) == NULL)
+   {
+     mailbox->magic = 0;
+@@ -357,6 +394,93 @@
  
    return 0;
  }
 +
-+/* update message counts for the sidebar */
-+void buffy_maildir_update (BUFFY* mailbox)
++#ifdef USE_SIDEBAR
++/**
++ * buffy_maildir_update_dir - Update counts for one directory
++ * @mailbox: BUFFY representing a maildir mailbox
++ * @dir:     Which directory to search
++ *
++ * Look through one directory of a maildir mailbox.  The directory could
++ * be either "new" or "cur".
++ *
++ * Count how many new, or flagged, messages there are.
++ */
++static void
++buffy_maildir_update_dir (BUFFY *mailbox, const char *dir)
 +{
-+  char path[_POSIX_PATH_MAX];
-+  DIR *dirp;
-+  struct dirent *de;
-+  char *p;
++  char path[_POSIX_PATH_MAX] = "";
++  DIR *dirp = NULL;
++  struct dirent *de = NULL;
++  char *p = NULL;
++  int read;
 +
-+  mailbox->msgcount = 0;
-+  mailbox->msg_unread = 0;
-+  mailbox->msg_flagged = 0;
++  snprintf (path, sizeof (path), "%s/%s", mailbox->path, dir);
 +
-+  snprintf (path, sizeof (path), "%s/new", mailbox->path);
-+        
-+  if ((dirp = opendir (path)) == NULL)
-+  {   
++  dirp = opendir (path);
++  if (!dirp)
++  {
 +    mailbox->magic = 0;
 +    return;
-+  } 
-+      
++  }
++
 +  while ((de = readdir (dirp)) != NULL)
 +  {
 +    if (*de->d_name == '.')
 +      continue;
 +
-+    if (!(p = strstr (de->d_name, ":2,")) || !strchr (p + 3, 'T')) {
-+      mailbox->new = 1;
-+      mailbox->msgcount++;
++    /* Matches maildir_parse_flags logic */
++    read = 0;
++    mailbox->msg_count++;
++    p = strstr (de->d_name, ":2,");
++    if (p)
++    {
++      p += 3;
++      if (strchr (p, 'S'))
++        read = 1;
++      if (strchr (p, 'F'))
++        mailbox->msg_flagged++;
++    }
++    if (!read) {
 +      mailbox->msg_unread++;
 +    }
 +  }
 +
 +  closedir (dirp);
-+  snprintf (path, sizeof (path), "%s/cur", mailbox->path);
-+        
-+  if ((dirp = opendir (path)) == NULL)
-+  {   
-+    mailbox->magic = 0;
-+    return;
-+  } 
-+      
-+  while ((de = readdir (dirp)) != NULL)
-+  {
-+    if (*de->d_name == '.')
-+      continue;
++}
 +
-+    if (!(p = strstr (de->d_name, ":2,")) || !strchr (p + 3, 'T')) {
-+      mailbox->msgcount++;
-+      if ((p = strstr (de->d_name, ":2,"))) {
-+        if (!strchr (p + 3, 'T')) {
-+          if (!strchr (p + 3, 'S'))
-+            mailbox->msg_unread++;
-+          if (strchr(p + 3, 'F'))
-+            mailbox->msg_flagged++;
-+        }
-+      }
-+    }
-+  }
++/**
++ * buffy_maildir_update - Update messages counts for a maildir mailbox
++ * @mailbox: BUFFY representing a maildir mailbox
++ *
++ * Open a mailbox directories and update our record of how many new, or
++ * flagged, messages there are.
++ */
++void
++buffy_maildir_update (BUFFY *mailbox)
++{
++	if (!option (OPTSIDEBAR))
++		return;
 +
-+  closedir (dirp);
++	mailbox->msg_count   = 0;
++	mailbox->msg_unread  = 0;
++	mailbox->msg_flagged = 0;
++
++	buffy_maildir_update_dir (mailbox, "new");
++	if (mailbox->msg_count) {
++		mailbox->new = 1;
++	}
++	buffy_maildir_update_dir (mailbox, "cur");
++
++	mailbox->sb_last_checked = time (NULL);
++
++	/* make sure the updates are actually put on screen */
++	if (SidebarWidth)
++		mutt_sb_draw();
 +}
 +
++#endif
++
  /* returns 1 if mailbox has new mail */ 
  static int buffy_mbox_hasnew (BUFFY* mailbox, struct stat *sb)
  {
-@@ -388,6 +495,20 @@ static int buffy_mbox_hasnew (BUFFY* mailbox, struct stat *sb)
+@@ -368,7 +491,11 @@
+   else
+     statcheck = sb->st_mtime > sb->st_atime
+       || (mailbox->newly_created && sb->st_ctime == sb->st_mtime && sb->st_ctime == sb->st_atime);
++#ifdef USE_SIDEBAR
++  if ((!option (OPTSIDEBAR) && statcheck) || (option (OPTSIDEBAR) && mailbox->msg_unread > 0))
++#else
+   if (statcheck)
++#endif
+   {
+     if (!option(OPTMAILCHECKRECENT) || sb->st_mtime > mailbox->last_visited)
+     {
+@@ -388,6 +515,42 @@
    return rc;
  }
  
-+/* update message counts for the sidebar */
-+void buffy_mbox_update (BUFFY* mailbox)
++#ifdef USE_SIDEBAR
++/**
++ * buffy_mbox_update - Update messages counts for an mbox mailbox
++ * @mailbox: BUFFY representing an mbox mailbox
++ * @sb:      stat(2) infomation about the mailbox file
++ *
++ * Open a mbox file and update our record of how many new, or flagged,
++ * messages there are. If the mailbox hasn't changed since the last call,
++ * the function does nothing.
++ */
++void
++buffy_mbox_update (BUFFY *mailbox, struct stat *sb)
 +{
 +  CONTEXT *ctx = NULL;
 +
-+  ctx = mx_open_mailbox(mailbox->path, M_READONLY | M_QUIET | M_NOSORT | M_PEEK, NULL);
-+  if(ctx)
++  if (!option (OPTSIDEBAR))
++    return;
++  if ((mailbox->sb_last_checked > sb->st_mtime) && (mailbox->msg_count != 0))
++    return; /* no check necessary */
++
++  ctx = mx_open_mailbox (mailbox->path, M_READONLY | M_QUIET | M_NOSORT | M_PEEK, NULL);
++  if (ctx)
 +  {
-+    mailbox->msgcount = ctx->msgcount;
-+    mailbox->msg_unread = ctx->unread;
-+    mx_close_mailbox(ctx, 0);
++    mailbox->msg_count       = ctx->msgcount;
++    mailbox->msg_unread      = ctx->unread;
++    mailbox->msg_flagged     = ctx->flagged;
++    mailbox->sb_last_checked = time (NULL);
++    mx_close_mailbox (ctx, 0);
 +  }
++
++  /* make sure the updates are actually put on screen */
++  if (SidebarWidth)
++    mutt_sb_draw();
 +}
++#endif
 +
  int mutt_buffy_check (int force)
  {
    BUFFY *tmp;
-@@ -461,16 +582,19 @@ int mutt_buffy_check (int force)
+@@ -461,16 +623,25 @@
        {
        case M_MBOX:
        case M_MMDF:
-+	buffy_mbox_update (tmp);
++#ifdef USE_SIDEBAR
++	buffy_mbox_update (tmp, &sb);
++#endif
  	if (buffy_mbox_hasnew (tmp, &sb) > 0)
  	  BuffyCount++;
  	break;
  
        case M_MAILDIR:
++#ifdef USE_SIDEBAR
 +	buffy_maildir_update (tmp);
++#endif
  	if (buffy_maildir_hasnew (tmp) > 0)
  	  BuffyCount++;
  	break;
  
        case M_MH:
-+	mh_buffy_update (tmp->path, &tmp->msgcount, &tmp->msg_unread, &tmp->msg_flagged);
++#ifdef USE_SIDEBAR
++	mh_buffy_update (tmp);
++#endif
  	mh_buffy(tmp);
  	if (tmp->new)
  	  BuffyCount++;
-diff --git a/buffy.h b/buffy.h
-index f9fc55a..672d178 100644
---- a/buffy.h
-+++ b/buffy.h
-@@ -25,7 +25,11 @@ typedef struct buffy_t
+diff -urN mutt-1.6.1/buffy.h mutt-1.6.1-sidebar/buffy.h
+--- mutt-1.6.1/buffy.h	2016-06-12 18:43:00.397447512 +0100
++++ mutt-1.6.1-sidebar/buffy.h	2016-06-12 18:43:03.951502935 +0100
+@@ -16,6 +16,9 @@
+  *     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+  */
+ 
++#ifndef _BUFFY_H
++#define _BUFFY_H
++
+ /*parameter to mutt_parse_mailboxes*/
+ #define M_MAILBOXES   1
+ #define M_UNMAILBOXES 2 
+@@ -23,13 +26,28 @@
+ typedef struct buffy_t
+ {
    char path[_POSIX_PATH_MAX];
++#ifdef USE_SIDEBAR
++  char realpath[_POSIX_PATH_MAX];
++#endif
    off_t size;
    struct buffy_t *next;
++#ifdef USE_SIDEBAR
 +  struct buffy_t *prev;
++#endif
    short new;			/* mailbox has new mail */
-+  int msgcount;			/* total number of messages */
++#ifdef USE_SIDEBAR
++  int msg_count;		/* total number of messages */
 +  int msg_unread;		/* number of unread messages */
 +  int msg_flagged;		/* number of flagged messages */
++  short is_hidden;		/* is hidden from the sidebar */
++#endif
    short notified;		/* user has been notified */
    short magic;			/* mailbox type */
    short newly_created;		/* mbox or mmdf just popped into existence */
-diff --git a/color.c b/color.c
-index 64a46dc..d6f9198 100644
---- a/color.c
-+++ b/color.c
-@@ -94,6 +94,8 @@ static const struct mapping_t Fields[] =
+   time_t last_visited;		/* time of last exit from this mailbox */
++#ifdef USE_SIDEBAR
++  time_t sb_last_checked;	/* time of last buffy check from sidebar */
++#endif
+ }
+ BUFFY;
+ 
+@@ -49,3 +67,5 @@
+ void mutt_buffy_setnotified (const char *path);
+ 
+ void mh_buffy (BUFFY *);
++
++#endif /* _BUFFY_H */
+diff -urN mutt-1.6.1/color.c mutt-1.6.1-sidebar/color.c
+--- mutt-1.6.1/color.c	2016-06-12 18:43:00.397447512 +0100
++++ mutt-1.6.1-sidebar/color.c	2016-06-12 18:43:03.951502935 +0100
+@@ -94,6 +94,14 @@
    { "underline",	MT_COLOR_UNDERLINE },
    { "index",		MT_COLOR_INDEX },
    { "prompt",		MT_COLOR_PROMPT },
-+  { "sidebar_new",	MT_COLOR_NEW },
++#ifdef USE_SIDEBAR
++  { "sidebar_divider",	MT_COLOR_DIVIDER },
 +  { "sidebar_flagged",	MT_COLOR_FLAGGED },
++  { "sidebar_highlight",MT_COLOR_HIGHLIGHT },
++  { "sidebar_indicator",MT_COLOR_SB_INDICATOR },
++  { "sidebar_new",	MT_COLOR_NEW },
++  { "sidebar_spoolfile",MT_COLOR_SB_SPOOLFILE },
++#endif
    { NULL,		0 }
  };
  
-diff --git a/compose.c b/compose.c
-index 9d87060..b63695f 100644
---- a/compose.c
-+++ b/compose.c
-@@ -72,7 +72,7 @@ enum
+@@ -146,6 +154,9 @@
+   ColorDefs[MT_COLOR_INDICATOR] = A_REVERSE;
+   ColorDefs[MT_COLOR_SEARCH] = A_REVERSE;
+   ColorDefs[MT_COLOR_MARKERS] = A_REVERSE;
++#ifdef USE_SIDEBAR
++  ColorDefs[MT_COLOR_HIGHLIGHT] = A_UNDERLINE;
++#endif
+   /* special meaning: toggle the relevant attribute */
+   ColorDefs[MT_COLOR_BOLD] = 0;
+   ColorDefs[MT_COLOR_UNDERLINE] = 0;
+diff -urN mutt-1.6.1/compose.c mutt-1.6.1-sidebar/compose.c
+--- mutt-1.6.1/compose.c	2016-06-12 18:43:00.398447528 +0100
++++ mutt-1.6.1-sidebar/compose.c	2016-06-12 18:43:03.952502951 +0100
+@@ -32,6 +32,9 @@
+ #include "mailbox.h"
+ #include "sort.h"
+ #include "charset.h"
++#ifdef USE_SIDEBAR
++#include "sidebar.h"
++#endif
+ 
+ #ifdef MIXMASTER
+ #include "remailer.h"
+@@ -72,7 +75,7 @@
  
  #define HDR_XOFFSET 10
  #define TITLE_FMT "%10s" /* Used for Prompts, which are ASCII */
@@ -309,16 +376,16 @@ index 9d87060..b63695f 100644
  
  static const char * const Prompts[] =
  {
-@@ -110,7 +110,7 @@ static void snd_entry (char *b, size_t blen, MUTTMENU *menu, int num)
+@@ -110,7 +113,7 @@
  
  static void redraw_crypt_lines (HEADER *msg)
  {
 -  mvaddstr (HDR_CRYPT, 0, "Security: ");
-+  mvaddstr (HDR_CRYPT, SidebarWidth, "Security: ");
++  mvprintw (HDR_CRYPT, SidebarWidth, TITLE_FMT, "Security: ");
  
    if ((WithCrypto & (APPLICATION_PGP | APPLICATION_SMIME)) == 0)
    {
-@@ -145,7 +145,7 @@ static void redraw_crypt_lines (HEADER *msg)
+@@ -145,16 +148,16 @@
        addstr (_(" (OppEnc mode)"));
  
    clrtoeol ();
@@ -327,7 +394,18 @@ index 9d87060..b63695f 100644
    clrtoeol ();
  
    if ((WithCrypto & APPLICATION_PGP)
-@@ -162,7 +162,7 @@ static void redraw_crypt_lines (HEADER *msg)
+       && (msg->security & APPLICATION_PGP) && (msg->security & SIGN))
+-    printw ("%s%s", _(" sign as: "), PgpSignAs ? PgpSignAs : _("<default>"));
++    printw (TITLE_FMT "%s", _("sign as: "), PgpSignAs ? PgpSignAs : _("<default>"));
+ 
+   if ((WithCrypto & APPLICATION_SMIME)
+       && (msg->security & APPLICATION_SMIME) && (msg->security & SIGN)) {
+-      printw ("%s%s", _(" sign as: "), SmimeDefaultKey ? SmimeDefaultKey : _("<default>"));
++      printw (TITLE_FMT "%s", _("sign as: "), SmimeDefaultKey ? SmimeDefaultKey : _("<default>"));
+   }
+ 
+   if ((WithCrypto & APPLICATION_SMIME)
+@@ -162,7 +165,7 @@
        && (msg->security & ENCRYPT)
        && SmimeCryptAlg
        && *SmimeCryptAlg) {
@@ -336,16 +414,17 @@ index 9d87060..b63695f 100644
  		NONULL(SmimeCryptAlg));
    }
  }
-@@ -175,7 +175,7 @@ static void redraw_mix_line (LIST *chain)
+@@ -175,7 +178,8 @@
    int c;
    char *t;
  
 -  mvaddstr (HDR_MIX, 0,     "     Mix: ");
-+  mvaddstr (HDR_MIX, SidebarWidth,     "     Mix: ");
++  /* L10N: "Mix" refers to the MixMaster chain for anonymous email */
++  mvprintw (HDR_MIX, SidebarWidth, TITLE_FMT, _("Mix: "));
  
    if (!chain)
    {
-@@ -190,7 +190,7 @@ static void redraw_mix_line (LIST *chain)
+@@ -190,7 +194,7 @@
      if (t && t[0] == '0' && t[1] == '\0')
        t = "<random>";
      
@@ -354,7 +433,7 @@ index 9d87060..b63695f 100644
        break;
  
      addstr (NONULL(t));
-@@ -242,7 +242,7 @@ static void draw_envelope_addr (int line, ADDRESS *addr)
+@@ -242,20 +246,23 @@
  
    buf[0] = 0;
    rfc822_write_address (buf, sizeof (buf), addr, 1);
@@ -363,7 +442,12 @@ index 9d87060..b63695f 100644
    mutt_paddstr (W, buf);
  }
  
-@@ -252,10 +252,10 @@ static void draw_envelope (HEADER *msg, char *fcc)
+ static void draw_envelope (HEADER *msg, char *fcc)
+ {
++#ifdef USE_SIDEBAR
++  mutt_sb_draw();
++#endif
+   draw_envelope_addr (HDR_FROM, msg->env->from);
    draw_envelope_addr (HDR_TO, msg->env->to);
    draw_envelope_addr (HDR_CC, msg->env->cc);
    draw_envelope_addr (HDR_BCC, msg->env->bcc);
@@ -376,7 +460,7 @@ index 9d87060..b63695f 100644
    mutt_paddstr (W, fcc);
  
    if (WithCrypto)
-@@ -266,7 +266,7 @@ static void draw_envelope (HEADER *msg, char *fcc)
+@@ -266,7 +273,7 @@
  #endif
  
    SETCOLOR (MT_COLOR_STATUS);
@@ -385,16 +469,25 @@ index 9d87060..b63695f 100644
    clrtoeol ();
  
    NORMAL_COLOR;
-@@ -302,7 +302,7 @@ static int edit_address_list (int line, ADDRESS **addr)
+@@ -302,7 +309,7 @@
    /* redraw the expanded list so the user can see the result */
    buf[0] = 0;
    rfc822_write_address (buf, sizeof (buf), *addr, 1);
 -  move (line, HDR_XOFFSET);
-+  move (line, HDR_XOFFSET+SidebarWidth);
++  move (line, HDR_XOFFSET + SidebarWidth);
    mutt_paddstr (W, buf);
    
    return 0;
-@@ -562,7 +562,7 @@ int mutt_compose_menu (HEADER *msg,   /* structure for new message */
+@@ -515,7 +522,7 @@
+   menu->tag = mutt_tag_attach;
+   menu->data = idx;
+   menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_COMPOSE, ComposeHelp);
+-  
++
+   while (loop)
+   {
+     switch (op = mutt_menuLoop (menu))
+@@ -564,7 +571,7 @@
  	if (mutt_get_field ("Subject: ", buf, sizeof (buf), 0) == 0)
  	{
  	  mutt_str_replace (&msg->env->subject, buf);
@@ -403,7 +496,7 @@ index 9d87060..b63695f 100644
  	  if (msg->env->subject)
  	    mutt_paddstr (W, msg->env->subject);
  	  else
-@@ -580,7 +580,7 @@ int mutt_compose_menu (HEADER *msg,   /* structure for new message */
+@@ -582,7 +589,7 @@
  	{
  	  strfcpy (fcc, buf, fcclen);
  	  mutt_pretty_mailbox (fcc, fcclen);
@@ -412,57 +505,118 @@ index 9d87060..b63695f 100644
  	  mutt_paddstr (W, fcc);
  	  fccSet = 1;
  	}
-diff --git a/curs_main.c b/curs_main.c
-index 9d718ee..ea530a6 100644
---- a/curs_main.c
-+++ b/curs_main.c
-@@ -26,7 +26,9 @@
+diff -urN mutt-1.6.1/configure.ac mutt-1.6.1-sidebar/configure.ac
+--- mutt-1.6.1/configure.ac	2016-06-12 18:43:00.398447528 +0100
++++ mutt-1.6.1-sidebar/configure.ac	2016-06-12 18:43:03.952502951 +0100
+@@ -175,6 +175,14 @@
+ 	SMIMEAUX_TARGET="smime_keys"
+ fi
+ 
++AC_ARG_ENABLE(sidebar, AC_HELP_STRING([--enable-sidebar], [Enable Sidebar support]),
++[       if test x$enableval = xyes ; then
++		AC_DEFINE(USE_SIDEBAR, 1, [Define if you want support for the sidebar.])
++		OPS="$OPS \$(srcdir)/OPS.SIDEBAR"
++                MUTT_LIB_OBJECTS="$MUTT_LIB_OBJECTS sidebar.o"
++        fi
++])
++
+ AC_ARG_WITH(mixmaster, AS_HELP_STRING([--with-mixmaster@<:@=PATH@:>@],[Include Mixmaster support]),
+   [if test "$withval" != no
+    then
+diff -urN mutt-1.6.1/copy.c mutt-1.6.1-sidebar/copy.c
+--- mutt-1.6.1/copy.c	2016-06-12 18:43:00.398447528 +0100
++++ mutt-1.6.1-sidebar/copy.c	2016-06-12 18:43:03.952502951 +0100
+@@ -288,7 +288,8 @@
+       if (flags & (CH_DECODE|CH_PREFIX))
+       {
+ 	if (mutt_write_one_header (out, 0, headers[x], 
+-				   flags & CH_PREFIX ? prefix : 0, mutt_term_width (Wrap), flags) == -1)
++				   flags & CH_PREFIX ? prefix : 0,
++                                   mutt_term_width (Wrap), flags) == -1)
+ 	{
+ 	  error = TRUE;
+ 	  break;
+diff -urN mutt-1.6.1/curs_main.c mutt-1.6.1-sidebar/curs_main.c
+--- mutt-1.6.1/curs_main.c	2016-06-12 18:43:00.399447544 +0100
++++ mutt-1.6.1-sidebar/curs_main.c	2016-06-12 18:43:03.953502966 +0100
+@@ -26,8 +26,13 @@
  #include "mailbox.h"
  #include "mapping.h"
  #include "sort.h"
 +#include "buffy.h"
  #include "mx.h"
-+#include "sidebar.h"
  
++#ifdef USE_SIDEBAR
++#include "sidebar.h"
++#endif
++
  #ifdef USE_POP
  #include "pop.h"
-@@ -596,8 +598,12 @@ int mutt_index_menu (void)
+ #endif
+@@ -595,21 +600,39 @@
         menu->redraw |= REDRAW_STATUS;
       if (do_buffy_notify)
       {
 -       if (mutt_buffy_notify () && option (OPTBEEPNEW))
 - 	beep ();
-+       if (mutt_buffy_notify ())
++       if (mutt_buffy_notify())
 +       {
-+         menu->redraw |= REDRAW_FULL;
++         menu->redraw |= REDRAW_STATUS;
 +         if (option (OPTBEEPNEW))
-+           beep ();
++           beep();
 +       }
       }
       else
         do_buffy_notify = 1;
-@@ -609,6 +615,7 @@ int mutt_index_menu (void)
+     }
+ 
++#ifdef USE_SIDEBAR
++    if (option (OPTSIDEBAR))
++        menu->redraw |= REDRAW_SIDEBAR;
++#endif
++
+     if (op != -1)
+       mutt_curs_set (0);
+ 
      if (menu->redraw & REDRAW_FULL)
      {
        menu_redraw_full (menu);
-+      draw_sidebar(menu->menu);
++#ifdef USE_SIDEBAR
++      mutt_sb_draw();
++#endif
        mutt_show_error ();
      }
++#ifdef USE_SIDEBAR
++    else if (menu->redraw & REDRAW_SIDEBAR) {
++      mutt_sb_draw();
++      menu->redraw &= ~REDRAW_SIDEBAR;
++    }
++#endif
  
-@@ -631,9 +638,12 @@ int mutt_index_menu (void)
+     if (menu->menu == MENU_MAIN)
+     {
+@@ -630,9 +653,20 @@
  
        if (menu->redraw & REDRAW_STATUS)
        {
-+	DrawFullLine = 1;
++#ifdef USE_SIDEBAR
++        /* Temporarily lie about the sidebar width */
++	short sw = SidebarWidth;
++	SidebarWidth = 0;
++#endif
  	menu_status_line (buf, sizeof (buf), menu, NONULL (Status));
-+	DrawFullLine = 0;
++#ifdef USE_SIDEBAR
++        SidebarWidth = sw; /* Restore the sidebar width */
++#endif
  	move (option (OPTSTATUSONTOP) ? 0 : LINES-2, 0);
  	SETCOLOR (MT_COLOR_STATUS);
-+	set_buffystats(Context);
++#ifdef USE_SIDEBAR
++	mutt_sb_set_buffystats (Context);
++#endif
  	mutt_paddstr (COLS, buf);
  	NORMAL_COLOR;
  	menu->redraw &= ~REDRAW_STATUS;
-@@ -653,7 +663,7 @@ int mutt_index_menu (void)
+@@ -652,7 +686,7 @@
  	menu->oldcurrent = -1;
  
        if (option (OPTARROWCURSOR))
@@ -471,229 +625,1948 @@ index 9d718ee..ea530a6 100644
        else if (option (OPTBRAILLEFRIENDLY))
  	move (menu->current - menu->top + menu->offset, 0);
        else
-@@ -1154,6 +1164,7 @@ int mutt_index_menu (void)
+@@ -1091,6 +1125,9 @@
+ 	  break;
+ 
+ 	CHECK_MSGCOUNT;
++#ifdef USE_SIDEBAR
++	CHECK_VISIBLE;
++#endif
+ 	CHECK_READONLY;
+ 	{
+ 	  int oldvcount = Context->vcount;
+@@ -1150,6 +1187,9 @@
  	  menu->redraw = REDRAW_FULL;
  	break;
  
++#ifdef USE_SIDEBAR
 +      case OP_SIDEBAR_OPEN:
++#endif
        case OP_MAIN_CHANGE_FOLDER:
        case OP_MAIN_NEXT_UNREAD_MAILBOX:
  
-@@ -1185,7 +1196,11 @@ int mutt_index_menu (void)
+@@ -1181,6 +1221,14 @@
  	{
  	  mutt_buffy (buf, sizeof (buf));
  
--	  if (mutt_enter_fname (cp, buf, sizeof (buf), &menu->redraw, 1) == -1)
-+          if ( op == OP_SIDEBAR_OPEN ) {
-+              if(!CurBuffy)
-+                break;
-+            strncpy( buf, CurBuffy->path, sizeof(buf) );  
-+	    } else if (mutt_enter_fname (cp, buf, sizeof (buf), &menu->redraw, 1) == -1)
++#ifdef USE_SIDEBAR
++	  if (op == OP_SIDEBAR_OPEN) {
++	    const char *path = mutt_sb_get_highlight();
++	    if (!path)
++	      break;
++	    strncpy (buf, path, sizeof (buf));
++	  } else
++#endif
+ 	  if (mutt_enter_fname (cp, buf, sizeof (buf), &menu->redraw, 1) == -1)
  	  {
  	    if (menu->menu == MENU_PAGER)
- 	    {
-@@ -1203,6 +1218,7 @@ int mutt_index_menu (void)
+@@ -1199,6 +1247,9 @@
  	}
  
  	mutt_expand_path (buf, sizeof (buf));
-+        set_curbuffy(buf);
++#ifdef USE_SIDEBAR
++	mutt_sb_set_open_buffy (buf);
++#endif
  	if (mx_get_magic (buf) <= 0)
  	{
  	  mutt_error (_("%s is not a mailbox."), buf);
-@@ -2306,6 +2322,12 @@ int mutt_index_menu (void)
+@@ -2310,6 +2361,21 @@
  	mutt_what_key();
  	break;
  
-+      case OP_SIDEBAR_SCROLL_UP:
-+      case OP_SIDEBAR_SCROLL_DOWN:
++#ifdef USE_SIDEBAR
 +      case OP_SIDEBAR_NEXT:
++      case OP_SIDEBAR_NEXT_NEW:
++      case OP_SIDEBAR_PAGE_DOWN:
++      case OP_SIDEBAR_PAGE_UP:
 +      case OP_SIDEBAR_PREV:
-+        scroll_sidebar(op, menu->menu);
++      case OP_SIDEBAR_PREV_NEW:
++        mutt_sb_change_mailbox (op);
 +        break;
++
++      case OP_SIDEBAR_TOGGLE_VISIBLE:
++	toggle_option (OPTSIDEBAR);
++	menu->redraw = REDRAW_FULL;
++	break;
++#endif
        default:
  	if (menu->menu == MENU_MAIN)
  	  km_error_key (MENU_MAIN);
-diff --git a/flags.c b/flags.c
-index 133fa35..48fb287 100644
---- a/flags.c
-+++ b/flags.c
-@@ -22,8 +22,10 @@
+diff -urN mutt-1.6.1/doc/manual.xml.head mutt-1.6.1-sidebar/doc/manual.xml.head
+--- mutt-1.6.1/doc/manual.xml.head	2016-06-12 18:43:00.402447590 +0100
++++ mutt-1.6.1-sidebar/doc/manual.xml.head	2016-06-12 18:43:03.955502998 +0100
+@@ -405,6 +405,623 @@
+ 
+ </sect2>
+ 
++<sect2 id="intro-sidebar">
++	<title>Sidebar</title>
++	<para>
++		The Sidebar shows a list of all your mailboxes.  The list can be
++		turned on and off, it can be themed and the list style can be
++		configured.
++	</para>
++	<para>
++		This part of the manual is suitable for beginners.
++		If you already know Mutt you could skip ahead to the main
++		<link linkend="sidebar">Sidebar guide</link>.
++		If you just want to get started, you could use the sample
++		<link linkend="sidebar-muttrc">Sidebar muttrc</link>.
++	</para>
++	<para>
++		This version of Sidebar is based on Terry Chan's
++		<ulink url="http://www.lunar-linux.org/mutt-sidebar/">2015-11-11 release</ulink>.
++		It contains many
++		<emphasis role="bold"><link linkend="intro-sidebar-features">new features</link></emphasis>,
++		lots of
++		<emphasis role="bold"><link linkend="intro-sidebar-bugfixes">bugfixes</link></emphasis>
++		and a generous helping of
++		<emphasis role="bold">new documentation</emphasis> which you are already reading.
++	</para>
++	<para>
++		To check if Mutt supports <quote>Sidebar</quote>, look for the string
++		<literal>+USE_SIDEBAR</literal> in the mutt version.
++	</para>
++<screen>
++mutt -v
++</screen>
++	<para>
++		<emphasis role="bold">Let's turn on the Sidebar:</emphasis>
++	</para>
++	<screen>set sidebar_visible</screen>
++	<para>
++		You will see something like this.
++		A list of mailboxes on the left.
++		A list of emails, from the selected mailbox, on the right.
++	</para>
++<screen>
++<emphasis role="indicator">Fruit [1]     3/8</emphasis>|  1    + Jan 24  Rhys Lee         (192)  Yew
++Animals [1]   2/6|  2    + Feb 11  Grace Hall       (167)  Ilama
++Cars            4|  3      Feb 23  Aimee Scott      (450)  Nectarine
++Seas          1/7|  4    ! Feb 28  Summer Jackson   (264)  Lemon
++                 |  5      Mar 07  Callum Harrison  (464)  Raspberry
++                 |<emphasis role="indicator">  6 N  + Mar 24  Samuel Harris    (353)  Tangerine          </emphasis>
++                 |  7 N  + Sep 05  Sofia Graham     (335)  Cherry
++                 |  8 N    Sep 16  Ewan Brown       (105)  Ugli
++                 |
++                 |
++</screen>
++<para>
++	This user has four mailboxes: <quote>Fruit</quote>,
++	<quote>Cars</quote>, <quote>Animals</quote> and
++	<quote>Seas</quote>.
++</para>
++<para>
++	The current, open, mailbox is <quote>Fruit</quote>.  We can
++	also see information about the other mailboxes.  For example:
++	The <quote>Animals</quote> mailbox contains, 1 flagged email, 2
++	new emails out of a total of 6 emails.
++</para>
++	<sect3 id="intro-sidebar-navigation">
++		<title>Navigation</title>
++		<para>
++			The Sidebar adds some new <link linkend="sidebar-functions">functions</link>
++			to Mutt.
++		</para>
++		<para>
++			The user pressed the <quote>c</quote> key to
++			<literal>&lt;change-folder&gt;</literal> to the
++			<quote>Animals</quote> mailbox.  The Sidebar automatically
++			updated the indicator to match.
++		</para>
++<screen>
++Fruit [1]     3/8|  1      Jan 03  Tia Gibson       (362)  Caiman
++<emphasis role="indicator">Animals [1]   2/6</emphasis>|  2    + Jan 22  Rhys Lee         ( 48)  Dolphin
++Cars            4|  3    ! Aug 16  Ewan Brown       (333)  Hummingbird
++Seas          1/7|  4      Sep 25  Grace Hall       ( 27)  Capybara
++                 |<emphasis role="indicator">  5 N  + Nov 12  Evelyn Rogers    (453)  Tapir              </emphasis>
++                 |  6 N  + Nov 16  Callum Harrison  (498)  Hedgehog
++                 |
++                 |
++                 |
++                 |
++</screen>
++		<para>
++			Let's map some functions:
++		</para>
++<screen>
++bind index,pager \CP sidebar-prev       <emphasis role="comment"># Ctrl-Shift-P - Previous Mailbox</emphasis>
++bind index,pager \CN sidebar-next       <emphasis role="comment"># Ctrl-Shift-N - Next Mailbox</emphasis>
++bind index,pager \CO sidebar-open       <emphasis role="comment"># Ctrl-Shift-O - Open Highlighted Mailbox</emphasis>
++</screen>
++		<para>
++			Press <quote>Ctrl-Shift-N</quote> (Next mailbox) twice will
++			move the Sidebar <emphasis role="bold">highlight</emphasis> to
++			down to the <quote>Seas</quote> mailbox.
++		</para>
++<screen>
++Fruit [1]     3/8|  1      Jan 03  Tia Gibson       (362)  Caiman
++<emphasis role="indicator">Animals [1]   2/6</emphasis>|  2    + Jan 22  Rhys Lee         ( 48)  Dolphin
++Cars            4|  3    ! Aug 16  Ewan Brown       (333)  Hummingbird
++<emphasis role="highlight">Seas          1/7</emphasis>|  4      Sep 25  Grace Hall       ( 27)  Capybara
++                 |<emphasis role="indicator">  5 N  + Nov 12  Evelyn Rogers    (453)  Tapir              </emphasis>
++                 |  6 N  + Nov 16  Callum Harrison  (498)  Hedgehog
++                 |
++                 |
++                 |
++                 |
++</screen>
++		<note>
++			Functions <literal>&lt;sidebar-next&gt;</literal> and
++			<literal>&lt;sidebar-prev&gt;</literal> move the Sidebar
++			<emphasis role="bold">highlight</emphasis>.
++			They <emphasis role="bold">do not</emphasis> change the open
++			mailbox.
++		</note>
++		<para>
++			Press <quote>Ctrl-Shift-O</quote>
++			(<literal>&lt;sidebar-open&gt;</literal>)
++			to open the highlighted mailbox.
++		</para>
++<screen>
++Fruit [1]     3/8|  1    ! Mar 07  Finley Jones     (139)  Molucca Sea
++Animals [1]   2/6|  2    + Mar 24  Summer Jackson   ( 25)  Arafura Sea
++Cars            4|  3    + Feb 28  Imogen Baker     (193)  Pechora Sea
++<emphasis role="indicator">Seas          1/7</emphasis>|<emphasis role="indicator">  4 N  + Feb 23  Isla Hussain     (348)  Balearic Sea       </emphasis>
++                 |
++                 |
++                 |
++                 |
++                 |
++                 |
++</screen>
++	</sect3>
++	<sect3 id="intro-sidebar-features">
++		<title>Features</title>
++		<para>
++			The Sidebar shows a list of mailboxes in a panel.
++		<para>
++		</para>
++			Everything about the Sidebar can be configured.
++		</para>
++		<itemizedlist>
++		<title><link linkend="intro-sidebar-basics">State of the Sidebar</link></title>
++			<listitem><para>Visibility</para></listitem>
++			<listitem><para>Width</para></listitem>
++		</itemizedlist>
++		<itemizedlist>
++		<title><link linkend="intro-sidebar-limit">Which mailboxes are displayed</link></title>
++			<listitem><para>Display all</para></listitem>
++			<listitem><para>Limit to mailboxes with new mail</para></listitem>
++			<listitem><para>Whitelist mailboxes to display always</para></listitem>
++		</itemizedlist>
++		<itemizedlist>
++		<title><link linkend="sidebar-sort">The order in which mailboxes are displayed</link></title>
++		<title></title>
++			<listitem><para>Unsorted (order of mailboxes commands)</para></listitem>
++			<listitem><para>Sorted alphabetically</para></listitem>
++			<listitem><para>Sorted by number of new mails</para></listitem>
++		</itemizedlist>
++		<itemizedlist>
++		<title><link linkend="intro-sidebar-colors">Color</link></title>
++			<listitem><para>Sidebar indicators and divider</para></listitem>
++			<listitem><para>Mailboxes depending on their type</para></listitem>
++			<listitem><para>Mailboxes depending on their contents</para></listitem>
++		</itemizedlist>
++		<itemizedlist>
++		<title><link linkend="sidebar-functions">Key bindings</link></title>
++			<listitem><para>Hide/Unhide the Sidebar</para></listitem>
++			<listitem><para>Select previous/next mailbox</para></listitem>
++			<listitem><para>Select previous/next mailbox with new mail</para></listitem>
++			<listitem><para>Page up/down through a list of mailboxes</para></listitem>
++		</itemizedlist>
++		<itemizedlist>
++		<title>Misc</title>
++			<listitem><para><link linkend="intro-sidebar-format">Formatting string for mailbox</link></para></listitem>
++			<listitem><para><link linkend="sidebar-next-new-wrap">Wraparound searching</link></para></listitem>
++			<listitem><para><link linkend="intro-sidebar-abbrev">Flexible mailbox abbreviations</link></para></listitem>
++			<listitem><para>Support for Unicode mailbox names (utf-8)</para></listitem>
++		</itemizedlist>
++	</sect3>
++	<sect3 id="intro-sidebar-display">
++		<title>Display</title>
++		<para>
++			Everything about the Sidebar can be configured.
++		</para>
++		<itemizedlist>
++			<title>For a quick reference:</title>
++			<listitem><para><link linkend="sidebar-variables">Sidebar variables to set</link> </para></listitem>
++			<listitem><para><link linkend="sidebar-colors">Sidebar colors to apply</link></para></listitem>
++			<listitem><para><link linkend="sidebar-sort">Sidebar sort methods</link></para></listitem>
++		</itemizedlist>
++		<sect4 id="intro-sidebar-basics">
++			<title>Sidebar Basics</title>
++			<para>
++				The most important variable is <literal>$sidebar_visible</literal>.
++				You can set this in your <quote>muttrc</quote>, or bind a key to the
++				function <literal>&lt;sidebar-toggle-visible&gt;</literal>.
++			</para>
++<screen>
++set sidebar_visible                         <emphasis role="comment"># Make the Sidebar visible by default</emphasis>
++bind index,pager B sidebar-toggle-visible   <emphasis role="comment"># Use 'B' to switch the Sidebar on and off</emphasis>
++</screen>
++			<para>
++				Next, decide how wide you want the Sidebar to be.  25
++				characters might be enough for the mailbox name and some numbers.
++		Remember, you can hide/show the Sidebar at the press of button.
++		</para>
++		<para>
++		Finally, you might want to change the divider character.
++		By default, Sidebar draws an ASCII line between it and the Index panel
++				If your terminal supports it, you can use a Unicode line-drawing character.
++			</para>
++<screen>
++set sidebar_width = 25                  <emphasis role="comment"># Plenty of space</emphasis>
++set sidebar_divider_char = '│'          <emphasis role="comment"># Pretty line-drawing character</emphasis>
++</screen>
++		</sect4>
++		<sect4 id="intro-sidebar-format">
++			<title>Sidebar Format String</title>
++			<para>
++				<literal>$sidebar_format</literal> allows you to customize the Sidebar display.
++				For an introduction, read <link linkend="index-format">format strings</link>
++				including the section about <link linkend="formatstrings-conditionals">conditionals</link>.
++			</para>
++			<para>
++				The default value is <literal>%B%?F? [%F]?%* %?N?%N/?%S</literal>
++			</para>
++			<itemizedlist>
++				<title>Which breaks down as:</title>
++				<listitem><para><literal>%B</literal> - Mailbox name</para></listitem>
++				<listitem><para><literal>%?F? [%F]?</literal> - If flagged emails <literal>[%F]</literal>, otherwise nothing</para></listitem>
++				<listitem><para><literal>%* </literal> - Pad with spaces</para></listitem>
++				<listitem><para><literal>%?N?%N/?</literal> - If new emails <literal>%N/</literal>, otherwise nothing</para></listitem>
++				<listitem><para><literal>%S</literal> - Total number of emails</para></listitem>
++			</itemizedlist>
++			<table>
++				<title>sidebar_format</title>
++				<tgroup cols="3">
++					<thead>
++						<row>
++							<entry>Format</entry>
++							<entry>Notes</entry>
++							<entry>Description</entry>
++						</row>
++					</thead>
++					<tbody>
++						<row>
++							<entry>%B</entry>
++							<entry></entry>
++							<entry>Name of the mailbox</entry>
++						</row>
++						<row>
++							<entry>%S</entry>
++							<entry>*</entry>
++							<entry>Size of mailbox (total number of messages)</entry>
++						</row>
++						<row>
++							<entry>%N</entry>
++							<entry>*</entry>
++							<entry>Number of New messages in the mailbox</entry>
++						</row>
++						<row>
++							<entry>%F</entry>
++							<entry>*</entry>
++							<entry>Number of Flagged messages in the mailbox</entry>
++						</row>
++						<row>
++							<entry>%!</entry>
++							<entry></entry>
++							<entry>
++								<quote>!</quote>: one flagged message;
++								<quote>!!</quote>: two flagged messages;
++								<quote>n!</quote>: n flagged messages (for n &gt; 2).
++								Otherwise prints nothing.
++							</entry>
++						</row>
++						<row>
++							<entry>%d</entry>
++							<entry>* ‡</entry>
++							<entry>Number of deleted messages</entry>
++						</row>
++						<row>
++							<entry>%L</entry>
++							<entry>* ‡</entry>
++							<entry>Number of messages after limiting</entry>
++						</row>
++						<row>
++							<entry>%t</entry>
++							<entry>* ‡</entry>
++							<entry>Number of tagged messages</entry>
++						</row>
++						<row>
++							<entry>%&gt;X</entry>
++							<entry></entry>
++							<entry>Right justify the rest of the string and pad with <quote>X</quote></entry>
++						</row>
++						<row>
++							<entry>%|X</entry>
++							<entry></entry>
++							<entry>Pad to the end of the line with
++							<quote>X</quote></entry>
++						</row>
++						<row>
++							<entry>%*X</entry>
++							<entry></entry>
++							<entry>Soft-fill with character <quote>X</quote>as pad</entry>
++						</row>
++					</tbody>
++				</tgroup>
++			</table>
++			<para>
++			* = Can be optionally printed if nonzero
++			</para>
++			<para>
++			‡ = Only applicable to the current folder
++			</para>
++			<para>
++				Here are some examples.
++				They show the number of (F)lagged, (N)ew and (S)ize.
++			</para>
++			<table>
++				<title>sidebar_format</title>
++				<tgroup cols="2">
++					<thead>
++						<row>
++							<entry>Format</entry>
++							<entry>Example</entry>
++						</row>
++					</thead>
++					<tbody>
++						<row>
++							<entry><literal>%B%?F? [%F]?%* %?N?%N/?%S</literal></entry>
++							<entry><screen>mailbox [F]            N/S</screen></entry>
++						</row>
++						<row>
++							<entry><literal>%B%* %F:%N:%S</literal></entry>
++							<entry><screen>mailbox              F:N:S</screen></entry>
++						</row>
++						<row>
++							<entry><literal>%B %?N?(%N)?%* %S</literal></entry>
++							<entry><screen>mailbox (N)              S</screen></entry>
++						</row>
++						<row>
++							<entry><literal>%B%* ?F?%F/?%N</literal></entry>
++							<entry><screen>mailbox                F/S</screen></entry>
++						</row>
++					</tbody>
++				</tgroup>
++			</table>
++		</sect4>
++		<sect4 id="intro-sidebar-abbrev">
++			<title>Abbreviating Mailbox Names</title>
++			<para>
++				<literal>$sidebar_delim_chars</literal> tells Sidebar
++				how to split up mailbox paths.  For local directories
++				use <quote>/</quote>; for IMAP folders use <quote>.</quote>
++			</para>
++			<sect5 id="intro-sidebar-abbrev-ex1">
++				<title>Example 1</title>
++				<para>
++					This example works well if your mailboxes have unique names
++					after the last separator.
++				</para>
++				<para>
++					Add some mailboxes of diffent depths.
++				</para>
++<screen>
++set folder="~/mail"
++mailboxes =fruit/apple          =fruit/banana          =fruit/cherry
++mailboxes =water/sea/sicily     =water/sea/archipelago =water/sea/sibuyan
++mailboxes =water/ocean/atlantic =water/ocean/pacific   =water/ocean/arctic
++</screen>
++				<para>
++					Shorten the names:
++				</para>
++<screen>
++set sidebar_short_path                  <emphasis role="comment"># Shorten mailbox names</emphasis>
++set sidebar_delim_chars="/"             <emphasis role="comment"># Delete everything up to the last / character</emphasis>
++</screen>
++				<para>
++					The screenshot below shows what the Sidebar would look like
++					before and after shortening.
++				</para>
++<screen>
++|fruit/apple                            |apple
++|fruit/banana                           |banana
++|fruit/cherry                           |cherry
++|water/sea/sicily                       |sicily
++|water/sea/archipelago                  |archipelago
++|water/sea/sibuyan                      |sibuyan
++|water/ocean/atlantic                   |atlantic
++|water/ocean/pacific                    |pacific
++|water/ocean/arctic                     |arctic
++</screen>
++			</sect5>
++			<sect5 id="intro-sidebar-abbrev-ex2">
++				<title>Example 2</title>
++				<para>
++					This example works well if you have lots of mailboxes which are arranged
++					in a tree.
++				</para>
++				<para>
++					Add some mailboxes of diffent depths.
++				</para>
++<screen>
++set folder="~/mail"
++mailboxes =fruit
++mailboxes =fruit/apple =fruit/banana =fruit/cherry
++mailboxes =water
++mailboxes =water/sea
++mailboxes =water/sea/sicily =water/sea/archipelago =water/sea/sibuyan
++mailboxes =water/ocean
++mailboxes =water/ocean/atlantic =water/ocean/pacific =water/ocean/arctic
++</screen>
++				<para>
++					Shorten the names:
++				</para>
++<screen>
++set sidebar_short_path                  <emphasis role="comment"># Shorten mailbox names</emphasis>
++set sidebar_delim_chars="/"             <emphasis role="comment"># Delete everything up to the last / character</emphasis>
++set sidebar_folder_indent               <emphasis role="comment"># Indent folders whose names we've shortened</emphasis>
++set sidebar_indent_string="  "          <emphasis role="comment"># Indent with two spaces</emphasis>
++</screen>
++				<para>
++					The screenshot below shows what the Sidebar would look like
++					before and after shortening.
++				</para>
++<screen>
++|fruit                                  |fruit
++|fruit/apple                            |  apple
++|fruit/banana                           |  banana
++|fruit/cherry                           |  cherry
++|water                                  |water
++|water/sea                              |  sea
++|water/sea/sicily                       |    sicily
++|water/sea/archipelago                  |    archipelago
++|water/sea/sibuyan                      |    sibuyan
++|water/ocean                            |  ocean
++|water/ocean/atlantic                   |    atlantic
++|water/ocean/pacific                    |    pacific
++|water/ocean/arctic                     |    arctic
++</screen>
++				<para>
++					Sometimes, it will be necessary to add mailboxes, that you
++					don't use, to fill in part of the tree.	 This will trade
++					vertical space for horizonal space (but it looks good).
++				</para>
++			</sect5>
++		</sect4>
++		<sect4 id="intro-sidebar-limit">
++			<title>Limiting the Number of Mailboxes</title>
++			<para>
++				If you have a lot of mailboxes, sometimes it can be useful to hide
++				the ones you aren't using.	<literal>$sidebar_new_mail_only</literal>
++				tells Sidebar to only show mailboxes that contain new, or flagged, email.
++			</para>
++			<para>
++				If you want some mailboxes to be always visible, then use the
++				<literal>sidebar_whitelist</literal> command.  It takes a list of
++				mailboxes as parameters.
++			</para>
++<screen>
++set sidebar_new_mail_only               <emphasis role="comment"># Only mailboxes with new/flagged email</emphasis>
++sidebar_whitelist fruit fruit/apple     <emphasis role="comment"># Always display these two mailboxes</emphasis>
++</screen>
++		</sect4>
++	</sect3>
++	<sect3 id="intro-sidebar-colors">
++		<title>Colors</title>
++		<para>
++			Here is a sample color scheme:
++		</para>
++<screen>
++color sidebar_indicator default color17         <emphasis role="comment"># Dark blue background</emphasis>
++color sidebar_highlight white   color238        <emphasis role="comment"># Grey background</emphasis>
++color sidebar_spoolfile yellow  default         <emphasis role="comment"># Yellow</emphasis>
++color sidebar_new       green   default         <emphasis role="comment"># Green</emphasis>
++color sidebar_flagged   red     default         <emphasis role="comment"># Red</emphasis>
++color sidebar_divider   color8  default         <emphasis role="comment"># Dark grey</emphasis>
++</screen>
++		<para>
++			There is a priority order when coloring Sidebar mailboxes.
++			e.g.  If a mailbox has new mail it will have the
++			<literal>sidebar_new</literal> color, even if it also contains
++			flagged mails.
++		</para>
++		<table id="table-intro-sidebar-colors">
++			<title>Sidebar Color Priority</title>
++			<tgroup cols="3">
++				<thead>
++					<row>
++						<entry>Priority</entry>
++						<entry>Color</entry>
++						<entry>Description</entry>
++					</row>
++				</thead>
++				<tbody>
++					<row>
++						<entry>Highest</entry>
++						<entry><literal>sidebar_indicator</literal></entry>
++						<entry>Mailbox is open</entry>
++					</row>
++					<row>
++						<entry></entry>
++						<entry><literal>sidebar_highlight</literal></entry>
++						<entry>Mailbox is highlighed</entry>
++					</row>
++					<row>
++						<entry></entry>
++						<entry><literal>sidebar_spoolfile</literal></entry>
++						<entry>Mailbox is the spoolfile (receives incoming mail)</entry>
++					</row>
++					<row>
++						<entry></entry>
++						<entry><literal>sidebar_new</literal></entry>
++						<entry>Mailbox contains new mail</entry>
++					</row>
++					<row>
++						<entry></entry>
++						<entry><literal>sidebar_flagged</literal></entry>
++						<entry>Mailbox contains flagged mail</entry>
++					</row>
++					<row>
++						<entry>Lowest</entry>
++						<entry>(None)</entry>
++						<entry>Mailbox does not match above</entry>
++					</row>
++				</tbody>
++			</tgroup>
++		</table>
++	</sect3>
++	<sect3 id="intro-sidebar-bugfixes">
++		<title>Bug-fixes</title>
++		<para>
++			If you haven't used Sidebar before, you can ignore this section.
++		</para>
++		<para>
++			These bugs have been fixed since the previous Sidebar release: 2015-11-11.
++		</para>
++		<itemizedlist>
++			<listitem><para>Fix bug when starting in compose mode</para></listitem>
++			<listitem><para>Fix bug with empty sidebar_divider_char string</para></listitem>
++			<listitem><para>Fix bug with header wrapping</para></listitem>
++			<listitem><para>Correctly handle utf8 character sequences</para></listitem>
++			<listitem><para>Fix a bug in mh_buffy_update</para></listitem>
++			<listitem><para>Fix refresh -- time overflowed short</para></listitem>
++			<listitem><para>Protect against empty format strings</para></listitem>
++			<listitem><para>Limit Sidebar width to COLS</para></listitem>
++			<listitem><para>Handle unmailboxes * safely</para></listitem>
++			<listitem><para>Refresh Sidebar after timeout</para></listitem>
++		</itemizedlist>
++	</sect3>
++	<sect3 id="intro-sidebar-config-changes">
++		<title>Config Changes</title>
++		<para>
++			If you haven't used Sidebar before, you can ignore this section.
++		</para>
++		<para>
++			Some of the Sidebar config has been changed to make its meaning clearer.
++			These changes have been made since the previous Sidebar release: 2015-11-11.
++		</para>
++		<table id="table-intro-sidebar-config-changes">
++			<title>Config Changes</title>
++			<tgroup cols="2">
++				<thead>
++					<row>
++						<entry>Old Name</entry>
++						<entry>New Name</entry>
++					</row>
++				</thead>
++				<tbody>
++					<row>
++						<entry><literal>$sidebar_delim</literal></entry>
++						<entry><literal>$sidebar_divider_char</literal></entry>
++					</row>
++					<row>
++						<entry><literal>$sidebar_folderindent</literal></entry>
++						<entry><literal>$sidebar_folder_indent</literal></entry>
++					</row>
++					<row>
++						<entry><literal>$sidebar_indentstr</literal></entry>
++						<entry><literal>$sidebar_indent_string</literal></entry>
++					</row>
++					<row>
++						<entry><literal>$sidebar_newmail_only</literal></entry>
++						<entry><literal>$sidebar_new_mail_only</literal></entry>
++					</row>
++					<row>
++						<entry><literal>$sidebar_refresh</literal></entry>
++						<entry><literal>$sidebar_refresh_time</literal></entry>
++					</row>
++					<row>
++						<entry><literal>$sidebar_shortpath</literal></entry>
++						<entry><literal>$sidebar_short_path</literal></entry>
++					</row>
++					<row>
++						<entry><literal>$sidebar_sort</literal></entry>
++						<entry><literal>$sidebar_sort_method</literal></entry>
++					</row>
++					<row>
++						<entry><literal>&lt;sidebar-scroll-down&gt;</literal></entry>
++						<entry><literal>&lt;sidebar-page-down&gt;</literal></entry>
++					</row>
++					<row>
++						<entry><literal>&lt;sidebar-scroll-up&gt;</literal></entry>
++						<entry><literal>&lt;sidebar-page-up&gt;</literal></entry>
++					</row>
++				</tbody>
++			</tgroup>
++		</table>
++	</sect3>
++</sect2>
++
+ <sect2 id="intro-help">
+ <title>Help</title>
+ 
+@@ -6773,6 +7390,17 @@
+ </para>
+ 
+ <para>
++Mutt will set the <literal>COLUMNS</literal> environment variable to
++the width of the pager.  Some programs make use of this environment
++variable automatically.  Others provide a command line argument that
++can use this to set the output width:
++</para>
++
++<screen>
++text/html; lynx -dump -width ${COLUMNS:-80} %s; copiousoutput
++</screen>
++
++<para>
+ Note that when using the built-in pager, <emphasis>only</emphasis>
+ entries with this flag will be considered a handler for a MIME type
+ &mdash; all other entries will be ignored.
+@@ -7467,6 +8095,16 @@
+ 
+ </sect2>
+ 
++<sect2 id="mutt-patches">
++<title>Mutt Patches</title>
++<para>
++Mutt may also be <quote>patched</quote> to support smaller features.
++These patches should add a free-form string to the end Mutt's version string.
++Running <literal>mutt -v</literal> might show:
++<screen>patch-1.6.1.sidebar.20160502</screen>
++</para>
++</sect2>
++
+ <sect2 id="url-syntax">
+ <title>URL Syntax</title>
+ 
+@@ -8081,6 +8719,469 @@
+ 
+ </sect1>
+ 
++<sect1 id="sidebar">
++	<title>Sidebar Patch</title>
++	<subtitle>Overview of mailboxes</subtitle>
++
++	<sect2 id="sidebar-patch">
++		<title>Patch</title>
++
++		<para>
++			To check if Mutt supports <quote>Sidebar</quote>, look for
++			<quote>+USE_SIDEBAR</quote> in the mutt version.
++			See: <xref linkend="compile-time-features"/>.
++		</para>
++
++		<itemizedlist>
++			<title>Dependencies:</title>
++			<listitem><para>mutt-1.6.1</para></listitem>
++		</itemizedlist>
++
++		<para>This patch is part of the <ulink url="http://www.neomutt.org/">NeoMutt Project</ulink>.</para>
++	</sect2>
++
++	<sect2 id="sidebar-intro">
++		<title>Introduction</title>
++
++		<para>
++			The Sidebar shows a list of all your mailboxes.  The list can be
++			turned on and off, it can be themed and the list style can be
++			configured.
++		</para>
++
++		<para>
++			This part of the manual is a reference guide.
++			If you want a simple introduction with examples see the
++			<link linkend="intro-sidebar">Sidebar Howto</link>.
++			If you just want to get started, you could use the sample
++			<link linkend="sidebar-muttrc">Sidebar muttrc</link>.
++		</para>
++
++		<para>
++			This version of Sidebar is based on Terry Chan's
++			<ulink url="http://www.lunar-linux.org/mutt-sidebar/">2015-11-11 release</ulink>.
++			It contains many
++			<emphasis role="bold"><link linkend="intro-sidebar-features">new features</link></emphasis>,
++			lots of
++			<emphasis role="bold"><link linkend="intro-sidebar-bugfixes">bugfixes</link></emphasis>.
++		</para>
++	</sect2>
++
++	<sect2 id="sidebar-variables">
++		<title>Variables</title>
++
++		<table id="table-sidebar-variables">
++			<title>Sidebar Variables</title>
++			<tgroup cols="3">
++				<thead>
++					<row>
++						<entry>Name</entry>
++						<entry>Type</entry>
++						<entry>Default</entry>
++					</row>
++				</thead>
++				<tbody>
++					<row>
++						<entry><literal>sidebar_delim_chars</literal></entry>
++						<entry>string</entry>
++						<entry><literal>/.</literal></entry>
++					</row>
++					<row>
++						<entry><literal>sidebar_divider_char</literal></entry>
++						<entry>string</entry>
++						<entry><literal>|</literal></entry>
++					</row>
++					<row>
++						<entry><literal>sidebar_folder_indent</literal></entry>
++						<entry>boolean</entry>
++						<entry><literal>no</literal></entry>
++					</row>
++					<row>
++						<entry><literal>sidebar_format</literal></entry>
++						<entry>string</entry>
++						<entry><literal>%B%?F? [%F]?%* %?N?%N/?%S</literal></entry>
++					</row>
++					<row>
++						<entry><literal>sidebar_indent_string</literal></entry>
++						<entry>string</entry>
++						<entry><literal>&nbsp;&nbsp;</literal> (two spaces)</entry>
++					</row>
++					<row>
++						<entry><literal>sidebar_new_mail_only</literal></entry>
++						<entry>boolean</entry>
++						<entry><literal>no</literal></entry>
++					</row>
++					<row>
++						<entry><literal>sidebar_next_new_wrap</literal></entry>
++						<entry>boolean</entry>
++						<entry><literal>no</literal></entry>
++					</row>
++					<row>
++						<entry><literal>sidebar_refresh_time</literal></entry>
++						<entry>number</entry>
++						<entry><literal>60</literal></entry>
++					</row>
++					<row>
++						<entry><literal>sidebar_short_path</literal></entry>
++						<entry>boolean</entry>
++						<entry><literal>no</literal></entry>
++					</row>
++					<row>
++						<entry><literal>sidebar_sort_method</literal></entry>
++						<entry>enum</entry>
++						<entry><literal>SORT_ORDER</literal></entry>
++					</row>
++					<row>
++						<entry><literal>sidebar_visible</literal></entry>
++						<entry>boolean</entry>
++						<entry><literal>no</literal></entry>
++					</row>
++					<row>
++						<entry><literal>sidebar_whitelist</literal></entry>
++						<entry>list</entry>
++						<entry>(empty)</entry>
++					</row>
++					<row>
++						<entry><literal>sidebar_width</literal></entry>
++						<entry>number</entry>
++						<entry><literal>20</literal></entry>
++					</row>
++				</tbody>
++			</tgroup>
++		</table>
++	</sect2>
++
++	<sect2 id="sidebar-functions">
++		<title>Functions</title>
++
++		<para>
++			Sidebar adds the following functions to Mutt.
++			By default, none of them are bound to keys.
++		</para>
++
++		<table id="table-sidebar-functions">
++			<title>Sidebar Functions</title>
++			<tgroup cols="3">
++				<thead>
++					<row>
++						<entry>Menus</entry>
++						<entry>Function</entry>
++						<entry>Description</entry>
++					</row>
++				</thead>
++				<tbody>
++					<row>
++						<entry>index,pager</entry>
++						<entry><literal>&lt;sidebar-next&gt;</literal></entry>
++						<entry>Move the highlight to next mailbox</entry>
++					</row>
++					<row>
++						<entry>index,pager</entry>
++						<entry><literal>&lt;sidebar-next-new&gt;</literal></entry>
++						<entry>Move the highlight to next mailbox with new mail</entry>
++					</row>
++					<row>
++						<entry>index,pager</entry>
++						<entry><literal>&lt;sidebar-open&gt;</literal></entry>
++						<entry>Open highlighted mailbox</entry>
++					</row>
++					<row>
++						<entry>index,pager</entry>
++						<entry><literal>&lt;sidebar-page-down&gt;</literal></entry>
++						<entry>Scroll the Sidebar down 1 page</entry>
++					</row>
++					<row>
++						<entry>index,pager</entry>
++						<entry><literal>&lt;sidebar-page-up&gt;</literal></entry>
++						<entry>Scroll the Sidebar up 1 page</entry>
++					</row>
++					<row>
++						<entry>index,pager</entry>
++						<entry><literal>&lt;sidebar-prev&gt;</literal></entry>
++						<entry>Move the highlight to previous mailbox</entry>
++					</row>
++					<row>
++						<entry>index,pager</entry>
++						<entry><literal>&lt;sidebar-prev-new&gt;</literal></entry>
++						<entry>Move the highlight to previous mailbox with new mail</entry>
++					</row>
++					<row>
++						<entry>index,pager</entry>
++						<entry><literal>&lt;sidebar-toggle-visible&gt;</literal></entry>
++						<entry>Make the Sidebar (in)visible</entry>
++					</row>
++				</tbody>
++			</tgroup>
++		</table>
++	</sect2>
++
++	<sect2 id="sidebar-commands">
++		<title>Commands</title>
++		<cmdsynopsis>
++			<command>sidebar_whitelist</command>
++			<arg choice="plain">
++				<replaceable class="parameter">mailbox</replaceable>
++			</arg>
++			<arg choice="opt" rep="repeat">
++				<replaceable class="parameter">mailbox</replaceable>
++			</arg>
++		</cmdsynopsis>
++	</sect2>
++
++	<sect2 id="sidebar-colors">
++		<title>Colors</title>
++
++		<table id="table-sidebar-colors">
++			<title>Sidebar Colors</title>
++			<tgroup cols="3">
++				<thead>
++					<row>
++						<entry>Name</entry>
++						<entry>Default Color</entry>
++						<entry>Description</entry>
++					</row>
++				</thead>
++				<tbody>
++					<row>
++						<entry><literal>sidebar_divider</literal></entry>
++						<entry>default</entry>
++						<entry>The dividing line between the Sidebar and the Index/Pager panels</entry>
++					</row>
++					<row>
++						<entry><literal>sidebar_flagged</literal></entry>
++						<entry>default</entry>
++						<entry>Mailboxes containing flagged mail</entry>
++					</row>
++					<row>
++						<entry><literal>sidebar_highlight</literal></entry>
++						<entry>underline</entry>
++						<entry>Cursor to select a mailbox</entry>
++					</row>
++					<row>
++						<entry><literal>sidebar_indicator</literal></entry>
++						<entry>mutt <literal>indicator</literal></entry>
++						<entry>The mailbox open in the Index panel</entry>
++					</row>
++					<row>
++						<entry><literal>sidebar_new</literal></entry>
++						<entry>default</entry>
++						<entry>Mailboxes containing new mail</entry>
++					</row>
++					<row>
++						<entry><literal>sidebar_spoolfile</literal></entry>
++						<entry>default</entry>
++						<entry>Mailbox that receives incoming mail</entry>
++					</row>
++				</tbody>
++			</tgroup>
++		</table>
++
++		If the <literal>sidebar_indicator</literal> color isn't set, then the default Mutt
++		indicator color will be used (the color used in the index panel).
++	</sect2>
++
++	<sect2 id="sidebar-sort">
++		<title>Sort</title>
++
++		<table id="table-sidebar-sort">
++			<title>Sidebar Sort</title>
++			<tgroup cols="2">
++				<thead>
++					<row>
++						<entry>Sort</entry>
++						<entry>Description</entry>
++					</row>
++				</thead>
++				<tbody>
++					<row>
++						<entry><literal>alpha</literal></entry>
++						<entry>Alphabetically by path</entry>
++					</row>
++					<row>
++						<entry><literal>count</literal></entry>
++						<entry>Total number of messages</entry>
++					</row>
++					<row>
++						<entry><literal>flagged</literal></entry>
++						<entry>Number of flagged messages</entry>
++					</row>
++					<row>
++						<entry><literal>name</literal></entry>
++						<entry>Alphabetically by path</entry>
++					</row>
++					<row>
++						<entry><literal>new</literal></entry>
++						<entry>Number of new messages</entry>
++					</row>
++					<row>
++						<entry><literal>path</literal></entry>
++						<entry>Alphabetically by path</entry>
++					</row>
++					<row>
++						<entry><literal>unsorted</literal></entry>
++						<entry>Do not resort the paths</entry>
++					</row>
++				</tbody>
++			</tgroup>
++		</table>
++	</sect2>
++
++	<sect2 id="sidebar-muttrc">
++		<title>Muttrc</title>
++<screen>
++<emphasis role="comment"># This is a complete list of sidebar-related configuration.
++ 
++# --------------------------------------------------------------------------
++# VARIABLES - shown with their default values
++# --------------------------------------------------------------------------
++ 
++# Should the Sidebar be shown?</emphasis>
++set sidebar_visible = no
++ 
++<emphasis role="comment"># How wide should the Sidebar be in screen columns?
++# Note: Some characters, e.g. Chinese, take up two columns each.</emphasis>
++set sidebar_width = 20
++ 
++<emphasis role="comment"># Should the mailbox paths be abbreviated?</emphasis>
++set sidebar_short_path = no
++ 
++<emphasis role="comment"># When abbreviating mailbox path names, use any of these characters as path
++# separators.  Only the part after the last separators will be shown.
++# For file folders '/' is good.  For IMAP folders, often '.' is useful.</emphasis>
++set sidebar_delim_chars = '/.'
++ 
++<emphasis role="comment"># If the mailbox path is abbreviated, should it be indented?</emphasis>
++set sidebar_folder_indent = no
++ 
++<emphasis role="comment"># Indent mailbox paths with this string.</emphasis>
++set sidebar_indent_string = '  '
++ 
++<emphasis role="comment"># Make the Sidebar only display mailboxes that contain new, or flagged,
++# mail.</emphasis>
++set sidebar_new_mail_only = no
++ 
++<emphasis role="comment"># Any mailboxes that are whitelisted will always be visible, even if the
++# sidebar_new_mail_only option is enabled.</emphasis>
++sidebar_whitelist '/home/user/mailbox1'
++sidebar_whitelist '/home/user/mailbox2'
++ 
++<emphasis role="comment"># When searching for mailboxes containing new mail, should the search wrap
++# around when it reaches the end of the list?</emphasis>
++set sidebar_next_new_wrap = no
++ 
++<emphasis role="comment"># The character to use as the divider between the Sidebar and the other Mutt
++# panels.
++# Note: Only the first character of this string is used.</emphasis>
++set sidebar_divider_char = '|'
++ 
++<emphasis role="comment"># Display the Sidebar mailboxes using this format string.</emphasis>
++set sidebar_format = '%B%?F? [%F]?%* %?N?%N/?%S'
++ 
++<emphasis role="comment"># Sidebar will not refresh its list of mailboxes any more frequently than
++# this number of seconds.  This will help reduce disk/network traffic.</emphasis>
++set sidebar_refresh_time = 60
++ 
++<emphasis role="comment"># Sort the mailboxes in the Sidebar using this method:
++#       count    - total number of messages
++#       flagged  - number of flagged messages
++#       new      - number of new messages
++#       path     - mailbox path
++#       unsorted - do not sort the mailboxes</emphasis>
++set sidebar_sort_method = 'unsorted'
++ 
++<emphasis role="comment"># --------------------------------------------------------------------------
++# FUNCTIONS - shown with an example mapping
++# --------------------------------------------------------------------------
++ 
++# Move the highlight to the previous mailbox</emphasis>
++bind index,pager \Cp sidebar-prev
++ 
++<emphasis role="comment"># Move the highlight to the next mailbox</emphasis>
++bind index,pager \Cn sidebar-next
++ 
++<emphasis role="comment"># Open the highlighted mailbox</emphasis>
++bind index,pager \Co sidebar-open
++ 
++<emphasis role="comment"># Move the highlight to the previous page
++# This is useful if you have a LOT of mailboxes.</emphasis>
++bind index,pager &lt;F3&gt; sidebar-page-up
++ 
++<emphasis role="comment"># Move the highlight to the next page
++# This is useful if you have a LOT of mailboxes.</emphasis>
++bind index,pager &lt;F4&gt; sidebar-page-down
++ 
++<emphasis role="comment"># Move the highlight to the previous mailbox containing new, or flagged,
++# mail.</emphasis>
++bind index,pager &lt;F5&gt; sidebar-prev-new
++ 
++<emphasis role="comment"># Move the highlight to the next mailbox containing new, or flagged, mail.</emphasis>
++bind index,pager &lt;F6&gt; sidebar-next-new
++ 
++<emphasis role="comment"># Toggle the visibility of the Sidebar.</emphasis>
++bind index,pager B sidebar-toggle-visible
++ 
++<emphasis role="comment"># --------------------------------------------------------------------------
++# COLORS - some unpleasant examples are given
++# --------------------------------------------------------------------------
++# Note: All color operations are of the form:
++#       color OBJECT FOREGROUND BACKGROUND
++ 
++# Color of the current, open, mailbox
++# Note: This is a general Mutt option which colors all selected items.</emphasis>
++color indicator cyan black
++ 
++<emphasis role="comment"># Color of the highlighted, but not open, mailbox.</emphasis>
++color sidebar_highlight black color8
++ 
++<emphasis role="comment"># Color of the divider separating the Sidebar from Mutt panels</emphasis>
++color sidebar_divider color8 black
++ 
++<emphasis role="comment"># Color to give mailboxes containing flagged mail</emphasis>
++color sidebar_flagged red black
++ 
++<emphasis role="comment"># Color to give mailboxes containing new mail</emphasis>
++color sidebar_new green black
++ 
++<emphasis role="comment"># --------------------------------------------------------------------------
++ 
++# vim: syntax=muttrc</emphasis>
++</screen>
++	</sect2>
++
++	<sect2 id="sidebar-see-also">
++		<title>See Also</title>
++
++		<itemizedlist>
++			<listitem><para><link linkend="regexp">Regular Expressions</link></para></listitem>
++			<listitem><para><link linkend="patterns">Patterns</link></para></listitem>
++			<listitem><para><link linkend="color">Color command</link></para></listitem>
++			<listitem><para><link linkend="notmuch">notmuch patch</link></para></listitem>
++		</itemizedlist>
++	</sect2>
++
++	<sect2 id="sidebar-known-bugs">
++		<title>Known Bugs</title>
++		Unsorted isn't
++	</sect2>
++
++	<sect2 id="sidebar-credits">
++		<title>Credits</title>
++		<itemizedlist>
++		<listitem><para>Justin Hibbits <email>jrh29@po.cwru.edu</email></para></listitem>
++		<listitem><para>Thomer M. Gil <email>mutt@thomer.com</email></para></listitem>
++		<listitem><para>David Sterba <email>dsterba@suse.cz</email></para></listitem>
++		<listitem><para>Evgeni Golov <email>evgeni@debian.org</email></para></listitem>
++		<listitem><para>Fabian Groffen <email>grobian@gentoo.org</email></para></listitem>
++		<listitem><para>Jason DeTiberus <email>jdetiber@redhat.com</email></para></listitem>
++		<listitem><para>Stefan Assmann <email>sassmann@kpanic.de</email></para></listitem>
++		<listitem><para>Steve Kemp <email>steve@steve.org.uk</email></para></listitem>
++		<listitem><para>Terry Chan <email>tchan@lunar-linux.org</email></para></listitem>
++		<listitem><para>Tyler Earnest <email>tylere@rne.st</email></para></listitem>
++		<listitem><para>Richard Russon <email>rich@flatcap.org</email></para></listitem>
++		</itemizedlist>
++	</sect2>
++</sect1>
++
+ </chapter>
+ 
+ <chapter id="security">
+@@ -9237,6 +10338,17 @@
+ 
+ <listitem>
+ <cmdsynopsis>
++<command><link linkend="sidebar-whitelist">sidebar_whitelist</link></command>
++<arg choice="plain">
++<replaceable class="parameter">item</replaceable>
++</arg>
++<arg choice="plain">
++<replaceable class="parameter">command</replaceable>
++</arg>
++</cmdsynopsis>
++</listitem>
++<listitem>
++<cmdsynopsis>
+ <command><link linkend="source">source</link></command>
+ <arg choice="plain">
+ <replaceable class="parameter">filename</replaceable>
+diff -urN mutt-1.6.1/doc/mutt.css mutt-1.6.1-sidebar/doc/mutt.css
+--- mutt-1.6.1/doc/mutt.css	2016-06-12 18:43:00.402447590 +0100
++++ mutt-1.6.1-sidebar/doc/mutt.css	2016-06-12 18:43:03.811500752 +0100
+@@ -9,17 +9,24 @@
+ div.table-contents table th, div.informaltable table th {
+     font-family:sans-serif;
+     background:#d0d0d0;
+-    font-weight:normal;
++    font-weight:bold;
+     vertical-align:top;
+ }
+-div.cmdsynopsis { border-left:1px solid #707070; padding-left:5px; }
++div.cmdsynopsis { border-left:1px solid #707070; padding-left: 1em; }
+ li div.cmdsynopsis { border-left:none; padding-left:0px; }
+-pre.screen, div.note { background:#f0f0f0; border:1px solid #c0c0c0; padding:5px; margin-left:2%; margin-right:2%; }
++li p { margin: 0; }
++pre.screen, div.note { border:1px solid #c0c0c0; margin-left:2%; margin-right:2%; }
++pre.screen { color: #ffffff; background:#000000; padding: 0.5em; }
++div.note { background:#ffff80; padding: 0.5em; }
+ div.example p.title { margin-left:2%; }
+ div.note h3 { font-size:small; font-style:italic; font-variant: small-caps; }
+ div.note h3:after { content: ":" }
+ div.note { margin-bottom: 5px; }
+-.command { font-family: monospace; font-weight: normal; }
++div.literallayout, .command { font-family: monospace; font-weight: normal; }
+ .command strong { font-weight: normal; }
+ tr { vertical-align: top; }
+-.comment { color:#707070; }
++.comment { color:#00c000; }
++code.literal { background: #f0f0f0; color: #000000; }
++span.indicator { background: #000060; color: #ffffff; }
++span.highlight { background: #404040; color: #ffffff; }
++span.reverse { background: #ffffff; color: #000000; }
+diff -urN mutt-1.6.1/doc/muttrc.sidebar mutt-1.6.1-sidebar/doc/muttrc.sidebar
+--- mutt-1.6.1/doc/muttrc.sidebar	1970-01-01 01:00:00.000000000 +0100
++++ mutt-1.6.1-sidebar/doc/muttrc.sidebar	2016-06-12 18:43:03.812500768 +0100
+@@ -0,0 +1,116 @@
++# This is a complete list of sidebar-related configuration.
++
++# --------------------------------------------------------------------------
++# VARIABLES - shown with their default values
++# --------------------------------------------------------------------------
++
++# Should the Sidebar be shown?
++set sidebar_visible = no
++
++# How wide should the Sidebar be in screen columns?
++# Note: Some characters, e.g. Chinese, take up two columns each.
++set sidebar_width = 20
++
++# Should the mailbox paths be abbreviated?
++set sidebar_short_path = no
++
++# When abbreviating mailbox path names, use any of these characters as path
++# separators.  Only the part after the last separators will be shown.
++# For file folders '/' is good.  For IMAP folders, often '.' is useful.
++set sidebar_delim_chars = '/.'
++
++# If the mailbox path is abbreviated, should it be indented?
++set sidebar_folder_indent = no
++
++# Indent mailbox paths with this string.
++set sidebar_indent_string = '  '
++
++# Make the Sidebar only display mailboxes that contain new, or flagged,
++# mail.
++set sidebar_new_mail_only = no
++
++# Any mailboxes that are whitelisted will always be visible, even if the
++# sidebar_new_mail_only option is enabled.
++sidebar_whitelist '/home/user/mailbox1'
++sidebar_whitelist '/home/user/mailbox2'
++
++# When searching for mailboxes containing new mail, should the search wrap
++# around when it reaches the end of the list?
++set sidebar_next_new_wrap = no
++
++# The character to use as the divider between the Sidebar and the other Mutt
++# panels.
++# Note: Only the first character of this string is used.
++set sidebar_divider_char = '|'
++
++# Display the Sidebar mailboxes using this format string.
++set sidebar_format = '%B%?F? [%F]?%* %?N?%N/?%S'
++
++# Sidebar will not refresh its list of mailboxes any more frequently than
++# this number of seconds.  This will help reduce disk/network traffic.
++set sidebar_refresh_time = 60
++
++# Sort the mailboxes in the Sidebar using this method:
++#       count    - total number of messages
++#       flagged  - number of flagged messages
++#       new      - number of new messages
++#       path     - mailbox path
++#       unsorted - do not sort the mailboxes
++set sidebar_sort_method = 'unsorted'
++
++# --------------------------------------------------------------------------
++# FUNCTIONS - shown with an example mapping
++# --------------------------------------------------------------------------
++
++# Move the highlight to the previous mailbox
++bind index,pager \Cp sidebar-prev
++
++# Move the highlight to the next mailbox
++bind index,pager \Cn sidebar-next
++
++# Open the highlighted mailbox
++bind index,pager \Co sidebar-open
++
++# Move the highlight to the previous page
++# This is useful if you have a LOT of mailboxes.
++bind index,pager <F3> sidebar-page-up
++
++# Move the highlight to the next page
++# This is useful if you have a LOT of mailboxes.
++bind index,pager <F4> sidebar-page-down
++
++# Move the highlight to the previous mailbox containing new, or flagged,
++# mail.
++bind index,pager <F5> sidebar-prev-new
++
++# Move the highlight to the next mailbox containing new, or flagged, mail.
++bind index,pager <F6> sidebar-next-new
++
++# Toggle the visibility of the Sidebar.
++bind index,pager B sidebar-toggle-visible
++
++# --------------------------------------------------------------------------
++# COLORS - some unpleasant examples are given
++# --------------------------------------------------------------------------
++# Note: All color operations are of the form:
++#       color OBJECT FOREGROUND BACKGROUND
++
++# Color of the current, open, mailbox
++# Note: This is a general Mutt option which colors all selected items.
++color indicator cyan black
++
++# Color of the highlighted, but not open, mailbox.
++color sidebar_highlight black color8
++
++# Color of the divider separating the Sidebar from Mutt panels
++color sidebar_divider color8 black
++
++# Color to give mailboxes containing flagged mail
++color sidebar_flagged red black
++
++# Color to give mailboxes containing new mail
++color sidebar_new green black
++
++# --------------------------------------------------------------------------
++
++# vim: syntax=muttrc
+diff -urN mutt-1.6.1/doc/vimrc.sidebar mutt-1.6.1-sidebar/doc/vimrc.sidebar
+--- mutt-1.6.1/doc/vimrc.sidebar	1970-01-01 01:00:00.000000000 +0100
++++ mutt-1.6.1-sidebar/doc/vimrc.sidebar	2016-06-12 18:43:03.813500783 +0100
+@@ -0,0 +1,35 @@
++" Vim syntax file for the mutt sidebar patch
++
++syntax keyword muttrcVarBool    skipwhite contained sidebar_folder_indent nextgroup=muttrcSetBoolAssignment,muttrcVPrefix,muttrcVarBool,muttrcVarQuad,muttrcVarNum,muttrcVarStr
++syntax keyword muttrcVarBool    skipwhite contained sidebar_new_mail_only nextgroup=muttrcSetBoolAssignment,muttrcVPrefix,muttrcVarBool,muttrcVarQuad,muttrcVarNum,muttrcVarStr
++syntax keyword muttrcVarBool    skipwhite contained sidebar_next_new_wrap nextgroup=muttrcSetBoolAssignment,muttrcVPrefix,muttrcVarBool,muttrcVarQuad,muttrcVarNum,muttrcVarStr
++syntax keyword muttrcVarBool    skipwhite contained sidebar_short_path    nextgroup=muttrcSetBoolAssignment,muttrcVPrefix,muttrcVarBool,muttrcVarQuad,muttrcVarNum,muttrcVarStr
++syntax keyword muttrcVarBool    skipwhite contained sidebar_visible       nextgroup=muttrcSetBoolAssignment,muttrcVPrefix,muttrcVarBool,muttrcVarQuad,muttrcVarNum,muttrcVarStr
++
++syntax keyword muttrcVarNum     skipwhite contained sidebar_refresh_time  nextgroup=muttrcSetNumAssignment,muttrcVPrefix,muttrcVarBool,muttrcVarQuad,muttrcVarNum,muttrcVarStr
++syntax keyword muttrcVarNum     skipwhite contained sidebar_width         nextgroup=muttrcSetNumAssignment,muttrcVPrefix,muttrcVarBool,muttrcVarQuad,muttrcVarNum,muttrcVarStr
++
++syntax keyword muttrcVarStr     contained skipwhite sidebar_divider_char  nextgroup=muttrcVarEqualsIdxFmt
++syntax keyword muttrcVarStr     contained skipwhite sidebar_delim_chars   nextgroup=muttrcVarEqualsIdxFmt
++syntax keyword muttrcVarStr     contained skipwhite sidebar_format        nextgroup=muttrcVarEqualsIdxFmt
++syntax keyword muttrcVarStr     contained skipwhite sidebar_indent_string nextgroup=muttrcVarEqualsIdxFmt
++syntax keyword muttrcVarStr     contained skipwhite sidebar_sort_method   nextgroup=muttrcVarEqualsIdxFmt
++
++syntax keyword muttrcCommand    sidebar_whitelist
++
++syntax match muttrcFunction     contained "\<sidebar-next\>"
++syntax match muttrcFunction     contained "\<sidebar-next-new\>"
++syntax match muttrcFunction     contained "\<sidebar-open\>"
++syntax match muttrcFunction     contained "\<sidebar-page-down\>"
++syntax match muttrcFunction     contained "\<sidebar-page-up\>"
++syntax match muttrcFunction     contained "\<sidebar-prev\>"
++syntax match muttrcFunction     contained "\<sidebar-prev-new\>"
++syntax match muttrcFunction     contained "\<sidebar-toggle-visible\>"
++
++syntax keyword muttrcColorField contained sidebar_divider
++syntax keyword muttrcColorField contained sidebar_flagged
++syntax keyword muttrcColorField contained sidebar_highlight
++syntax keyword muttrcColorField contained sidebar_indicator
++syntax keyword muttrcColorField contained sidebar_new
++
++" vim: syntax=vim
+diff -urN mutt-1.6.1/filter.c mutt-1.6.1-sidebar/filter.c
+--- mutt-1.6.1/filter.c	2016-06-12 18:43:00.403447606 +0100
++++ mutt-1.6.1-sidebar/filter.c	2016-06-12 18:43:03.835501127 +0100
+@@ -21,6 +21,7 @@
+ #endif
  
  #include "mutt.h"
- #include "mutt_curses.h"
-+#include "mutt_menu.h"
++#include "mutt_curses.h"
+ 
+ #include <unistd.h>
+ #include <stdlib.h>
+@@ -34,6 +35,7 @@
+ 		       int fdin, int fdout, int fderr)
+ {
+   int pin[2], pout[2], perr[2], thepid;
++  char columns[11];
+ 
+   if (in)
+   {
+@@ -117,6 +119,9 @@
+       close (fderr);
+     }
+ 
++    snprintf (columns, sizeof (columns), "%d", COLS - SidebarWidth);
++    setenv ("COLUMNS", columns, 1);
++
+     execl (EXECSHELL, "sh", "-c", cmd, NULL);
+     _exit (127);
+   }
+diff -urN mutt-1.6.1/flags.c mutt-1.6.1-sidebar/flags.c
+--- mutt-1.6.1/flags.c	2016-06-12 18:43:00.403447606 +0100
++++ mutt-1.6.1-sidebar/flags.c	2016-06-12 18:43:03.956503013 +0100
+@@ -25,6 +25,10 @@
  #include "sort.h"
  #include "mx.h"
-+#include "sidebar.h"
  
++#ifdef USE_SIDEBAR
++#include "sidebar.h"
++#endif
++
  void _mutt_set_flag (CONTEXT *ctx, HEADER *h, int flag, int bf, int upd_ctx)
  {
-@@ -290,6 +292,7 @@ void _mutt_set_flag (CONTEXT *ctx, HEADER *h, int flag, int bf, int upd_ctx)
+   int changed = h->changed;
+@@ -263,6 +267,9 @@
     */
    if (h->searched && (changed != h->changed || deleted != ctx->deleted || tagged != ctx->tagged || flagged != ctx->flagged))
      h->searched = 0;
-+	draw_sidebar(0);
++#ifdef USE_SIDEBAR
++  mutt_sb_draw();
++#endif
  }
  
  void mutt_tag_set_flag (int flag, int bf)
-diff --git a/functions.h b/functions.h
-index 26171a0..ef8937a 100644
---- a/functions.h
-+++ b/functions.h
-@@ -170,6 +170,11 @@ const struct binding_t OpMain[] = { /* map: index */
+diff -urN mutt-1.6.1/functions.h mutt-1.6.1-sidebar/functions.h
+--- mutt-1.6.1/functions.h	2016-06-12 18:43:00.403447606 +0100
++++ mutt-1.6.1-sidebar/functions.h	2016-06-12 18:43:03.956503013 +0100
+@@ -168,6 +168,16 @@
+   { "decrypt-copy",		OP_DECRYPT_COPY,		NULL },
    { "decrypt-save",		OP_DECRYPT_SAVE,		NULL },
  
++#ifdef USE_SIDEBAR
++  { "sidebar-next",		OP_SIDEBAR_NEXT,		NULL },
++  { "sidebar-next-new",		OP_SIDEBAR_NEXT_NEW,		NULL },
++  { "sidebar-open",		OP_SIDEBAR_OPEN,		NULL },
++  { "sidebar-page-down",	OP_SIDEBAR_PAGE_DOWN,		NULL },
++  { "sidebar-page-up",		OP_SIDEBAR_PAGE_UP,		NULL },
++  { "sidebar-prev",		OP_SIDEBAR_PREV,		NULL },
++  { "sidebar-prev-new",		OP_SIDEBAR_PREV_NEW,		NULL },
++  { "sidebar-toggle-visible",	OP_SIDEBAR_TOGGLE_VISIBLE,	NULL },
++#endif
  
-+ { "sidebar-scroll-up",	OP_SIDEBAR_SCROLL_UP, NULL },
-+ { "sidebar-scroll-down",	OP_SIDEBAR_SCROLL_DOWN, NULL },
-+ { "sidebar-next",		OP_SIDEBAR_NEXT, NULL },
-+ { "sidebar-prev",		OP_SIDEBAR_PREV, NULL },
-+ { "sidebar-open",		OP_SIDEBAR_OPEN, NULL },
    { NULL,			0,				NULL }
  };
- 
-@@ -274,6 +279,11 @@ const struct binding_t OpPager[] = { /* map: pager */
+@@ -272,6 +282,17 @@
  
    { "what-key",		OP_WHAT_KEY,		NULL },
  
-+  { "sidebar-scroll-up",	OP_SIDEBAR_SCROLL_UP, NULL },
-+  { "sidebar-scroll-down",	OP_SIDEBAR_SCROLL_DOWN, NULL },
-+  { "sidebar-next",	OP_SIDEBAR_NEXT, NULL },
-+  { "sidebar-prev",	OP_SIDEBAR_PREV, NULL },
-+  { "sidebar-open", OP_SIDEBAR_OPEN, NULL },
++#ifdef USE_SIDEBAR
++  { "sidebar-next",		OP_SIDEBAR_NEXT,		NULL },
++  { "sidebar-next-new",		OP_SIDEBAR_NEXT_NEW,		NULL },
++  { "sidebar-open",		OP_SIDEBAR_OPEN,		NULL },
++  { "sidebar-page-down",	OP_SIDEBAR_PAGE_DOWN,		NULL },
++  { "sidebar-page-up",		OP_SIDEBAR_PAGE_UP,		NULL },
++  { "sidebar-prev",		OP_SIDEBAR_PREV,		NULL },
++  { "sidebar-prev-new",		OP_SIDEBAR_PREV_NEW,		NULL },
++  { "sidebar-toggle-visible",	OP_SIDEBAR_TOGGLE_VISIBLE,	NULL },
++#endif
++
    { NULL,		0,				NULL }
  };
  
-diff --git a/globals.h b/globals.h
-index 282fde3..004c795 100644
---- a/globals.h
-+++ b/globals.h
-@@ -118,6 +118,7 @@ WHERE short SearchContext;
+diff -urN mutt-1.6.1/globals.h mutt-1.6.1-sidebar/globals.h
+--- mutt-1.6.1/globals.h	2016-06-12 18:43:00.403447606 +0100
++++ mutt-1.6.1-sidebar/globals.h	2016-06-12 18:43:03.956503013 +0100
+@@ -118,6 +118,12 @@
  WHERE char *SendCharset;
  WHERE char *Sendmail;
  WHERE char *Shell;
-+WHERE char *SidebarDelim;
++#ifdef USE_SIDEBAR
++WHERE char *SidebarDelimChars;
++WHERE char *SidebarDividerChar;
++WHERE char *SidebarFormat;
++WHERE char *SidebarIndentString;
++#endif
  WHERE char *Signature;
  WHERE char *SimpleSearch;
  #if USE_SMTP
-@@ -214,6 +215,9 @@ WHERE short ScoreThresholdDelete;
+@@ -214,6 +220,14 @@
  WHERE short ScoreThresholdRead;
  WHERE short ScoreThresholdFlag;
  
-+WHERE struct buffy_t *CurBuffy INITVAL(0);
-+WHERE short DrawFullLine INITVAL(0);
++/* This isn't excluded from the build because it's too entwined in the code.
++ * For now. */
 +WHERE short SidebarWidth;
++#ifdef USE_SIDEBAR
++WHERE short SidebarRefreshTime;
++WHERE LIST *SidebarWhitelist INITVAL(0);
++#endif
++
  #ifdef USE_IMAP
  WHERE short ImapKeepalive;
  WHERE short ImapPipelineDepth;
-diff --git a/imap/command.c b/imap/command.c
-index 32f8417..d68e3ab 100644
---- a/imap/command.c
-+++ b/imap/command.c
-@@ -1012,6 +1012,13 @@ static void cmd_parse_status (IMAP_DATA* idata, char* s)
+diff -urN mutt-1.6.1/imap/command.c mutt-1.6.1-sidebar/imap/command.c
+--- mutt-1.6.1/imap/command.c	2016-06-12 18:43:00.405447637 +0100
++++ mutt-1.6.1-sidebar/imap/command.c	2016-06-12 18:43:03.839501189 +0100
+@@ -1016,6 +1016,14 @@
  	     opened */
  	  status->uidnext = oldun;
  
-+        /* Added to make the sidebar show the correct numbers */
-+        if (status->messages)
-+        {
-+          inc->msgcount = status->messages;
-+          inc->msg_unread = status->unseen;
-+        }
++#ifdef USE_SIDEBAR
++	/* Make the sidebar show the correct numbers */
++	if (status->messages) {
++	  inc->msg_count  = status->messages;
++	  inc->msg_unread = status->unseen;
++	}
++#endif
 +
          FREE (&value);
          return;
        }
-diff --git a/imap/imap.c b/imap/imap.c
-index f476873..af3ac3d 100644
---- a/imap/imap.c
-+++ b/imap/imap.c
-@@ -1529,7 +1529,7 @@ int imap_buffy_check (int force)
+diff -urN mutt-1.6.1/imap/imap.c mutt-1.6.1-sidebar/imap/imap.c
+--- mutt-1.6.1/imap/imap.c	2016-06-12 18:43:00.405447637 +0100
++++ mutt-1.6.1-sidebar/imap/imap.c	2016-06-12 18:43:03.958503044 +0100
+@@ -1535,7 +1535,11 @@
  
-     imap_munge_mbox_name (munged, sizeof (munged), name);
+     imap_munge_mbox_name (idata, munged, sizeof (munged), name);
      snprintf (command, sizeof (command),
--	      "STATUS %s (UIDNEXT UIDVALIDITY UNSEEN RECENT)", munged);
++#ifdef USE_SIDEBAR
 +	      "STATUS %s (UIDNEXT UIDVALIDITY UNSEEN RECENT MESSAGES)", munged);
++#else
+ 	      "STATUS %s (UIDNEXT UIDVALIDITY UNSEEN RECENT)", munged);
++#endif
  
      if (imap_exec (idata, command, IMAP_CMD_QUEUE) < 0)
      {
-diff --git a/init.h b/init.h
-index 35224c1..c664e5f 100644
---- a/init.h
-+++ b/init.h
-@@ -2030,6 +2030,27 @@ struct option_t MuttVars[] = {
-   ** not used.
-   ** (PGP only)
+diff -urN mutt-1.6.1/init.c mutt-1.6.1-sidebar/init.c
+--- mutt-1.6.1/init.c	2016-06-12 18:43:00.406447652 +0100
++++ mutt-1.6.1-sidebar/init.c	2016-06-12 18:43:03.959503060 +0100
+@@ -2173,6 +2173,9 @@
+ 	case DT_SORT_AUX:
+ 	  map = SortAuxMethods;
+ 	  break;
++	case DT_SORT_SIDEBAR:
++	  map = SortSidebarMethods;
++	  break;
+ 	default:
+ 	  map = SortMethods;
+ 	  break;
+diff -urN mutt-1.6.1/init.h mutt-1.6.1-sidebar/init.h
+--- mutt-1.6.1/init.h	2016-06-12 18:43:00.408447684 +0100
++++ mutt-1.6.1-sidebar/init.h	2016-06-12 18:43:03.960503075 +0100
+@@ -42,11 +42,12 @@
+ #define DTYPE(x) ((x) & DT_MASK)
+ 
+ /* subtypes */
+-#define DT_SUBTYPE_MASK	0xf0
++#define DT_SUBTYPE_MASK	0xff0
+ #define DT_SORT_ALIAS	0x10
+ #define DT_SORT_BROWSER 0x20
+ #define DT_SORT_KEYS	0x40
+ #define DT_SORT_AUX	0x80
++#define DT_SORT_SIDEBAR	0x100
+ 
+ /* flags to parse_set() */
+ #define M_SET_INV	(1<<0)	/* default is to invert all vars */
+@@ -2665,6 +2666,147 @@
+   ** Command to use when spawning a subshell.  By default, the user's login
+   ** shell from \fC/etc/passwd\fP is used.
    */
-+  {"sidebar_delim", DT_STR, R_BOTH, UL &SidebarDelim, "|"},
++#ifdef USE_SIDEBAR
++  { "sidebar_divider_char", DT_STR, R_BOTH, UL &SidebarDividerChar, UL "|" },
 +  /*
 +  ** .pp
-+  ** This specifies the delimiter between the sidebar (if visible) and 
-+  ** other screens.
++  ** This specifies the characters to be drawn between the sidebar (when
++  ** visible) and the other Mutt panels. ASCII and Unicode line-drawing
++  ** characters are supported.
 +  */
-+  { "sidebar_visible", DT_BOOL, R_BOTH, OPTSIDEBAR, 0 },
++  { "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.
++  ** .pp
++  ** Local mail is often arranged in directories: `dir1/dir2/mailbox'.
++  ** .ts
++  ** set sidebar_delim_chars='/'
++  ** .te
++  ** .pp
++  ** IMAP mailboxes are often named: `folder1.folder2.mailbox'.
++  ** .ts
++  ** set sidebar_delim_chars='.'
++  ** .te
++  ** .pp
++  ** \fBSee also:\fP $$sidebar_short_path, $$sidebar_folder_indent, $$sidebar_indent_string.
++  */
++  { "sidebar_folder_indent", DT_BOOL, R_BOTH, OPTSIDEBARFOLDERINDENT, 0 },
++  /*
++  ** .pp
++  ** Set this to indent mailboxes in the sidebar.
++  ** .pp
++  ** \fBSee also:\fP $$sidebar_short_path, $$sidebar_indent_string, $$sidebar_delim_chars.
++  */
++  { "sidebar_format", DT_STR, R_NONE, UL &SidebarFormat, UL "%B%?F? [%F]?%* %?N?%N/?%S" },
++  /*
++  ** .pp
++  ** This variable allows you to customize the sidebar display. This string is
++  ** similar to $$index_format, but has its own set of \fCprintf(3)\fP-like
++  ** sequences:
++  ** .dl
++  ** .dt %B  .dd Name of the mailbox
++  ** .dt %S  .dd * Size of mailbox (total number of messages)
++  ** .dt %N  .dd * Number of New messages in the mailbox
++  ** .dt %F  .dd * Number of Flagged messages in the mailbox
++  ** .dt %!  .dd ``!'' : one flagged message;
++  **             ``!!'' : two flagged messages;
++  **             ``n!'' : n flagged messages (for n > 2).
++  **             Otherwise prints nothing.
++  ** .dt %d  .dd * @ Number of deleted messages
++  ** .dt %L  .dd * @ Number of messages after limiting
++  ** .dt %t  .dd * @ Number of tagged messages
++  ** .dt %>X .dd right justify the rest of the string and pad with ``X''
++  ** .dt %|X .dd pad to the end of the line with ``X''
++  ** .dt %*X .dd soft-fill with character ``X'' as pad
++  ** .de
++  ** .pp
++  ** * = Can be optionally printed if nonzero
++  ** @ = Only applicable to the current folder
++  */
++  { "sidebar_indent_string", DT_STR, R_BOTH, UL &SidebarIndentString, UL "  " },
++  /*
++  ** .pp
++  ** This specifies the string that is used to indent mailboxes in the sidebar.
++  ** It defaults to two spaces.
++  ** .pp
++  ** \fBSee also:\fP $$sidebar_short_path, $$sidebar_folder_indent, $$sidebar_delim_chars.
++  */
++  { "sidebar_new_mail_only", DT_BOOL, R_BOTH, OPTSIDEBARNEWMAILONLY, 0 },
++  /*
++  ** .pp
++  ** When set, the sidebar will only display mailboxes containing new, or
++  ** flagged, mail.
++  ** .pp
++  ** \fBSee also:\fP $sidebar_whitelist.
++  */
++  { "sidebar_next_new_wrap", DT_BOOL, R_BOTH, UL OPTSIDEBARNEXTNEWWRAP, 0 },
++  /*
++  ** .pp
++  ** When set, the \fC<sidebar-next-new>\fP command will not stop and the end of
++  ** the list of mailboxes, but wrap around to the beginning. The
++  ** \fC<sidebar-prev-new>\fP command is similarly affected, wrapping around to
++  ** the end of the list.
++  */
++  { "sidebar_refresh_time", DT_NUM, R_BOTH, UL &SidebarRefreshTime, 60 },
++  /*
++  ** .pp
++  ** Set sidebar_refresh_time to the minimum number of seconds between refreshes.
++  ** This will reduce network traffic.
++  ** .pp
++  ** \fBNote:\fP Set to 0 to disable refreshing.
++  */
++  { "sidebar_short_path", DT_BOOL, R_BOTH, OPTSIDEBARSHORTPATH, 0 },
++  /*
++  ** .pp
++  ** By default the sidebar will show the mailbox's path, relative to the
++  ** $$folder variable. Setting \fCsidebar_shortpath=yes\fP will shorten the
++  ** names relative to the previous name. Here's an example:
++  ** .dl
++  ** .dt \fBshortpath=no\fP .dd \fBshortpath=yes\fP .dd \fBshortpath=yes, folderindent=yes, indentstr=".."\fP
++  ** .dt \fCfruit\fP        .dd \fCfruit\fP         .dd \fCfruit\fP
++  ** .dt \fCfruit.apple\fP  .dd \fCapple\fP         .dd \fC..apple\fP
++  ** .dt \fCfruit.banana\fP .dd \fCbanana\fP        .dd \fC..banana\fP
++  ** .dt \fCfruit.cherry\fP .dd \fCcherry\fP        .dd \fC..cherry\fP
++  ** .de
++  ** .pp
++  ** \fBSee also:\fP $$sidebar_delim_chars, $$sidebar_folder_indent, $$sidebar_indent_string.
++  */
++  { "sidebar_sort_method", DT_SORT|DT_SORT_SIDEBAR, R_NONE, UL &SidebarSortMethod, SORT_ORDER },
 +  /*
 +  ** .pp
-+  ** This specifies whether or not to show sidebar (left-side list of folders).
++  ** Specifies how to sort entries in the file browser.  By default, the
++  ** entries are sorted alphabetically.  Valid values:
++  ** .il
++  ** .dd alpha (alphabetically)
++  ** .dd count (all message count)
++  ** .dd date
++  ** .dd desc (description)
++  ** .dd new (new message count)
++  ** .dd size
++  ** .dd unsorted
++  ** .ie
++  ** .pp
++  ** You may optionally use the ``reverse-'' prefix to specify reverse sorting
++  ** order (example: ``\fCset sort_browser=reverse-date\fP'').
 +  */
-+  { "sidebar_sort", DT_BOOL, R_BOTH, OPTSIDEBARSORT, 0 },
++  { "sidebar_visible", DT_BOOL, R_BOTH, OPTSIDEBAR, 0 },
 +  /*
 +  ** .pp
-+  ** This specifies whether or not to sort the sidebar alphabetically.
++  ** This specifies whether or not to show sidebar. The sidebar shows a list of
++  ** all your mailboxes.
++  ** .pp
++  ** \fBSee also:\fP $$sidebar_format, $$sidebar_width
 +  */
 +  { "sidebar_width", DT_NUM, R_BOTH, UL &SidebarWidth, 0 },
 +  /*
 +  ** .pp
-+  ** The width of the sidebar.
++  ** This controls the width of the sidebar.  It is measured in screen columns.
++  ** For example: sidebar_width=20 could display 20 ASCII characters, or 10
++  ** Chinese characters.
 +  */
-   { "pgp_use_gpg_agent", DT_BOOL, R_NONE, OPTUSEGPGAGENT, 0},
++#endif
+   { "sig_dashes",	DT_BOOL, R_NONE, OPTSIGDASHES, 1 },
    /*
    ** .pp
-diff --git a/mailbox.h b/mailbox.h
-index 2b2c9a1..000503d 100644
---- a/mailbox.h
-+++ b/mailbox.h
-@@ -27,6 +27,7 @@
+@@ -3652,6 +3794,19 @@
+   { NULL,       0 }
+ };
+ 
++const struct mapping_t SortSidebarMethods[] = {
++  { "alpha",		SORT_PATH },
++  { "count",		SORT_COUNT },
++  { "desc",		SORT_DESC },
++  { "flagged",		SORT_FLAGGED },
++  { "mailbox-order",	SORT_ORDER },
++  { "name",		SORT_PATH },
++  { "new",		SORT_COUNT_NEW },
++  { "path",		SORT_PATH },
++  { "unsorted",		SORT_ORDER },
++  { NULL,		0 }
++};
++
+ 
+ /* functions used to parse commands in a rc file */
+ 
+@@ -3741,6 +3896,9 @@
+   { "send-hook",	mutt_parse_hook,	M_SENDHOOK },
+   { "send2-hook",	mutt_parse_hook,	M_SEND2HOOK },
+   { "set",		parse_set,		0 },
++#ifdef USE_SIDEBAR
++  { "sidebar_whitelist",parse_list,		UL &SidebarWhitelist },
++#endif
+   { "source",		parse_source,		0 },
+   { "spam",		parse_spam_list,	M_SPAM },
+   { "nospam",		parse_spam_list,	M_NOSPAM },
+diff -urN mutt-1.6.1/keymap.c mutt-1.6.1-sidebar/keymap.c
+--- mutt-1.6.1/keymap.c	2016-06-12 18:43:00.408447684 +0100
++++ mutt-1.6.1-sidebar/keymap.c	2016-06-12 18:43:03.960503075 +0100
+@@ -453,6 +453,9 @@
+     }
+ #endif
+ 
++    /* update sidebar stats */
++    mutt_buffy_check(0);
++
+     timeout (i * 1000);
+     tmp = mutt_getch();
+     timeout (-1);
+diff -urN mutt-1.6.1/mailbox.h mutt-1.6.1-sidebar/mailbox.h
+--- mutt-1.6.1/mailbox.h	2016-06-12 18:43:00.408447684 +0100
++++ mutt-1.6.1-sidebar/mailbox.h	2016-06-12 18:43:03.960503075 +0100
+@@ -27,6 +27,9 @@
  #define M_NEWFOLDER	(1<<4) /* create a new folder - same as M_APPEND, but uses
  				* safe_fopen() for mbox-style folders.
  				*/
++#ifdef USE_SIDEBAR
 +#define M_PEEK		(1<<5) /* revert atime back after taking a look (if applicable) */
++#endif
  
  /* mx_open_new_message() */
  #define M_ADD_FROM	(1<<0)	/* add a From_ line */
-diff --git a/mbox.c b/mbox.c
-index 6d3b6bd..fa82eb3 100644
---- a/mbox.c
-+++ b/mbox.c
-@@ -104,6 +104,7 @@ int mmdf_parse_mailbox (CONTEXT *ctx)
+diff -urN mutt-1.6.1/main.c mutt-1.6.1-sidebar/main.c
+--- mutt-1.6.1/main.c	2016-06-12 18:43:00.409447699 +0100
++++ mutt-1.6.1-sidebar/main.c	2016-06-12 18:43:03.961503091 +0100
+@@ -31,6 +31,9 @@
+ #include "url.h"
+ #include "mutt_crypt.h"
+ #include "mutt_idna.h"
++#ifdef USE_SIDEBAR
++#include "sidebar.h"
++#endif
+ 
+ #ifdef USE_SASL
+ #include "mutt_sasl.h"
+@@ -485,6 +488,12 @@
+ 	"-USE_HCACHE  "
+ #endif
+ 
++#ifdef USE_SIDEBAR
++	"+USE_SIDEBAR  "
++#else
++	"-USE_SIDEBAR  "
++#endif
++
+ 	);
+ 
+ #ifdef ISPELL
+@@ -557,7 +566,11 @@
+ 
+ int main (int argc, char **argv)
+ {
++#ifdef USE_SIDEBAR
++  char folder[PATH_MAX] = "";
++#else
+   char folder[_POSIX_PATH_MAX] = "";
++#endif
+   char *subject = NULL;
+   char *includeFile = NULL;
+   char *draftFile = NULL;
+@@ -828,6 +841,9 @@
+     clear ();
+     mutt_error = mutt_curses_error;
+     mutt_message = mutt_curses_message;
++#ifdef USE_SIDEBAR
++    mutt_sb_init();
++#endif
+   }
+ 
+   /* Create the Maildir directory if it doesn't exist. */
+@@ -1184,6 +1200,15 @@
+       strfcpy (folder, NONULL(Spoolfile), sizeof (folder));
+     mutt_expand_path (folder, sizeof (folder));
+ 
++#ifdef USE_SIDEBAR
++    {
++      char tmpfolder[PATH_MAX] = "";
++      strfcpy (tmpfolder, folder, sizeof (tmpfolder));
++      if (!realpath (tmpfolder, folder))
++        strfcpy (folder, tmpfolder, sizeof (tmpfolder));
++    }
++#endif
++
+     mutt_str_replace (&CurrentFolder, folder);
+     mutt_str_replace (&LastFolder, folder);
+ 
+@@ -1206,6 +1231,9 @@
+     if((Context = mx_open_mailbox (folder, ((flags & M_RO) || option (OPTREADONLY)) ? M_READONLY : 0, NULL))
+        || !explicit_folder)
+     {
++#ifdef USE_SIDEBAR
++      mutt_sb_set_open_buffy (folder);
++#endif
+       mutt_index_menu ();
+       if (Context)
+ 	FREE (&Context);
+diff -urN mutt-1.6.1/Makefile.am mutt-1.6.1-sidebar/Makefile.am
+--- mutt-1.6.1/Makefile.am	2016-06-12 18:43:00.389447388 +0100
++++ mutt-1.6.1-sidebar/Makefile.am	2016-06-12 18:43:03.944502826 +0100
+@@ -56,7 +56,7 @@
+ 	mutt_idna.c mutt_sasl.c mutt_socket.c mutt_ssl.c mutt_ssl_gnutls.c \
+ 	mutt_tunnel.c pgp.c pgpinvoke.c pgpkey.c pgplib.c pgpmicalg.c \
+ 	pgppacket.c pop.c pop_auth.c pop_lib.c remailer.c resize.c sha1.c \
+-	smime.c smtp.c utf8.c wcwidth.c \
++	sidebar.c smime.c smtp.c utf8.c wcwidth.c \
+ 	bcache.h browser.h hcache.h mbyte.h mutt_idna.h remailer.h url.h
+ 
+ EXTRA_DIST = COPYRIGHT GPL OPS OPS.PGP OPS.CRYPT OPS.SMIME TODO UPDATING \
+@@ -71,7 +71,7 @@
+ 	mbyte.h lib.h extlib.c pgpewrap.c smime_keys.pl pgplib.h \
+ 	README.SSL smime.h group.h \
+ 	muttbug pgppacket.h depcomp ascii.h BEWARE PATCHES patchlist.sh \
+-	ChangeLog mkchangelog.sh mutt_idna.h \
++	ChangeLog mkchangelog.sh mutt_idna.h sidebar.h OPS.sidebar \
+ 	snprintf.c regex.c crypt-gpgme.h hcachever.sh.in sys_socket.h \
+ 	txt2c.c txt2c.sh version.sh check_sec.sh
+ 
+@@ -129,9 +129,9 @@
+ keymap_defs.h: $(OPS) $(srcdir)/gen_defs
+ 	$(srcdir)/gen_defs $(OPS) > keymap_defs.h
+ 
+-keymap_alldefs.h: $(srcdir)/OPS $(srcdir)/OPS.PGP $(srcdir)/OPS.MIX $(srcdir)/OPS.CRYPT $(srcdir)/OPS.SMIME $(srcdir)/gen_defs
++keymap_alldefs.h: $(srcdir)/OPS $(srcdir)/OPS.SIDEBAR $(srcdir)/OPS.PGP $(srcdir)/OPS.MIX $(srcdir)/OPS.CRYPT $(srcdir)/OPS.SMIME $(srcdir)/gen_defs
+ 	rm -f $@
+-	$(srcdir)/gen_defs $(srcdir)/OPS $(srcdir)/OPS.PGP \
++	$(srcdir)/gen_defs $(srcdir)/OPS $(srcdir)/OPS.SIDEBAR $(srcdir)/OPS.PGP \
+ 		$(srcdir)/OPS.MIX $(srcdir)/OPS.CRYPT $(srcdir)/OPS.SMIME \
+ 			> keymap_alldefs.h
+ 
+diff -urN mutt-1.6.1/mbox.c mutt-1.6.1-sidebar/mbox.c
+--- mutt-1.6.1/mbox.c	2016-06-12 18:43:00.409447699 +0100
++++ mutt-1.6.1-sidebar/mbox.c	2016-06-12 18:43:03.961503091 +0100
+@@ -100,6 +100,9 @@
      mutt_perror (ctx->path);
      return (-1);
    }
++#ifdef USE_SIDEBAR
 +  ctx->atime = sb.st_atime;
++#endif
    ctx->mtime = sb.st_mtime;
    ctx->size = sb.st_size;
  
-@@ -255,6 +256,7 @@ int mbox_parse_mailbox (CONTEXT *ctx)
+@@ -251,6 +254,9 @@
  
    ctx->size = sb.st_size;
    ctx->mtime = sb.st_mtime;
++#ifdef USE_SIDEBAR
 +  ctx->atime = sb.st_atime;
++#endif
  
  #ifdef NFS_ATTRIBUTE_HACK
    if (sb.st_mtime > sb.st_atime)
-diff --git a/menu.c b/menu.c
-index 27b5f8e..bc3a02f 100644
---- a/menu.c
-+++ b/menu.c
-@@ -24,6 +24,7 @@
+diff -urN mutt-1.6.1/menu.c mutt-1.6.1-sidebar/menu.c
+--- mutt-1.6.1/menu.c	2016-06-12 18:43:00.409447699 +0100
++++ mutt-1.6.1-sidebar/menu.c	2016-06-12 18:43:03.961503091 +0100
+@@ -24,6 +24,9 @@
  #include "mutt_curses.h"
  #include "mutt_menu.h"
  #include "mbyte.h"
++#ifdef USE_SIDEBAR
 +#include "sidebar.h"
++#endif
  
- extern size_t UngetCount;
+ char* SearchBuffers[MENU_MAX];
  
-@@ -186,7 +187,7 @@ static void menu_pad_string (char *s, size_t n)
+@@ -184,7 +187,7 @@
  {
    char *scratch = safe_strdup (s);
    int shift = option (OPTARROWCURSOR) ? 3 : 0;
@@ -702,15 +2575,17 @@ index 27b5f8e..bc3a02f 100644
  
    mutt_format_string (s, n, cols, cols, FMT_LEFT, ' ', scratch, mutt_strlen (scratch), 1);
    s[n - 1] = 0;
-@@ -239,6 +240,7 @@ void menu_redraw_index (MUTTMENU *menu)
+@@ -237,6 +240,9 @@
    int do_color;
    int attr;
  
-+  draw_sidebar(1);
++#ifdef USE_SIDEBAR
++  mutt_sb_draw();
++#endif
    for (i = menu->top; i < menu->top + menu->pagelen; i++)
    {
      if (i < menu->max)
-@@ -249,7 +251,7 @@ void menu_redraw_index (MUTTMENU *menu)
+@@ -247,7 +253,7 @@
        menu_pad_string (buf, sizeof (buf));
  
        ATTRSET(attr);
@@ -719,16 +2594,19 @@ index 27b5f8e..bc3a02f 100644
        do_color = 1;
  
        if (i == menu->current)
-@@ -272,7 +274,7 @@ void menu_redraw_index (MUTTMENU *menu)
+@@ -270,7 +276,11 @@
      else
      {
        NORMAL_COLOR;
--      CLEARLINE(i - menu->top + menu->offset);
++#ifdef USE_SIDEBAR
 +      CLEARLINE_WIN(i - menu->top + menu->offset);
++#else
+       CLEARLINE(i - menu->top + menu->offset);
++#endif
      }
    }
    NORMAL_COLOR;
-@@ -289,7 +291,7 @@ void menu_redraw_motion (MUTTMENU *menu)
+@@ -287,7 +297,7 @@
      return;
    }
    
@@ -737,7 +2615,7 @@ index 27b5f8e..bc3a02f 100644
    ATTRSET(menu->color (menu->oldcurrent));
  
    if (option (OPTARROWCURSOR))
-@@ -301,13 +303,13 @@ void menu_redraw_motion (MUTTMENU *menu)
+@@ -299,13 +309,13 @@
      {
        menu_make_entry (buf, sizeof (buf), menu, menu->oldcurrent);
        menu_pad_string (buf, sizeof (buf));
@@ -753,7 +2631,7 @@ index 27b5f8e..bc3a02f 100644
    }
    else
    {
-@@ -320,7 +322,7 @@ void menu_redraw_motion (MUTTMENU *menu)
+@@ -318,7 +328,7 @@
      menu_make_entry (buf, sizeof (buf), menu, menu->current);
      menu_pad_string (buf, sizeof (buf));
      SETCOLOR(MT_COLOR_INDICATOR);
@@ -762,7 +2640,7 @@ index 27b5f8e..bc3a02f 100644
      print_enriched_string (menu->color(menu->current), (unsigned char *) buf, 0);
    }
    menu->redraw &= REDRAW_STATUS;
-@@ -332,7 +334,7 @@ void menu_redraw_current (MUTTMENU *menu)
+@@ -330,7 +340,7 @@
    char buf[LONG_STRING];
    int attr = menu->color (menu->current);
    
@@ -771,7 +2649,7 @@ index 27b5f8e..bc3a02f 100644
    menu_make_entry (buf, sizeof (buf), menu, menu->current);
    menu_pad_string (buf, sizeof (buf));
  
-@@ -881,7 +883,7 @@ int mutt_menuLoop (MUTTMENU *menu)
+@@ -873,7 +883,7 @@
      
      
      if (option (OPTARROWCURSOR))
@@ -780,160 +2658,207 @@ index 27b5f8e..bc3a02f 100644
      else if (option (OPTBRAILLEFRIENDLY))
        move (menu->current - menu->top + menu->offset, 0);
      else
-diff --git a/mh.c b/mh.c
-index 63e12d2..4a84a99 100644
---- a/mh.c
-+++ b/mh.c
-@@ -295,6 +295,28 @@ void mh_buffy(BUFFY *b)
+diff -urN mutt-1.6.1/mh.c mutt-1.6.1-sidebar/mh.c
+--- mutt-1.6.1/mh.c	2016-06-12 18:43:00.410447715 +0100
++++ mutt-1.6.1-sidebar/mh.c	2016-06-12 18:43:03.962503107 +0100
+@@ -295,6 +295,48 @@
    mhs_free_sequences (&mhs);
  }
  
-+void mh_buffy_update (const char *path, int *msgcount, int *msg_unread, int *msg_flagged)
++#ifdef USE_SIDEBAR
++/**
++ * mh_buffy_update - Update messages counts for an mh mailbox
++ * @mailbox: BUFFY representing a maildir mailbox
++ *
++ * Read through an mh mailbox and count messages.  Save the number of new,
++ * flagged messages and a timestamp for now.
++ */
++void
++mh_buffy_update (BUFFY *mailbox)
 +{
 +  int i;
 +  struct mh_sequences mhs;
++
++  if (!mailbox)
++    return;
++
++  if (!option (OPTSIDEBAR))
++    return;
++
 +  memset (&mhs, 0, sizeof (mhs));
 +
-+  if (mh_read_sequences (&mhs, path) < 0)
++  if (mh_read_sequences (&mhs, mailbox->path) < 0)
 +    return;
 +
-+  msgcount = 0;
-+  msg_unread = 0;
-+  msg_flagged = 0;
++  mailbox->msg_count   = 0;
++  mailbox->msg_unread  = 0;
++  mailbox->msg_flagged = 0;
++
 +  for (i = 0; i <= mhs.max; i++)
-+    msgcount++;
-+  if (mhs_check (&mhs, i) & MH_SEQ_UNSEEN) {
-+    msg_unread++;
++  {
++    mailbox->msg_count++;
++    if (mhs_check (&mhs, i) & MH_SEQ_UNSEEN)
++      mailbox->msg_unread++;
++    if (mhs_check (&mhs, i) & MH_SEQ_FLAGGED)
++      mailbox->msg_flagged++;
 +  }
-+  if (mhs_check (&mhs, i) & MH_SEQ_FLAGGED)
-+    msg_flagged++;
 +  mhs_free_sequences (&mhs);
++  mailbox->sb_last_checked = time (NULL);
 +}
++#endif
 +
  static int mh_mkstemp (CONTEXT * dest, FILE ** fp, char **tgt)
  {
    int fd;
-diff --git a/mutt.h b/mutt.h
-index 01d47de..5f25406 100644
---- a/mutt.h
-+++ b/mutt.h
-@@ -435,6 +435,8 @@ enum
+diff -urN mutt-1.6.1/mutt_curses.h mutt-1.6.1-sidebar/mutt_curses.h
+--- mutt-1.6.1/mutt_curses.h	2016-06-12 18:43:00.410447715 +0100
++++ mutt-1.6.1-sidebar/mutt_curses.h	2016-06-12 18:43:03.962503107 +0100
+@@ -64,6 +64,9 @@
+ #undef lines
+ #endif /* lines */
+ 
++#ifdef USE_SIDEBAR
++#define CLEARLINE_WIN(x) move (x,SidebarWidth), clrtoeol()
++#endif
+ #define CLEARLINE(x) move(x,0), clrtoeol()
+ #define CENTERLINE(x,y) move(y, (COLS-strlen(x))/2), addstr(x)
+ #define BEEP() do { if (option (OPTBEEP)) beep(); } while (0)
+@@ -124,6 +127,14 @@
+   MT_COLOR_UNDERLINE,
+   MT_COLOR_INDEX,
+   MT_COLOR_PROMPT,
++#ifdef USE_SIDEBAR
++  MT_COLOR_DIVIDER,
++  MT_COLOR_FLAGGED,
++  MT_COLOR_HIGHLIGHT,
++  MT_COLOR_NEW,
++  MT_COLOR_SB_INDICATOR,
++  MT_COLOR_SB_SPOOLFILE,
++#endif
+   MT_COLOR_MAX
+ };
+ 
+@@ -163,12 +174,16 @@
+ 
+ static inline int mutt_term_width(short wrap)
+ {
++  int cols = COLS;
++#ifdef USE_SIDEBAR
++  cols -= SidebarWidth;
++#endif
+   if (wrap < 0)
+-    return COLS > -wrap ? COLS + wrap : COLS;
++    return cols > -wrap ? cols + wrap : cols;
+   else if (wrap)
+-    return wrap < COLS ? wrap : COLS;
++    return wrap < cols ? wrap : cols;
+   else
+-    return COLS;
++    return cols;
+ }
+ 
+ extern int *ColorQuote;
+diff -urN mutt-1.6.1/mutt.h mutt-1.6.1-sidebar/mutt.h
+--- mutt-1.6.1/mutt.h	2016-06-12 18:43:00.410447715 +0100
++++ mutt-1.6.1-sidebar/mutt.h	2016-06-12 18:43:03.962503107 +0100
+@@ -428,6 +428,13 @@
    OPTSAVEEMPTY,
    OPTSAVENAME,
    OPTSCORE,
++#ifdef USE_SIDEBAR
 +  OPTSIDEBAR,
-+  OPTSIDEBARSORT,
++  OPTSIDEBARFOLDERINDENT,
++  OPTSIDEBARNEWMAILONLY,
++  OPTSIDEBARNEXTNEWWRAP,
++  OPTSIDEBARSHORTPATH,
++#endif
    OPTSIGDASHES,
    OPTSIGONTOP,
    OPTSORTRE,
-@@ -880,6 +882,7 @@ typedef struct _context
+@@ -872,6 +879,9 @@
  {
    char *path;
    FILE *fp;
++#ifdef USE_SIDEBAR
 +  time_t atime;
++#endif
    time_t mtime;
    off_t size;
    off_t vsize;
-@@ -920,6 +923,7 @@ typedef struct _context
+@@ -906,6 +916,9 @@
    unsigned int quiet : 1;	/* inhibit status messages? */
    unsigned int collapsed : 1;   /* are all threads collapsed? */
    unsigned int closing : 1;	/* mailbox is being closed */
++#ifdef USE_SIDEBAR
 +  unsigned int peekonly : 1;	/* just taking a glance, revert atime */
++#endif
  
    /* driver hooks */
    void *data;			/* driver specific data */
-diff --git a/mutt_curses.h b/mutt_curses.h
-index f8bc47c..ef9884e 100644
---- a/mutt_curses.h
-+++ b/mutt_curses.h
-@@ -64,6 +64,7 @@
- #undef lines
- #endif /* lines */
- 
-+#define CLEARLINE_WIN(x) move(x,SidebarWidth), clrtoeol()
- #define CLEARLINE(x) move(x,0), clrtoeol()
- #define CENTERLINE(x,y) move(y, (COLS-strlen(x))/2), addstr(x)
- #define BEEP() do { if (option (OPTBEEP)) beep(); } while (0)
-@@ -121,6 +122,8 @@ enum
-   MT_COLOR_UNDERLINE,
-   MT_COLOR_INDEX,
-   MT_COLOR_PROMPT,
-+  MT_COLOR_NEW,
-+  MT_COLOR_FLAGGED,
-   MT_COLOR_MAX
- };
- 
-diff --git a/muttlib.c b/muttlib.c
-index c1d565f..039e7c3 100644
---- a/muttlib.c
-+++ b/muttlib.c
-@@ -1279,6 +1279,8 @@ void mutt_FormatString (char *dest,		/* output buffer */
+diff -urN mutt-1.6.1/muttlib.c mutt-1.6.1-sidebar/muttlib.c
+--- mutt-1.6.1/muttlib.c	2016-06-12 18:43:00.411447731 +0100
++++ mutt-1.6.1-sidebar/muttlib.c	2016-06-12 18:43:03.963503122 +0100
+@@ -1282,7 +1282,7 @@
  	  pl = pw = 1;
  
  	/* see if there's room to add content, else ignore */
-+        if ( DrawFullLine )
-+        {
- 	if ((col < COLS && wlen < destlen) || soft)
+-	if ((col < COLS && wlen < destlen) || soft)
++	if ((col < (COLS - SidebarWidth) && (wlen < destlen)) || soft)
  	{
  	  int pad;
-@@ -1322,6 +1324,52 @@ void mutt_FormatString (char *dest,		/* output buffer */
- 	  col += wid;
- 	  src += pl;
- 	}
-+        }
-+        else
-+        {
-+	if ((col < COLS-SidebarWidth && wlen < destlen) || soft)
-+        {
-+	  int pad;
-+
-+	  /* get contents after padding */
-+	  mutt_FormatString (buf, sizeof (buf), 0, src + pl, callback, data, flags);
-+	  len = mutt_strlen (buf);
-+	  wid = mutt_strwidth (buf);
-+
-+	  /* try to consume as many columns as we can, if we don't have
-+	   * memory for that, use as much memory as possible */
+ 
+@@ -1293,7 +1293,7 @@
+ 
+ 	  /* try to consume as many columns as we can, if we don't have
+ 	   * memory for that, use as much memory as possible */
+-	  pad = (COLS - col - wid) / pw;
 +	  pad = (COLS - SidebarWidth - col - wid) / pw;
-+	  if (pad > 0 && wlen + (pad * pl) + len > destlen)
-+	    pad = ((signed)(destlen - wlen - len)) / pl;
-+	  if (pad > 0)
-+	  {
-+	    while (pad--)
-+	    {
-+	      memcpy (wptr, src, pl);
-+	      wptr += pl;
-+	      wlen += pl;
-+	      col += pw;
-+	    }
-+	  }
-+	  else if (soft && pad < 0)
-+	  {
-+	    /* \0-terminate dest for length computation in mutt_wstr_trunc() */
-+	    *wptr = 0;
-+	    /* make sure right part is at most as wide as display */
-+	    len = mutt_wstr_trunc (buf, destlen, COLS, &wid);
-+	    /* truncate left so that right part fits completely in */
-+	    wlen = mutt_wstr_trunc (dest, destlen - len, col + pad, &col);
-+	    wptr = dest + wlen;
-+	  }
-+	  if (len + wlen > destlen)
+ 	  if (pad > 0 && wlen + (pad * pl) + len > destlen)
+ 	    pad = ((signed)(destlen - wlen - len)) / pl;
+ 	  if (pad > 0)
+@@ -1312,13 +1312,13 @@
+ 	    /* \0-terminate dest for length computation in mutt_wstr_trunc() */
+ 	    *wptr = 0;
+ 	    /* make sure right part is at most as wide as display */
+-	    len = mutt_wstr_trunc (buf, destlen, COLS-offset, &wid);
++	    len = mutt_wstr_trunc (buf, destlen, COLS - offset - SidebarWidth, &wid);
+ 	    /* truncate left so that right part fits completely in */
+ 	    wlen = mutt_wstr_trunc (dest, destlen - len, col + pad*pw -offset, &col);
+ 	    wptr = dest + wlen;
+ 	  }
+ 	  if (len + wlen > destlen)
+-	    len = mutt_wstr_trunc (buf, destlen - wlen, COLS - col, NULL);
 +	    len = mutt_wstr_trunc (buf, destlen - wlen, COLS - SidebarWidth - col, NULL);
-+	  memcpy (wptr, buf, len);
-+	  wptr += len;
-+	  wlen += len;
-+	  col += wid;
-+	  src += pl;
-+	}
-+        }
- 	break; /* skip rest of input */
-       }
-       else if (ch == '|')
-diff --git a/mx.c b/mx.c
-index 0a1a80e..e80b8ff 100644
---- a/mx.c
-+++ b/mx.c
-@@ -595,6 +595,7 @@ static int mx_open_mailbox_append (CONTEXT *ctx, int flags)
+ 	  memcpy (wptr, buf, len);
+ 	  wptr += len;
+ 	  wlen += len;
+diff -urN mutt-1.6.1/mutt_menu.h mutt-1.6.1-sidebar/mutt_menu.h
+--- mutt-1.6.1/mutt_menu.h	2016-06-12 18:43:00.410447715 +0100
++++ mutt-1.6.1-sidebar/mutt_menu.h	2016-06-12 18:43:03.962503107 +0100
+@@ -34,6 +34,9 @@
+ #define REDRAW_FULL		(1<<5)
+ #define REDRAW_BODY		(1<<6)
+ #define REDRAW_SIGWINCH		(1<<7)
++#ifdef USE_SIDEBAR
++#define REDRAW_SIDEBAR		(1<<8)
++#endif
+ 
+ #define M_MODEFMT "-- Mutt: %s"
+ 
+diff -urN mutt-1.6.1/mx.c mutt-1.6.1-sidebar/mx.c
+--- mutt-1.6.1/mx.c	2016-06-12 18:43:00.411447731 +0100
++++ mutt-1.6.1-sidebar/mx.c	2016-06-12 18:43:03.963503122 +0100
+@@ -29,6 +29,9 @@
+ #include "copy.h"
+ #include "keymap.h"
+ #include "url.h"
++#ifdef USE_SIDEBAR
++#include "sidebar.h"
++#endif
+ 
+ #ifdef USE_IMAP
+ #include "imap.h"
+@@ -580,6 +583,7 @@
   *		M_APPEND	open mailbox for appending
   *		M_READONLY	open mailbox in read-only mode
   *		M_QUIET		only print error messages
@@ -941,70 +2866,128 @@ index 0a1a80e..e80b8ff 100644
   *	ctx	if non-null, context struct to use
   */
  CONTEXT *mx_open_mailbox (const char *path, int flags, CONTEXT *pctx)
-@@ -617,6 +618,8 @@ CONTEXT *mx_open_mailbox (const char *path, int flags, CONTEXT *pctx)
+@@ -602,6 +606,10 @@
      ctx->quiet = 1;
    if (flags & M_READONLY)
      ctx->readonly = 1;
++#ifdef USE_SIDEBAR
 +  if (flags & M_PEEK)
 +    ctx->peekonly = 1;
++#endif
  
    if (flags & (M_APPEND|M_NEWFOLDER))
    {
-@@ -721,9 +724,21 @@ CONTEXT *mx_open_mailbox (const char *path, int flags, CONTEXT *pctx)
- void mx_fastclose_mailbox (CONTEXT *ctx)
- {
-   int i;
-+#ifndef BUFFY_SIZE
-+  struct utimbuf ut;
-+#endif
- 
+@@ -705,8 +713,21 @@
    if(!ctx) 
      return;
-+#ifndef BUFFY_SIZE
+ 
++#ifdef USE_SIDEBAR
 +  /* fix up the times so buffy won't get confused */
-+  if (ctx->peekonly && ctx->path && ctx->mtime > ctx->atime)
-+  {
-+    ut.actime = ctx->atime;
++  struct utimbuf ut;
++  if (ctx->peekonly && ctx->path && (ctx->mtime > ctx->atime)) {
++    ut.actime  = ctx->atime;
 +    ut.modtime = ctx->mtime;
-+    utime (ctx->path, &ut); 
++    utime (ctx->path, &ut);
 +  }
 +#endif
- 
++
    /* never announce that a mailbox we've just left has new mail. #3290
     * XXX: really belongs in mx_close_mailbox, but this is a nice hook point */
-diff --git a/mx.h b/mx.h
-index 2ef4ec7..4aabadf 100644
---- a/mx.h
-+++ b/mx.h
-@@ -60,6 +60,7 @@ void mbox_reset_atime (CONTEXT *, struct stat *);
++#ifdef USE_SIDEBAR
++  if (!ctx->peekonly)
++#endif
+   mutt_buffy_setnotified(ctx->path);
+ 
+   if (ctx->mx_close)
+@@ -812,6 +833,12 @@
+     if (!ctx->hdrs[i]->deleted && ctx->hdrs[i]->read 
+         && !(ctx->hdrs[i]->flagged && option (OPTKEEPFLAGGED)))
+       read_msgs++;
++#ifdef USE_SIDEBAR
++    if (ctx->hdrs[i]->deleted && !ctx->hdrs[i]->read)
++      ctx->unread--;
++    if (ctx->hdrs[i]->deleted && ctx->hdrs[i]->flagged)
++      ctx->flagged--;
++#endif
+   }
+ 
+   if (read_msgs && quadoption (OPT_MOVE) != M_NO)
+@@ -981,6 +1008,11 @@
+       !mutt_is_spool(ctx->path) && !option (OPTSAVEEMPTY))
+     mx_unlink_empty (ctx->path);
+ 
++#ifdef USE_SIDEBAR
++  ctx->msgcount -= ctx->deleted;
++  mutt_sb_set_buffystats (ctx);
++#endif
++
+   mx_fastclose_mailbox (ctx);
+ 
+   return 0;
+diff -urN mutt-1.6.1/mx.h mutt-1.6.1-sidebar/mx.h
+--- mutt-1.6.1/mx.h	2016-06-12 18:43:00.411447731 +0100
++++ mutt-1.6.1-sidebar/mx.h	2016-06-12 18:43:03.963503122 +0100
+@@ -26,6 +26,7 @@
+ #define _MX_H
+ 
+ #include "mailbox.h"
++#include "buffy.h"
+ 
+ /* supported mailbox formats */
+ enum
+@@ -57,6 +58,9 @@
  int mh_read_dir (CONTEXT *, const char *);
  int mh_sync_mailbox (CONTEXT *, int *);
  int mh_check_mailbox (CONTEXT *, int *);
-+void mh_buffy_update (const char *, int *, int *, int *);
++#ifdef USE_SIDEBAR
++void mh_buffy_update (BUFFY *mailbox);
++#endif
  int mh_check_empty (const char *);
  
  int maildir_read_dir (CONTEXT *);
-diff --git a/pager.c b/pager.c
-index c99f1e4..5cfcb75 100644
---- a/pager.c
-+++ b/pager.c
-@@ -29,6 +29,7 @@
+diff -urN mutt-1.6.1/OPS.SIDEBAR mutt-1.6.1-sidebar/OPS.SIDEBAR
+--- mutt-1.6.1/OPS.SIDEBAR	1970-01-01 01:00:00.000000000 +0100
++++ mutt-1.6.1-sidebar/OPS.SIDEBAR	2016-06-12 18:43:03.944502826 +0100
+@@ -0,0 +1,8 @@
++OP_SIDEBAR_NEXT "Move the highlight to next mailbox"
++OP_SIDEBAR_NEXT_NEW "Move the highlight to next mailbox with new mail"
++OP_SIDEBAR_OPEN "Open highlighted mailbox"
++OP_SIDEBAR_PAGE_DOWN "Scroll the Sidebar down 1 page"
++OP_SIDEBAR_PAGE_UP "Scroll the Sidebar up 1 page"
++OP_SIDEBAR_PREV "Move the highlight to previous mailbox"
++OP_SIDEBAR_PREV_NEW "Move the highlight to previous mailbox with new mail"
++OP_SIDEBAR_TOGGLE_VISIBLE "Make the Sidebar (in)visible"
+diff -urN mutt-1.6.1/pager.c mutt-1.6.1-sidebar/pager.c
+--- mutt-1.6.1/pager.c	2016-06-12 18:43:00.412447746 +0100
++++ mutt-1.6.1-sidebar/pager.c	2016-06-12 18:43:03.964503138 +0100
+@@ -29,6 +29,9 @@
  #include "pager.h"
  #include "attach.h"
  #include "mbyte.h"
++#ifdef USE_SIDEBAR
 +#include "sidebar.h"
++#endif
  
  #include "mutt_crypt.h"
  
-@@ -1095,6 +1096,7 @@ static int format_line (struct line_t **lineInfo, int n, unsigned char *buf,
-   wchar_t wc;
-   mbstate_t mbstate;
-   int wrap_cols = mutt_term_width ((flags & M_PAGER_NOWRAP) ? 0 : Wrap);
-+  wrap_cols -= SidebarWidth;
+@@ -1491,7 +1494,7 @@
+    * a newline (grr!).
+    */
+ #ifndef USE_SLANG_CURSES
+-    if (col < COLS)
++    if (col < (COLS - SidebarWidth))
+ #endif
+       addch ('\n');
+ 
+@@ -1573,6 +1576,7 @@
  
-   if (check_attachment_marker ((char *)buf) == 0)
-     wrap_cols = COLS;
-@@ -1746,7 +1748,7 @@ mutt_pager (const char *banner, const char *fname, int flags, pager_t *extra)
+   int bodyoffset = 1;			/* offset of first line of real text */
+   int statusoffset = 0; 		/* offset for the status bar */
++  int statuswidth = COLS;
+   int helpoffset = LINES - 2;		/* offset for the help bar. */
+   int bodylen = LINES - 2 - bodyoffset; /* length of displayable area */
+ 
+@@ -1747,7 +1751,7 @@
      if ((redraw & REDRAW_BODY) || topline != oldtopline)
      {
        do {
@@ -1013,465 +2996,1455 @@ index c99f1e4..5cfcb75 100644
  	curline = oldtopline = topline;
  	lines = 0;
  	force_redraw = 0;
-@@ -1759,6 +1761,7 @@ mutt_pager (const char *banner, const char *fname, int flags, pager_t *extra)
+@@ -1760,6 +1764,9 @@
  			    &QuoteList, &q_level, &force_redraw, &SearchRE) > 0)
  	    lines++;
  	  curline++;
-+  	  move(lines + bodyoffset, SidebarWidth);
++#ifdef USE_SIDEBAR
++	  move (lines + bodyoffset, SidebarWidth);
++#endif
  	}
  	last_offset = lineInfo[curline].offset;
        } while (force_redraw);
-@@ -1771,6 +1774,7 @@ mutt_pager (const char *banner, const char *fname, int flags, pager_t *extra)
+@@ -1772,6 +1779,9 @@
  	  addch ('~');
  	addch ('\n');
  	lines++;
-+  	move(lines + bodyoffset, SidebarWidth);
++#ifdef USE_SIDEBAR
++	move (lines + bodyoffset, SidebarWidth);
++#endif
        }
        NORMAL_COLOR;
  
-@@ -1794,22 +1798,22 @@ mutt_pager (const char *banner, const char *fname, int flags, pager_t *extra)
+@@ -1789,29 +1799,49 @@
+       hfi.ctx = Context;
+       hfi.pager_progress = pager_progress_str;
+ 
++#ifdef USE_SIDEBAR
++      statuswidth = COLS;
++      if (option (OPTSTATUSONTOP) && (PagerIndexLines > 0))
++        statuswidth -= SidebarWidth;
++#endif
++
+       if (last_pos < sb.st_size - 1)
+ 	snprintf(pager_progress_str, sizeof(pager_progress_str), OFF_T_FMT "%%", (100 * last_offset / sb.st_size));
+       else
  	strfcpy(pager_progress_str, (topline == 0) ? "all" : "end", sizeof(pager_progress_str));
  
        /* print out the pager status bar */
 -      move (statusoffset, 0);
 +      move (statusoffset, SidebarWidth);
        SETCOLOR (MT_COLOR_STATUS);
++#ifdef USE_SIDEBAR
++      short sw = SidebarWidth;
++      if (option (OPTSTATUSONTOP) && PagerIndexLines > 0) {
++        CLEARLINE_WIN (statusoffset);
++      } else {
++        CLEARLINE (statusoffset);
++        /* Temporarily lie about the sidebar width */
++        SidebarWidth = 0;
++      }
++#endif
  
        if (IsHeader (extra) || IsMsgAttach (extra))
        {
 -	size_t l1 = COLS * MB_LEN_MAX;
-+	size_t l1 = (COLS-SidebarWidth) * MB_LEN_MAX;
++	size_t l1 = statuswidth * MB_LEN_MAX;
  	size_t l2 = sizeof (buffer);
  	hfi.hdr = (IsHeader (extra)) ? extra->hdr : extra->bdy->hdr;
  	mutt_make_string_info (buffer, l1 < l2 ? l1 : l2, NONULL (PagerFmt), &hfi, M_FORMAT_MAKEPRINT);
 -	mutt_paddstr (COLS, buffer);
-+	mutt_paddstr (COLS-SidebarWidth, buffer);
++	mutt_paddstr (statuswidth, buffer);
        }
        else
        {
  	char bn[STRING];
  	snprintf (bn, sizeof (bn), "%s (%s)", banner, pager_progress_str);
 -	mutt_paddstr (COLS, bn);
-+	mutt_paddstr (COLS-SidebarWidth, bn);
++	mutt_paddstr (statuswidth, bn);
        }
++#ifdef USE_SIDEBAR
++      if (!option (OPTSTATUSONTOP) || PagerIndexLines == 0)
++        SidebarWidth = sw; /* Restore the sidebar width */
++#endif
        NORMAL_COLOR;
        if (option(OPTTSENABLED) && TSSupported)
-@@ -1826,16 +1830,21 @@ mutt_pager (const char *banner, const char *fname, int flags, pager_t *extra)
+       {
+@@ -1827,16 +1857,26 @@
        /* redraw the pager_index indicator, because the
         * flags for this message might have changed. */
        menu_redraw_current (index);
-+      draw_sidebar(MENU_PAGER);
++#ifdef USE_SIDEBAR
++      mutt_sb_draw();
++#endif
  
        /* 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);
++      move (indexoffset + (option (OPTSTATUSONTOP) ? 0 : (indexlen - 1)),
++          (option(OPTSTATUSONTOP) ? 0: SidebarWidth));
        SETCOLOR (MT_COLOR_STATUS);
 -      mutt_paddstr (COLS, buffer);
-+      mutt_paddstr (COLS-SidebarWidth, buffer);
++      mutt_paddstr (COLS - (option(OPTSTATUSONTOP) ? 0 : SidebarWidth), buffer);
        NORMAL_COLOR;
      }
  
++#ifdef USE_SIDEBAR
 +    /* if we're not using the index, update every time */
-+    if ( index == 0 )
-+      draw_sidebar(MENU_PAGER);
++    if (index == 0)
++      mutt_sb_draw();
++#endif
 +
      redraw = 0;
  
      if (option(OPTBRAILLEFRIENDLY)) {
-@@ -2776,6 +2785,13 @@ search_next:
+@@ -2498,8 +2538,12 @@
+ 	  ch = 0;
+ 	}
+ 
+-	if (option (OPTFORCEREDRAWPAGER))
++	if (option (OPTFORCEREDRAWPAGER)) {
+ 	  redraw = REDRAW_FULL;
++#ifdef USE_SIDEBAR
++	  mutt_sb_draw();
++#endif
++	}
+ 	unset_option (OPTFORCEREDRAWINDEX);
+ 	unset_option (OPTFORCEREDRAWPAGER);
+ 	break;
+@@ -2777,6 +2821,22 @@
  	mutt_what_key ();
  	break;
  
-+      case OP_SIDEBAR_SCROLL_UP:
-+      case OP_SIDEBAR_SCROLL_DOWN:
++#ifdef USE_SIDEBAR
 +      case OP_SIDEBAR_NEXT:
++      case OP_SIDEBAR_NEXT_NEW:
++      case OP_SIDEBAR_PAGE_DOWN:
++      case OP_SIDEBAR_PAGE_UP:
 +      case OP_SIDEBAR_PREV:
-+	scroll_sidebar(ch, MENU_PAGER);
-+ 	break;
++      case OP_SIDEBAR_PREV_NEW:
++	mutt_sb_change_mailbox (ch);
++	break;
++
++      case OP_SIDEBAR_TOGGLE_VISIBLE:
++	toggle_option (OPTSIDEBAR);
++	redraw = REDRAW_FULL;
++	break;
++#endif
 +
        default:
  	ch = -1;
  	break;
-diff --git a/sidebar.c b/sidebar.c
-new file mode 100644
-index 0000000..6098c2a
---- /dev/null
-+++ b/sidebar.c
-@@ -0,0 +1,333 @@
-+/*
-+ * Copyright (C) ????-2004 Justin Hibbits <jrh29@po.cwru.edu>
+diff -urN mutt-1.6.1/PATCHES mutt-1.6.1-sidebar/PATCHES
+--- mutt-1.6.1/PATCHES	2016-06-12 18:43:00.395447481 +0100
++++ mutt-1.6.1-sidebar/PATCHES	2016-06-12 18:43:03.949502904 +0100
+@@ -0,0 +1 @@
++patch-sidebar-neo-20160612
+diff -urN mutt-1.6.1/README.sidebar mutt-1.6.1-sidebar/README.sidebar
+--- mutt-1.6.1/README.sidebar	1970-01-01 01:00:00.000000000 +0100
++++ mutt-1.6.1-sidebar/README.sidebar	2016-06-12 18:43:03.792500456 +0100
+@@ -0,0 +1,145 @@
++Sidebar Patch
++=============
++
++    Overview of mailboxes
++
++    NOTES:
++
++    If you haven't used the sidebar before, you might like to read the
++    Sidebar Introduction:
++
++        http://www.neomutt.org/sidebar-intro.html
++
++    If you have used an older version of the Sidebar, please note that some
++    of the configuration has changed.
++
++        http://www.neomutt.org/sidebar-intro.html#intro-sidebar-config-changes
++
++Patch
++-----
++
++    To check if Mutt supports "Sidebar", look for "+USE_SIDEBAR" in the mutt
++    version.
++
++    Dependencies
++    * mutt-1.6.1
++
++Introduction
++------------
++
++    The Sidebar shows a list of all your mailboxes. The list can be turned on
++    and off, it can be themed and the list style can be configured.
++
++    This part of the manual is a reference guide. If you want a simple
++    introduction with examples see the Sidebar Howto. If you just want to get
++    started, you could use the sample Sidebar muttrc.
++
++    This version of Sidebar is based on Terry Chan's [2015-11-11
++    release](http://www.lunar-linux.org/mutt-sidebar/). It contains many new
++    features, lots of bugfixes.
++
++Variables
++---------
++
++    Sidebar Variables
++
++    | Name                    | Type    | Default                     |
++    |-------------------------|---------|-----------------------------|
++    | 'sidebar_delim_chars'   | string  | '/.'                        |
++    | 'sidebar_divider_char'  | string  | '|'                         |
++    | 'sidebar_folder_indent' | boolean | 'no'                        |
++    | 'sidebar_format'        | string  | '%B%?F? [%F]?%* %?N?%N/?%S' |
++    | 'sidebar_indent_string' | string  | '  ' (two spaces)           |
++    | 'sidebar_new_mail_only' | boolean | 'no'                        |
++    | 'sidebar_next_new_wrap' | boolean | 'no'                        |
++    | 'sidebar_refresh_time'  | number  | '60'                        |
++    | 'sidebar_short_path'    | boolean | 'no'                        |
++    | 'sidebar_sort_method'   | enum    | 'SORT_ORDER'                |
++    | 'sidebar_visible'       | boolean | 'no'                        |
++    | 'sidebar_whitelist'     | list    | (empty)                     |
++    | 'sidebar_width'         | number  | '20'                        |
++
++Functions
++---------
++
++    Sidebar Functions
++
++    Sidebar adds the following functions to Mutt. By default, none of them are
++    bound to keys.
++
++    | Menus       | Function                   | Description                                          |
++    |-------------|----------------------------|------------------------------------------------------|
++    | index,pager | '<sidebar-next>'           | Move the highlight to next mailbox                   |
++    | index,pager | '<sidebar-next-new>'       | Move the highlight to next mailbox with new mail     |
++    | index,pager | '<sidebar-open>'           | Open highlighted mailbox                             |
++    | index,pager | '<sidebar-page-down>'      | Scroll the Sidebar down 1 page                       |
++    | index,pager | '<sidebar-page-up>'        | Scroll the Sidebar up 1 page                         |
++    | index,pager | '<sidebar-prev>'           | Move the highlight to previous mailbox               |
++    | index,pager | '<sidebar-prev-new>'       | Move the highlight to previous mailbox with new mail |
++    | index,pager | '<sidebar-toggle-visible>' | Make the Sidebar (in)visible                         |
++
++Commands
++--------
++
++        sidebar_whitelist mailbox [ mailbox... ]
++
++Colors
++------
++
++    Sidebar Colors
++
++    | Name                | Default Color    | Description                                                      |
++    |---------------------|------------------|------------------------------------------------------------------|
++    | 'sidebar_divider'   | default          | The dividing line between the Sidebar and the Index/Pager panels |
++    | 'sidebar_flagged'   | default          | Mailboxes containing flagged mail                                |
++    | 'sidebar_highlight' | underline        | Cursor to select a mailbox                                       |
++    | 'sidebar_indicator' | mutt 'indicator' | The mailbox open in the Index panel                              |
++    | 'sidebar_new'       | default          | Mailboxes containing new mail                                    |
++    | 'sidebar_spoolfile' | default          | Mailbox that receives incoming mail                              |
++
++    If the sidebar_indicator color isn't set, then the default Mutt indicator
++    color will be used (the color used in the index panel).
++
++Sort
++----
++
++    Sidebar Sort
++
++    | Sort       | Description                |
++    |------------|----------------------------|
++    | 'alpha'    | Alphabetically by path     |
++    | 'count'    | Total number of messages   |
++    | 'flagged'  | Number of flagged messages |
++    | 'name'     | Alphabetically by path     |
++    | 'new'      | Number of new messages     |
++    | 'path'     | Alphabetically by path     |
++    | 'unsorted' | Do not resort the paths    |
++
++See Also
++--------
++
++    * Regular Expressions
++    * Patterns
++    * Color command
++    * notmuch patch
++
++Known Bugs
++----------
++
++    Unsorted isn't
++
++Credits
++-------
++
++    * Justin Hibbits <jrh29@po.cwru.edu>
++    * Thomer M. Gil <mutt@thomer.com>
++    * David Sterba <dsterba@suse.cz>
++    * Evgeni Golov <evgeni@debian.org>
++    * Fabian Groffen <grobian@gentoo.org>
++    * Jason DeTiberus <jdetiber@redhat.com>
++    * Stefan Assmann <sassmann@kpanic.de>
++    * Steve Kemp <steve@steve.org.uk>
++    * Terry Chan <tchan@lunar-linux.org>
++    * Tyler Earnest <tylere@rne.st>
++    * Richard Russon <rich@flatcap.org>
++
+diff -urN mutt-1.6.1/sidebar.c mutt-1.6.1-sidebar/sidebar.c
+--- mutt-1.6.1/sidebar.c	1970-01-01 01:00:00.000000000 +0100
++++ mutt-1.6.1-sidebar/sidebar.c	2016-06-14 18:46:00.000000000 +0100
+@@ -0,0 +1,1090 @@
++/* Copyright (C) 2004 Justin Hibbits <jrh29@po.cwru.edu>
 + * Copyright (C) 2004 Thomer M. Gil <mutt@thomer.com>
-+ * 
++ * Copyright (C) 2015-2016 Richard Russon <rich@flatcap.org>
++ *
 + *     This program is free software; you can redistribute it and/or modify
 + *     it under the terms of the GNU General Public License as published by
 + *     the Free Software Foundation; either version 2 of the License, or
 + *     (at your option) any later version.
-+ * 
++ *
 + *     This program is distributed in the hope that it will be useful,
 + *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 + *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 + *     GNU General Public License for more details.
-+ * 
++ *
 + *     You should have received a copy of the GNU General Public License
 + *     along with this program; if not, write to the Free Software
 + *     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
-+ */ 
-+
++ */
 +
 +#if HAVE_CONFIG_H
 +# include "config.h"
 +#endif
 +
 +#include "mutt.h"
-+#include "mutt_menu.h"
-+#include "mutt_curses.h"
-+#include "sidebar.h"
 +#include "buffy.h"
-+#include <libgen.h>
 +#include "keymap.h"
-+#include <stdbool.h>
++#include "mutt_curses.h"
++#include "mutt_menu.h"
++#include "sort.h"
++
++/* Previous values for some sidebar config */
++static short  OldVisible;	/* sidebar_visible */
++static short  OldWidth;		/* sidebar_width */
++static short  PreviousSort;	/* sidebar_sort_method */
++static time_t LastRefresh;	/* Time of last refresh */
++
++/* Keep track of various BUFFYs */
++static BUFFY *TopBuffy;		/* First mailbox visible in sidebar */
++static BUFFY *OpnBuffy;		/* Current (open) mailbox */
++static BUFFY *HilBuffy;		/* Highlighted mailbox */
++static BUFFY *BotBuffy;		/* Last mailbox visible in sidebar */
++static BUFFY *Outgoing;		/* Last mailbox in the linked list */
++
++/**
++ * struct sidebar_entry - Info about folders in the sidebar
++ *
++ * Used in the mutt_FormatString callback
++ */
++struct sidebar_entry
++{
++  char         box[STRING];
++  BUFFY       *buffy;
++};
 +
-+/*BUFFY *CurBuffy = 0;*/
-+static BUFFY *TopBuffy = 0;
-+static BUFFY *BottomBuffy = 0;
-+static int known_lines = 0;
 +
-+static int quick_log10(int n)
++/**
++ * find_next_new - Find the next folder that contains new mail
++ * @wrap: Wrap around to the beginning if the end is reached
++ *
++ * Search down the list of mail folders for one containing new mail.
++ *
++ * Returns:
++ *	BUFFY*: Success
++ *	NULL:   Failure
++ */
++static BUFFY *find_next_new (int wrap)
 +{
-+        char string[32];
-+        sprintf(string, "%d", n);
-+        return strlen(string);
++  BUFFY *b = HilBuffy;
++  if (!b)
++    return NULL;
++
++  do
++  {
++    b = b->next;
++    if (!b && wrap)
++      b = Incoming;
++    if (!b || (b == HilBuffy))
++      break;
++    if (b->msg_unread > 0)
++      return b;
++  } while (b);
++
++  return NULL;
 +}
 +
-+void calc_boundaries (int menu)
++/**
++ * find_prev_new - Find the previous folder that contains new mail
++ * @wrap: Wrap around to the beginning if the end is reached
++ *
++ * Search up the list of mail folders for one containing new mail.
++ *
++ * Returns:
++ *	BUFFY*: Success
++ *	NULL:   Failure
++ */
++static BUFFY *find_prev_new (int wrap)
 +{
-+	BUFFY *tmp = Incoming;
++  BUFFY *b = HilBuffy;
++  if (!b)
++    return NULL;
 +
-+	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 || option(OPTSTATUSONTOP));
-+		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;
-+	}
++  do
++  {
++    b = b->prev;
++    if (!b && wrap)
++      b = Outgoing;
++    if (!b || (b == HilBuffy))
++      break;
++    if (b->msg_unread > 0)
++      return b;
++  } while (b);
++
++  return NULL;
 +}
 +
-+char *make_sidebar_entry(char *box, int size, int new, int flagged)
++/**
++ * cb_format_str - Create the string to show in the sidebar
++ * @dest:        Buffer in which to save string
++ * @destlen:     Buffer length
++ * @col:         Starting column, UNUSED
++ * @op:          printf-like operator, e.g. 'B'
++ * @src:         printf-like format string
++ * @prefix:      Field formatting string, UNUSED
++ * @ifstring:    If condition is met, display this string
++ * @elsestring:  Otherwise, display this string
++ * @data:        Pointer to our sidebar_entry
++ * @flags:       Format flags, e.g. M_FORMAT_OPTIONAL
++ *
++ * cb_format_str is a callback function for mutt_FormatString.  It understands
++ * five operators. '%B' : Mailbox name, '%F' : Number of flagged messages,
++ * '%N' : Number of new messages, '%S' : Size (total number of messages),
++ * '%!' : Icon denoting number of flagged messages.
++ *
++ * Returns: src (unchanged)
++ */
++static const char *cb_format_str(char *dest, size_t destlen, size_t col, char op,
++                                 const char *src, const char *prefix, const char *ifstring,
++                                 const char *elsestring, unsigned long data, format_flag flags)
 +{
-+	static char *entry = 0;
-+	char *c;
-+	int i = 0;
-+	int delim_len = strlen(SidebarDelim);
-+
-+	c = realloc(entry, SidebarWidth - delim_len + 2);
-+	if ( c ) entry = c;
-+	entry[SidebarWidth - delim_len + 1] = 0;
-+	for (; i < SidebarWidth - delim_len + 1; entry[i++] = ' ' );
-+	i = strlen(box);
-+	strncpy( entry, box, i < (SidebarWidth - delim_len + 1) ? i : (SidebarWidth - delim_len + 1) );
-+
-+        if (size == -1)
-+                sprintf(entry + SidebarWidth - delim_len - 3, "?");
-+        else if ( new ) {
-+          if (flagged > 0) {
-+              sprintf(
-+		        entry + SidebarWidth - delim_len - 5 - quick_log10(size) - quick_log10(new) - quick_log10(flagged),
-+		        "% d(%d)[%d]", size, new, flagged);
-+          } else {
-+              sprintf(
-+                      entry + SidebarWidth - delim_len - 3 - quick_log10(size) - quick_log10(new),
-+                      "% d(%d)", size, new);
-+          }
-+        } else if (flagged > 0) {
-+              sprintf( entry + SidebarWidth - delim_len - 3 - quick_log10(size) - quick_log10(flagged), "% d[%d]", size, flagged);
-+        } else {
-+              sprintf( entry + SidebarWidth - delim_len - 1 - quick_log10(size), "% d", size);
-+        }
-+	return entry;
++  struct sidebar_entry *sbe = (struct sidebar_entry *) data;
++  unsigned int optional;
++  char fmt[STRING];
++
++  if (!sbe || !dest)
++    return src;
++
++  dest[0] = 0;	/* Just in case there's nothing to do */
++
++  BUFFY *b = sbe->buffy;
++  if (!b)
++    return src;
++
++  int c = Context && (mutt_strcmp (Context->path, b->path) == 0);
++
++  optional = flags & M_FORMAT_OPTIONAL;
++
++  switch (op)
++  {
++    case 'B':
++      mutt_format_s (dest, destlen, prefix, sbe->box);
++      break;
++
++    case 'd':
++      if (!optional)
++      {
++        snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
++        snprintf (dest, destlen, fmt, c ? Context->deleted : 0);
++      }
++      else if ((c && Context->deleted == 0) || !c)
++        optional = 0;
++      break;
++
++    case 'F':
++      if (!optional)
++      {
++        snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
++        snprintf (dest, destlen, fmt, b->msg_flagged);
++      }
++      else if (b->msg_flagged == 0)
++        optional = 0;
++      break;
++
++    case 'L':
++      if (!optional)
++      {
++        snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
++        snprintf (dest, destlen, fmt, c ? Context->vcount : b->msg_count);
++      }
++      else if ((c && Context->vcount == b->msg_count) || !c)
++        optional = 0;
++      break;
++
++    case 'N':
++      if (!optional)
++      {
++        snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
++        snprintf (dest, destlen, fmt, b->msg_unread);
++      }
++      else if (b->msg_unread == 0)
++        optional = 0;
++      break;
++
++    case 'S':
++      if (!optional)
++      {
++        snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
++        snprintf (dest, destlen, fmt, b->msg_count);
++      }
++      else if (b->msg_count == 0)
++        optional = 0;
++      break;
++
++    case 't':
++      if (!optional)
++      {
++        snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
++        snprintf (dest, destlen, fmt, c ? Context->tagged : 0);
++      }
++      else if ((c && Context->tagged == 0) || !c)
++        optional = 0;
++      break;
++
++    case '!':
++      if (b->msg_flagged == 0)
++        mutt_format_s (dest, destlen, prefix, "");
++      else if (b->msg_flagged == 1)
++        mutt_format_s (dest, destlen, prefix, "!");
++      else if (b->msg_flagged == 2)
++        mutt_format_s (dest, destlen, prefix, "!!");
++      else
++      {
++        snprintf (fmt, sizeof (fmt), "%d!", b->msg_flagged);
++        mutt_format_s (dest, destlen, prefix, fmt);
++      }
++      break;
++  }
++
++  if (optional)
++    mutt_FormatString (dest, destlen, col, ifstring,   cb_format_str, (unsigned long) sbe, flags);
++  else if (flags & M_FORMAT_OPTIONAL)
++    mutt_FormatString (dest, destlen, col, elsestring, cb_format_str, (unsigned long) sbe, flags);
++
++  /* We return the format string, unchanged */
++  return src;
 +}
 +
-+void set_curbuffy(char buf[LONG_STRING])
++/**
++ * make_sidebar_entry - Turn mailbox data into a sidebar string
++ * @buf:     Buffer in which to save string
++ * @buflen:  Buffer length
++ * @width:   Desired width in screen cells
++ * @box:     Mailbox name
++ * @size:    Size (total number of messages)
++ * @new:     Number of new messages
++ * @flagged: Number of flagged messages
++ *
++ * Take all the relevant mailbox data and the desired screen width and then get
++ * mutt_FormatString to do the actual work. mutt_FormatString will callback to
++ * us using cb_format_str() for the sidebar specific formatting characters.
++ */
++static void make_sidebar_entry (char *buf, unsigned int buflen, int width, char *box,
++                                BUFFY *b)
 +{
-+  BUFFY* tmp = CurBuffy = Incoming;
++  struct sidebar_entry sbe;
 +
-+  if (!Incoming)
++  if (!buf || !box || !b)
 +    return;
 +
-+  while(1) {
-+    if(!strcmp(tmp->path, buf)) {
-+      CurBuffy = tmp;
++  sbe.buffy = b;
++  strfcpy (sbe.box, box, sizeof (sbe.box));
++
++  /* Temporarily lie about the screen width */
++  int oc = COLS;
++  COLS = width + SidebarWidth;
++  mutt_FormatString (buf, buflen, 0, NONULL(SidebarFormat), cb_format_str, (unsigned long) &sbe, 0);
++  COLS = oc;
++
++  /* Force string to be exactly the right width */
++  int w = mutt_strwidth (buf);
++  int s = strlen (buf);
++  width = MIN(buflen, width);
++  if (w < width)
++  {
++    /* Pad with spaces */
++    memset (buf + s, ' ', width - w);
++    buf[s + width - w] = 0;
++  }
++  else if (w > width)
++  {
++    /* Truncate to fit */
++    int len = mutt_wstr_trunc (buf, buflen, width, NULL);
++    buf[len] = 0;
++  }
++}
++
++/**
++ * cb_qsort_buffy - qsort callback to sort BUFFYs
++ * @a: First  BUFFY to compare
++ * @b: Second BUFFY to compare
++ *
++ * Compare the paths of two BUFFYs taking the locale into account.
++ *
++ * Returns:
++ *	-1: a precedes b
++ *	 0: a and b are identical
++ *	 1: b precedes a
++ */
++static int cb_qsort_buffy (const void *a, const void *b)
++{
++  const BUFFY *b1 = *(const BUFFY **) a;
++  const BUFFY *b2 = *(const BUFFY **) b;
++
++  /* Special case -- move hidden BUFFYs to the end */
++  if (b1->is_hidden != b2->is_hidden)
++  {
++    if (b1->is_hidden)
++      return 1;
++    else
++      return -1;
++  }
++
++  int result = 0;
++
++  switch ((SidebarSortMethod & SORT_MASK))
++  {
++    case SORT_COUNT:
++      result = (b2->msg_count - b1->msg_count);
++      break;
++    case SORT_COUNT_NEW:
++      result = (b2->msg_unread - b1->msg_unread);
++      break;
++    case SORT_FLAGGED:
++      result = (b2->msg_flagged - b1->msg_flagged);
 +      break;
++    case SORT_PATH:
++      result = mutt_strcasecmp (b1->path, b2->path);
++      break;
++  }
++
++  if (SidebarSortMethod & SORT_REVERSE)
++    result = -result;
++
++  return result;
++}
++
++/**
++ * buffy_going - Prevent our pointers becoming invalid
++ * @b: BUFFY about to be deleted
++ *
++ * If we receive a delete-notification for a BUFFY, we need to change any
++ * pointers we have to reference a different BUFFY, or set them to NULL.
++ *
++ * We don't update the prev/next pointers, they'll be fixed on the next
++ * call to prepare_sidebar().
++ *
++ * Returns:
++ *	A valid alternative BUFFY, or NULL
++ */
++static BUFFY *buffy_going (const BUFFY *b)
++{
++  if (!b)
++    return NULL;
++
++  if (b->prev)
++  {
++    b->prev->next = NULL;
++  }
++
++  if (b->next)
++  {
++    b->next->prev = NULL;
++    return b->next;
++  }
++
++  return b->prev;
++}
++
++/**
++ * update_buffy_visibility - Should a BUFFY be displayed in the sidebar
++ * @arr:     array of BUFFYs
++ * @arr_len: number of BUFFYs in array
++ *
++ * For each BUFFY in the array, check whether we should display it.
++ * This is determined by several criteria.  If the BUFFY:
++ *	is the currently open mailbox
++ *	is the currently highlighted mailbox
++ *	has unread messages
++ *	has flagged messages
++ *	is whitelisted
++ */
++static void update_buffy_visibility (BUFFY **arr, int arr_len)
++{
++  if (!arr)
++    return;
++
++  short new_only = option (OPTSIDEBARNEWMAILONLY);
++
++  BUFFY *b;
++  int i;
++  for (i = 0; i < arr_len; i++)
++  {
++    b = arr[i];
++
++    b->is_hidden = 0;
++
++    if (!new_only)
++      continue;
++
++    if ((b == OpnBuffy) || (b->msg_unread  > 0) ||
++        (b == HilBuffy) || (b->msg_flagged > 0))
++      continue;
++
++    if (Context && (strcmp (b->path, Context->path) == 0))
++      /* Spool directory */
++      continue;
++
++    if (mutt_find_list (SidebarWhitelist, b->path))
++      /* Explicitly asked to be visible */
++      continue;
++
++    b->is_hidden = 1;
++  }
++}
++
++/**
++ * sort_buffy_array - Sort an array of BUFFY pointers
++ * @arr:     array of BUFFYs
++ * @arr_len: number of BUFFYs in array
++ *
++ * Sort an array of BUFFY pointers according to the current sort config
++ * option "sidebar_sort_method". This calls qsort to do the work which calls our
++ * callback function "cb_qsort_buffy".
++ *
++ * Once sorted, the prev/next links will be reconstructed.
++ */
++static void sort_buffy_array (BUFFY **arr, int arr_len)
++{
++  if (!arr)
++    return;
++
++  /* These are the only sort methods we understand */
++  short ssm = (SidebarSortMethod & SORT_MASK);
++  if ((ssm == SORT_COUNT)     ||
++      (ssm == SORT_COUNT_NEW) ||
++      (ssm == SORT_DESC)      ||
++      (ssm == SORT_FLAGGED)   ||
++      (ssm == SORT_PATH))
++    qsort (arr, arr_len, sizeof (*arr), cb_qsort_buffy);
++
++  int i;
++  for (i = 0; i < (arr_len - 1); i++)
++    arr[i]->next = arr[i + 1];
++  arr[arr_len - 1]->next = NULL;
++
++  for (i = 1; i < arr_len; i++)
++    arr[i]->prev = arr[i - 1];
++  arr[0]->prev = NULL;
++}
++
++/**
++ * prepare_sidebar - Prepare the list of BUFFYs for the sidebar display
++ * @page_size:  The number of lines on a page
++ *
++ * Before painting the sidebar, we count the BUFFYs, determine which are
++ * visible, sort them and set up our page pointers.
++ *
++ * This is a lot of work to do each refresh, but there are many things that
++ * can change outside of the sidebar that we don't hear about.
++ *
++ * Returns:
++ *	0: No, don't draw the sidebar
++ *	1: Yes, draw the sidebar
++ */
++static int prepare_sidebar (int page_size)
++{
++  BUFFY *b = Incoming;
++  if (!b)
++    return 0;
++
++  int count = 0;
++  for (; b; b = b->next)
++    count++;
++
++  BUFFY **arr = safe_malloc (count * sizeof (*arr));
++
++  int i = 0;
++  for (b = Incoming; b; b = b->next, i++)
++    arr[i] = b;
++
++  update_buffy_visibility (arr, count);
++  sort_buffy_array        (arr, count);
++
++  Incoming = arr[0];
++
++  int top_index =  0;
++  int opn_index = -1;
++  int hil_index = -1;
++  int bot_index = -1;
++
++  for (i = 0; i < count; i++)
++  {
++    if (OpnBuffy == arr[i])
++      opn_index = i;
++    if (HilBuffy == arr[i])
++      hil_index = i;
++  }
++
++  if (!HilBuffy || (SidebarSortMethod != PreviousSort))
++  {
++    if (OpnBuffy)
++    {
++      HilBuffy  = OpnBuffy;
++      hil_index = opn_index;
 +    }
++    else
++    {
++      HilBuffy  = arr[0];
++      hil_index = 0;
++    }
++  }
++  if (TopBuffy)
++    top_index = (hil_index / page_size) * page_size;
++  else
++    top_index = hil_index;
++  TopBuffy = arr[top_index];
++
++  bot_index = top_index + page_size - 1;
++  if (bot_index > (count - 1))
++    bot_index = count - 1;
++  BotBuffy  = arr[bot_index];
++
++  Outgoing = arr[count - 1];
++
++  PreviousSort = SidebarSortMethod;
++  FREE (&arr);
++  return 1;
++}
++
++/**
++ * visible - Should we display the sidebar?
++ *
++ * After validating the config options "sidebar_visible" and "sidebar_width",
++ * determine whether we should should display the sidebar.
++ *
++ * When not visible, set the global SidebarWidth to 0.
++ *
++ * Returns:
++ *	Boolean
++ */
++static short
++visible (void)
++{
++  short new_visible = option (OPTSIDEBAR);
++  short new_width   = SidebarWidth;
 +
-+    if(tmp->next)
-+      tmp = tmp->next;
++  if (OldWidth != new_width)
++  {
++    if (new_width > 0)
++    {
++      OldWidth = new_width;
++    }
++  }
++
++  if (OldVisible != new_visible)
++  {
++    if (new_visible)
++    {
++      set_option (OPTSIDEBAR);
++    }
 +    else
-+      break;
++    {
++      unset_option (OPTSIDEBAR);
++    }
++    OldVisible = new_visible;
++  }
++  else if (new_width == 0)
++  {
++    unset_option (OPTSIDEBAR);
++    OldVisible = 0;
++  }
++
++  if (!option (OPTSIDEBAR))
++  {
++    SidebarWidth = 0;
++  }
++  else if (new_width == 0)
++  {
++    SidebarWidth = OldWidth;
 +  }
++  else
++  {
++    SidebarWidth = new_width;
++  }
++
++  return new_visible;
 +}
 +
-+int draw_sidebar(int menu) {
++/**
++ * draw_divider - Draw a line between the sidebar and the rest of mutt
++ * @first_row:  Screen line to start (0-based)
++ * @num_rows:   Number of rows to fill
++ *
++ * Draw a divider using characters from the config option "sidebar_divider_char".
++ * This can be an ASCII or Unicode character.  First we calculate this
++ * characters' width in screen columns, then subtract that from the config
++ * option "sidebar_width".
++ *
++ * Returns:
++ *	-1: Error: bad character, etc
++ *	0:  Error: 0 width character
++ *	n:  Success: character occupies n screen columns
++ */
++static int draw_divider (int first_row, int num_rows)
++{
++  /* Calculate the width of the delimiter in screen cells */
++  int delim_len = mutt_strwidth (SidebarDividerChar);
 +
-+	int lines = option(OPTHELP) ? 1 : 0;
-+	BUFFY *tmp;
-+#ifndef USE_SLANG_CURSES
-+        attr_t attrs;
-+#endif
-+        short delim_len = strlen(SidebarDelim);
-+        short color_pair;
++  if (delim_len < 1)
++    return delim_len;
++
++  if ((SidebarWidth + delim_len) > (COLS + 1))
++    return 0;
++
++  if (delim_len > SidebarWidth)
++    return -1;
++
++  SETCOLOR(MT_COLOR_DIVIDER);
++
++  int i;
++  for (i = 0; i < num_rows; i++)
++  {
++    move (first_row + i, SidebarWidth - delim_len);
++    addstr (NONULL(SidebarDividerChar));
++  }
++
++  return delim_len;
++}
++
++/**
++ * fill_empty_space - Wipe the remaining Sidebar space
++ * @first_row:  Screen line to start (0-based)
++ * @num_rows:   Number of rows to fill
++ * @width:      Width of the Sidebar (minus the divider)
++ *
++ * Write spaces over the area the sidebar isn't using.
++ */
++static void fill_empty_space (int first_row, int num_rows, int width)
++{
++  /* Fill the remaining rows with blank space */
++  SETCOLOR(MT_COLOR_NORMAL);
++
++  int r;
++  for (r = 0; r < num_rows; r++)
++  {
++    int i = 0;
++    move (first_row + r, 0);
++    for (; i < width; i++)
++      addch (' ');
++  }
++}
++
++/**
++ * draw_sidebar - Write out a list of mailboxes, on the left
++ * @first_row:  Screen line to start (0-based)
++ * @num_rows:   Number of rows to fill
++ * @div_width:  Width in screen characters taken by the divider
++ *
++ * Display a list of mailboxes in a panel on the left.  What's displayed will
++ * depend on our index markers: TopBuffy, OpnBuffy, HilBuffy, BotBuffy.
++ * On the first run they'll be NULL, so we display the top of Mutt's list
++ * (Incoming).
++ *
++ * TopBuffy - first visible mailbox
++ * BotBuffy - last  visible mailbox
++ * OpnBuffy - mailbox shown in Mutt's Index Panel
++ * HilBuffy - Unselected mailbox (the paging follows this)
++ *
++ * The entries are formatted using "sidebar_format" and may be abbreviated:
++ * "sidebar_short_path", indented: "sidebar_folder_indent",
++ * "sidebar_indent_string" and sorted: "sidebar_sort_method".  Finally, they're
++ * trimmed to fit the available space.
++ */
++static void draw_sidebar (int first_row, int num_rows, int div_width)
++{
++  BUFFY *b = TopBuffy;
++  if (!b)
++    return;
++
++  int w = MIN(COLS, (SidebarWidth - div_width));
++  int row = 0;
++  for (b = TopBuffy; b && (row < num_rows); b = b->next)
++  {
++    if (b->is_hidden)
++      continue;
++
++    if (b == OpnBuffy)
++    {
++      if ((ColorDefs[MT_COLOR_SB_INDICATOR] != 0))
++        SETCOLOR(MT_COLOR_SB_INDICATOR);
++      else
++        SETCOLOR(MT_COLOR_INDICATOR);
++    }
++    else if (b == HilBuffy)
++      SETCOLOR(MT_COLOR_HIGHLIGHT);
++    else if ((ColorDefs[MT_COLOR_SB_SPOOLFILE] != 0) &&
++               (mutt_strcmp (b->path, Spoolfile) == 0))
++      SETCOLOR(MT_COLOR_SB_SPOOLFILE);
++    else if (b->msg_unread > 0)
++      SETCOLOR(MT_COLOR_NEW);
++    else if (b->msg_flagged > 0)
++      SETCOLOR(MT_COLOR_FLAGGED);
++    else
++      SETCOLOR(MT_COLOR_NORMAL);
++
++    move (first_row + row, 0);
++    if (Context && Context->path &&
++        (!strcmp (b->path, Context->path)||
++         !strcmp (b->realpath, Context->path)))
++    {
++      b->msg_unread  = Context->unread;
++      b->msg_count   = Context->msgcount;
++      b->msg_flagged = Context->flagged;
++    }
++
++    /* compute length of Maildir without trailing separator */
++    size_t maildirlen = strlen (Maildir);
++    if (SidebarDelimChars && strchr (SidebarDelimChars, Maildir[maildirlen - 1]))
++      maildirlen--;
 +
-+        static bool initialized = false;
-+        static int prev_show_value;
-+        static short saveSidebarWidth;
++    /* check whether Maildir is a prefix of the current folder's path */
++    short maildir_is_prefix = 0;
++    if ((strlen (b->path) > maildirlen) && (strncmp (Maildir, b->path, maildirlen) == 0))
++      maildir_is_prefix = 1;
 +
-+        /* initialize first time */
-+        if(!initialized) {
-+                prev_show_value = option(OPTSIDEBAR);
-+                saveSidebarWidth = SidebarWidth;
-+                if(!option(OPTSIDEBAR)) SidebarWidth = 0;
-+                initialized = true;
++    /* calculate depth of current folder and generate its display name with indented spaces */
++    int sidebar_folder_depth = 0;
++    char *sidebar_folder_name;
++    int i;
++    if (option (OPTSIDEBARSHORTPATH))
++    {
++      /* disregard a trailing separator, so strlen() - 2 */
++      sidebar_folder_name = b->path;
++      for (i = strlen (sidebar_folder_name) - 2; i >= 0; i--)
++      {
++        if (SidebarDelimChars &&
++            strchr (SidebarDelimChars, sidebar_folder_name[i]))
++        {
++          sidebar_folder_name += (i + 1);
++          break;
 +        }
++      }
++    }
++    else
++      sidebar_folder_name = b->path + maildir_is_prefix * (maildirlen + 1);
 +
-+        /* save or restore the value SidebarWidth */
-+        if(prev_show_value != option(OPTSIDEBAR)) {
-+                if(prev_show_value && !option(OPTSIDEBAR)) {
-+                        saveSidebarWidth = SidebarWidth;
-+                        SidebarWidth = 0;
-+                } else if(!prev_show_value && option(OPTSIDEBAR)) {
-+                        SidebarWidth = saveSidebarWidth;
-+                }
-+                prev_show_value = option(OPTSIDEBAR);
++    if (maildir_is_prefix && option (OPTSIDEBARFOLDERINDENT))
++    {
++      const char *tmp_folder_name;
++      int lastsep = 0;
++      tmp_folder_name = b->path + maildirlen + 1;
++      int tmplen = (int) strlen (tmp_folder_name) - 1;
++      for (i = 0; i < tmplen; i++)
++      {
++        if (SidebarDelimChars && strchr (SidebarDelimChars, tmp_folder_name[i]))
++        {
++          sidebar_folder_depth++;
++          lastsep = i + 1;
 +        }
++      }
++      if (sidebar_folder_depth > 0)
++      {
++        if (option (OPTSIDEBARSHORTPATH))
++          tmp_folder_name += lastsep;  /* basename */
++        sidebar_folder_name = malloc (strlen (tmp_folder_name) + sidebar_folder_depth*strlen (NONULL(SidebarIndentString)) + 1);
++        sidebar_folder_name[0]=0;
++        for (i=0; i < sidebar_folder_depth; i++)
++          strncat (sidebar_folder_name, NONULL(SidebarIndentString), strlen (NONULL(SidebarIndentString)));
++        strncat (sidebar_folder_name, tmp_folder_name, strlen (tmp_folder_name));
++      }
++    }
++    char str[STRING];
++    make_sidebar_entry (str, sizeof (str), w, sidebar_folder_name, b);
++    printw ("%s", str);
++    if (sidebar_folder_depth > 0)
++      FREE (&sidebar_folder_name);
++    row++;
++  }
 +
++  fill_empty_space (first_row + row, num_rows - row, w);
++}
 +
-+//	if ( SidebarWidth == 0 ) return 0;
-+       if (SidebarWidth > 0 && option (OPTSIDEBAR)
-+           && delim_len >= SidebarWidth) {
-+         unset_option (OPTSIDEBAR);
-+         /* saveSidebarWidth = SidebarWidth; */
-+         if (saveSidebarWidth > delim_len) {
-+           SidebarWidth = saveSidebarWidth;
-+           mutt_error (_("Value for sidebar_delim is too long. Disabling sidebar."));
-+           sleep (2);
-+         } else {
-+           SidebarWidth = 0;
-+           mutt_error (_("Value for sidebar_delim is too long. Disabling sidebar. Please set your sidebar_width to a sane value."));
-+           sleep (4); /* the advise to set a sane value should be seen long enough */
-+         }
-+         saveSidebarWidth = 0;
-+         return (0);
-+       }
 +
-+    if ( SidebarWidth == 0 || !option(OPTSIDEBAR)) {
-+      if (SidebarWidth > 0) {
-+        saveSidebarWidth = SidebarWidth;
-+        SidebarWidth = 0;
-+      }
-+      unset_option(OPTSIDEBAR);
-+      return 0;
++/**
++ * mutt_sb_init - Set some default values for the sidebar.
++ */
++void
++mutt_sb_init (void)
++{
++  OldVisible = option (OPTSIDEBAR);
++  if (SidebarWidth > 0)
++  {
++    OldWidth = SidebarWidth;
++  }
++  else
++  {
++    OldWidth = 20;
++    if (OldVisible)
++    {
++      SidebarWidth = OldWidth;
 +    }
++  }
++}
 +
-+        /* get attributes for divider */
-+	SETCOLOR(MT_COLOR_STATUS);
-+#ifndef USE_SLANG_CURSES
-+        attr_get(&attrs, &color_pair, 0);
-+#else
-+        color_pair = attr_get();
-+#endif
-+	SETCOLOR(MT_COLOR_NORMAL);
++/**
++ * mutt_sb_draw - Completely redraw the sidebar
++ *
++ * Completely refresh the sidebar region.  First draw the divider; then, for
++ * each BUFFY, call make_sidebar_entry; finally blank out any remaining space.
++ */
++void mutt_sb_draw (void)
++{
++  if (!visible())
++    return;
 +
-+	/* draw the divider */
++  /* XXX - if transitioning from invisible to visible */
++  /* if (OldVisible == 0) */
++  /* 	mutt_buffy_check (1); we probably have bad or no numbers */
 +
-+	for ( ; lines < LINES-1-(menu != MENU_PAGER || option(OPTSTATUSONTOP)); lines++ ) {
-+		move(lines, SidebarWidth - delim_len);
-+		addstr(NONULL(SidebarDelim));
-+#ifndef USE_SLANG_CURSES
-+                mvchgat(lines, SidebarWidth - delim_len, delim_len, 0, color_pair, NULL);
-+#endif
-+	}
++  int x = getcurx (stdscr);
++  int y = getcury (stdscr);
 +
-+	if ( Incoming == 0 ) return 0;
-+	lines = option(OPTHELP) ? 1 : 0; /* go back to the top */
-+
-+	if ( known_lines != LINES || TopBuffy == 0 || BottomBuffy == 0 ) 
-+		calc_boundaries(menu);
-+	if ( CurBuffy == 0 ) CurBuffy = Incoming;
-+
-+	tmp = TopBuffy;
-+
-+	SETCOLOR(MT_COLOR_NORMAL);
-+
-+	for ( ; tmp && lines < LINES-1 - (menu != MENU_PAGER || option(OPTSTATUSONTOP)); tmp = tmp->next ) {
-+		if ( tmp == CurBuffy )
-+			SETCOLOR(MT_COLOR_INDICATOR);
-+		else if ( tmp->msg_unread > 0 )
-+			SETCOLOR(MT_COLOR_NEW);
-+		else if ( tmp->msg_flagged > 0 )
-+		        SETCOLOR(MT_COLOR_FLAGGED);
-+		else
-+			SETCOLOR(MT_COLOR_NORMAL);
-+
-+		move( lines, 0 );
-+		if ( Context && !strcmp( tmp->path, Context->path ) ) {
-+			tmp->msg_unread = Context->unread;
-+			tmp->msgcount = Context->msgcount;
-+			tmp->msg_flagged = Context->flagged;
-+		}
-+		// check whether Maildir is a prefix of the current folder's path
-+		short maildir_is_prefix = 0;
-+		if ( (strlen(tmp->path) > strlen(Maildir)) &&
-+			(strncmp(Maildir, tmp->path, strlen(Maildir)) == 0) )
-+        		maildir_is_prefix = 1;
-+		// 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);
-+		if ( maildir_is_prefix ) {
-+			char *tmp_folder_name;
-+			int i;
-+			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++;
-+			}   
-+			if (sidebar_folder_depth > 0) {
-+				sidebar_folder_name = malloc(strlen(basename(tmp->path)) + 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);
-+			}
-+		}
-+		printw( "%.*s", SidebarWidth - delim_len + 1,
-+			make_sidebar_entry(sidebar_folder_name, tmp->msgcount,
-+			tmp->msg_unread, tmp->msg_flagged));
-+		if (sidebar_folder_depth > 0)
-+		        free(sidebar_folder_name);
-+		lines++;
-+	}
-+	SETCOLOR(MT_COLOR_NORMAL);
-+	for ( ; lines < LINES-1 - (menu != MENU_PAGER || option(OPTSTATUSONTOP)); lines++ ) {
-+		int i = 0;
-+		move( lines, 0 );
-+		for ( ; i < SidebarWidth - delim_len; i++ )
-+			addch(' ');
-+	}
-+	return 0;
++  int first_row = 0;
++  int num_rows  = LINES - 2;
++
++  if (option (OPTHELP) || option (OPTSTATUSONTOP))
++    first_row++;
++
++  if (option (OPTHELP))
++    num_rows--;
++
++  int div_width = draw_divider (first_row, num_rows);
++  if (div_width < 0)
++    return;
++
++  if (!Incoming)
++  {
++    int w = MIN(COLS, (SidebarWidth - div_width));
++    fill_empty_space (first_row, num_rows, w);
++    return;
++  }
++
++  if (!prepare_sidebar (num_rows))
++    return;
++
++  draw_sidebar (first_row, num_rows, div_width);
++  move (y, x);
 +}
 +
++/**
++ * mutt_sb_should_refresh - Check if the sidebar is due to be refreshed
++ *
++ * The "sidebar_refresh_time" config option allows the user to limit the frequency
++ * with which the sidebar is refreshed.
++ *
++ * Returns:
++ *	1  Yes, refresh is due
++ *	0  No,  refresh happened recently
++ */
++int mutt_sb_should_refresh (void)
++{
++  if (!option (OPTSIDEBAR))
++    return 0;
++
++  if (SidebarRefreshTime == 0)
++    return 0;
++
++  time_t diff = (time (NULL) - LastRefresh);
++
++  return (diff >= SidebarRefreshTime);
++}
 +
-+void set_buffystats(CONTEXT* Context)
++/**
++ * mutt_sb_change_mailbox - Change the selected mailbox
++ * @op: Operation code
++ *
++ * Change the selected mailbox, e.g. "Next mailbox", "Previous Mailbox
++ * with new mail". The operations are listed OPS.SIDEBAR which is built
++ * into an enum in keymap_defs.h.
++ *
++ * If the operation is successful, HilBuffy will be set to the new mailbox.
++ * This function only *selects* the mailbox, doesn't *open* it.
++ *
++ * Allowed values are: OP_SIDEBAR_NEXT, OP_SIDEBAR_NEXT_NEW,
++ * OP_SIDEBAR_PAGE_DOWN, OP_SIDEBAR_PAGE_UP, OP_SIDEBAR_PREV,
++ * OP_SIDEBAR_PREV_NEW.
++ */
++void mutt_sb_change_mailbox (int op)
 +{
-+        BUFFY *tmp = Incoming;
-+        while(tmp) {
-+                if(Context && !strcmp(tmp->path, Context->path)) {
-+			tmp->msg_unread = Context->unread;
-+			tmp->msgcount = Context->msgcount;
-+                        break;
-+                }
-+                tmp = tmp->next;
-+        }
++  BUFFY *b;
++  if (!HilBuffy)	/* It'll get reset on the next draw */
++    return;
++
++  switch (op)
++  {
++    case OP_SIDEBAR_NEXT:
++      if (!HilBuffy->next)
++        return;
++      if (HilBuffy->next->is_hidden)
++        return;
++      HilBuffy = HilBuffy->next;
++      break;
++    case OP_SIDEBAR_NEXT_NEW:
++      b = find_next_new (option (OPTSIDEBARNEXTNEWWRAP));
++      if (!b)
++        return;
++      else
++        HilBuffy = b;
++      break;
++    case OP_SIDEBAR_PAGE_DOWN:
++      HilBuffy = BotBuffy;
++      if (HilBuffy->next)
++        HilBuffy = HilBuffy->next;
++      break;
++    case OP_SIDEBAR_PAGE_UP:
++      HilBuffy = TopBuffy;
++      if (HilBuffy != Incoming)
++        HilBuffy = HilBuffy->prev;
++      break;
++    case OP_SIDEBAR_PREV:
++      if (!HilBuffy->prev)
++        return;
++      if (HilBuffy->prev->is_hidden)	/* Can't happen, we've sorted the hidden to the end */
++        return;
++      HilBuffy = HilBuffy->prev;
++      break;
++    case OP_SIDEBAR_PREV_NEW:
++      b = find_prev_new (option (OPTSIDEBARNEXTNEWWRAP));
++      if (!b)
++        return;
++      else
++        HilBuffy = b;
++      break;
++    default:
++      return;
++  }
++
++  /* We can change folder even if the sidebar is hidden */
++  if (option (OPTSIDEBAR))
++    mutt_sb_draw();
 +}
 +
-+void scroll_sidebar(int op, int menu)
++/**
++ * mutt_sb_set_buffystats - Update the BUFFY's message counts from the CONTEXT
++ * @ctx:  A mailbox CONTEXT
++ *
++ * Given a mailbox CONTEXT, find a matching mailbox BUFFY and copy the message
++ * counts into it.
++ */
++void mutt_sb_set_buffystats (const CONTEXT *ctx)
 +{
-+        if(!SidebarWidth) return;
-+        if(!CurBuffy) return;
-+
-+	switch (op) {
-+		case OP_SIDEBAR_NEXT:
-+			if ( CurBuffy->next == NULL ) return;
-+			CurBuffy = CurBuffy->next;
-+			break;
-+		case OP_SIDEBAR_PREV:
-+			if ( CurBuffy->prev == NULL ) return;
-+			CurBuffy = CurBuffy->prev;
-+			break;
-+		case OP_SIDEBAR_SCROLL_UP:
-+			CurBuffy = TopBuffy;
-+			if ( CurBuffy != Incoming ) {
-+				calc_boundaries(menu);
-+				CurBuffy = CurBuffy->prev;
-+			}
-+			break;
-+		case OP_SIDEBAR_SCROLL_DOWN:
-+			CurBuffy = BottomBuffy;
-+			if ( CurBuffy->next ) {
-+				calc_boundaries(menu);
-+				CurBuffy = CurBuffy->next;
-+			}
-+			break;
-+		default:
-+			return;
-+	}
-+	calc_boundaries(menu);
-+	draw_sidebar(menu);
++  /* Even if the sidebar's hidden,
++   * we should take note of the new data. */
++  BUFFY *b = Incoming;
++  if (!ctx || !b)
++    return;
++
++  for (; b; b = b->next)
++  {
++    if (!strcmp (b->path,     ctx->path) ||
++        !strcmp (b->realpath, ctx->path))
++    {
++      b->msg_unread  = ctx->unread;
++      b->msg_count   = ctx->msgcount;
++      b->msg_flagged = ctx->flagged;
++      break;
++    }
++  }
++}
++
++/**
++ * mutt_sb_get_highlight - Get the BUFFY that's highlighted in the sidebar
++ *
++ * Get the path of the mailbox that's highlighted in the sidebar.
++ *
++ * Returns:
++ *	Mailbox path
++ */
++const char *mutt_sb_get_highlight (void)
++{
++  if (!HilBuffy)
++    return NULL;
++
++  return HilBuffy->path;
++}
++
++/**
++ * mutt_sb_set_open_buffy - Set the OpnBuffy based on a mailbox path
++ * @path: Mailbox path
++ *
++ * Search through the list of mailboxes.  If a BUFFY has a matching path, set
++ * OpnBuffy to it.
++ */
++BUFFY *mutt_sb_set_open_buffy (const char *path)
++{
++  /* Even if the sidebar is hidden */
++
++  BUFFY *b = Incoming;
++
++  if (!path || !b)
++    return NULL;
++
++  OpnBuffy = NULL;
++
++  for (; b; b = b->next)
++  {
++    if (!strcmp (b->path,     path) ||
++        !strcmp (b->realpath, path))
++    {
++      OpnBuffy = b;
++      HilBuffy = b;
++      break;
++    }
++  }
++
++  return OpnBuffy;
 +}
 +
-diff --git a/sidebar.h b/sidebar.h
-new file mode 100644
-index 0000000..d195f11
---- /dev/null
-+++ b/sidebar.h
++/**
++ * mutt_sb_set_update_time - Note the time that the sidebar was updated
++ *
++ * Update the timestamp representing the last sidebar update.  If the user
++ * configures "sidebar_refresh_time", this will help to reduce traffic.
++ */
++void mutt_sb_set_update_time (void)
++{
++  /* XXX - should this be public? */
++
++  LastRefresh = time (NULL);
++}
++
++/**
++ * mutt_sb_notify_mailbox - The state of a BUFFY is about to change
++ *
++ * We receive a notification:
++ *	After a new BUFFY has been created
++ *	Before a BUFFY is deleted
++ *
++ * Before a deletion, check that our pointers won't be invalidated.
++ */
++void mutt_sb_notify_mailbox (BUFFY *b, int created)
++{
++  if (!b)
++    return;
++
++  /* Any new/deleted mailboxes will cause a refresh.  As long as
++   * they're valid, our pointers will be updated in prepare_sidebar() */
++
++  if (created)
++  {
++    if (!TopBuffy)
++      TopBuffy = b;
++    if (!HilBuffy)
++      HilBuffy = b;
++    if (!BotBuffy)
++      BotBuffy = b;
++    if (!Outgoing)
++      Outgoing = b;
++    if (!OpnBuffy && Context)
++    {
++      /* This might happen if the user "unmailboxes *", then
++       * "mailboxes" our current mailbox back again */
++      if (mutt_strcmp (b->path, Context->path) == 0)
++        OpnBuffy = b;
++    }
++  }
++  else
++  {
++    BUFFY *replacement = buffy_going (b);
++    if (TopBuffy == b)
++      TopBuffy = replacement;
++    if (OpnBuffy == b)
++      OpnBuffy = NULL;
++    if (HilBuffy == b)
++      HilBuffy = replacement;
++    if (BotBuffy == b)
++      BotBuffy = replacement;
++    if (Outgoing == b)
++      Outgoing = replacement;
++  }
++}
+diff -urN mutt-1.6.1/sidebar.h mutt-1.6.1-sidebar/sidebar.h
+--- mutt-1.6.1/sidebar.h	1970-01-01 01:00:00.000000000 +0100
++++ mutt-1.6.1-sidebar/sidebar.h	2016-06-12 18:43:03.967503185 +0100
 @@ -0,0 +1,36 @@
-+/*
-+ * Copyright (C) ????-2004 Justin Hibbits <jrh29@po.cwru.edu>
++/* Copyright (C) 2004 Justin Hibbits <jrh29@po.cwru.edu>
 + * Copyright (C) 2004 Thomer M. Gil <mutt@thomer.com>
-+ * 
++ * Copyright (C) 2015-2016 Richard Russon <rich@flatcap.org>
++ *
 + *     This program is free software; you can redistribute it and/or modify
 + *     it under the terms of the GNU General Public License as published by
 + *     the Free Software Foundation; either version 2 of the License, or
 + *     (at your option) any later version.
-+ * 
++ *
 + *     This program is distributed in the hope that it will be useful,
 + *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 + *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 + *     GNU General Public License for more details.
-+ * 
++ *
 + *     You should have received a copy of the GNU General Public License
 + *     along with this program; if not, write to the Free Software
 + *     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
-+ */ 
++ */
 +
 +#ifndef SIDEBAR_H
 +#define SIDEBAR_H
 +
-+struct MBOX_LIST {
-+	char *path;
-+	int msgcount;
-+	int new;
-+} MBLIST;
++#include "mutt.h"
++#include "buffy.h"
 +
-+/* parameter is whether or not to go to the status line */
-+/* used for omitting the last | that covers up the status bar in the index */
-+int draw_sidebar(int);
-+void scroll_sidebar(int, int);
-+void set_curbuffy(char*);
-+void set_buffystats(CONTEXT*);
++void         mutt_sb_change_mailbox (int op);
++void         mutt_sb_draw (void);
++const char * mutt_sb_get_highlight (void);
++void         mutt_sb_init (void);
++void         mutt_sb_notify_mailbox (BUFFY *b, int created);
++void         mutt_sb_set_buffystats (const CONTEXT *ctx);
++BUFFY *      mutt_sb_set_open_buffy (const char *path);
++void         mutt_sb_set_update_time (void);
++int          mutt_sb_should_refresh (void);
 +
 +#endif /* SIDEBAR_H */
+diff -urN mutt-1.6.1/sort.h mutt-1.6.1-sidebar/sort.h
+--- mutt-1.6.1/sort.h	2016-06-12 18:43:00.415447793 +0100
++++ mutt-1.6.1-sidebar/sort.h	2016-06-12 18:43:03.968503200 +0100
+@@ -31,6 +31,12 @@
+ #define SORT_KEYID	12
+ #define SORT_TRUST	13
+ #define SORT_SPAM	14
++#define SORT_COUNT	15
++#define SORT_COUNT_NEW	16
++#define SORT_DESC	17
++#define SORT_FLAGGED	18
++#define SORT_PATH	19
++
+ /* dgc: Sort & SortAux are shorts, so I'm bumping these bitflags up from
+  * bits 4 & 5 to bits 8 & 9 to make room for more sort keys in the future. */
+ #define SORT_MASK	0xff
+@@ -50,6 +56,7 @@
+ WHERE short Sort INITVAL (SORT_DATE);
+ WHERE short SortAux INITVAL (SORT_DATE); /* auxiliary sorting method */
+ WHERE short SortAlias INITVAL (SORT_ALIAS);
++WHERE short SidebarSortMethod INITVAL (SORT_ORDER);
+ 
+ /* FIXME: This one does not belong to here */
+ WHERE short PgpSortKeys INITVAL (SORT_ADDRESS);
diff --git a/pkgs/applications/networking/mailreaders/mutt/trash-folder.patch b/pkgs/applications/networking/mailreaders/mutt/trash-folder.patch
deleted file mode 100644
index ce47b0c30e5d7..0000000000000
--- a/pkgs/applications/networking/mailreaders/mutt/trash-folder.patch
+++ /dev/null
@@ -1,316 +0,0 @@
-From: Cedric Duval <cedricduval@free.fr>
-Date: Thu, 27 Feb 2014 12:27:41 +0100
-Subject: trash-folder
-
-With this patch, if the trash variable is set to a path (unset by default), the
-deleted mails will be moved to a trash folder instead of being irremediably
-purged when syncing the mailbox.
-
-For instance, set trash="~/Mail/trash" will cause every deleted mail to go to
-this folder.
-
-Note that the append to the trash folder doesn't occur until the resync is
-done. This allows you to change your mind and undo deletes, and thus the moves
-to the trash folder are unnecessary.
-
-Notes
-
-    * You might also want to have a look at the purge message feature below
-      which is related to this patch.
-    * IMAP is now supported. To retain the previous behavior, add this to your
-      muttrc:
-      folder-hook ^imap:// 'unset trash'
-
-FAQ
-
-Every once in a while, someone asks what are the advantages of this patch over
-a macro based solution. Here's an attempt to answer this question:
-
-    * The folder history doesn't clutter up with unwanted trash entries.
-    * Delayed move to the trash allows to change one's mind.
-    * No need to treat the case of "normal folders" and trash folders
-      separately with folder-hooks, and to create two sets of macros (one for
-      the index, one for the pager).
-    * Works not only with delete-message, but also with every deletion
-      functions like delete-pattern, delete-thread or delete-subthread.
-
-To sum up, it's more integrated and transparent to the user.
-
-* Patch last synced with upstream:
-  - Date: 2007-02-15
-  - File: http://cedricduval.free.fr/mutt/patches/download/patch-1.5.5.1.cd.trash_folder.3.4
-
-* Changes made:
-  - Updated to 1.5.13:
-    - structure of _mutt_save_message changed (commands.c)
-    - context of option (OPTCONFIRMAPPEND) changed (muttlib.c)
-  - Fixed indentation of "appended" in mutt.h.
-
-Signed-off-by: Matteo F. Vescovi <mfvescovi@gmail.com>
-
-Gbp-Pq: Topic features
----
- commands.c     |  1 +
- flags.c        | 19 +++++++++++++++++-
- globals.h      |  1 +
- imap/message.c |  2 ++
- init.h         | 10 ++++++++++
- mutt.h         |  3 +++
- muttlib.c      |  4 +++-
- mx.c           | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- postpone.c     |  3 +++
- 9 files changed, 103 insertions(+), 2 deletions(-)
-
-diff --git a/commands.c b/commands.c
-index 5dbd100..7fd014b 100644
---- a/commands.c
-+++ b/commands.c
-@@ -720,6 +720,7 @@ int _mutt_save_message (HEADER *h, CONTEXT *ctx, int delete, int decode, int dec
-     if (option (OPTDELETEUNTAG))
-       mutt_set_flag (Context, h, M_TAG, 0);
-   }
-+  mutt_set_flag (Context, h, M_APPENDED, 1);
-   
-   return 0;
- }
-diff --git a/flags.c b/flags.c
-index f0f3d81..dfa6a50 100644
---- a/flags.c
-+++ b/flags.c
-@@ -65,7 +65,13 @@ void _mutt_set_flag (CONTEXT *ctx, HEADER *h, int flag, int bf, int upd_ctx)
-       {
- 	h->deleted = 0;
-         update = 1;
--	if (upd_ctx) ctx->deleted--;
-+	if (upd_ctx)
-+	{
-+	  ctx->deleted--;
-+	  if (h->appended)
-+	    ctx->appended--;
-+	}
-+	h->appended = 0; /* when undeleting, also reset the appended flag */
- #ifdef USE_IMAP
-         /* see my comment above */
- 	if (ctx->magic == M_IMAP) 
-@@ -87,6 +93,17 @@ void _mutt_set_flag (CONTEXT *ctx, HEADER *h, int flag, int bf, int upd_ctx)
-       }
-       break;
- 
-+    case M_APPENDED:
-+      if (bf)
-+      {
-+	if (!h->appended)
-+	{
-+	  h->appended = 1;
-+	  if (upd_ctx) ctx->appended++;
-+	}
-+      }
-+      break;
-+
-     case M_NEW:
- 
-       if (!mutt_bit_isset(ctx->rights,M_ACL_SEEN))
-diff --git a/globals.h b/globals.h
-index e77030c..6a1b8da 100644
---- a/globals.h
-+++ b/globals.h
-@@ -144,6 +144,7 @@ WHERE char *Tochars;
- WHERE char *TSStatusFormat;
- WHERE char *TSIconFormat;
- WHERE short TSSupported;
-+WHERE char *TrashPath;
- WHERE char *Username;
- WHERE char *Visual;
- 
-diff --git a/imap/message.c b/imap/message.c
-index 3877381..039fda6 100644
---- a/imap/message.c
-+++ b/imap/message.c
-@@ -884,6 +884,7 @@ int imap_copy_messages (CONTEXT* ctx, HEADER* h, char* dest, int delete)
-         if (ctx->hdrs[n]->tagged)
-         {
-           mutt_set_flag (ctx, ctx->hdrs[n], M_DELETE, 1);
-+	  mutt_set_flag (ctx, ctx->hdrs[n], M_APPENDED, 1);
-           if (option (OPTDELETEUNTAG))
-             mutt_set_flag (ctx, ctx->hdrs[n], M_TAG, 0);
-         }
-@@ -891,6 +892,7 @@ int imap_copy_messages (CONTEXT* ctx, HEADER* h, char* dest, int delete)
-     else
-     {
-       mutt_set_flag (ctx, h, M_DELETE, 1);
-+      mutt_set_flag (ctx, h, M_APPENDED, 1);
-       if (option (OPTDELETEUNTAG))
-         mutt_set_flag (ctx, h, M_TAG, 0);
-     }
-diff --git a/init.h b/init.h
-index 6b49341..d3206f9 100644
---- a/init.h
-+++ b/init.h
-@@ -3341,6 +3341,16 @@ struct option_t MuttVars[] = {
-   ** provided that ``$$ts_enabled'' has been set. This string is identical in
-   ** formatting to the one used by ``$$status_format''.
-   */
-+  { "trash",		DT_PATH, R_NONE, UL &TrashPath, 0 },
-+  /*
-+  ** .pp
-+  ** If set, this variable specifies the path of the trash folder where the
-+  ** mails marked for deletion will be moved, instead of being irremediably
-+  ** purged.
-+  ** .pp
-+  ** NOTE: When you delete a message in the trash folder, it is really
-+  ** deleted, so that you have a way to clean the trash.
-+  */
- #ifdef USE_SOCKET
-   { "tunnel",            DT_STR, R_NONE, UL &Tunnel, UL 0 },
-   /*
-diff --git a/mutt.h b/mutt.h
-index f8565fa..29bb6c2 100644
---- a/mutt.h
-+++ b/mutt.h
-@@ -185,6 +185,7 @@ enum
-   M_DELETE,
-   M_UNDELETE,
-   M_DELETED,
-+  M_APPENDED,
-   M_FLAG,
-   M_TAG,
-   M_UNTAG,
-@@ -713,6 +714,7 @@ typedef struct header
-   unsigned int mime : 1;    		/* has a MIME-Version header? */
-   unsigned int flagged : 1; 		/* marked important? */
-   unsigned int tagged : 1;
-+  unsigned int appended : 1;		/* has been saved */
-   unsigned int deleted : 1;
-   unsigned int changed : 1;
-   unsigned int attach_del : 1; 		/* has an attachment marked for deletion */
-@@ -885,6 +887,7 @@ typedef struct _context
-   int new;			/* how many new messages? */
-   int unread;			/* how many unread messages? */
-   int deleted;			/* how many deleted messages */
-+  int appended;                 /* how many saved messages? */
-   int flagged;			/* how many flagged messages */
-   int msgnotreadyet;		/* which msg "new" in pager, -1 if none */
- 
-diff --git a/muttlib.c b/muttlib.c
-index 02067cc..0fd9766 100644
---- a/muttlib.c
-+++ b/muttlib.c
-@@ -1505,7 +1505,9 @@ int mutt_save_confirm (const char *s, struct stat *st)
- 
-   if (magic > 0 && !mx_access (s, W_OK))
-   {
--    if (option (OPTCONFIRMAPPEND))
-+    if (option (OPTCONFIRMAPPEND) &&
-+	(!TrashPath || (mutt_strcmp (s, TrashPath) != 0)))
-+      /* if we're appending to the trash, there's no point in asking */
-     {
-       snprintf (tmp, sizeof (tmp), _("Append messages to %s?"), s);
-       if ((rc = mutt_yesorno (tmp, M_YES)) == M_NO)
-diff --git a/mx.c b/mx.c
-index 4c5cb07..c0a6d30 100644
---- a/mx.c
-+++ b/mx.c
-@@ -776,6 +776,53 @@ static int sync_mailbox (CONTEXT *ctx, int *index_hint)
-   return rc;
- }
- 
-+/* move deleted mails to the trash folder */
-+static int trash_append (CONTEXT *ctx)
-+{
-+    CONTEXT *ctx_trash;
-+    int i = 0;
-+    struct stat st, stc;
-+
-+    if (!TrashPath || !ctx->deleted ||
-+	(ctx->magic == M_MAILDIR && option (OPTMAILDIRTRASH)))
-+      return 0;
-+
-+    for (;i < ctx->msgcount && (!ctx->hdrs[i]->deleted ||
-+				ctx->hdrs[i]->appended); i++);
-+    if (i == ctx->msgcount)
-+      return 0; /* nothing to be done */
-+
-+    if (mutt_save_confirm (TrashPath, &st) != 0)
-+    {
-+      mutt_error _("message(s) not deleted");
-+      return -1;
-+    }
-+
-+    if (lstat (ctx->path, &stc) == 0 && stc.st_ino == st.st_ino
-+	&& stc.st_dev == st.st_dev && stc.st_rdev == st.st_rdev)
-+      return 0;  /* we are in the trash folder: simple sync */
-+
-+    if ((ctx_trash = mx_open_mailbox (TrashPath, M_APPEND, NULL)) != NULL)
-+    {
-+      for (i = 0 ; i < ctx->msgcount ; i++)
-+	if (ctx->hdrs[i]->deleted && !ctx->hdrs[i]->appended
-+	    && mutt_append_message (ctx_trash, ctx, ctx->hdrs[i], 0, 0) == -1)
-+	  {
-+	    mx_close_mailbox (ctx_trash, NULL);
-+	    return -1;
-+	  }
-+
-+      mx_close_mailbox (ctx_trash, NULL);
-+    }
-+    else
-+    {
-+      mutt_error _("Can't open trash folder");
-+      return -1;
-+    }
-+
-+    return 0;
-+}
-+
- /* save changes and close mailbox */
- int mx_close_mailbox (CONTEXT *ctx, int *index_hint)
- {
-@@ -912,6 +959,7 @@ int mx_close_mailbox (CONTEXT *ctx, int *index_hint)
- 	  if (mutt_append_message (&f, ctx, ctx->hdrs[i], 0, CH_UPDATE_LEN) == 0)
- 	  {
- 	    mutt_set_flag (ctx, ctx->hdrs[i], M_DELETE, 1);
-+	    mutt_set_flag (ctx, ctx->hdrs[i], M_APPENDED, 1);
- 	  }
- 	  else
- 	  {
-@@ -936,6 +984,14 @@ int mx_close_mailbox (CONTEXT *ctx, int *index_hint)
-     return 0;
-   }
-   
-+  /* copy mails to the trash before expunging */
-+  if (purge && ctx->deleted && mutt_strcmp(ctx->path, TrashPath))
-+    if (trash_append (ctx) != 0)
-+    {
-+      ctx->closing = 0;
-+      return -1;
-+    }
-+
- #ifdef USE_IMAP
-   /* allow IMAP to preserve the deleted flag across sessions */
-   if (ctx->magic == M_IMAP)
-@@ -1133,6 +1189,12 @@ int mx_sync_mailbox (CONTEXT *ctx, int *index_hint)
-   msgcount = ctx->msgcount;
-   deleted = ctx->deleted;
- 
-+  if (purge && ctx->deleted && mutt_strcmp(ctx->path, TrashPath))
-+  {
-+    if (trash_append (ctx) == -1)
-+      return -1;
-+  }
-+
- #ifdef USE_IMAP
-   if (ctx->magic == M_IMAP)
-     rc = imap_sync_mailbox (ctx, purge, index_hint);
-diff --git a/postpone.c b/postpone.c
-index a703161..7a4cbb1 100644
---- a/postpone.c
-+++ b/postpone.c
-@@ -277,6 +277,9 @@ int mutt_get_postponed (CONTEXT *ctx, HEADER *hdr, HEADER **cur, char *fcc, size
-   /* finished with this message, so delete it. */
-   mutt_set_flag (PostContext, h, M_DELETE, 1);
- 
-+  /* and consider it saved, so that it won't be moved to the trash folder */
-+  mutt_set_flag (PostContext, h, M_APPENDED, 1);
-+
-   /* update the count for the status display */
-   PostCount = PostContext->msgcount - PostContext->deleted;
- 
diff --git a/pkgs/applications/networking/mailreaders/mutt/trash.patch b/pkgs/applications/networking/mailreaders/mutt/trash.patch
new file mode 100644
index 0000000000000..a7bda4c4c8b84
--- /dev/null
+++ b/pkgs/applications/networking/mailreaders/mutt/trash.patch
@@ -0,0 +1,797 @@
+diff -urN mutt-1.6.1/commands.c mutt-1.6.1-trash/commands.c
+--- mutt-1.6.1/commands.c	2016-06-12 18:43:00.397447512 +0100
++++ mutt-1.6.1-trash/commands.c	2016-06-12 18:43:04.892517610 +0100
+@@ -720,6 +720,7 @@
+     if (option (OPTDELETEUNTAG))
+       mutt_set_flag (Context, h, M_TAG, 0);
+   }
++  mutt_set_flag (Context, h, M_APPENDED, 1);
+   
+   return 0;
+ }
+diff -urN mutt-1.6.1/curs_main.c mutt-1.6.1-trash/curs_main.c
+--- mutt-1.6.1/curs_main.c	2016-06-12 18:43:00.399447544 +0100
++++ mutt-1.6.1-trash/curs_main.c	2016-06-12 18:43:04.895517656 +0100
+@@ -1919,6 +1919,7 @@
+ 	MAYBE_REDRAW (menu->redraw);
+ 	break;
+ 
++      case OP_PURGE_MESSAGE:
+       case OP_DELETE:
+ 
+ 	CHECK_MSGCOUNT;
+@@ -1930,6 +1931,7 @@
+ 	if (tag)
+ 	{
+ 	  mutt_tag_set_flag (M_DELETE, 1);
++	  mutt_tag_set_flag (M_PURGED, (op != OP_PURGE_MESSAGE) ? 0 : 1);
+ 	  if (option (OPTDELETEUNTAG))
+ 	    mutt_tag_set_flag (M_TAG, 0);
+ 	  menu->redraw = REDRAW_INDEX;
+@@ -1937,6 +1939,8 @@
+ 	else
+ 	{
+ 	  mutt_set_flag (Context, CURHDR, M_DELETE, 1);
++	  mutt_set_flag (Context, CURHDR, M_PURGED,
++			 (op != OP_PURGE_MESSAGE) ? 0 : 1);
+ 	  if (option (OPTDELETEUNTAG))
+ 	    mutt_set_flag (Context, CURHDR, M_TAG, 0);
+ 	  if (option (OPTRESOLVE))
+@@ -2242,11 +2246,13 @@
+ 	if (tag)
+ 	{
+ 	  mutt_tag_set_flag (M_DELETE, 0);
++	  mutt_tag_set_flag (M_PURGED, 0);
+ 	  menu->redraw = REDRAW_INDEX;
+ 	}
+ 	else
+ 	{
+ 	  mutt_set_flag (Context, CURHDR, M_DELETE, 0);
++	  mutt_set_flag (Context, CURHDR, M_PURGED, 0);
+ 	  if (option (OPTRESOLVE) && menu->current < Context->vcount - 1)
+ 	  {
+ 	    menu->current++;
+@@ -2268,9 +2274,11 @@
+ 	CHECK_ACL(M_ACL_DELETE, _("Cannot undelete message(s)"));
+ 
+ 	rc = mutt_thread_set_flag (CURHDR, M_DELETE, 0,
+-				   op == OP_UNDELETE_THREAD ? 0 : 1);
++				   op == OP_UNDELETE_THREAD ? 0 : 1)
++	  + mutt_thread_set_flag (CURHDR, M_PURGED, 0,
++				  (op == OP_UNDELETE_THREAD) ? 0 : 1);
+ 
+-	if (rc != -1)
++	if (rc > -1)
+ 	{
+ 	  if (option (OPTRESOLVE))
+ 	  {
+diff -urN mutt-1.6.1/doc/manual.xml.head mutt-1.6.1-trash/doc/manual.xml.head
+--- mutt-1.6.1/doc/manual.xml.head	2016-06-12 18:43:00.402447590 +0100
++++ mutt-1.6.1-trash/doc/manual.xml.head	2016-06-12 18:43:04.901517750 +0100
+@@ -7467,6 +7467,16 @@
+ 
+ </sect2>
+ 
++<sect2 id="mutt-patches">
++<title>Mutt Patches</title>
++<para>
++Mutt may also be <quote>patched</quote> to support smaller features.
++These patches should add a free-form string to the end Mutt's version string.
++Running <literal>mutt -v</literal> might show:
++<screen>patch-1.6.1.sidebar.20160502</screen>
++</para>
++</sect2>
++
+ <sect2 id="url-syntax">
+ <title>URL Syntax</title>
+ 
+@@ -8081,6 +8091,175 @@
+ 
+ </sect1>
+ 
++<sect1 id="trash-folder">
++	<title>Trash Folder Patch</title>
++	<subtitle>Automatically move "deleted" emails to a trash bin</subtitle>
++
++	<sect2 id="trash-folder-patch">
++		<title>Patch</title>
++
++		<para>
++			To check if Mutt supports <quote>Trash Folder</quote>, look for
++			<quote>patch-trash</quote> in the mutt version.
++			See: <xref linkend="mutt-patches"/>.
++		</para>
++
++		If IMAP is enabled, this patch will use it
++
++		<itemizedlist>
++			<title>Dependencies:</title>
++			<listitem><para>mutt-1.6.1</para></listitem>
++			<listitem><para>IMAP support</para></listitem>
++		</itemizedlist>
++
++		<para>This patch is part of the <ulink url="http://www.neomutt.org/">NeoMutt Project</ulink>.</para>
++	</sect2>
++
++	<sect2 id="trash-folder-intro">
++		<title>Introduction</title>
++
++		<para>
++		In Mutt, when you <quote>delete</quote> an email it is first marked
++		deleted.  The email isn't really gone until
++		<link linkend="index-map">&lt;sync-mailbox&gt;</link> is called.
++		This happens when the user leaves the folder, or the function is called
++		manually.
++		</para>
++
++		<para>
++		After <literal>&lt;sync-mailbox&gt;</literal> has been called the email is gone forever.
++		</para>
++
++		<para>
++		The <link linkend="trash">$trash</link> variable defines a folder in
++		which to keep old emails.  As before, first you mark emails for
++		deletion.  When &lt;sync-mailbox&gt; is called the emails are moved to
++		the trash folder.
++		</para>
++
++		<para>
++		The <literal>$trash</literal> path can be either a full directory,
++		or be relative to the <link linkend="folder">$folder</link>
++		variable, like the <literal>mailboxes</literal> command.
++		</para>
++
++		<note>
++		Emails deleted from the trash folder are gone forever.
++		</note>
++	</sect2>
++
++	<sect2 id="trash-folder-variables">
++		<title>Variables</title>
++		<table id="table-trash-variables">
++			<title>Trash Variables</title>
++			<tgroup cols="3">
++				<thead>
++					<row>
++						<entry>Name</entry>
++						<entry>Type</entry>
++						<entry>Default</entry>
++					</row>
++				</thead>
++				<tbody>
++					<row>
++						<entry>trash</entry>
++						<entry>string</entry>
++						<entry>(none)</entry>
++					</row>
++				</tbody>
++			</tgroup>
++		</table>
++	</sect2>
++
++	<sect2 id="trash-folder-functions">
++		<title>Functions</title>
++		<table id="table-trash-functions">
++			<title>Trash Functions</title>
++			<tgroup cols="4">
++				<thead>
++					<row>
++						<entry>Menus</entry>
++						<entry>Default Key</entry>
++						<entry>Function</entry>
++						<entry>Description</entry>
++					</row>
++				</thead>
++				<tbody>
++					<row>
++						<entry>index,pager</entry>
++						<entry>(none)</entry>
++						<entry><literal>&lt;purge-message&gt;</literal></entry>
++						<entry>really delete the current entry, bypassing the trash folder</entry>
++					</row>
++				</tbody>
++			</tgroup>
++		</table>
++	</sect2>
++
++<!--
++	<sect2 id="trash-folder-commands">
++		<title>Commands</title>
++		<para>None</para>
++	</sect2>
++
++	<sect2 id="trash-folder-colors">
++		<title>Colors</title>
++		<para>None</para>
++	</sect2>
++
++	<sect2 id="trash-folder-sort">
++		<title>Sort</title>
++		<para>None</para>
++	</sect2>
++-->
++
++	<sect2 id="trash-folder-muttrc">
++		<title>Muttrc</title>
++<screen>
++<emphasis role="comment"># Example Mutt config file for the 'trash' feature.
++ 
++# This feature defines a new 'trash' folder.
++# When mail is deleted it will be moved to this folder.
++ 
++# Folder in which to put deleted emails</emphasis>
++set trash='+Trash'
++set trash='/home/flatcap/Mail/Trash'
++ 
++<emphasis role="comment"># The default delete key 'd' will move an email to the 'trash' folder
++# Bind 'D' to REALLY delete an email</emphasis>
++bind index D purge-message
++ 
++<emphasis role="comment"># Note: Deleting emails from the 'trash' folder will REALLY delete them.
++ 
++# vim: syntax=muttrc</emphasis>
++</screen>
++	</sect2>
++
++	<sect2 id="trash-folder-see-also">
++		<title>See Also</title>
++
++		<itemizedlist>
++			<listitem><para><ulink url="http://www.neomutt.org/">NeoMutt Project</ulink></para></listitem>
++			<listitem><para><link linkend="folder-hook">folder-hook</link></para></listitem>
++		</itemizedlist>
++	</sect2>
++
++	<sect2 id="trash-folder-known-bugs">
++		<title>Known Bugs</title>
++		<para>None</para>
++	</sect2>
++
++	<sect2 id="trash-folder-credits">
++		<title>Credits</title>
++		<itemizedlist>
++		<listitem><para>Cedric Duval <email>cedricduval@free.fr</email></para></listitem>
++		<listitem><para>Benjamin Kuperman <email>kuperman@acm.org</email></para></listitem>
++		<listitem><para>Paul Miller <email>paul@voltar.org</email></para></listitem>
++		<listitem><para>Richard Russon <email>rich@flatcap.org</email></para></listitem>
++		</itemizedlist>
++	</sect2>
++</sect1>
++
+ </chapter>
+ 
+ <chapter id="security">
+diff -urN mutt-1.6.1/doc/muttrc.trash mutt-1.6.1-trash/doc/muttrc.trash
+--- mutt-1.6.1/doc/muttrc.trash	1970-01-01 01:00:00.000000000 +0100
++++ mutt-1.6.1-trash/doc/muttrc.trash	2016-06-12 18:43:04.768515676 +0100
+@@ -0,0 +1,16 @@
++# Example Mutt config file for the 'trash' feature.
++
++# This feature defines a new 'trash' folder.
++# When mail is deleted it will be moved to this folder.
++
++# Folder in which to put deleted emails
++set trash='+Trash'
++set trash='/home/flatcap/Mail/Trash'
++
++# The default delete key 'd' will move an email to the 'trash' folder
++# Bind 'D' to REALLY delete an email
++bind index D purge-message
++
++# Note: Deleting emails from the 'trash' folder will REALLY delete them.
++
++# vim: syntax=muttrc
+diff -urN mutt-1.6.1/doc/vimrc.trash mutt-1.6.1-trash/doc/vimrc.trash
+--- mutt-1.6.1/doc/vimrc.trash	1970-01-01 01:00:00.000000000 +0100
++++ mutt-1.6.1-trash/doc/vimrc.trash	2016-06-12 18:43:04.769515692 +0100
+@@ -0,0 +1,7 @@
++" Vim syntax file for the mutt trash patch
++
++syntax keyword muttrcVarStr     contained skipwhite trash                 nextgroup=muttrcVarEqualsIdxFmt
++
++syntax match muttrcFunction     contained "\<purge-message\>"
++
++" vim: syntax=vim
+diff -urN mutt-1.6.1/flags.c mutt-1.6.1-trash/flags.c
+--- mutt-1.6.1/flags.c	2016-06-12 18:43:00.403447606 +0100
++++ mutt-1.6.1-trash/flags.c	2016-06-12 18:43:04.902517766 +0100
+@@ -65,7 +65,13 @@
+       {
+ 	h->deleted = 0;
+         update = 1;
+-	if (upd_ctx) ctx->deleted--;
++        if (upd_ctx) {
++          ctx->deleted--;
++          if (h->appended) {
++            ctx->appended--;
++	  }
++        }
++        h->appended = 0; /* when undeleting, also reset the appended flag */
+ #ifdef USE_IMAP
+         /* see my comment above */
+ 	if (ctx->magic == M_IMAP) 
+@@ -87,6 +93,27 @@
+       }
+       break;
+ 
++    case M_APPENDED:
++      if (bf) {
++        if (!h->appended) {
++          h->appended = 1;
++          if (upd_ctx) {
++            ctx->appended++;
++          }
++        }
++      }
++      break;
++
++    case M_PURGED:
++      if (bf) {
++        if (!h->purged) {
++          h->purged = 1;
++        }
++      } else if (h->purged) {
++        h->purged = 0;
++      }
++      break;
++
+     case M_NEW:
+ 
+       if (!mutt_bit_isset(ctx->rights,M_ACL_SEEN))
+diff -urN mutt-1.6.1/functions.h mutt-1.6.1-trash/functions.h
+--- mutt-1.6.1/functions.h	2016-06-12 18:43:00.403447606 +0100
++++ mutt-1.6.1-trash/functions.h	2016-06-12 18:43:04.902517766 +0100
+@@ -121,6 +121,7 @@
+   { "toggle-write",		OP_TOGGLE_WRITE,		"%" },
+   { "next-thread",		OP_MAIN_NEXT_THREAD,		"\016" },
+   { "next-subthread",		OP_MAIN_NEXT_SUBTHREAD,		"\033n" },
++  { "purge-message",		OP_PURGE_MESSAGE,		NULL },
+   { "query",			OP_QUERY,			"Q" },
+   { "quit",			OP_QUIT,			"q" },
+   { "reply",			OP_REPLY,			"r" },
+@@ -213,6 +214,7 @@
+   { "print-message",	OP_PRINT,			"p" },
+   { "previous-thread",	OP_MAIN_PREV_THREAD,		"\020" },
+   { "previous-subthread",OP_MAIN_PREV_SUBTHREAD,	"\033p" },
++  { "purge-message",	OP_PURGE_MESSAGE,		NULL },
+   { "quit",		OP_QUIT,			"Q" },
+   { "exit",		OP_EXIT,			"q" },
+   { "reply",		OP_REPLY,			"r" },
+diff -urN mutt-1.6.1/globals.h mutt-1.6.1-trash/globals.h
+--- mutt-1.6.1/globals.h	2016-06-12 18:43:00.403447606 +0100
++++ mutt-1.6.1-trash/globals.h	2016-06-12 18:43:04.903517781 +0100
+@@ -141,6 +141,7 @@
+ WHERE char *Status;
+ WHERE char *Tempdir;
+ WHERE char *Tochars;
++WHERE char *TrashPath;
+ WHERE char *TSStatusFormat;
+ WHERE char *TSIconFormat;
+ WHERE short TSSupported;
+diff -urN mutt-1.6.1/imap/imap.c mutt-1.6.1-trash/imap/imap.c
+--- mutt-1.6.1/imap/imap.c	2016-06-12 18:43:00.405447637 +0100
++++ mutt-1.6.1-trash/imap/imap.c	2016-06-12 18:43:04.905517812 +0100
+@@ -888,6 +888,12 @@
+           if (hdrs[n]->deleted != HEADER_DATA(hdrs[n])->deleted)
+             match = invert ^ hdrs[n]->deleted;
+ 	  break;
++        case M_EXPIRED: /* imap_fast_trash version of M_DELETED */
++	  if (hdrs[n]->purged)
++	    break;
++          if (hdrs[n]->deleted != HEADER_DATA(hdrs[n])->deleted)
++            match = invert ^ (hdrs[n]->deleted && !hdrs[n]->appended);
++	  break;
+         case M_FLAG:
+           if (hdrs[n]->flagged != HEADER_DATA(hdrs[n])->flagged)
+             match = invert ^ hdrs[n]->flagged;
+@@ -2038,3 +2044,53 @@
+ 
+   return -1;
+ }
++
++/**
++ * imap_fast_trash - XXX
++ */
++int
++imap_fast_trash (void)
++{
++	if ((Context->magic == M_IMAP) && mx_is_imap (TrashPath)) {
++		IMAP_MBOX mx;
++		IMAP_DATA *idata = (IMAP_DATA *) Context->data;
++		char mbox[LONG_STRING];
++		char mmbox[LONG_STRING];
++		int rc;
++		dprint (1, (debugfile, "[itf] trashcan seems to be on imap.\n"));
++
++		if (imap_parse_path (TrashPath, &mx) == 0) {
++			if (mutt_account_match (&(idata->conn->account), &(mx.account))) {
++				dprint (1, (debugfile, "[itf] trashcan seems to be on the same account.\n"));
++
++				imap_fix_path (idata, mx.mbox, mbox, sizeof (mbox));
++				if (!*mbox)
++					strfcpy (mbox, "INBOX", sizeof (mbox));
++				imap_munge_mbox_name (idata, mmbox, sizeof (mmbox), mbox);
++
++				rc = imap_exec_msgset (idata, "UID COPY", mmbox, M_EXPIRED, 0, 0);
++				if (rc == 0) {
++					dprint (1, (debugfile, "imap_copy_messages: No messages del-tagged\n"));
++					rc = -1;
++					goto old_way;
++				} else if (rc < 0) {
++					dprint (1, (debugfile, "could not queue copy\n"));
++					goto old_way;
++				} else {
++					mutt_message (_("Copying %d messages to %s..."), rc, mbox);
++					return 0;
++				}
++			} else {
++				dprint (1, (debugfile, "[itf] trashcan seems to be on a different account.\n"));
++			}
++old_way:
++			FREE(&mx.mbox); /* we probably only need to free this when the parse works */
++		} else {
++			dprint (1, (debugfile, "[itf] failed to parse TrashPath.\n"));
++		}
++
++		dprint (1, (debugfile, "[itf] giving up and trying old fasioned way.\n"));
++	}
++
++	return 1;
++}
+diff -urN mutt-1.6.1/imap/imap.h mutt-1.6.1-trash/imap/imap.h
+--- mutt-1.6.1/imap/imap.h	2016-06-12 18:43:00.405447637 +0100
++++ mutt-1.6.1-trash/imap/imap.h	2016-06-12 18:43:04.774515769 +0100
+@@ -72,4 +72,7 @@
+ 
+ int imap_account_match (const ACCOUNT* a1, const ACCOUNT* a2);
+ 
++/* trash */
++int imap_fast_trash (void);
++
+ #endif
+diff -urN mutt-1.6.1/imap/message.c mutt-1.6.1-trash/imap/message.c
+--- mutt-1.6.1/imap/message.c	2016-06-12 18:43:00.406447652 +0100
++++ mutt-1.6.1-trash/imap/message.c	2016-06-12 18:43:04.906517828 +0100
+@@ -886,6 +886,7 @@
+         if (ctx->hdrs[n]->tagged)
+         {
+           mutt_set_flag (ctx, ctx->hdrs[n], M_DELETE, 1);
++          mutt_set_flag (ctx, ctx->hdrs[n], M_APPENDED, 1);
+           if (option (OPTDELETEUNTAG))
+             mutt_set_flag (ctx, ctx->hdrs[n], M_TAG, 0);
+         }
+@@ -893,6 +894,7 @@
+     else
+     {
+       mutt_set_flag (ctx, h, M_DELETE, 1);
++      mutt_set_flag (ctx, h, M_APPENDED, 1);
+       if (option (OPTDELETEUNTAG))
+         mutt_set_flag (ctx, h, M_TAG, 0);
+     }
+diff -urN mutt-1.6.1/init.h mutt-1.6.1-trash/init.h
+--- mutt-1.6.1/init.h	2016-06-12 18:43:00.408447684 +0100
++++ mutt-1.6.1-trash/init.h	2016-06-12 18:43:04.909517875 +0100
+@@ -3419,6 +3419,16 @@
+   ** provided that ``$$ts_enabled'' has been set. This string is identical in
+   ** formatting to the one used by ``$$status_format''.
+   */
++  { "trash",            DT_PATH, R_NONE, UL &TrashPath, 0 },
++  /*
++  ** .pp
++  ** If set, this variable specifies the path of the trash folder where the
++  ** mails marked for deletion will be moved, instead of being irremediably
++  ** purged.
++  ** .pp
++  ** NOTE: When you delete a message in the trash folder, it is really
++  ** deleted, so that you have a way to clean the trash.
++  */
+ #ifdef USE_SOCKET
+   { "tunnel",            DT_STR, R_NONE, UL &Tunnel, UL 0 },
+   /*
+diff -urN mutt-1.6.1/mutt.h mutt-1.6.1-trash/mutt.h
+--- mutt-1.6.1/mutt.h	2016-06-12 18:43:00.410447715 +0100
++++ mutt-1.6.1-trash/mutt.h	2016-06-12 18:43:04.912517922 +0100
+@@ -182,6 +182,8 @@
+   M_DELETE,
+   M_UNDELETE,
+   M_DELETED,
++  M_APPENDED,
++  M_PURGED,
+   M_FLAG,
+   M_TAG,
+   M_UNTAG,
+@@ -719,6 +721,8 @@
+   unsigned int mime : 1;    		/* has a MIME-Version header? */
+   unsigned int flagged : 1; 		/* marked important? */
+   unsigned int tagged : 1;
++  unsigned int appended : 1;		/* has been saved */
++  unsigned int purged : 1;   /* bypassing the trash folder */
+   unsigned int deleted : 1;
+   unsigned int changed : 1;
+   unsigned int attach_del : 1; 		/* has an attachment marked for deletion */
+@@ -891,6 +895,7 @@
+   int new;			/* how many new messages? */
+   int unread;			/* how many unread messages? */
+   int deleted;			/* how many deleted messages */
++  int appended;                 /* how many saved messages? */
+   int flagged;			/* how many flagged messages */
+   int msgnotreadyet;		/* which msg "new" in pager, -1 if none */
+ 
+diff -urN mutt-1.6.1/muttlib.c mutt-1.6.1-trash/muttlib.c
+--- mutt-1.6.1/muttlib.c	2016-06-12 18:43:00.411447731 +0100
++++ mutt-1.6.1-trash/muttlib.c	2016-06-12 18:43:04.913517937 +0100
+@@ -1511,7 +1511,9 @@
+ 
+   if (magic > 0 && !mx_access (s, W_OK))
+   {
+-    if (option (OPTCONFIRMAPPEND))
++    if (option (OPTCONFIRMAPPEND) &&
++       (!TrashPath || (mutt_strcmp (s, TrashPath) != 0)))
++       /* if we're appending to the trash, there's no point in asking */
+     {
+       snprintf (tmp, sizeof (tmp), _("Append messages to %s?"), s);
+       if ((rc = mutt_yesorno (tmp, M_YES)) == M_NO)
+diff -urN mutt-1.6.1/mx.c mutt-1.6.1-trash/mx.c
+--- mutt-1.6.1/mx.c	2016-06-12 18:43:00.411447731 +0100
++++ mutt-1.6.1-trash/mx.c	2016-06-12 18:43:04.914517953 +0100
+@@ -776,6 +776,62 @@
+   return rc;
+ }
+ 
++/**
++ * trash_append - XXX
++ *
++ * move deleted mails to the trash folder
++ */
++static int trash_append (CONTEXT *ctx)
++{
++	CONTEXT *ctx_trash;
++	int i = 0;
++	struct stat st, stc;
++
++	if (!TrashPath || !ctx->deleted ||
++	   ((ctx->magic == M_MAILDIR) && option (OPTMAILDIRTRASH))) {
++		return 0;
++	}
++
++	for (; i < ctx->msgcount && (!ctx->hdrs[i]->deleted || ctx->hdrs[i]->appended); i++);
++		/* nothing */
++
++	if (i == ctx->msgcount)
++		return 0; /* nothing to be done */
++
++	if (mutt_save_confirm (TrashPath, &st) != 0) {
++		mutt_error _("message(s) not deleted");
++		return -1;
++	}
++
++	if (lstat (ctx->path, &stc) == 0 && stc.st_ino == st.st_ino
++	    && stc.st_dev == st.st_dev && stc.st_rdev == st.st_rdev) {
++		return 0;  /* we are in the trash folder: simple sync */
++	}
++
++#ifdef USE_IMAP
++	if (!imap_fast_trash())
++		return 0;
++#endif
++
++	if ((ctx_trash = mx_open_mailbox (TrashPath, M_APPEND, NULL)) != NULL) {
++		for (i = 0 ; i < ctx->msgcount ; i++) {
++			if (ctx->hdrs[i]->deleted && !ctx->hdrs[i]->appended
++			    && !ctx->hdrs[i]->purged
++			    && mutt_append_message (ctx_trash, ctx, ctx->hdrs[i], 0, 0) == -1) {
++				mx_close_mailbox (ctx_trash, NULL);
++				return -1;
++			}
++		}
++
++		mx_close_mailbox (ctx_trash, NULL);
++	} else {
++		mutt_error _("Can't open trash folder");
++		return -1;
++	}
++
++	return 0;
++}
++
+ /* save changes and close mailbox */
+ int mx_close_mailbox (CONTEXT *ctx, int *index_hint)
+ {
+@@ -912,6 +968,7 @@
+ 	  if (mutt_append_message (&f, ctx, ctx->hdrs[i], 0, CH_UPDATE_LEN) == 0)
+ 	  {
+ 	    mutt_set_flag (ctx, ctx->hdrs[i], M_DELETE, 1);
++	    mutt_set_flag (ctx, ctx->hdrs[i], M_APPENDED, 1);
+ 	  }
+ 	  else
+ 	  {
+@@ -936,6 +993,14 @@
+     return 0;
+   }
+   
++  /* copy mails to the trash before expunging */
++  if (purge && ctx->deleted && mutt_strcmp (ctx->path, TrashPath)) {
++    if (trash_append (ctx) != 0) {
++      ctx->closing = 0;
++      return -1;
++    }
++  }
++
+ #ifdef USE_IMAP
+   /* allow IMAP to preserve the deleted flag across sessions */
+   if (ctx->magic == M_IMAP)
+@@ -1140,6 +1205,12 @@
+   msgcount = ctx->msgcount;
+   deleted = ctx->deleted;
+ 
++  if (purge && ctx->deleted && mutt_strcmp (ctx->path, TrashPath)) {
++    if (trash_append (ctx) == -1) {
++      return -1;
++    }
++  }
++
+ #ifdef USE_IMAP
+   if (ctx->magic == M_IMAP)
+     rc = imap_sync_mailbox (ctx, purge, index_hint);
+diff -urN mutt-1.6.1/OPS mutt-1.6.1-trash/OPS
+--- mutt-1.6.1/OPS	2016-06-12 18:43:00.389447388 +0100
++++ mutt-1.6.1-trash/OPS	2016-06-12 18:43:04.883517469 +0100
+@@ -142,6 +142,7 @@
+ OP_PREV_LINE "scroll up one line"
+ OP_PREV_PAGE "move to the previous page"
+ OP_PRINT "print the current entry"
++OP_PURGE_MESSAGE "really delete the current entry, bypassing the trash folder"
+ OP_QUERY "query external program for addresses"
+ OP_QUERY_APPEND "append new query results to current results"
+ OP_QUIT "save changes to mailbox and quit"
+diff -urN mutt-1.6.1/pager.c mutt-1.6.1-trash/pager.c
+--- mutt-1.6.1/pager.c	2016-06-12 18:43:00.412447746 +0100
++++ mutt-1.6.1-trash/pager.c	2016-06-12 18:43:04.915517968 +0100
+@@ -2351,6 +2351,7 @@
+ 	MAYBE_REDRAW (redraw);
+ 	break;
+ 
++      case OP_PURGE_MESSAGE:
+       case OP_DELETE:
+ 	CHECK_MODE(IsHeader (extra));
+ 	CHECK_READONLY;
+@@ -2358,6 +2359,8 @@
+ 	CHECK_ACL(M_ACL_DELETE, _("Cannot delete message"));
+ 
+ 	mutt_set_flag (Context, extra->hdr, M_DELETE, 1);
++	mutt_set_flag (Context, extra->hdr, M_PURGED,
++		       ch != OP_PURGE_MESSAGE ? 0 : 1);
+         if (option (OPTDELETEUNTAG))
+ 	  mutt_set_flag (Context, extra->hdr, M_TAG, 0);
+ 	redraw = REDRAW_STATUS | REDRAW_INDEX;
+@@ -2688,6 +2691,7 @@
+ 	CHECK_ACL(M_ACL_DELETE, _("Cannot undelete message"));
+ 
+ 	mutt_set_flag (Context, extra->hdr, M_DELETE, 0);
++	mutt_set_flag (Context, extra->hdr, M_PURGED, 0);
+ 	redraw = REDRAW_STATUS | REDRAW_INDEX;
+ 	if (option (OPTRESOLVE))
+ 	{
+@@ -2704,9 +2708,11 @@
+ 	CHECK_ACL(M_ACL_DELETE, _("Cannot undelete message(s)"));
+ 
+ 	r = mutt_thread_set_flag (extra->hdr, M_DELETE, 0,
++				  ch == OP_UNDELETE_THREAD ? 0 : 1)
++	  + mutt_thread_set_flag (extra->hdr, M_PURGED, 0,
+ 				  ch == OP_UNDELETE_THREAD ? 0 : 1);
+ 
+-	if (r != -1)
++	if (r > -1)
+ 	{
+ 	  if (option (OPTRESOLVE))
+ 	  {
+diff -urN mutt-1.6.1/PATCHES mutt-1.6.1-trash/PATCHES
+--- mutt-1.6.1/PATCHES	2016-06-12 18:43:00.395447481 +0100
++++ mutt-1.6.1-trash/PATCHES	2016-06-12 18:43:04.889517563 +0100
+@@ -0,0 +1 @@
++patch-trash-neo-20160612
+diff -urN mutt-1.6.1/pattern.c mutt-1.6.1-trash/pattern.c
+--- mutt-1.6.1/pattern.c	2016-06-12 18:43:00.413447762 +0100
++++ mutt-1.6.1-trash/pattern.c	2016-06-12 18:43:04.916517984 +0100
+@@ -1367,8 +1367,9 @@
+       {
+ 	switch (op)
+ 	{
+-	  case M_DELETE:
+ 	  case M_UNDELETE:
++	    mutt_set_flag (Context, Context->hdrs[Context->v2r[i]], M_PURGED, 0);
++	  case M_DELETE:
+ 	    mutt_set_flag (Context, Context->hdrs[Context->v2r[i]], M_DELETE, 
+ 			  (op == M_DELETE));
+ 	    break;
+diff -urN mutt-1.6.1/postpone.c mutt-1.6.1-trash/postpone.c
+--- mutt-1.6.1/postpone.c	2016-06-12 18:43:00.414447777 +0100
++++ mutt-1.6.1-trash/postpone.c	2016-06-12 18:43:04.917518000 +0100
+@@ -277,6 +277,9 @@
+   /* finished with this message, so delete it. */
+   mutt_set_flag (PostContext, h, M_DELETE, 1);
+ 
++  /* and consider it saved, so that it won't be moved to the trash folder */
++  mutt_set_flag (PostContext, h, M_APPENDED, 1);
++
+   /* update the count for the status display */
+   PostCount = PostContext->msgcount - PostContext->deleted;
+ 
+diff -urN mutt-1.6.1/README.trash mutt-1.6.1-trash/README.trash
+--- mutt-1.6.1/README.trash	1970-01-01 01:00:00.000000000 +0100
++++ mutt-1.6.1-trash/README.trash	2016-06-12 18:43:04.748515364 +0100
+@@ -0,0 +1,74 @@
++Trash Folder Patch
++==================
++
++    Automatically move "deleted" emails to a trash bin
++
++Patch
++-----
++
++    To check if Mutt supports "Trash Folder", look for "patch-trash" in the
++    mutt version.
++
++    If IMAP is enabled, this patch will use it
++
++    Dependencies
++    * mutt-1.6.1
++    * IMAP support
++
++Introduction
++------------
++
++    In Mutt, when you "delete" an email it is first marked deleted. The email
++    isn't really gone until <sync-mailbox> is called. This happens when the
++    user leaves the folder, or the function is called manually.
++
++    After '<sync-mailbox>' has been called the email is gone forever.
++
++    The $trash variable defines a folder in which to keep old emails. As
++    before, first you mark emails for deletion. When <sync-mailbox> is called
++    the emails are moved to the trash folder.
++
++    The '$trash' path can be either a full directory, or be relative to the
++    $folder variable, like the 'mailboxes' command.
++
++    > Note
++    >
++    > Emails deleted from the trash folder are gone forever.
++
++Variables
++---------
++
++    Trash Variables
++
++    | Name  | Type   | Default |
++    |-------|--------|---------|
++    | trash | string | (none)  |
++
++Functions
++---------
++
++    Trash Functions
++
++    | Menus       | Default Key | Function          | Description                                                 |
++    |-------------|-------------|-------------------|-------------------------------------------------------------|
++    | index,pager | (none)      | '<purge-message>' | really delete the current entry, bypassing the trash folder |
++
++See Also
++--------
++
++    * NeoMutt project
++    * folder-hook
++
++Known Bugs
++----------
++
++    None
++
++Credits
++-------
++
++    * Cedric Duval <cedricduval@free.fr>
++    * Benjamin Kuperman <kuperman@acm.org>
++    * Paul Miller <paul@voltar.org>
++    * Richard Russon <rich@flatcap.org>
++
diff --git a/pkgs/applications/networking/mailreaders/neomutt/default.nix b/pkgs/applications/networking/mailreaders/neomutt/default.nix
index fd5f4a18bd4fe..00d472b11bcb1 100644
--- a/pkgs/applications/networking/mailreaders/neomutt/default.nix
+++ b/pkgs/applications/networking/mailreaders/neomutt/default.nix
@@ -2,14 +2,14 @@
 , cyrus_sasl, gdbm, gpgme, kerberos, libidn, notmuch, openssl }:
 
 stdenv.mkDerivation rec {
-  version = "20160502";
+  version = "20160611";
   name = "neomutt-${version}";
 
   src = fetchFromGitHub {
     owner = "neomutt";
     repo = "neomutt";
     rev = "neomutt-${version}";
-    sha256 = "0r7nn7yjhf3d7nc89gwpgrq45gqiwsrcaw1pkgmvrd16p0jhga1m";
+    sha256 = "12487hydn9x1yyxzc0x7hssgjwji3i64glmbi7synjc8arfqc5zs";
   };
 
   buildInputs =
@@ -25,7 +25,9 @@ stdenv.mkDerivation rec {
     "--enable-pgp"
     "--enable-pop"
     "--enable-sidebar"
+    "--enable-keywords"
     "--enable-smtp"
+    "--enable-nntp"
     "--with-homespool=mailbox"
     "--with-gss"
     "--with-mailpath="
@@ -46,6 +48,6 @@ stdenv.mkDerivation rec {
     homepage = http://www.neomutt.org;
     license = stdenv.lib.licenses.gpl2Plus;
     platforms = platforms.unix;
-    maintainers = with maintainers; [ hiberno cstrahan ];
+    maintainers = with maintainers; [ hiberno cstrahan vrthra ];
   };
 }
diff --git a/pkgs/applications/networking/mailreaders/thunderbird-bin/generate_sources.rb b/pkgs/applications/networking/mailreaders/thunderbird-bin/generate_sources.rb
index 07374a827f2ef..43b41658413e2 100644
--- a/pkgs/applications/networking/mailreaders/thunderbird-bin/generate_sources.rb
+++ b/pkgs/applications/networking/mailreaders/thunderbird-bin/generate_sources.rb
@@ -29,7 +29,7 @@ puts(<<"EOH")
 # This file is generated from generate_sources.rb. DO NOT EDIT.
 # Execute the following command to update the file.
 #
-# ruby generate_sources.rb 45.1.0 > sources.nix
+# ruby generate_sources.rb 45.1.1 > sources.nix
 
 {
   version = "#{version}";
diff --git a/pkgs/applications/networking/mailreaders/thunderbird-bin/sources.nix b/pkgs/applications/networking/mailreaders/thunderbird-bin/sources.nix
index 227babe397d41..84845c764bccb 100644
--- a/pkgs/applications/networking/mailreaders/thunderbird-bin/sources.nix
+++ b/pkgs/applications/networking/mailreaders/thunderbird-bin/sources.nix
@@ -1,126 +1,126 @@
 # This file is generated from generate_sources.rb. DO NOT EDIT.
 # Execute the following command to update the file.
 #
-# ruby generate_sources.rb 45.1.0 > sources.nix
+# ruby generate_sources.rb 45.1.1 > sources.nix
 
 {
-  version = "45.1.1";
+  version = "45.2.0";
   sources = [
-    { locale = "ar"; arch = "linux-i686"; sha512 = "9825f8a9cc465435539aface355797d1f35437abd4a684efbc39ffe9948302e095e7aa9ab336e239a9d11a592f2c7d75fe21ef20747ff18a27ab404d0a43c659"; }
-    { locale = "ar"; arch = "linux-x86_64"; sha512 = "b2d16d69b78ade4fa9e5827411670e0a19d7fe7c1e2d893865f94514f5b50832ccf9ca5fb92354b152041605b1d7b7c1673d697537fc48ea3323b6b9563c4599"; }
-    { locale = "ast"; arch = "linux-i686"; sha512 = "37fcf68df5d69e56d9ab20e84542fd95b0e0f4fae56bc652b5037c9af97596ba27e4b3b92ea76dc81dc878cd125ee1b024ab5cf05662fbe6354eac303382396e"; }
-    { locale = "ast"; arch = "linux-x86_64"; sha512 = "f29f59ad51794e4bf1c570fdf3c5d45c61c23dc8ec9aaab5827abd961ce1228211277200782bf95c76a1c87138c2e1005d9474a055f4bbc1f0d9401b75cc856c"; }
-    { locale = "be"; arch = "linux-i686"; sha512 = "c2064f08f4e7f8154764d14605bf30d687670b0e617f21f99b80852ed41ef942a6573a2ec4bc4e01cbf1823efe064da011dd1f29841b2765323d78694465c8d2"; }
-    { locale = "be"; arch = "linux-x86_64"; sha512 = "d0c96406e0d889cbef011bdcb6f7d65f2ca4077b4c1c28d1790cf54fc6553092f7188ac32d5e2d80389c316ae205a982cb7d95b4bffe57f7e159304d3256978e"; }
-    { locale = "bg"; arch = "linux-i686"; sha512 = "43c7f27b227af8dd647008247bc0bd858d65126d34543a1e8376887fefe27d8f42997e9832802429343cc80c2b9cbdf02f99a195fcd99d9fcecea66e9a6968cc"; }
-    { locale = "bg"; arch = "linux-x86_64"; sha512 = "98da4029e345db4b123a32f57a2bdc01277b023d5e2463b04c31703fb5bb7e59cdf5322af62f62a0388a5046e8a2a151849110b24b51295c2f68fe96db0d936e"; }
-    { locale = "bn-BD"; arch = "linux-i686"; sha512 = "2b87536b6b9205d6078a028941703f19788c09e62cd1e17f00aac6da20859fcf4ca284d651e57e0b4332f197d5420b4f2121818445aa03f0580c10cb383c64e9"; }
-    { locale = "bn-BD"; arch = "linux-x86_64"; sha512 = "8a70702117a5a270b5f2dae44dec45471d7c7e791c3ed65aebc6fc016dee9df950dae7f5c9186c5b10d2b3cf483b57bfc43905862283bea6406c99c744c5b87e"; }
-    { locale = "br"; arch = "linux-i686"; sha512 = "7b2caaab28a8615fa68fab3ac93c9ddda08715d6c3674908febb50bf3a876659ed868656d545e1021056e64115a56e4bf7a88fcfc42d7e2292f9947ccfd2c42c"; }
-    { locale = "br"; arch = "linux-x86_64"; sha512 = "8d6a53a190c99fa4686139ad5f5c2f41572f8a5d6e2937035975585505eaa445807cbc5e7abc5584e82328dbb39b525b555dba6a13ff26d4ce53e564dc494344"; }
-    { locale = "ca"; arch = "linux-i686"; sha512 = "428d48e3609611354eead00a123d48cfe5e214fa405a97e701180b14c82329620fa7df45e703c5e8a8f84616839d022fb3be7192ff340ddb996229dba110b7e9"; }
-    { locale = "ca"; arch = "linux-x86_64"; sha512 = "560f6bdcc55c62db0ded2abfcbedf006a1b27c127ad193a4deebf117402aaa531a7069954e94cbe7b1c3d6b95e4cdfb46543e9ed623a22b6e14a64bff1b7b682"; }
-    { locale = "cs"; arch = "linux-i686"; sha512 = "48b984956b2f2139704caca7c45fdbeb0e0c138b7ce0548a3946be2dd2de5f83e9ac1b0605c08ed32e54d34fc830d2aabd127a8679c1d933d802e89db1ddad1e"; }
-    { locale = "cs"; arch = "linux-x86_64"; sha512 = "9a28daa1f56d5e676e9bb9c2fea52f7324c40eaf237ea5cd4614c66ec67ef9604967c864ac1fb1ab81d2e490c829916b4f5a2a93179fdcae55495837fd002700"; }
-    { locale = "cy"; arch = "linux-i686"; sha512 = "7e97b3ea0046406aa0c7254125215dc7cd109e7ffdbb8586c1b9928f3474a75f022d36f7f5e0d102b3a8dfd3c13ab78b7a3d4478e8334e685136ece57e2abbe7"; }
-    { locale = "cy"; arch = "linux-x86_64"; sha512 = "4445d1e434f7bfc646a9ac3ee796e70345f109fea93824cd4eea95f2b58fe81e3c1b2a6a667ff1c6b9f648294b3b2ea2d42b98477bb7e6ebd8d66bbb6fe4eaf5"; }
-    { locale = "da"; arch = "linux-i686"; sha512 = "1ea50eedeab6be84fe94ae52d50dba4d17bbcefb31f06cf439ce5e7dd743c03a87c59d4e17dbd931bb8e833701fb273a536fc3a89345686462fec12b64f50908"; }
-    { locale = "da"; arch = "linux-x86_64"; sha512 = "df90ab827acd69ff8e47011020e8d4a02cf669e1994d0238d11027270a8bc97fc7ff6f52ac766af6817b44efb62b985c8688d23efda3ab0a740734bf6764f755"; }
-    { locale = "de"; arch = "linux-i686"; sha512 = "3d0f2db8eefcecec01f6d102c413f6125a2eb37f2ce03458f75a34a9c1086531c0df4979a02bcf760c26f7d43aa4f6a5444b662cebf124f5f8b02ed5decbf83f"; }
-    { locale = "de"; arch = "linux-x86_64"; sha512 = "9de6e8002e57c9c51bcd01b3e49f6fb04e527ee9fd961ca5ad22806cbfaf9cc2e01e554576606866576094a2331e9aae36bd40b83a8c5fe892c726148ac08c0b"; }
-    { locale = "dsb"; arch = "linux-i686"; sha512 = "4600a52aa52ac9efc077b50e6b0b756af3e14c84fdfab2eddd83cd95568f6ca143754b0bd152a36165728f5c47b757cd3a21c06f4c92edc244b7be5775c298a4"; }
-    { locale = "dsb"; arch = "linux-x86_64"; sha512 = "472d1de923605ab68989cec03f9d447366d3afdddf94272bed9a52c7bbe2b50b172702e54004e4fd80a5f98d5170d541f060dd8fea0dbf04fc5ad54ae9bac6fb"; }
-    { locale = "el"; arch = "linux-i686"; sha512 = "83b81f80adc8311a77972596b21a602260ccb8d1c7bafd88e791f2e5549b3e9498ff4d62954faf2937ed6b9419eba23610521b1ad73ffe20bd8d6d1a5ad65bb4"; }
-    { locale = "el"; arch = "linux-x86_64"; sha512 = "64f16763606d69a0a1fde2d8901064d9c64c44d5d1f0f791167e0223f9fc943eb71023f7fc636c978f56ab1c9354fe042530eac740bbd3dc78be82fa74873a39"; }
-    { locale = "en-GB"; arch = "linux-i686"; sha512 = "3c3ec265945f796df2fc5d4ba35c32903534c3520629c952ccc984e76812041282b338e662c9aeefb87417c5ad01753acaed21f8089eae66464365caa2cb9609"; }
-    { locale = "en-GB"; arch = "linux-x86_64"; sha512 = "c6d91ae956ab4698802f4208e381dd9d7310595179badd564b32d9fd7dd7f2735d9be4317b1c39886e7b8d6886c998e3c174fdbcc2159e5e6e3d62ce78f3451a"; }
-    { locale = "en-US"; arch = "linux-i686"; sha512 = "f5f85a0c0bbe8066fc06891760113323b23de7d90480c1aeaac3f5fb2a9492792fb0de1cb4b7d7cbedc93ded0098afb5a30d144748a1bfc0b59481885214f581"; }
-    { locale = "en-US"; arch = "linux-x86_64"; sha512 = "88d037587e5d80d02621881ce6ba4034f686b87e3fd25741127345b655edb106d5d43f5900504b7f41b5403389e4f8317d715e6fb3994425dadcd4a5e527cde3"; }
-    { locale = "es-AR"; arch = "linux-i686"; sha512 = "3419e117a6c92db56be90d2511c726ba61606ca23ecc6c1d6939d2645a9d903459cc4400e229b2f5c59f5579eedf5d5c5506476093b864109796e619d3273a15"; }
-    { locale = "es-AR"; arch = "linux-x86_64"; sha512 = "c073b5502f37837ad418cca401a81d2b72100e86a5628062f2a24f8a978ba5f1f71bb75be707e9078fdbb9de797ecebc3d17b0a09cde8846e6900297dc6ded7e"; }
-    { locale = "es-ES"; arch = "linux-i686"; sha512 = "995abd683ae784fa337cb992b8741e729ea487e766895f226dbd37db79b78d9af0ed5cb3b06b9d50cbfdc9699fe06a65f6cda698661b74159fe9465cbc599a46"; }
-    { locale = "es-ES"; arch = "linux-x86_64"; sha512 = "d09be3138272a7061b48ef71b02a4faa6ef1010df4a99387364dc89c329a173c9843c0a4a8ca8e035999b0c5d69e91b647e79240505a4e474612423e232c802d"; }
-    { locale = "et"; arch = "linux-i686"; sha512 = "7d70752e672686602f94f80cfbaf24fe7e839b95a4868b1e88bd3a851a1aacb294a0ee7931ab5132dca7a06d5a4b2e3e1f1812af38f92b7d544ee1f08516f31f"; }
-    { locale = "et"; arch = "linux-x86_64"; sha512 = "a54cecb455a6a294dc8ea6f55b150d13d96c5f6c0dbfd81065f96efa5b41859c82a767de186eb4d0329b103bb516ad9a86789c4101f7c9cb0fe1773ddfae27c7"; }
-    { locale = "eu"; arch = "linux-i686"; sha512 = "fc813f13d74161baf8bd46bec0db69cfa33ba5cc4eaeb6b12f3ed48d294af973c35f1b8c03ea20ac254e00f2b8a30d0ac4a5e649998886b429e2d043f1755dbf"; }
-    { locale = "eu"; arch = "linux-x86_64"; sha512 = "2ce51531f64afc7b578d9972225d95b371161ba758aca52b9a6328e4c50a3337a2a7aa8d1307de6a00ac42ed53351efe8c8e83caec8192ff1bc2897b679668a2"; }
-    { locale = "fi"; arch = "linux-i686"; sha512 = "43d31ad2d6f59f17fd4704f8f8de089e90938454bd9b3755b30e50abbd18f3cd3ce4a4207c3cf5e4d70ddee73318643fc9913b6543a16989ad74d60e246e7392"; }
-    { locale = "fi"; arch = "linux-x86_64"; sha512 = "83055313856408d29079e8feaacbcc777fba655ed5bcec8400807ee3a497276d1fe4a6c1f911098c348a3789cef53db7c172c1771608e0c7241ce3739114b059"; }
-    { locale = "fr"; arch = "linux-i686"; sha512 = "170120a291c764280cdd00f8d4b2e59a0be31326c41943920e54eb816163b9182a531235aa96564e94db47716c8ce7aa87ff60817c262652822427a02dcb571d"; }
-    { locale = "fr"; arch = "linux-x86_64"; sha512 = "3ed963c5a7221ace7585caa34ad58db2ee087d90ad7de649fc397f26d512e180c10c25588ffb13ab7fc363d1bcc44d4e82fed67aa0561222af9af87e12330ebd"; }
-    { locale = "fy-NL"; arch = "linux-i686"; sha512 = "c59591f05938110429c2ef6d0751850f01b02c936e8af3ee9cf895af41a96bef9d3b9c62ef3af88ed8c2772094eeb85e6914351c8a3233a7800643c159b9aa12"; }
-    { locale = "fy-NL"; arch = "linux-x86_64"; sha512 = "f90ad1d08c44380b97f79e5b771abcf2aab8f69dcfed718e3ef44e64163e85e63203bdda65f01a231bb63bb04a8cf00aa87141499366996c568cbf9897b7d306"; }
-    { locale = "ga-IE"; arch = "linux-i686"; sha512 = "5449f8bbcb5a693f7c4d2f09a2e43b76a78aa9e5cdfaec450aebba7c11f061b6cd2e189889c56001304ae6ac8687b52275111dd39bc752885abb26add1ad2b84"; }
-    { locale = "ga-IE"; arch = "linux-x86_64"; sha512 = "82c3cc95bb4ca0a3def0deb5ecae003229cd62494a896c8706a600f70819c1709ad4b7c35f3edd14dda1560a300b4626898ec42057efe1835a718fd976d0d574"; }
-    { locale = "gd"; arch = "linux-i686"; sha512 = "ab4f895734cf6242efecf35306d79601bc2bb4d695170cf069cc740d49213828e86b3d26754c38438cbf4ada0abfe5195e9406658c4bc2da98583a427c132ff9"; }
-    { locale = "gd"; arch = "linux-x86_64"; sha512 = "2f710c027b7187a2e668a236e2b967490ecdd4c66ab9f4fbfc1a609431ff3f998371e0f14c673ce0647b0aa7d8ea5b0e31cc88238b69853a178705c00eefdc82"; }
-    { locale = "gl"; arch = "linux-i686"; sha512 = "7ee2fe3154adbb1f9a43a0e4979fb101205229e786b45a5edc5d9f39889ddff7abc45be73137e0df2bf789d0e9ab2b6f62e29a5a5a220a345d798a6fc48d009d"; }
-    { locale = "gl"; arch = "linux-x86_64"; sha512 = "294ca5fba76da62ba467b75798e55480beb672405a675a0050db76b07c612e44617ba8b316afa47b8041ec765dc3067e3d743e229f49ff75a1a3ce810aaec9a5"; }
-    { locale = "he"; arch = "linux-i686"; sha512 = "e91b8e2ec22e79d603d3047245d3f9da849f24c124f256dc993f6f4dd2f76c8c5b87a73b8b4c3152b7e5be71524ce7a7e17067bbc62bee57c0124e613fc71c29"; }
-    { locale = "he"; arch = "linux-x86_64"; sha512 = "97c2a2d9186c1816e9209ebc91e831c1c705e00030881c5e86c1e30b31a1866e9fe3abc4f02a359782d537f25d147c0011a7a03898b54882277ebe59da25a0d0"; }
-    { locale = "hr"; arch = "linux-i686"; sha512 = "5cf6afd2ceb62dbef77ff86eb995532901edc4bbd03d5e79916bef72d813e2f55ef40098c7029f7f380cbe9db195bca2a5fc0a7a1a561a607b38f9b32f6b2a18"; }
-    { locale = "hr"; arch = "linux-x86_64"; sha512 = "658dafb507d9521dba2c6757a0c98e10f0976672850aff6b88ce4eb2b047cab9661925ace07b49b901c3c19759d76d62eee5fe0b1ac986c6da7dc82fa7cad2be"; }
-    { locale = "hsb"; arch = "linux-i686"; sha512 = "37f582d813b991a25c66788ae013fb4cfa49ffd5d45da6f56c54c976e268b7418f25ad00cd7335238c16753fed4114e49ecadcb67ca26fa61094b72c74245c2b"; }
-    { locale = "hsb"; arch = "linux-x86_64"; sha512 = "28ab2743f87ea4a240d09cb5eb7bd6fce168c44eec3dfdefd1345b9c819381fac1699d133fe2c39244bcc7dda796e76f4ce495f5e530098bf19d4929d344f95c"; }
-    { locale = "hu"; arch = "linux-i686"; sha512 = "53312f4feeb4dc88ee102bfb8ff16f4cb67624b427f1852748eebaa1eb6faa5b66569e655f5f03a3c99584593b00d5d76f6e38ac473d589076e203da28d37ec7"; }
-    { locale = "hu"; arch = "linux-x86_64"; sha512 = "1719e0c33584508ea6e5528a7dca9f94d3b546cde758bf6fede8346c66f6c2ec9c85d49667aebcf065c09a81e0e1ea6b149af809eb9584aacfbd4674c6c66583"; }
-    { locale = "hy-AM"; arch = "linux-i686"; sha512 = "4b9f24ea4a3c53db1b667fdcb441f237dbe63a4a8ffa27c72387548369d1b56d818540f1e82c0121734009d3ae9e8bc266695a8ff64ac1f2aaddb86e56da0238"; }
-    { locale = "hy-AM"; arch = "linux-x86_64"; sha512 = "4b3a6c97be1d38ed1e556ec7567f12af1aec054a76fedc74bb26a53f6185009d7254f0aecd8ff14d07553abe1e0356e443707b0d9800c7d19a8e883bee9ca2ef"; }
-    { locale = "id"; arch = "linux-i686"; sha512 = "bbd6f3caac34e74469043a25935fdd4ee5cecf180025403ddf3d7b651fd52a9aad26dfe9f73cb1f4e3dde2a463d3a9c773fe08ebce42ed908ef107bde231c9d1"; }
-    { locale = "id"; arch = "linux-x86_64"; sha512 = "09dda35699dc17eca61b063d53c9a0326ad34cd43cc2ed4e822b4597bd108068db6cbe2b6347d0d28ec34f1271012cc42c31ef471e4f4d6cce211e5b31de33dc"; }
-    { locale = "is"; arch = "linux-i686"; sha512 = "b08603695e3539619b7450d03c88aec309d2f9b938b89455705fde1c75540e1d14a3d3111446aa6a41a8d271c5633b6d14861540751ddd7f45dd936322af6bd4"; }
-    { locale = "is"; arch = "linux-x86_64"; sha512 = "7ca4d5ca884713ab1bdcbae470be7435f7c20d273a50d6ff8304374f5a8c43d06702a1690080a94e28238d9afc4d6dfabc170ed842bf8359ada774a8e8b2d474"; }
-    { locale = "it"; arch = "linux-i686"; sha512 = "a27de0ec1735dc30e7c6a06bdad5fd7604f02446d8a9838251a6f6a0f621948d05beebb8e2f308ebb2df6207d3c6fb17dcfe5d1c2c2a48b3ca826006527271ba"; }
-    { locale = "it"; arch = "linux-x86_64"; sha512 = "dcf639e215e8941b0fee2c20471840fa77d7b9684f2e196042e201ae7de0b4aa8fabbc712e2217cf1c1883c78415b7839f8669cb897cf345ae00296b887ffd59"; }
-    { locale = "ja"; arch = "linux-i686"; sha512 = "497aa0048b4f53913e3a4461282fc809b99e7a1c43024dc937d5defd85e29b354290bf4962b200fdaa4dc2871f24b10a0aa2401e52b7b47a8c16dd32d49e2311"; }
-    { locale = "ja"; arch = "linux-x86_64"; sha512 = "61433f6cda12b4d7843c76f8a3a7a2fed3d08dac0c7df00fbef0a732df65afca595320ac9e01169f3ab277bbc0074e589b12737c4d2b9e031211e1aa10cfb18b"; }
-    { locale = "ko"; arch = "linux-i686"; sha512 = "d9a3538b444821d14fb8636d7282001a8130aea7437b8a919d71b7261c445443113dc1e45bf8ecce20679b4995175334918e58ac7c9d63ed40773f901c8168aa"; }
-    { locale = "ko"; arch = "linux-x86_64"; sha512 = "07d8661036b0dfa7390a940f879c961d25d08dd7eb8ab19cf3dd1964d44f74117bf2e8bfa64697d9576851270b5cf411c1660db9f7ce988970650b5824f8da42"; }
-    { locale = "lt"; arch = "linux-i686"; sha512 = "cc583cac7892ecc6a5c32a44761750efc9d566abab65fbb802f40b0f23b60099a0977b66ff1869db8723f8956aa370e1dc6a1ecffa739ec064a0c270471ba0f6"; }
-    { locale = "lt"; arch = "linux-x86_64"; sha512 = "20e7619a4f16492e73ba4576c6be9228c2377a57300b48fee5109dd21771f33200a9127db6215cb078cf1e76dc1ccdffd72dd361ebeeb76f1562fc4e82951e47"; }
-    { locale = "nb-NO"; arch = "linux-i686"; sha512 = "c64ceff628e315d7bc4991df0e7e5d872d8f3111948461c26cc9535977afb5c5123e3d8b575478ab0b1ab0fe07fd21c3484109e46b0407ad86933e082b29e491"; }
-    { locale = "nb-NO"; arch = "linux-x86_64"; sha512 = "9caf7fc7d5a5d11e532f60757f0bd6000d96ac42bf67c2ddf0a018bec8299b2f1e28cbeb97d862254a5036c44871ac14d059563b3b37d41efc5773e4a300391b"; }
-    { locale = "nl"; arch = "linux-i686"; sha512 = "3c5f36dd64d2f170339e7762e357fa901547891ed4f278dba8b835fe8be999e93869682747463f9364ca9b728e3dc63639b992898bd0cc1eb5e70edf0b9f2628"; }
-    { locale = "nl"; arch = "linux-x86_64"; sha512 = "17881c4a3771b1a96659278d87b242dcdf4f7fa85be100126c246babb61efd34a8e1ca45ef2f5501c5369f2c741ff44cd2d968b3e252b0a7c8ee2d3cfdda7bae"; }
-    { locale = "nn-NO"; arch = "linux-i686"; sha512 = "c28c62615b8c882373e2fc774733982b990b31ad291b6a48ca0d1f3583063e2c66b0dc7b4b9a17246e252255e75546752c84ec015c913ab312d573dcabf9146f"; }
-    { locale = "nn-NO"; arch = "linux-x86_64"; sha512 = "0b5ece430c8511cbdd7121f8f2128ece8cbfac954f4471e5358b425cfb5c7f09c925428fce03fd411c7d5d3258f2fb4e1003be3404deb0ecd4d79d40dac9fa7c"; }
-    { locale = "pa-IN"; arch = "linux-i686"; sha512 = "16cd5714f216637dee401ebf3b081f61400a05eafb3ac35b1db35b9afa4736e8334af7930fba6a87d2a7ce042eee235b3a57e1abd03964d28dad23fdb547a31d"; }
-    { locale = "pa-IN"; arch = "linux-x86_64"; sha512 = "865044c92a277fcde2fa9cfa21266f1737cda59f60cefaf852a80e0d1960bbb9af500b74c591e90dcea43643bc73e1adb726488a51e29746978bad84bf9a867c"; }
-    { locale = "pl"; arch = "linux-i686"; sha512 = "85ccc72a9d4421d6112e37fb2664b3189c6fef3efa3ad86d32658e40b102541f1fa345810d44e0e19b6c757a31bad934fa9a7b1df6cdbef7c6c0fb120dc38505"; }
-    { locale = "pl"; arch = "linux-x86_64"; sha512 = "08023b730410b4be5df7ed15261e1c1346be56e58645fc476dac6228adc21dae336b25ef11b9adec7ac8b9b1f7f942c1c579118a99bb6897099948bbd1c3f45a"; }
-    { locale = "pt-BR"; arch = "linux-i686"; sha512 = "84e80dfc3bd12f4900205dfbf1c4d20b64bc2ea220275c85f0ca2f9a9a2caf357ecdebc0d72788873524ff16a97e7c24afa3aa69314553cf4e693618334427a6"; }
-    { locale = "pt-BR"; arch = "linux-x86_64"; sha512 = "fc6de72f9457a6967f0ae18e5a71bd7b463d8c4a7c091795cac8f676125e580929382862d79a8b7659ade8ff8f87478f705c057270d9953900f36fa467dad3b2"; }
-    { locale = "pt-PT"; arch = "linux-i686"; sha512 = "7f454b2c5dfda9518b32c117955f04a3c582ce186e97146735891a3fcbd5873db56cd3495688b63eb59665bf3055d0db1ca426d5b5e98f559faea2da10c7daf2"; }
-    { locale = "pt-PT"; arch = "linux-x86_64"; sha512 = "f5f397958c9c10869381f0facb64530f7c3d1e4c669ebb0e2b32fccbee560b742b7350c9c314683f949e5c9cb0161beae4e706243f1214f0cca84244a7d2df84"; }
-    { locale = "rm"; arch = "linux-i686"; sha512 = "90aed589668ca02cd33ae08d430871b16ac5778c43f042ba9b8df7701b074636c61fcff059471fd9c5796df3a68d08cfcef190790fd4059fa47c118971882648"; }
-    { locale = "rm"; arch = "linux-x86_64"; sha512 = "eff8e94a8779771f66571febb9e793653484b45660285107020f871ffc70ad935a3fc68ea3f8eb942b3b7e05533c8235770d1727c2a43b27201872638685a464"; }
-    { locale = "ro"; arch = "linux-i686"; sha512 = "9fb422f3eff8417db103f8481acef1bcbf794e6e05bf831aa6b8bd839f42fd4baca1aaf999249e1776e9758ef041494ccb3a93c65c9060e240a73f77867df262"; }
-    { locale = "ro"; arch = "linux-x86_64"; sha512 = "fae562ec1ce02c4183f971f849aa904adc719470cfef55ac7f79ad8a57a1d31f9f926638565c9ee0e0cba51507a827e15a130f54406c59b7c0ac8fcac81fdc3c"; }
-    { locale = "ru"; arch = "linux-i686"; sha512 = "0039d541632368c41e2ce7f89263c6f6a6adf330ebd6205e637eca43fedd1a06a20080d621ba19163a0b9d4a91fc9a4b4b5ce50a694cdf985f36d9eb41c5311f"; }
-    { locale = "ru"; arch = "linux-x86_64"; sha512 = "cf289f78ffb353457eacaaea091ababf4b284cf4caa01f50fef3ae36d8c67f5d0786f366fcc1a35d231bd8ec1077392be662442852791337caa80a0b00f7fa40"; }
-    { locale = "si"; arch = "linux-i686"; sha512 = "9db7054433c6e06f8188478ee639a7b9d20ca9f868143de7861eb804276e5f620736f1ec44d21017eb126d62814cc276d75734ae32cae590194558bfc41375ff"; }
-    { locale = "si"; arch = "linux-x86_64"; sha512 = "258d1db736872157b276c67e7a7c5d5e89740c8e19de09091c05d2de1610ae1e50e17f8d020ee74b8b9e0ec70bc419b357289368c90de5b6c6067ba692564567"; }
-    { locale = "sk"; arch = "linux-i686"; sha512 = "8ae01308c4013b53a009c95114fe349cee67c1bd918e42da976994941aad6ece4b285168ce26634a0eba9a589a1e0a9d9a6fcd742113b69220ea504cb076e547"; }
-    { locale = "sk"; arch = "linux-x86_64"; sha512 = "9af3e23397534c6b72d5b720842ab6aa2df5e7c62134947555dea0837caadcaff57fd4fcfbf68d623be8875940fe20983a9144ef9f1ec0d228e8ac956ca9b708"; }
-    { locale = "sl"; arch = "linux-i686"; sha512 = "f58e111856ab370b5720acd96578874dcdbc0913cec8f5f6956e33802f2fc7648ee39f0d0b8df9fce85d6df42186ccc0df070afc597f032b3f30af4b00074c1e"; }
-    { locale = "sl"; arch = "linux-x86_64"; sha512 = "1dbdcf95dfa3a6148c23d5e5ef5b2520ad3558f8c6e528a6a1585d57545f7f3ad81761a0c4ec04794753ddffc089135168dc5ec82b0eb8699f09e29722f90aad"; }
-    { locale = "sq"; arch = "linux-i686"; sha512 = "b7759d1b50bd3700d717c0bfe2a3b384aea864b2a62f41e04aed12e5f24be9ace991f8e2a142e1c1c329818fd3a0643f538412f03999dc7d1cba5a87a82c3bc9"; }
-    { locale = "sq"; arch = "linux-x86_64"; sha512 = "cc55ec09a7fbd1a798bfb1d4f0199ecf125329873515c549e6a701e3bdf0e0d6d444be203c424a67e27ad96f2e486ac9b823e6d286b0699adb8812f43ebd6437"; }
-    { locale = "sr"; arch = "linux-i686"; sha512 = "65562e1be17a16ff6d09e1f6bc0d6f9b0fdfe67de8661992f561b57778c52e49931b8b1f9b658c65c540cc1e3596ea06d3ca5da644b39c05b7964c2fd6927fb3"; }
-    { locale = "sr"; arch = "linux-x86_64"; sha512 = "784cf692425ce351d5fea5dfa33f80eabe0d996a6158ada1c50d8937571549f06cb52eaf8faefcc73f39eeb2a4a79b5fb9a5c4b221796c0da1b23fd3aa36f74f"; }
-    { locale = "sv-SE"; arch = "linux-i686"; sha512 = "fa7dd0bf6440cbfc4ed01f34be82c86bae770c7e8b7ea84ab4ee30ea087c4d3fc10c09f9c8e8b2d3dc1b285ac12db611d18f1cab62411b1e4d2ff16edef02a45"; }
-    { locale = "sv-SE"; arch = "linux-x86_64"; sha512 = "1bbb03695bfe04c1dc3cac1fd37b24910f746a128efd10274db4b7e8025ef5270a66c344a2e9dacb88b6eb2a186e10bde0fa0ba41a73a241d548454806d049e6"; }
-    { locale = "ta-LK"; arch = "linux-i686"; sha512 = "ea498d149d452321f98de5f6320f0980c22cf9859e332e08e359e9399caaa1e2b0d2d66880e045cc1d17636f0821386be9ddcb510840c7d442f1eb1b4051494b"; }
-    { locale = "ta-LK"; arch = "linux-x86_64"; sha512 = "055b33db08bf48e016077242e8d52a1f0fa72a36e72bcadde5429eb3ddf39898ab7514d70173b4f8b765014d984bff1180da7e57e6235bfc41f5ba5e502fb423"; }
-    { locale = "tr"; arch = "linux-i686"; sha512 = "a4d04d2430935904377d995646c84acf75d2c0b6a05a7b4935ad49b89fc5f895c6e9b772ad09cca7d9634614ff685aa268f834e1d09dd0d5d4fd33402c56bdd5"; }
-    { locale = "tr"; arch = "linux-x86_64"; sha512 = "bf29e50b724fadc0ff324664ff191ed49799bd540d9e4483651caa87a5cb6e3614b87a5e3cc4957560627698e0991b97c3501f4fe8bbdc87b1afa5018e9d6e02"; }
-    { locale = "uk"; arch = "linux-i686"; sha512 = "44c9a47daf570f6a669210ec8cb883c5cc1cdb614b7fdbf98a4a087d87f862cf00695849ec73c9d79c99008ee98e4b1ddc96ac050ed5af7ff20db52163026188"; }
-    { locale = "uk"; arch = "linux-x86_64"; sha512 = "0d67fe5c1ab189b25d0ef22b3180b1b67139cca94a02aad622b5b000e212bf88b84b65e034c6720b41bfeb98e4cde38a8f4998f40661f7a0334f5df743de2152"; }
-    { locale = "vi"; arch = "linux-i686"; sha512 = "f8fe254886133e05a297ebdaf97de0115595c5a6243e58e7b3057c1d007c75fb85ec78e1942c7d005d5fdf218b52ac9418f120788e2000c121168c7c82f4b4b7"; }
-    { locale = "vi"; arch = "linux-x86_64"; sha512 = "7db410ee86ae7810315b8349dada32411fcd37bc5670e1aaa15be15a00bcf40280f1d4e94aa934ee507baedb1a5b2d096697d6ae7bba953263c7b6943877ab08"; }
-    { locale = "zh-CN"; arch = "linux-i686"; sha512 = "f7f0d6794ffa6128941cec38266cf68c9718d702a261808d1f689adb34bc03cfda2c1e30d496974f1d2c98acde2461c17f99691a8a46f52b27ce02123e1d52d2"; }
-    { locale = "zh-CN"; arch = "linux-x86_64"; sha512 = "15239b95519c79b16fc09f6ed1058e48aaf932a796661c800371ba69e67f7e9712d191019b4d8a4dd32a391f688fe023e0e9b284a58de7d8918a198c24c63d08"; }
-    { locale = "zh-TW"; arch = "linux-i686"; sha512 = "abfa901719a55673831c41ca5363f993e14b555766fb63d6e0e33def7bbc021fade2ce9b34c8354b8315c614114be58c0a19c9b74766400ca284fdac6057ab5b"; }
-    { locale = "zh-TW"; arch = "linux-x86_64"; sha512 = "66b3b31e00ec4ff8dc9810d07e1928554f78535975b54f1ac436d7b9eeee3b6dcf2aeb485e80f2d10b07f75eaffb2fdbd7be7208da67bac60515320efd5d60df"; }
+    { locale = "ar"; arch = "linux-i686"; sha512 = "fa7457cf48ca68f559b14b79acefe90f8d449e7dd7a32a97f728ef33b26e3f513064bf733eed77b12237902491852a66fce690b1cf1de049e2f09d27416d8786"; }
+    { locale = "ar"; arch = "linux-x86_64"; sha512 = "6b2bc528ef7401a5ca6d6c5e68eaf68386a706925a3087ed16b4a2560a449ccba52c8dacae39d9a761323cc46f934ca2ea3c07bc5ef49df07eff9760a8a0ed15"; }
+    { locale = "ast"; arch = "linux-i686"; sha512 = "2917644f88a775441634a8b2dc214e29a34eb0cc7ad88c423a5cc02f7603cf321392c7fc3c7ce97231835fd39d1d8e264d8a9fb084651ec722719d5110d83cbb"; }
+    { locale = "ast"; arch = "linux-x86_64"; sha512 = "d047bc41a3ee0a444c8e4870a986c0068a67deff043bf96a9ae6338247461f2b51ecf02348c4a5b5e2ae4f68f7bd665c64582f0afc45bd480588cc82cdebc1e5"; }
+    { locale = "be"; arch = "linux-i686"; sha512 = "830fce5b2361acef206876a43af60963ddd720ad4c49c30936b0231c94096c5f43fb9479679c0260846a28a315f359ee2cdcb66e1f2bce0d222f1495b1cf1f58"; }
+    { locale = "be"; arch = "linux-x86_64"; sha512 = "8ec67cd108abb51b86fb8cc528a6bd43628847e47e2a7e5ffe3bc971b6c89aa0c7cbce2ce0738a7316a54c4ab376502187ddf5be9d74db31985187b7e6ae3038"; }
+    { locale = "bg"; arch = "linux-i686"; sha512 = "d18965ad8f1456d688811e972b09e293cedaa98832b4d5898d62a80dc9cb4799d898a14ad968fc2f05c3e6dcf3fc480d21d1d8de63a4ea9c10b8081b28c321fa"; }
+    { locale = "bg"; arch = "linux-x86_64"; sha512 = "a7dcbe29dc4b28b3273693bec60f9ed66d1eb81899a049f7181271e84763f13817f97e07a9696ce803d151b382f3339f3b0d2b1bdfc5bc687c3f6198627e2fd3"; }
+    { locale = "bn-BD"; arch = "linux-i686"; sha512 = "3919ffd44cb501f5c8d273651e3bef27203270ae269e8682f2c749a32eb6a622a8106179cb9a493f7e62f255da62381ab497e2a590f84bd207a1bbabc039827d"; }
+    { locale = "bn-BD"; arch = "linux-x86_64"; sha512 = "8e4d026bf30a0fc69eb2c7982b3866a4745f506f5365677540e050cba81a569df1b367c42b9bcaf58ae20243a82a9e7d006c476a83ecc29b4b77f042f8aad5d1"; }
+    { locale = "br"; arch = "linux-i686"; sha512 = "cd00e42cce4a5efd18ba5b9a784dc93282c200a43796b826cc05eb4858d44775df827dafcda0c6468d17ea5f7f930590db1546b544fc19ad52d9d5e1cf7c522d"; }
+    { locale = "br"; arch = "linux-x86_64"; sha512 = "be84c92859014a055606588fd7e9c8d8c13fed8ca253ccaed560a2b457305b487cb2664df8af7416220349a85a4db15f7420674ab46c1ba8f8cdec03f0002d83"; }
+    { locale = "ca"; arch = "linux-i686"; sha512 = "2e678aec4efde29b659f1e4de071f7b5cf2fc56b28b362bfc7fc2a3ba8ceaaa53a3452cb9c2a565ea5bf83304be87fa18dd246d2207e5ba6f5ad16a0f008ffe7"; }
+    { locale = "ca"; arch = "linux-x86_64"; sha512 = "7bebca69abdf5510793e376693d82e626fbce49d01fc66d28bc53ad51ab70fd9432266e2cc1b0d83359fb2bfdd075daa181c66618f6094996355f6cc0920b239"; }
+    { locale = "cs"; arch = "linux-i686"; sha512 = "2f8d5faaa0952ad37e3777a2d15e2a1ac7aed1ed275faf909e479f56e4ee2e9f385aedf6b08cdb3abd9e0830949b6b6b1048e19ac489d0d0e881595b31816068"; }
+    { locale = "cs"; arch = "linux-x86_64"; sha512 = "01e807c22d90e07503b92e3821ddf91b509763d9c7b2ebc5e21ec9788333086de25508979422446a2e0469be611f890db682757ddebf15e549bb8714f40877d4"; }
+    { locale = "cy"; arch = "linux-i686"; sha512 = "e87718bbd286e1e2fcef8e114aa27b81a1917b37cba996c59ddc30d5300bf53a4e3662d3770f70362850d41e564887ba510f605412e57d8e6510f02e5a4d54d8"; }
+    { locale = "cy"; arch = "linux-x86_64"; sha512 = "f3287f4cec54f6814a678dfd9875952d5109716cd15d097ad5589fb2bbf75aabf2496cff6d320929c825b1a1e61d50f060b9d9fd7f7011078620995570dbe88a"; }
+    { locale = "da"; arch = "linux-i686"; sha512 = "6cc8e7c2c3aec96dc9639a8663915db2e86437b8b9a598570946b2dc63c9d261a257dcba3359762668683a67cf39d5448e0203eeeeb4da41f6d5df51c955da3d"; }
+    { locale = "da"; arch = "linux-x86_64"; sha512 = "bcba101b8438ff5a61ecb76f1328174aaaf7dccf5031a836cfcd8e597db8d0b120623e15a8c8231373732b6796015ed9fe212797bf0f664055d3be3755bf38d5"; }
+    { locale = "de"; arch = "linux-i686"; sha512 = "fffa1b9a61ef75ac077bf03f85abbb5a40131a9a35a49835ac40b424870b773a42f8fb534ba5757da7c0bf6781efe39dbe2942ddd436860efe5799170952dbed"; }
+    { locale = "de"; arch = "linux-x86_64"; sha512 = "db88539be38c0a62d9c56b5295af2bb67d342996c85e788a17fe2a74e974a8d196765343ca005207b8b1ebb8f76421640dc7cdf36c51e23a4bc03edfbdbfe73c"; }
+    { locale = "dsb"; arch = "linux-i686"; sha512 = "2191707e5c796eb5ef210798c3519004f5cfcc9be0f56a22c03eef52a34f04f011e556894dc932467c142c8ec876105cab628c947ded0e11d7a63733db83bdac"; }
+    { locale = "dsb"; arch = "linux-x86_64"; sha512 = "07a9bb323db8f626ff0614dd8cfbbb1f0c8d922aac4c7ce21770b79c40e79ca09c798903998d44c236cfaa76daaaa94814bff697d34aafa417533078405cef1f"; }
+    { locale = "el"; arch = "linux-i686"; sha512 = "4325888c1b2585d7f2bf9c999407dba260783570816b0edfadd90bdebe6d6db637f9aa9589f2b5824ab6e833c4527fa760e177ed866ce302fce85d9b9daa2608"; }
+    { locale = "el"; arch = "linux-x86_64"; sha512 = "bbb2971ba5c3ebda94312f740c54ef0b4b4b4f2311d4a017e272260945a9f063eb4d341857919da4107f2207f3265df9439aea78d636d9c357fd79a11239fd9e"; }
+    { locale = "en-GB"; arch = "linux-i686"; sha512 = "507f8f79718698b9599d52e7b5a4a9157c05ae1642622eff1b3547861532ece9727b3d56f67a20ca38df0f32375beec65ec3c7b1ba929799ddc057b4b95d1b8d"; }
+    { locale = "en-GB"; arch = "linux-x86_64"; sha512 = "bbaceccac3ad841259058c738ef2baef780e96177b3b6a635fbc8a18de53137ec6831729b9f98bcb6b4442fe58b5dd71f526a9f0f3b86231a41bb0a48ea4c930"; }
+    { locale = "en-US"; arch = "linux-i686"; sha512 = "28b5d2699a65792457414d178bb3bc4d73abf911860ecbcf75bbcfae91b24a056fd67d6aa4d50e4b3003ef84c63750050e16e74c92b690fe9b24347de3ad54a7"; }
+    { locale = "en-US"; arch = "linux-x86_64"; sha512 = "08034ab8d833f7a2e63a7e40a56dfc78a2dd762e73d1a4b8fd0dd70ad23da5d525771846f47c8e7798517d1f85fef9bc2a8437af3d6ba71d7402a9f6a93d5679"; }
+    { locale = "es-AR"; arch = "linux-i686"; sha512 = "3f08fc47b03cf095bcfc0af78064fd7179006a4b3240292fbd109b2a4c58c55719328eed631a67ca7a3f0f68ac8d2fcc577596bf532ad95442fba728270ef28a"; }
+    { locale = "es-AR"; arch = "linux-x86_64"; sha512 = "cfe7e9f8dd67fb52462f840048115e54e5f789a34b63c5d7ec592ccc3a2b25220a66fb7499a50f32539d61205fc46199c0167ad5a75ea46123b96070329a236d"; }
+    { locale = "es-ES"; arch = "linux-i686"; sha512 = "d2c4cc32d2ae7bfdde1870686675f644f4eb3f2bd0870fa72986f5cef2cc3c45b8070b6df3196e67275bc67c1ece63706f1fcae3b89d80fea8db5c34b9f4b638"; }
+    { locale = "es-ES"; arch = "linux-x86_64"; sha512 = "6f4d295638ab8d16e1ec1db176d9a60946ee76cacb21c7e10018c2b908e5dad0527705d37b7050d11587244e922fa9e218482fcef40c3beab06c07db3dd8ccfb"; }
+    { locale = "et"; arch = "linux-i686"; sha512 = "e352de0fb13570e5fd39bae39ea7dfab746529e8617beb8cca51c0a6183614722f62f93e91065c74fbe24e0cd91c03428d76c6e70369a60a64957ebebd1052d7"; }
+    { locale = "et"; arch = "linux-x86_64"; sha512 = "583be1a8c7f1e2aac3242371ca8f34710510c6750b95f933e1574f9ba0e2a6ad733de4c9cc503909a063250d969aaaee6a53a69aae0c502274f5b0d43fc33b43"; }
+    { locale = "eu"; arch = "linux-i686"; sha512 = "9de8f87c48c65535c7b073ad90d9c1ad3b7f4932124529ffc1ece36175e5a139d4660efc4a850bd0034d885afc7d7889f137b10fb5972377a4ec97d6858c932f"; }
+    { locale = "eu"; arch = "linux-x86_64"; sha512 = "101beb0a0dc8f33a78583f9b15036815b030429d471ba0c8852dde7a2e2c91bb6436c8dd36f39e4eab1ecdb38cec08c7ab88f4649b5d25a246657d358984f7c2"; }
+    { locale = "fi"; arch = "linux-i686"; sha512 = "9670d209fabc23fed2dadb873335e3964b7107b67fbfda39e53fa28ff1d91fd617f73d041cd9d4d0b9dfbdc9e619f69ce05199f7afd383a4fd6717b9f912dee9"; }
+    { locale = "fi"; arch = "linux-x86_64"; sha512 = "3c2b135437a80047ec04e9995d119b32e948d105677bde0efe505272a0768d860e8b68dbe487bb81c38f9eee94a7bcc23c976a3dd614300056ec578bb5dbe7a1"; }
+    { locale = "fr"; arch = "linux-i686"; sha512 = "d14822f3ef67082a77488ee3f7b6e3294a01f12e48cf037fb2b41ab9c5e4af01f1b0a76b29673c9196f2caa16dade84183d69a6bbf1dd618e7742f9e1d903477"; }
+    { locale = "fr"; arch = "linux-x86_64"; sha512 = "e1fdb863309bcdf382c3533b15ff1c3e4e9ee6f4c0ea097790c432d302b4a0712d00b1f0851dbc4c4e9c3758f941eddffd82dd1d3912dc76afc20e05083b82ad"; }
+    { locale = "fy-NL"; arch = "linux-i686"; sha512 = "3881348184cdbac93b452e9f5c9ebbf14c542dff68cb500c82204dec42c3433e3b356f2d332c1fb5a4f6649e8bd5b03564bbd1f75bb25c2d946c72ba955c4b63"; }
+    { locale = "fy-NL"; arch = "linux-x86_64"; sha512 = "3182f39c26085bc882cb1a391c63f2ce58a8ffcffce4ae1ca9293a08e572d888691cb2968d93caee77576bc7568a0ad67f0ccb6815dfffadc9f8f798343c92b2"; }
+    { locale = "ga-IE"; arch = "linux-i686"; sha512 = "a653b578be20b8127de26e7c8ac90adc04024cd108e078b5a5e2e7634d834d76f9227341e52ab8b72fdc5f8c11787405eabc19403922c854f0d0fc7e9fcb0774"; }
+    { locale = "ga-IE"; arch = "linux-x86_64"; sha512 = "28dcbcefd11807482becc961244f58520498e0f9540f28c1e74d18f499cf5a209d51599783b8551ee937f228b406bd0605adef4146e29dccd8ccf2e5ef155a2c"; }
+    { locale = "gd"; arch = "linux-i686"; sha512 = "2b39ed0b1533cce97f4c4e5663ffef0fc88611334cceeaee0687ccc87e8c4b0f58afd9d826e7e9b66634b51249b776820cf03fc841e739ff3504eadc02597dd5"; }
+    { locale = "gd"; arch = "linux-x86_64"; sha512 = "525f632482577a3dcc2668495ad8c127bb8bc06412ef01ccf0188c1dbf735e73460cbabac439fc3dd80cf70519c45a439897ef91a1b32208d527e0b6487044f2"; }
+    { locale = "gl"; arch = "linux-i686"; sha512 = "232bbd56d92ce7648ba57a061d8154b38bc6068dbde32b9ef17199d3a8bb28e1b0b384859d99c526fa96fbb35405520675ab3b45adc90caf125ac813bc77b5bd"; }
+    { locale = "gl"; arch = "linux-x86_64"; sha512 = "5758ab0d5a6733395ba62601735193073fcee47ba7c3ab24d7031ce87447fb9018264bf3df1ab715ea786beb63a9d479e57217d56477d987021aa482c7b116a5"; }
+    { locale = "he"; arch = "linux-i686"; sha512 = "dc7cd600a93276995634303cff80d77724b56f0b7ff2fdfe8fe7da23d57d5f4f3d0e0169508c02c9ac57092da58d9ac9e3646f951ca4cb1fd398c70196fc6405"; }
+    { locale = "he"; arch = "linux-x86_64"; sha512 = "bdb385f4df861b1109169e1819860d46e8edf4d58588d4cdce609387117adeafe35e8bb17a0a2e43bcf12b1bb2244f089f3a1669cd69bb507434da202a1c7e15"; }
+    { locale = "hr"; arch = "linux-i686"; sha512 = "e7dc17107f762128bac6f0e173ceaec6a9e910dc84d486a0c9447365f1df07fcc1379dd2f05416aa904637836deac5a924f704396ab2af149676a6b1d075c52f"; }
+    { locale = "hr"; arch = "linux-x86_64"; sha512 = "74600954b56b03d4f2bcc71b32f6c8a19be483af16a7cd2b841fabea6eb042ded21afb1c196aa9bea97c81aae1732d7153e8419f97f439b44570ae53e53f88ea"; }
+    { locale = "hsb"; arch = "linux-i686"; sha512 = "d42d5b10480100a38d2fe275be060423593f54f9aa6cda13fdac96fca9a36590dd9bb8d1638cca935faedbd09bf2435c0a2858ae9c2ce653af7b2dd183f46f29"; }
+    { locale = "hsb"; arch = "linux-x86_64"; sha512 = "c41c5b57d7c170c54cd0817dbe21be8ba9e94b99fe28d7478ceb6545c6bf64a215d9ed6c66f99f116f43bb7b442ba6765613c15d14648ff64be3c0c5d7a6c763"; }
+    { locale = "hu"; arch = "linux-i686"; sha512 = "d2ee002d390bf44ecdadba86ece0d77bdb4ea96a69a79dac4064a4c3f3244c9aeed95df4a1101535fb02225e0305e1d7e97389d4419574ad98d9484237aaff84"; }
+    { locale = "hu"; arch = "linux-x86_64"; sha512 = "aca465875d8f3cb5815dd2de0546b7a822b55090c78f049d6d3a885f29c90fcbc437f0b7184e8249bb9c8dcc1ca4f146f1cf0067a751590df2d8c5fe4aeeea5d"; }
+    { locale = "hy-AM"; arch = "linux-i686"; sha512 = "567cba4a91dcc944e1922a429c8b328fc3b2843105056cef938a97c2ba73806f0fee2471b6fe6898856230c54ae0cb6110ebb249eaf9363a0beb35ed2aa0daba"; }
+    { locale = "hy-AM"; arch = "linux-x86_64"; sha512 = "34bf0a6638822fd1ea6c1a51e01d0d2f370202c61bb5a728abbeb2c1335c9130f3a4fbb7c26f9cb8025849aefde09eaf58567c7aedfd7d854d7313baeb8fd698"; }
+    { locale = "id"; arch = "linux-i686"; sha512 = "9dd1e0ba44787921fe8fce39f430575334e61948cbbd2e31923c67779c795dc0fc64cc0e46d62e3fa749a3d6cac12c3cb54c3f9e62e02930c1f4fd9a17fa50b2"; }
+    { locale = "id"; arch = "linux-x86_64"; sha512 = "78385b8276c5a9449d34a0233b40280437dacfc04a9d5d8291ae8603ee5b89337c5b53d4da80f41ca8c7153719654d6506027179c4a79575fd555d9dc8740d4f"; }
+    { locale = "is"; arch = "linux-i686"; sha512 = "02bc577e3d696735a280079fef84361d556a04c5d3f11f5af93f9ec5220ed729f237eb67120739192dfeedcb4570480bc40da9c413ca2b7f9023a5742cbb2e4a"; }
+    { locale = "is"; arch = "linux-x86_64"; sha512 = "5de6270e4dd79f402163fdd724fa0987563c1f474c54b555e84ebd94cdb865bd890de21e3dc44ace9dc2bcc70fb182b78752840b6860a6f0494fbfadf4f705c6"; }
+    { locale = "it"; arch = "linux-i686"; sha512 = "d81131a4322b0a069f3f914d394f8400b0d532aad4f1a0316288ed00df184798c5c61484cbb50a134e7b681a2f150bd04416147734f0d73731811349e537a2d3"; }
+    { locale = "it"; arch = "linux-x86_64"; sha512 = "7c9ce8e652dc994ee1155e4d1d3375ad093d8f684c422157a5c450edc3701151a1ca8036dda5f79781860ea1e138960266a7df77c16770418f4cb8327e2a2767"; }
+    { locale = "ja"; arch = "linux-i686"; sha512 = "6b96e8bba64fb004021838e41a36f13469eb48cb03659bceb12b897dd09fdc44f32d279e71e97b146a77fc0433cd85eb38449bf666355692a25f39eddc2775b8"; }
+    { locale = "ja"; arch = "linux-x86_64"; sha512 = "90c7f76fecc1c9eafbbd7f2f935a006266372d4192c2382c447b52a7993b650b6bb769d1f2f067540f038588b862a82ab4f1dc3b8a7c2a484fedaee55c82889e"; }
+    { locale = "ko"; arch = "linux-i686"; sha512 = "c2e509fd91664c9ae9d12ad4eebbc875b96c3b7124b88373fbbfb8ef3ec45b3525e8e9c6a295680c583b55564ee26855f2d607a661bfce9d9f57acdc4b90a3cb"; }
+    { locale = "ko"; arch = "linux-x86_64"; sha512 = "b5fb1e955dde624bdf52a58d5ffadf99cc7fb0a0e757d236c553675aca14fbc942d420a63c91f64e584486fda3e0ecc39c62dbba6b3a62910d01447d7cafd4fc"; }
+    { locale = "lt"; arch = "linux-i686"; sha512 = "a24deedd6a2ed118cbdb9fc66c17aeb5756d8bf3586a096164c0c1841e1bd7a4b6179cacff3f058bbc9bef40186acf3833a5b2e75aeca8ee525302953fd7ea58"; }
+    { locale = "lt"; arch = "linux-x86_64"; sha512 = "f4e0a5ec95a30f04a8ee84dd1f4f8bf7427255d382c0fc6a35f63a935edf54380dcd73bca5329ea01147e89c4d3faf30582412618e93a543643ee5922e9044b9"; }
+    { locale = "nb-NO"; arch = "linux-i686"; sha512 = "c10d7ce6f66d716c550f27ba793cd6239d98ef7fb1dc75605288f426bb2fb65357af95134c4c2241f0438ac90995f666a488a3a61e7696318180496bc29cc94f"; }
+    { locale = "nb-NO"; arch = "linux-x86_64"; sha512 = "a722d43addca22cfc791da37de60d5ab96e18d66fbb0d8b4b3de9f08202b01bec8c5b8300404df19689d154249d80b0f84a6e09335f607c74a7ee65f64daecee"; }
+    { locale = "nl"; arch = "linux-i686"; sha512 = "030da83ad81fcb1ce7188d8957fc0ea216372aa4e1fd6fd7d173ef5e329d95d8cd61d1ec9db3e28887d2f949056172644b0590e05815478abb42427d0ad5c06b"; }
+    { locale = "nl"; arch = "linux-x86_64"; sha512 = "6ea70e3fedc1cf1ea6f75ce9be7c8a7a6245e167f65baaabcdfd3194e70ca5474766e9ccd0d8180270b84c78697793a9af5b82a8f7a773c46b1af0a025382a99"; }
+    { locale = "nn-NO"; arch = "linux-i686"; sha512 = "354bb0c0447c8e7a54e8e8218f659f4810a6e2848f85c482cf289fe77518fce9c33bd817019bf089f254f71b141d65061c2a690190000c968badd939feaacec0"; }
+    { locale = "nn-NO"; arch = "linux-x86_64"; sha512 = "fa2484614a067461d8cc3c1fab8675f65b17fc6419c0fe1a8f15e98e8ffffea7297391ec8ec50ec8d2fe1cac4b348afe0b82f2db55584c46cbe2d62daf3a8e4b"; }
+    { locale = "pa-IN"; arch = "linux-i686"; sha512 = "045fa66125cc3c4fc4650bf4e5ea12aae1b26f2cc4191d6b464f41e5305f015611463b311f3bb55264d07b48edbbff606cb58f73d91b22b3bfaaf5de0b830121"; }
+    { locale = "pa-IN"; arch = "linux-x86_64"; sha512 = "696dad47dde2f2494f0410fb698b52ca87112e2c29310aea585b703f4633e404f533d37e6bbe09939aa6f575f426d0a4f2605ca5b95fccafc033569bfe258872"; }
+    { locale = "pl"; arch = "linux-i686"; sha512 = "1848c4c819fa0aebeeec75ac43f3bcf3fa332ba08b79c8296a17aadc7d0434d2b634280541c8d71a68390e3a892a88dd49a0ab4b25c3a2b4b5e7321132801ee9"; }
+    { locale = "pl"; arch = "linux-x86_64"; sha512 = "e9e0b937a165fd90e0639a01001c9b4ada645c9a1201b64ae6cbc1bbf885b5d0b89e195ca5732aaae66360dfc4f188ac8f1643bf12bdbfa029a348aa29a0f79a"; }
+    { locale = "pt-BR"; arch = "linux-i686"; sha512 = "4a69c26598d48d25d048288b6d1785dc8e4d89078eca3d300497a93d44639a8eaca0c32c1988abd831d33e0c32788e8ca6d07fdec9cd4ba7f451a23afbddc525"; }
+    { locale = "pt-BR"; arch = "linux-x86_64"; sha512 = "72d387d49ae5f4dd6406f63fd5c0003f99865079c9d63d7d3deaf15268437dba592642ee8bc759df85fb679da094078c1bdf9808de05bf5e35ac870a62b960e2"; }
+    { locale = "pt-PT"; arch = "linux-i686"; sha512 = "b3ff7eecd345f789bc4798e94402fe7cf7a0cbf27b03f3d8f92274f39764cfd38bd1e4ad5745f3d177645f2c5bea6cb4aa2f1110c90d524bc6b89916c00b2eb2"; }
+    { locale = "pt-PT"; arch = "linux-x86_64"; sha512 = "684849e41f77410c290688582488243fed9594c02ebdd85812a2c63e0cc410b470c14533d09184a83df43555b9ff1d775ed0f1ddbe24bb6890848ccce4e041f6"; }
+    { locale = "rm"; arch = "linux-i686"; sha512 = "02c4171d05c1f070cde474ad60edd7aded613ec1fd7bf51391fe4718554eed435282c44bf891703c356f5bfc0dd08093ef5bc7c979174d5b7fdab1529dde9dbe"; }
+    { locale = "rm"; arch = "linux-x86_64"; sha512 = "9ea31a30e8b5624c03c1627a6e2e1895a3ede5d35e1b9da0b16d6571c13af0e34cfcbe17f396638c8946b1f96037e9c833b3ed58ad46a9e0bf38ffc0e1dc8bba"; }
+    { locale = "ro"; arch = "linux-i686"; sha512 = "dc5b581971333067b25317b702a2e9f58484ae66f640ecda0f9d7c8323fbf8c9fb6ca47fb59c94494e641787f7e9b95c6a4cf3037bf2fc974cc394160359910e"; }
+    { locale = "ro"; arch = "linux-x86_64"; sha512 = "92ef0d86e46d8c80685e9bcd16331447e310147b87cdb45bf80ab2992b4ea11626cf5fbf860ee807d2d8d4e6c7c4fdd352de4c498a57c6951f66ebf72bd60aeb"; }
+    { locale = "ru"; arch = "linux-i686"; sha512 = "511f96bd7713ea798904216d466f362115922c1566d7214115df7665d9e152b9866bb66608f5426080251f55391ac92eb8ec8a0e76d9471563a0bd84fc8c4431"; }
+    { locale = "ru"; arch = "linux-x86_64"; sha512 = "57f6669ae5706a4673bb15b1eb06d89807a9a1a0fb59493b2380778efd8dd3f014d1e0a354c16e71207bf0121a561720caa1a71a846237044889916374b6a5d6"; }
+    { locale = "si"; arch = "linux-i686"; sha512 = "9eb41ae08570098f2cd9d099cec9d2a21490f5bbd7a5a9a422ae9c83b72fb50af2768ed7c33d0d174c3bd09b365107b1e726a57db8fd6bcf52dcc7430f8d22fe"; }
+    { locale = "si"; arch = "linux-x86_64"; sha512 = "03291a8e69b3b6ebb69e25627ed77fed3e7a008ae77f869b262983fb9334e61748a1028f6dd4e1aabf513b7f6cbaefef83c237107d88c1b177c31f34fff54e3f"; }
+    { locale = "sk"; arch = "linux-i686"; sha512 = "0152a947109f5257ec17889453cf650d1dcdd40825208053e65b70e8281579fce307d1f38e6d682d7a8d2f3da377c91ca1e249bc1d507c768d2f08292e5e6b90"; }
+    { locale = "sk"; arch = "linux-x86_64"; sha512 = "d2fdb7585af8a1507362b44b9383acc611668cc4aeb912d98424a49543cefb9a58f95aaa77c1b36a1082fd1334f60df939900e1673e32d3af764ca5ce746d144"; }
+    { locale = "sl"; arch = "linux-i686"; sha512 = "c2cedc7a07a27f439e5833ca9a1214d0e75b2154ff879fa39b06ab6baa05d13feac227b51d1126d70ef907942db1dcaf1e7c987128f752d0dc1d147266cf520f"; }
+    { locale = "sl"; arch = "linux-x86_64"; sha512 = "07aa88c7d281e247e9c30f9ae3b8329132d4a145e8a8b0f88b544995d39f58d196fb6ce6a5604954129222a848ce49aa07a0bf6f1ab3a4b1fd29e61f51c7664f"; }
+    { locale = "sq"; arch = "linux-i686"; sha512 = "e2afd03139f475ae68206cc1f35780261abd7646babd7f05c255acbcdbb712f11ea0b7b68887d0fc05e8bcded3a166cea490c86b2936be7d400c919efbb221cd"; }
+    { locale = "sq"; arch = "linux-x86_64"; sha512 = "7b91f7c6cdeda2735dbe7befcdec777a6d22c1aa278d4a1caa8cb15441841b4edb7599e8d4d4fbc1d198cc6178625ad4a29455e7195ab563e9bd3ac4faa1104c"; }
+    { locale = "sr"; arch = "linux-i686"; sha512 = "6b92ea68fde0ede23bdd7998a81d9924e35b8cb77cc396636fb91495cafe039c32efa272f8c3693fa4ec582eb04bc0db6d22991e3056d22188e0eb8c64bf352b"; }
+    { locale = "sr"; arch = "linux-x86_64"; sha512 = "3ca3f049f677f9283d9af660d2989f5c05ed418bb904e7695e456f73d9615da106e0f0db2c3a371109c77fd7348eef5a94d8061b3a0ad508d193e1234839f954"; }
+    { locale = "sv-SE"; arch = "linux-i686"; sha512 = "95bbcfaade0c12d87c8b591e3d9d6205e1056741e9eb526cc505687e2ee43fbdb96ff0b411c63b58c6fdd57260180a94d343155163518843a843f5f3b086b25b"; }
+    { locale = "sv-SE"; arch = "linux-x86_64"; sha512 = "15d0bfb22e6f0d3425737dd05dedc5af7e1f98744fb0d943cd88ad6125083bc86bbfb700d71839a090f9b54642cc1b0ebb8fbd205d46316f83cab75bd5442ec9"; }
+    { locale = "ta-LK"; arch = "linux-i686"; sha512 = "89b3a7997d3cc3a8372ee49df3dee21e535403d08a2aa742a1416c1e7c41c63fa56fe50fe133f588f3a34db180c4505f05034e99e078c0b19e1eef6f48e3d7fb"; }
+    { locale = "ta-LK"; arch = "linux-x86_64"; sha512 = "00c20fc4c27005e13cda53c5332bf874267e4bda6894480e599557e5e90a334b648a47ce28fff6353060d9a6fb4e547e632e2deb1513175023c1bf6d453a9583"; }
+    { locale = "tr"; arch = "linux-i686"; sha512 = "1b791b57b9d8c3da228293c83fa02fc1a24a0b6b8a6efaecbfef42962f2390fb448d2fb08e5a812df8efcf135f9cecb98cba3b2b174e59b43575236ba5fb2f76"; }
+    { locale = "tr"; arch = "linux-x86_64"; sha512 = "7040da3720ce3b0dad6e2863b48e025c32206c8a0d6cdae4e4fb13b7b6754796e9e1b83a09280303a83c97ddaf391c10a56aa8edfe1e7eca60534a6e1d4006d3"; }
+    { locale = "uk"; arch = "linux-i686"; sha512 = "54412cf33dab4be4553d267cad386d47ca38726e8643de10b8509828ba6c25f2c35e151165d3d999c22724ba57028b740f9b5e5f9a05aa773779759ffe6ced78"; }
+    { locale = "uk"; arch = "linux-x86_64"; sha512 = "3725c3c9c7ee8140b2c9ae3ad928e933afbfaab60ec27b8f1a8c56a87553c0123031d50d27c794407b6971b347b8f379c1c92ddff00db960bb635fb0cd945ebf"; }
+    { locale = "vi"; arch = "linux-i686"; sha512 = "92edb5e4789d1e1a63d5f69f99a06ae474d85949771c07ef572ce5ae66a125d5c04ea207b51fcb4ee2d1f00052f53ee8415d109cb06e53c55e9436f37e375d3f"; }
+    { locale = "vi"; arch = "linux-x86_64"; sha512 = "e786670f4033857873e5238118b23a86638b190db51d70ac55662718126621580bffd705803638bf71556caa397f3420efaa08e83e06abb4c2e2dbdd22f111af"; }
+    { locale = "zh-CN"; arch = "linux-i686"; sha512 = "9af79559703b8734df11c2773ccd7f77a88d9dc5ebf2df1bac14fdef4ad0f45c840102e5bb86f6172ad6e7d225af8a1723d4de84b877fb2574fd1a729213ea08"; }
+    { locale = "zh-CN"; arch = "linux-x86_64"; sha512 = "4d63dc15450d9297d4f161c72eded27d6176bc755f657012821cd9d9e989597c296f985e12af39d7a1b37dd5cf442fdbf9d2e1f7e6f11ba841ed87ea279d813b"; }
+    { locale = "zh-TW"; arch = "linux-i686"; sha512 = "7bca2ef8b1e597346c0450870fcd0058fac18b3f3607c6280774db97d594e98928bf291ee22146d70f2de40437e38088b9a8af71b0b076b9bbf2049067bfc448"; }
+    { locale = "zh-TW"; arch = "linux-x86_64"; sha512 = "64ee5cf56a48159c1a2aee2c8dc9118ce9187c5c68a9a1393e2c28a35786fd42042b13d48d30ececf1893973ccab92c0a8b23cbaec340a5150cc1a994236c6cc"; }
   ];
 }
diff --git a/pkgs/applications/networking/mailreaders/thunderbird/default.nix b/pkgs/applications/networking/mailreaders/thunderbird/default.nix
index cd919566138c3..dc6d43fefb819 100644
--- a/pkgs/applications/networking/mailreaders/thunderbird/default.nix
+++ b/pkgs/applications/networking/mailreaders/thunderbird/default.nix
@@ -13,7 +13,7 @@
   enableOfficialBranding ? false
 }:
 
-let version = "45.1.0"; in
+let version = "45.2.0"; in
 let verName = "${version}"; in
 
 stdenv.mkDerivation rec {
@@ -21,7 +21,7 @@ stdenv.mkDerivation rec {
 
   src = fetchurl {
     url = "mirror://mozilla/thunderbird/releases/${verName}/source/thunderbird-${verName}.source.tar.xz";
-    sha256 = "0293cwnqj4ys629ra87577c7snv4p8x2nbs1kzcnjpc96vjypsca";
+    sha256 = "1h1p14zswrg71qvzshwvw03mhicwwkfg29hvnj56cf41nb5qj8xx";
   };
 
   buildInputs = # from firefox30Pkgs.xulrunner, without gstreamer and libvpx
diff --git a/pkgs/applications/networking/mailreaders/trojita/default.nix b/pkgs/applications/networking/mailreaders/trojita/default.nix
new file mode 100644
index 0000000000000..892d9d8fa5787
--- /dev/null
+++ b/pkgs/applications/networking/mailreaders/trojita/default.nix
@@ -0,0 +1,41 @@
+{ stdenv
+, lib
+, fetchgit
+, cmake
+, qtbase
+, qtwebkit
+, makeQtWrapper
+}:
+
+stdenv.mkDerivation rec {
+  name = "trojita-${version}";
+  version = "0.7";
+
+  src = fetchgit {
+    url = "https://anongit.kde.org/trojita.git";
+    rev = "065d527c63e8e4a3ca0df73994f848b52e14ed58";
+    sha256 = "1zlwhir33hha2p3l08wnb4njnfdg69j88ycf1fa4q3x86qm3r7hw";
+  };
+
+  buildInputs = [
+    cmake
+    qtbase
+    qtwebkit
+  ];
+
+  nativeBuildInputs = [
+    makeQtWrapper
+  ];
+
+  postInstall = ''
+    wrapQtProgram "$out/bin/trojita"
+  '';
+
+
+  meta = {
+    description = "A Qt IMAP e-mail client";
+    homepage = http://trojita.flaska.net/;
+    license = with lib.licenses; [ gpl2 gpl3 ];
+  };
+
+}