From: Simon Martin <simon@nasilyan.com>
I noticed that when deleting an unread email from the current folder (or
moving it to another folder), the "visual unread count" is not
decremented (and later on I'm desperately looking for the mysterious
unread mail that does not exist anymore :-)).
This patch adds a parameter to AccountView.updateDirCounts stating
whether the caller reacts to a deletion, and makes sure to call it when
processing a MessagesDeleted message.
Signed-off-by: Simon Martin <simon@nasilyan.com>
---
app/account.go | 23 ++++++++++++++++-------
1 file changed, 16 insertions(+), 7 deletions(-)
diff --git a/app/account.go b/app/account.go
index 262d5f38..f40c1b75 100644
--- a/app/account.go
+++ b/app/account.go
@@ -470,15 +470,15 @@ func (acct *AccountView) onMessage(msg types.WorkerMessage) {
}
case *types.MessagesDeleted:
if dir := acct.dirlist.SelectedDirectory(); dir != nil {
- dir.Exists -= len(msg.Uids)
+ acct.updateDirCounts(dir.Name, msg.Uids, true)
}
if store, ok := acct.dirlist.SelectedMsgStore(); ok {
store.Update(msg)
}
case *types.MessagesCopied:
- acct.updateDirCounts(msg.Destination, msg.Uids)
+ acct.updateDirCounts(msg.Destination, msg.Uids, false)
case *types.MessagesMoved:
- acct.updateDirCounts(msg.Destination, msg.Uids)
+ acct.updateDirCounts(msg.Destination, msg.Uids, false)
case *types.LabelList:
acct.labels = msg.Labels
case *types.ConnError:
@@ -495,7 +495,7 @@ func (acct *AccountView) onMessage(msg types.WorkerMessage) {
acct.setTitle()
}
-func (acct *AccountView) updateDirCounts(destination string, uids []models.UID) {
+func (acct *AccountView) updateDirCounts(destination string, uids []models.UID, deleted bool) {
// Only update the destination destDir if it is initialized
if destDir := acct.dirlist.Directory(destination); destDir != nil {
var recent, unseen int
@@ -511,20 +511,29 @@ func (acct *AccountView) updateDirCounts(destination string, uids []models.UID)
accurate = false
break
}
- seen := msg.Flags.Has(models.SeenFlag)
if msg.Flags.Has(models.RecentFlag) {
recent++
}
+ seen := msg.Flags.Has(models.SeenFlag)
if !seen {
- unseen++
+ // If the message is unseen, the directory's current unseen
+ // count is off by one and (1) too low if the message is new,
+ // or (2) too high if the message has been deleted.
+ if !deleted {
+ unseen++
+ } else {
+ unseen--
+ }
}
}
if accurate {
destDir.Recent += recent
destDir.Unseen += unseen
+ }
+ if !deleted {
destDir.Exists += len(uids)
} else {
- destDir.Exists += len(uids)
+ destDir.Exists -= len(uids)
}
}
}
--
2.45.3
Hi inwit,
On Sun Mar 16, 2025 at 12:24 PM CET, inwit wrote:
> This has been biting me forever and it's now solved! Thanks, Simon!
Cool, glad that you like it.
There's another issue in this area, when moving an unread message to
another folder that uses folder mapping: the unread count in not
properly incremented in the destination folder (it works fine without
folder mapping). I will take care of this next :-)
> Tested-by: inwit <inwit@sindominio.net>
Thanks!
Simon
~simartin <simartin@git.sr.ht> wrote:
> From: Simon Martin <simon@nasilyan.com>
>
> I noticed that when deleting an unread email from the current folder (or
> moving it to another folder), the "visual unread count" is not
> decremented (and later on I'm desperately looking for the mysterious
> unread mail that does not exist anymore :-)).
>
> This patch adds a parameter to AccountView.updateDirCounts stating
> whether the caller reacts to a deletion, and makes sure to call it when
> processing a MessagesDeleted message.
>
> Signed-off-by: Simon Martin <simon@nasilyan.com>
> ---
Acked-by: Robin Jarry <robin@jarry.cc>
Tested-by: Inwit <inwit@sindominio.net>
Applied, thanks.
To git@git.sr.ht:~rjarry/aerc
46294ba5f795..b099981adbcf master -> master