How to have Nextcloud Mail stop retrieving emails for an account which was not fully removed?

Hello,

Context

I have Nextcloud Mail installed on a Nextcloud instance packaged by Yunohost. In such context, adding & removing a user in Nextcloud is managed at Yunohost’s level. However at the current state, there seems to be the following issue in the package - when removing a user, it does not appear anymore in Nextcloud’s users’s list but Nextcloud’s database is not cleared from the given user’s config. In particular, the table oc_mail_accounts still contains the email account configured in Nextcloud Mail for the given user.

Issue

Now, even though the user is supposed to be deleted, Nextcloud Mail still tries to retrieve emails for the email account which was once configured for that user. It happens that that email account was actually deleted from the mail server, so the following is regularly output in Nextcloud Mail’s log:

	Horde_Imap_Client_Exception: Authentication failed.

    /var/www/nextcloud/apps/mail/vendor/bytestream/horde-imap-client/lib/Horde/Imap/Client/Socket.php - line 4565:

    Horde_Imap_Client_Socket->_responseCode()

    /var/www/nextcloud/apps/mail/vendor/bytestream/horde-imap-client/lib/Horde/Imap/Client/Socket.php - line 4313:

    Horde_Imap_Client_Socket->_getLine()

    /var/www/nextcloud/apps/mail/vendor/bytestream/horde-imap-client/lib/Horde/Imap/Client/Socket.php - line 4241:

    Horde_Imap_Client_Socket->_sendCmdChunk()

    /var/www/nextcloud/apps/mail/vendor/bytestream/horde-imap-client/lib/Horde/Imap/Client/Socket.php - line 849:

    Horde_Imap_Client_Socket->_sendCmd()

    /var/www/nextcloud/apps/mail/vendor/bytestream/horde-imap-client/lib/Horde/Imap/Client/Socket.php - line 512:

    Horde_Imap_Client_Socket->_tryLogin("*** sensiti ... *")

    /var/www/nextcloud/apps/mail/vendor/bytestream/horde-imap-client/lib/Horde/Imap/Client/Base.php - line 850:

    Horde_Imap_Client_Socket->_login("*** sensiti ... *")

    /var/www/nextcloud/apps/mail/vendor/bytestream/horde-imap-client/lib/Horde/Imap/Client/Base.php - line 2507:

    Horde_Imap_Client_Base->login("*** sensiti ... *")

    /var/www/nextcloud/apps/mail/vendor/bytestream/horde-imap-client/lib/Horde/Imap/Client/Base.php - line 2490:

    Horde_Imap_Client_Base->_fetchWrapper()

    /var/www/nextcloud/apps/mail/lib/IMAP/MessageMapper.php - line 674:

    Horde_Imap_Client_Base->fetch()

    /var/www/nextcloud/apps/mail/lib/IMAP/PreviewEnhancer.php - line 86:

    OCA\Mail\IMAP\MessageMapper->getBodyStructureData()

    /var/www/nextcloud/apps/mail/lib/Service/PreprocessingService.php - line 81:

    OCA\Mail\IMAP\PreviewEnhancer->process()

    /var/www/nextcloud/apps/mail/lib/BackgroundJob/PreviewEnhancementProcessingJob.php - line 94:

    OCA\Mail\Service\PreprocessingService->process()

    /var/www/nextcloud/lib/public/BackgroundJob/Job.php - line 78:

    OCA\Mail\BackgroundJob\PreviewEnhancementProcessingJob->run()

    /var/www/nextcloud/lib/public/BackgroundJob/TimedJob.php - line 103:

    OCP\BackgroundJob\Job->start()

    /var/www/nextcloud/lib/public/BackgroundJob/TimedJob.php - line 93:

    OCP\BackgroundJob\TimedJob->start()

    /var/www/nextcloud/cron.php - line 152:

    OCP\BackgroundJob\TimedJob->execute()

Question

What would be the cleanest way to have Nextcloud Mail stop trying to connect to that email account ?

  • Should I simply delete the row associated to the faulty email account in oc_mail_accounts table in Nextcloud’s database ?
  • Or is there anything else like a dedicated Cron job to remove (I couldn’t locate it if so) which triggers the connection process?

Regards,
daokj

occ mail:account:delete (to delete the account) and mail:clean-up (to remove data related to it)

1 Like

Thank you for pointing me to occ.
I have tried occ user:delete testuser which I believe triggers both mail:account:delete & mail:clean-up actions since after running it there was nothing more about testuser in table oc_mail_accounts for instance.

However some data referring totestuser remains in the following tables:

  • oc_addressbookchanges (not sure why testuser remains here?)
  • oc_jobs (jobs history, this I understand, no need to delete)
  • oc_mail_tags (not sure why testuser remains here?)
  • oc_notifications_settings (not sure why testuser remains here?)
  • oc_storages (not sure why testuser remains here?)

It is not a such a big deal but would you be able to explain this behavior ?

user:delete testuser will mark the account as deleted and mail:clean-up will remove the data.

Good catch, the table is missing in our cleanup command.

I’m not too savvy with the other tables.
Can you report an issue on GitHub for it?

oc_addressbookchanges
oc_jobs
oc_storages

oc_notifications_settings

Just to be clear, I eventually only used user:delete testuser and it seemed to do the cleanup as well. I did not check the code to see how it works (maybe it actually callsmail:clean-up?) but only checked the DB tables where most of the data was succesfully removed, with the exception of above-mentioned tables.

Upon your request I have reported the issue at both Server & Notifications issues trackers.
I assumed you did not expect me to report it to Mail app Github tracker as well.