Neomutt: order mailboxes by modification time

Created on 27 Jan 2020  路  5Comments  路  Source: neomutt/neomutt

What would you like to be able to do?

I would like to be able to configure the sidebar to show mailboxes in order of modification time, so that most recently used ones show up at the top. Alternatively/in addition it would be great to have a cut-off as well, i.e. mailboxes unmodified for more than x days will not be shown.

What needs to change in NeoMutt?

An additional option for sidebar_sort_method would be needed. The code looks pretty clean, so if there is a straightforward way to get a mailboxes mtime this shouldn't be too difficult. If someone points me to the right place(s) I'll be happy to give it a go myself.

Have you tried any alternative methods?

For now I am using *sort_method=new (Incidentally new and unread seem to be identical in this context. Is that on purpose?), but that's rather unsatisfactory as I have plenty of mailboxes that contain huge numbers of unread mails but that I haven't touched in ages (yes, I am not terribly well organised).

discuss enhancement

Most helpful comment

Hi @mhinsch

I have plenty of mailboxes that contain huge numbers of unread mails
I am not terribly well (organised)

Sounds like you should investigate Notmuch :-)

configure the sidebar to show mailboxes in order of modification time

OK, that sounds reasonable.
Maildir and Mbox store the modification time in struct Mailbox, so sorting them should be pretty simple.

But... it won't work for other mailbox types: IMAP, NNTP, Notmuch.
Perhaps that doesn't matter.

If someone points me to the right place(s) I'll be happy to give it a go myself.

Certainly.

First you'll need to Fork the neomutt repo, create a branch and build NeoMutt.
See:

You'll need to add a new sort method:

Sidebar:

Update the docs:

There's a lot to take in when getting started with NeoMutt, so: Ask lots of questions
(here, or on irc: #neomutt on irc.freenode.net)

When you've made your first commit, you can create a Pull Request.
That'll allow us to help you and encourage others to contribute :-)

All 5 comments

Hi @mhinsch

I have plenty of mailboxes that contain huge numbers of unread mails
I am not terribly well (organised)

Sounds like you should investigate Notmuch :-)

configure the sidebar to show mailboxes in order of modification time

OK, that sounds reasonable.
Maildir and Mbox store the modification time in struct Mailbox, so sorting them should be pretty simple.

But... it won't work for other mailbox types: IMAP, NNTP, Notmuch.
Perhaps that doesn't matter.

If someone points me to the right place(s) I'll be happy to give it a go myself.

Certainly.

First you'll need to Fork the neomutt repo, create a branch and build NeoMutt.
See:

You'll need to add a new sort method:

Sidebar:

Update the docs:

There's a lot to take in when getting started with NeoMutt, so: Ask lots of questions
(here, or on irc: #neomutt on irc.freenode.net)

When you've made your first commit, you can create a Pull Request.
That'll allow us to help you and encourage others to contribute :-)

Hi @flatcap,

Thanks for the comprehensive introduction. I've started the implementation here. I've reused the date sort flag as it's used pretty much equivalently in the browser, so the changes are quite minimal.

Unfortunately, however, it doesn't appear to be working ATM. The log confirms that cb_qsort_sbe is called with the right settings (ssm == 1 in sidebar.c:453), but my sidebar still shows up in what appears to be essentially random order.

I can dig deeper and check which mtime values the sort function sees, but maybe someone with more experience with the code base immediately sees the issue.

@mhinsch: I think it would be easier to review/discuss any details if you opened a pull request.
You could make it a draft PR to stop it from being merged prematurely.

Oh, and first of all thank you for your contribution to NeoMutt. :heart:

Just a quick update on that:

Adding some debugging messages shows that the sort function sees mtime==0 for all maildirs on startup. Switching between maildirs appears to change that particular maildir's mtime and accordingly leads to a different order in the sidebar. All other maildirs still show mtime==0, however.

Hmm...
In maildir, Mailbox.mtime is updated in maildir_update_mtime(), which is only called by mh_read_dir() (reading the directory) and mh_mbox_sync() (syncing the directory).

If you've got set mail_check_stats = yes, then that'll happen quite soon after starting, but not immediately.

Perhaps adding maildir_update_mtime(m); to maildir_ac_add() will help.

That's called when the Mailbox is added to the Account, before anything's displayed on screen.

Was this page helpful?
0 / 5 - 0 ratings