Mail not clearing list of emails that have been deleted from server

I’ve successfully connected the Nextcloud mail client to my email service provider using IMAP.
But emails that have been deleted (or moved to folders) on the server persist in the Nextcloud client list of emails.
When I click on any of these (deleted or moved) emails in the list, the client then reports that the email is ‘Not found’ and ‘Could not load the desired message’. (I understand why it can’t load the desired message.)
It’s as though the list is coming from an out of date cache.
The problem I’d like to resolve is how to update the list of emails so that the deleted and moved emails no longer appear.
(Clicking on the 3 dots next to ‘Inbox’ in the menu displays the correct counts of unread and available emails, ie they reconcile with the server).

1 Like

You’re assumption is right, this is due to an outdated cache. The question is just why it doesn’t update.

Could you try forcing a refresh of the mailbox with the r shortcut? You will see a little loading spinner on the very top of the messages list. Let me know if the deleted messages vanish once that’s done.

Hi, and thanks.

‘r’ did result in the spinner being displayed, but no, the list didn’t change/refresh.

In case it might help, some more info about the instance:
Version: 19.0.2
|Operating System:|Linux 5.4.0-45-generic x86_64|
|CPU:|Intel® Pentium® CPU N3530 @ 2.16GHz (4 cores)|

It’s a snap install on Ubuntu Server 20.04.1 LTS.
The mail client successfully sends and receives email.

This error has appeared in the Nextcloud log - don’t know if it’s relevant but it mentions ‘mail’:
[lib] Error: ResourceLocator can not find a web root (root: /var/snap/nextcloud/23027/nextcloud/extra-apps/mail, file: index.php/css/mail/1e6d-82a9-mobile.css?v=d41d8cd98f00b204e9800998ecf8427e, webRoot: , throw: true)

Thanks for the info. That error is not related.

Do you have another mail client connected where you can trigger an expunge/compact of the mailbox, just to see if that and a successive r shortcut in Nextcloud Mail make the deleted messages vanish?

I assume you mean another Nextcloud email client?
No, but will install one and try. Any recommendation?

(If you mean a non-Nextcloud client - I’m already using one that is already current, ie not listing out of date emails.)
(Correction: if you mean another mail client on the same server - no. The only client currently is the Nextcloud Groupware mail client.)

Same problem with 19.0.2 and Apache 2.4, mails deleted with thunderbird are still visible. I have to delete them manually to make them disappear.

Yes, with a different client.

Because Nextcloud mail deletes emails by first setting the \deleted flag, then running EXPUNGE. Other client might only set the flag, but not clear the deleted items. And Nextcloud mail might wrongly sync/show the deleted items later.

I don’t have insights into how Thunderbird handles it.

I hope I’m understanding, please bear with me if not.
There is no other mail client (AFAIK) running on the Nextcloud server, ie no other client on the same server is deleting without expunging emails from the server.
The other ‘clients’ I am using (on other devices) are the Fastmail web ‘client’ on a Windows PC and the Fastmail Android client (on a tablet). Fastmail is a pretty solid email provider and I’d be surprised if either the webmail version or the Android client wasn’t expunging deleted emails.
Also, the webmail version and the Android client are staying in sync, ie they update correctly when emails are deleted or moved to folders, (unlike the Nextcloud mail client).

It’s not about what email clients are running in Nextcloud, it’s about which applications are connected to the same IMAP account.

I never said that the expunge command would be used wrongly in other clients. They do not have to run it for every message flagged as deleted. That is fine. It’s just that Nextcloud Mail might wrongly assume that mailboxes are always expunged, when other clients do this more lazily.

Ok, sorry about misunderstanding.
The only other email client that is connected to the same IMAP account is Fastmail’s own Android application.

If ‘lazily’ means that other clients might be slow to expunge deletions, some of the emails that are still appearing in the Nextcloud mail list have been deleted quite some time ago, at least several days and possibly a couple of weeks, implying that other lazy clients are very slow.
If ‘lazily’ means that other clients might never get around to expunging deletions perhaps I need to raise an issue with Fastmail re the Fastmail app.

Well, in my understanding there is no obligation to run the expunge. It could be fine (by the RFC) to only flag the messages.

I would rather suspect some faulty logic in Nextcloud Mail’s sync (because I wrote it), so let’s dig into that first.

Ok, thanks Christoph.
Please let me know if there is anyway I can help.

1 Like

I’m also running into this today.

I have two IMAP accounts integrated into nextcloud (same mail server / domain, just seperate accounts)

Meaning: same server, same settings, just different Accounts and passwords.
One of them is behaving like pj describes it: Deleted E-Mail remain listed. To be precise: I don’t delete them but fetch them via POP through thunderbird from time to time. But since today one Account still lists them in Nexcloud (no E-Mail body though if you select one of the ‘ghost’ mails).
The other one works fine. :thinking:

Could this also be a PHP Cache / APCu / Redis issue? @ChristophWurst
I have very little experience with those Caches.

Nextcloud 19.0.3
Mail 1.4.1
Debian 10
apache2

/edit

New Mails also work as expected. So there is just a certain amount of old mails ‘stuck’. :thinking:

When you navigate to one of those messages you should see the numeric message ID in the URL. Use that to query select * from oc_mail_messages where id=<id> so we can see the flags of that message.

I assume my (almost non existent) sql knowledge is letting me down here:

su - postgres
postgres-# psql nextcloud
nextcloud-# select * from oc_mail_messages where id=-66109   <---- this a correct E-Mail
nextcloud-#

nextcloud-# select * from oc_mail_messages where id=-66048   <---- a 'bad' one
nextcloud-#

Both return nothing.
My SQL Query is faulty / missing something I guess?

Hi Steven,
It’s pretty unlikely that the ids are negative numbers. Try again after removing the ‘-’ sign before each id.
Peter

I also tried without the “-”, same result (i.E. no result).

But it seems like all the Mails have a negative Number

image

Same here …

Same thing with me, but I found a workaround.

Dec 29 edit. Warning from the Nextcloud Mail Sync developer before you go on:

Important points to consider:

  • There are only 2 users on my instance, and they were not using the Mail app.
  • I have around 10 mail accounts setup, which sums around 2000 messages (before the cleanup), what made Nextcloud Mail impossible to use even for deleting messages on my slow computer. So I used this method as my last resort.

Now that with that warning in place, what worked on my instance was this:
End of the Dec 29 edit.

I truncated the database table oc_mail_messages and then forced each mail account to resync by running sudo -u www-data php ./occ mail mail:account:sync -f <account-id> from Nextcloud’s root directory. Accounts ids can be found on the table oc_mail_accounts.

Edit, for debugging purposes: some messages I deleted with K-9 Mail, some with SquirrelMail, and some I deleted directly from the email server. None of those ways seemed to have affected the messages showing on Nextcloud Mail.