mu4e-maildirs-extension gets incorrect counts with mu4e-maildirs-extension-custom-list

49 views
Skip to first unread message

Hippo Man

unread,
Aug 31, 2016, 3:13:48 PM8/31/16
to mu-discuss
I'm using `mu4e-maildirs-extension' with `mu4e-maildirs-extension-custom-list', because I only want to look at a subset of the maildirs within each account.

This works fine, except the message totals for the account reflects all of the maildirs in that account, not just the ones for the subsets that I specified.

For example, suppose I have an account called "myacconut", and assume that it contains the following maildirs: "INBOX", "Sent", "Drafts", and "Extra".

However, suppose I only want to see "INBOX", and "Sent", and so I set up `mu4e-maildirs-extension-custom-list' as follows:

(setq mu4e-maildirs-extension-custom-list
   
'("/myaccount/INBOX" "/myaccount/INBOX.Sent"))


Let's assume the maildirs have the following message counts:
INBOX:             1/123
INBOX.Sent:      0/10
INBOX.Drafts:    0/4
INBOX.Extra:     50/50

What I see in my main view is the following

Maildirs

   
- myaccount (51/187)
     
| INBOX (1/123)
     
| INBOX.Sent (0/10)


As you can see, the totals form myaccount reflect all four of its maildirs, even though only "INBOX" and "INBOX.Sent" are being shown, due to `mu4e-maildirs-extension-custom-list'.

I'd like it to appear as follows, where the account totals are in sync with the totals that only come from the maildirs which are displayed ...

Maildirs

   
- myaccount (1/133)
     
| INBOX (1/123)
     
| INBOX.Sent (0/10)


Is there any way in `my4e-maildirs-extension' to get the account totals to only show the values from the displayed maildirs when we're using `mu4e-maildirs-extension-custom-list'?

Thank you very much.


Hippo Man

unread,
Sep 3, 2016, 12:06:03 PM9/3/16
to mu-discuss
I checked with the author of `mu4e-maildirs-extension', and it turns out that unfortunately, he is not available to work on this.

Therefore, I hacked the code so that it now shows correct totals for the parent nodes in the Maildirs list.

I will test my code for a while, and once it's solid, I'll ask the author to push it into github.

Here's the patch for the latest version of mu4e-maildirs-extension.el. Let me know here if you come across any problems.

diff -u /opt/local/git/mu4e-maildirs-extension/mu4e-maildirs-extension.el /opt/local/share/emacs/site-lisp/mu4e-maildirs-extension.el
--- /opt/local/git/mu4e-maildirs-extension/mu4e-maildirs-extension.el    2016-08-16 19:03:36.090016279 -0400
+++ /opt/local/share/emacs/site-lisp/mu4e-maildirs-extension.el    2016-09-03 11:59:56.368494716 -0400
@@ -286,6 +286,9 @@
 
(defvar mu4e-maildirs-extension-main-view-func
   
'mu4e-maildirs-extension-main-view-handler)
 
+(defvar mu4e-maildirs-parent-count-hash-table (make-hash-table :test '
equal)
+  "*Totals for parent nodes.")
+
 
(define-obsolete-variable-alias
   
'mu4e-maildirs-extension-submaildir-indent
   '
mu4e-maildirs-extension-maildir-indent
@@ -430,7 +433,10 @@
                 
(mapc #'(lambda (parent-name)
                           
(setq path (concat path "/" parent-name))
                           
(unless (member path paths-to-show)
-                            (add-to-list 'paths-to-show (format "%s/*" path) t)))
+                            ;; Now, store parent nodes simply with a "/" at the end
+                            ;; so they can be identified for totalling within
+                            ;; `mu4e-maildirs-extension-load-maildirs'
.
+                            (add-to-list 'paths-to-show (format "%s/" path) t)))
                       parents))
 
               (add-to-list '
paths-to-show name t))
@@ -484,10 +490,31 @@
     
(let ((paths (mu4e-maildirs-extension-paths)))
       
(setq mu4e-maildirs-extension-maildirs
             
(mapcar #'mu4e-maildirs-extension-new-maildir paths))))
+  ;; Make two passes.
+  ;; The first pass puts the totals of the counts of the leafnodes into `mu4e-maildirs-parent-count-hash-table'.
+  ;; The second pass applies those counts to the parent nodes.
+  (clrhash mu4e-maildirs-parent-count-hash-table)
+  (mapc #'(lambda(it)
+            (let ((path (plist-get it :path))
+                  (unread-count (or (plist-get it :unread) 0))
+                  (total-count (or (plist-get it :total) 0))
+                  (counts '(0 0)))
+              (unless (string-match "/$" path)
+                (setq path (file-name-directory path))
+                (setq counts (gethash path mu4e-maildirs-parent-count-hash-table counts))
+                (setq counts (list (+ (car counts) unread-count) (+ (cadr counts) total-count)))
+                (puthash path counts mu4e-maildirs-parent-count-hash-table)
+                (mu4e-maildirs-extension-count-unread it)
+                (mu4e-maildirs-extension-count-total it))
+              (mu4e-maildirs-extension-update-maildir-prefix it)))
+        mu4e-maildirs-extension-maildirs)
   (mapc #'(lambda(it)
-            (mu4e-maildirs-extension-count-unread it)
-            (mu4e-maildirs-extension-count-total it)
-            (mu4e-maildirs-extension-update-maildir-prefix it))
+            (let ((path (plist-get it :path))
+                  (counts '(0 0)))
+              (when (string-match "/$" path)
+                (setq counts (gethash path mu4e-maildirs-parent-count-hash-table counts))
+                (plist-put it :unread (car counts))
+                (plist-put it :total (cadr counts)))))
         mu4e-maildirs-extension-maildirs)
   mu4e-maildirs-extension-maildirs)



Charles-H. Schulz

unread,
Sep 3, 2016, 5:04:57 PM9/3/16
to mu-di...@googlegroups.com
Hi,

Thanks a lot for that clarification. Unfortunately, something weird happened with this extension -it messed up my emacs.elc file and my init file itself. I got rid of it and I'm not sure why it created that problem. Basically, I had error messages at start-up, and the message was pointing to "mu4e-maildirs-extension" being somehow wrong inside the elc. Not sure why, or what the issue really was. I'll investigate if I have more time.

Cheers,

Charles.

Charles-H. Schulz

unread,
Sep 3, 2016, 5:33:47 PM9/3/16
to mu-di...@googlegroups.com

Oops. Wrong thread. Reposting ro the correct one.

Charles.

Reply all
Reply to author
Forward
0 new messages