Bug 339214

Summary: Starting KMail gives message "Could not create collection trash resourceId: 3 [MailCommon::Kernel::createDefaultCollectionDone, MailCommon::Kernel::emergencyExit]
Product: [Applications] kmail2 Reporter: Freek de Kruijf <freekdekruijf>
Component: miscAssignee: kdepim bugs <kdepim-bugs>
Status: REPORTED ---    
Severity: crash CC: 4ernov, a.nolting, arran4, bruno, chris, CisBug, cynicusrex, dave, dharman, dziltener, EMuede, fabian, floeschie, gianfrus, heri+kde, hey, hiphish, kde, kdenis, KirillPl, kmail.to.ck, life0s_50, luistraver, matti.viljanen, mdtiger, numebt, p.richard3, perso, post, pprkut, Ra1ndrope89, ron_collins, sergio, sgmoore, Stephan, ub1x, Uriel.home, zhx, zilti
Priority: VHI    
Version: 5.15.1   
Target Milestone: ---   
Platform: openSUSE   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:
Attachments: screenshot of window with error message in Dutch
output from "kmail >kmailoutput.txt 2>&1"
Crash log

Description Freek de Kruijf 2014-09-19 17:05:25 UTC
Created attachment 88754 [details]
screenshot of window with error message in Dutch

I tried to change the configuration of an IMAP account so pressing Del would move the message into the Trash folder of that account instead of in the Trash folder of the Local Folders, which seems to succeed. After that I started Kontact and got this error message, after which KMail/Kontact always stops.
Comment 1 Freek de Kruijf 2014-10-14 21:02:17 UTC
I got the same error while trying to configure KConfig/KMail. I have 4 IMAP accounts, of which 2 have a large number of messages, one which a small number of folders and the other with quite a lot of folders. Initially things went OK, but during retrieval of the message, the network connection went down or was not performing very well, so before retrieving all messages, KMail was stopped. Restarting it now gives the mentioned message and pressing OK ends Kontact/Kmail. So I am stuck. Starting KMail in a konsole gives the added attachment.
Comment 2 Freek de Kruijf 2014-10-14 21:05:47 UTC
Created attachment 89134 [details]
output from "kmail >kmailoutput.txt 2>&1"

output from "kmail >kmailoutput.txt 2>&1" blocks of 18 lines which are equal are removed
Comment 3 Scarlett Moore 2014-10-22 14:53:48 UTC
Testing Utopic (Kubuntu) Live session and got this error window. Unfortunately, I cannot reproduce -- restarting kontact works and the trash folder is there.
Comment 4 Freek de Kruijf 2014-10-22 20:27:46 UTC
I found a solution: remove folder ~/.local/share/local-mail/trash/
Solved my problem. There are more elaborated solutions when you google for the error message.
Comment 5 Dennis Schridde 2015-09-22 09:04:06 UTC
(In reply to Freek de Kruijf from comment #4)
> I found a solution: remove folder ~/.local/share/local-mail/trash/

I confirm, this workaround works.
Comment 6 Allen Winter 2015-09-22 12:03:24 UTC
*** Bug 345399 has been marked as a duplicate of this bug. ***
Comment 7 Gianluca Frustagli 2016-12-19 15:30:35 UTC
(In reply to Freek de Kruijf from comment #4)
> I found a solution: remove folder ~/.local/share/local-mail/trash/
> Solved my problem. There are more elaborated solutions when you google for
> the error message.

Unfortunately this didn't work for me. I had to start 'akonadiconsole', remove the 'Local Folder' agent from the agent's list and then click on the 'Restart' button.

After that it was possible to restart KMail that worked normally.

I achieved that only after a considerably amount of time searching the Internet for a solution ( https://forum.kde.org/viewtopic.php?f=215&t=120777&hilit=trash ) and I'm a good skilled Linux user.

This bug SHOULD be taken into proper consideration since it is not resolved from a long time and causes problems to users. We cannot expect normal users to browse through bug reports in order to be able to use their software, and this bug is a show stopper since it prevents people from starting the software.
Comment 8 Freek de Kruijf 2017-01-10 09:53:06 UTC
*** Bug 362339 has been marked as a duplicate of this bug. ***
Comment 9 Christoph Feck 2017-01-11 02:31:17 UTC
*** Bug 366388 has been marked as a duplicate of this bug. ***
Comment 10 Christoph Feck 2017-01-11 02:32:13 UTC
*** Bug 350841 has been marked as a duplicate of this bug. ***
Comment 11 Christoph Feck 2017-01-11 02:32:40 UTC
*** Bug 351213 has been marked as a duplicate of this bug. ***
Comment 12 Christoph Feck 2017-01-11 02:33:31 UTC
*** Bug 345895 has been marked as a duplicate of this bug. ***
Comment 13 Christoph Feck 2017-01-11 02:34:07 UTC
*** Bug 354804 has been marked as a duplicate of this bug. ***
Comment 14 Christoph Feck 2017-01-11 02:34:47 UTC
*** Bug 358650 has been marked as a duplicate of this bug. ***
Comment 15 Christoph Feck 2017-01-11 02:35:13 UTC
*** Bug 359461 has been marked as a duplicate of this bug. ***
Comment 16 Christoph Feck 2017-01-11 02:36:26 UTC
*** Bug 349085 has been marked as a duplicate of this bug. ***
Comment 17 Christoph Feck 2017-01-11 02:36:58 UTC
*** Bug 358145 has been marked as a duplicate of this bug. ***
Comment 18 Christoph Feck 2017-01-11 02:52:02 UTC
createDefaultCollectionDone() calls emergencyExit() on any error, causing a crash because of unexpected destroying of global objects.

Relevant part of the backtrace:

Thread 1 (Thread 0x7f7d948587c0 (LWP 3548)):
[KCrash Handler]
#15 0x00007f7d913f1b39 in __run_exit_handlers () at /lib64/libc.so.6
#16 0x00007f7d913f1b85 in  () at /lib64/libc.so.6
#17 0x00007f7d19436063 in MailCommon::Kernel::emergencyExit(QString const&) () at /usr/lib64/libKF5MailCommon.so.5
#18 0x00007f7d1943664a in MailCommon::Kernel::createDefaultCollectionDone(KJob*) () at /usr/lib64/libKF5MailCommon.so.5
#19 0x00007f7d91fb373f in QMetaObject::activate(QObject*, int, int, void**) () at /usr/lib64/libQt5Core.so.5
#20 0x00007f7d936135e2 in KJob::result(KJob*, KJob::QPrivateSignal) () at /usr/lib64/libKF5CoreAddons.so.5
#21 0x00007f7d93613e4f in KJob::finishJob(bool) () at /usr/lib64/libKF5CoreAddons.so.5
#22 0x00007f7d90ab8bce in  () at /usr/lib64/libKF5AkonadiCore.so.5
#23 0x00007f7d90abba28 in  () at /usr/lib64/libKF5AkonadiCore.so.5
Comment 19 Denis Kurz 2017-01-20 19:15:31 UTC
Confirmed by "popular reporting". It was reported for 5.1.3 in Bug 362339.
Comment 20 Bruno Friedmann 2017-02-09 20:57:55 UTC
I've 12 imap account each setup to move deleted message to their own trash folder.

Long ago, I was getting crash and background running kmail. To by pass this problem I've used the setting to not empty trash folder on exit, and after kmail never crashed again on exit.
Comment 21 Freek de Kruijf 2017-12-01 10:00:48 UTC
Recently the trash folder to remove is no longer ~/.local/share/local-mail/trash/ but ~/.local/share/akonadi_maildir_resource_0/trash/
You can also set it aside.
Comment 22 CnZhx 2017-12-01 11:02:44 UTC
(In reply to Freek de Kruijf from comment #21)
> Recently the trash folder to remove is no longer
> ~/.local/share/local-mail/trash/ but
> ~/.local/share/akonadi_maildir_resource_0/trash/
> You can also set it aside.

Thanks for the update.

I ran into this situation again this morning (I have not restart/shutdown my laptop for a long time). The kmail is recovered after I followed the instruction in Comment #7 "to start 'akonadiconsole', remove the 'Local Folder' agent from the agent's list and then click on the 'Restart' button".

I have not tried to remove the folder `~/.local/share/akonadi_maildir_resource_0/trash/`.
Comment 23 kde 2019-02-17 16:54:25 UTC
This still happens on KMail 5.10.2 / Frameworks 5.55.0
Comment 24 Sérgio Basto 2019-06-08 00:40:07 UTC
Hi, look likes https://forum.kde.org/viewtopic.php?t=120777

cd ~/.kde/share/apps/kmail/mail

and remove trash folder for example with :

mv trash/ ~
Comment 25 Martin Oemus 2019-11-24 14:16:37 UTC
This still happens in kmail 5.11.3, KDE Frameworks 5.64.0.

Deleting the local folder agent in aconadiconsole solves the problem.
Comment 26 Dennis Schridde 2020-03-07 23:34:10 UTC
Just ran into this again using:
* KMail 5.13.3 (19.12.3)
* KDE Frameworks 5.67.0
* Qt 5.14.1 (built against 5.14.1)
Comment 27 Daniel Ziltener 2020-10-02 00:21:25 UTC
This bug is still alive and kicking. Happens reliably every time when creating a mailbox and changing its trash folder from the local folders one to the account's IMAP folder.
Comment 28 Chris Josten 2020-11-10 16:49:34 UTC
Same problem here. I believe this Akonadi log lines have to do something with it:

org.kde.pim.akonadiserver: DATABASE ERROR:
org.kde.pim.akonadiserver:   Error code: "1062"
org.kde.pim.akonadiserver:   DB error:  "Duplicate entry '6-trash' for key 'CollectionTable_parentAndNameIndex'"
org.kde.pim.akonadiserver:   Error text: "Duplicate entry '6-trash' for key 'CollectionTable_parentAndNameIndex' QMYSQL3: Unable to execute statement"
org.kde.pim.akonadiserver:   Values: QMap((":0", QVariant(QString, ""))(":1", QVariant(QString, ""))(":10", QVariant(int, -1))(":11", QVariant(int, -1))(":12", QVariant(bool, false))(":13", QVariant(QString, ""))(":14", QVariant(bool, false))(":2", QVariant(QString, "trash"))(":3", QVariant(qlonglong, 6))(":4", QVariant(qlonglong, 4))(":5", QVariant(bool, true))(":6", QVariant(int, 2))(":7", QVariant(int, 2))(":8", QVariant(int, 2))(":9", QVariant(bool, true)))
org.kde.pim.akonadiserver:   Query: "INSERT INTO CollectionTable (remoteId, remoteRevision, name, parentId, resourceId, enabled, syncPref, displayPref, indexPref, cachePolicyInherit, cachePolicyCheckInterval, cachePolicyCacheTimeout, cachePolicySyncOnDemand, cachePolicyLocalParts, isVirtual) VALUES (:0, :1, :2, :3, :4, :5, :6, :7, :8, :9, :10, :11, :12, :13, :14)"
org.kde.pim.akonadiserver: Error during insertion into table "CollectionTable" "Duplicate entry '6-trash'
Comment 29 Sérgio Basto 2020-11-10 17:11:40 UTC
have you tried solution on https://bugs.kde.org/show_bug.cgi?id=339214#c24 ?
Comment 30 Daniel Ziltener 2020-12-29 14:05:08 UTC
(In reply to Sérgio Basto from comment #29)
> have you tried solution on https://bugs.kde.org/show_bug.cgi?id=339214#c24 ?

That's not a solution, that's a workaround at best.
Comment 31 Daniel Ziltener 2021-03-23 12:44:51 UTC
Created attachment 136981 [details]
Crash log
Comment 32 MoritzD 2021-11-22 13:16:15 UTC
Hi, I got the same problem. For me the solution of CnZhx  2017-12-01 11:02:44 UTC worked: "start 'akonadiconsole', remove the 'Local Folder' agent from the agent's list"

Please change this misleading error message. Especially I hate alert-messages with only one "accept"-button and modal windows in general. If there's a broken e-mail account kmail2 should start anyway complaining later. Nobody understands why a "collection trash" is that important the program doesn't starts at all.

Instead of akonadiconsole kmail2 should cure this problem from within.
Comment 33 Dave 2021-12-16 11:30:13 UTC
I have just run into this bug just by pointing my trashes off the local trash to respective IMAP located trash folders.
There are many people affected, several bug duplicates, and the status is still only "REPORTED" ... since 2014?
Comment 34 Fabian Vogt 2022-07-19 14:51:40 UTC
My Akonadi suddenly (no config changes) developed the same issue. KMail refuses to start because of "Could not create collection 'drafts'". The issue appears to be that the "drafts" collection had the "SpecialCollectionAttribute" set to "trash", with a matching icon, while "trash" also had that. As it couldn't find a proper "drafts" collection it tried to create "drafts" again. Using akonadiconsole I could fix the "SpecialCollectionAttribute" of the collection and KMail works for me again. Question is why the attribute changed.
Comment 35 Celeste Wouters 2022-08-31 12:29:00 UTC
Can reproduce on my machine, with a fresh new user profile, and KMail configured with one IMAP profile (which worked the first time).
"Could not create collection drafts, resourceId 4"
KMail 5.20.3 (22.04.3)
Akonadi 22.04.3
MariaDB 10.5.10
KF 5.96.0
Qt 5.15.5
Void Linux
Comment 36 Sérgio Basto 2022-08-31 14:27:18 UTC
check my comment #24 https://bugs.kde.org/show_bug.cgi?id=339214#c24
Comment 37 Ulf Bartholomäus 2022-10-03 08:15:17 UTC
I added a new IMAP account and also added the trash folder to IMAP-account/trash. Since than I received 
"Could not create collection trash, resourceId 4"

Also at my side on removing of "~/.local/share/local-mail/trash/" fixes the issue

kmail -v
kmail2 5.21.1 (22.08.1)

Operating System: openSUSE Tumbleweed 20220930
KDE Plasma Version: 5.25.5
KDE Frameworks Version: 5.98.0
Qt Version: 5.15.6
Kernel Version: 5.19.12-1-default (64-bit)
Graphics Platform: X11
Comment 38 Daniel Ziltener 2023-07-12 14:02:41 UTC
Is anyone interested in baking a cake or throwing a party for this bug's upcoming 9th or 10th birthday? It spent its entire life without a caretaker, and I am sure it would enjoy spending some time with friendly people.
Comment 39 dharman 2023-07-12 14:17:38 UTC
(In reply to Daniel Ziltener from comment #38)
> Is anyone interested in baking a cake or throwing a party for this bug's
> upcoming 9th or 10th birthday? It spent its entire life without a caretaker,
> and I am sure it would enjoy spending some time with friendly people.

🎂🎂🎂🎂🎂🎂🎂🎂🎂🎂

I'm very so sorry, but I suspect kmail doesn't have developers that love it.
Not only are there bugs like this, but also untreated regressions like delivery confirmation request. ;-(
Comment 40 Christof Konstantinopoulos 2023-12-25 22:32:55 UTC
(In reply to Freek de Kruijf from comment #21)
> Recently the trash folder to remove is no longer
> ~/.local/share/local-mail/trash/ but
> ~/.local/share/akonadi_maildir_resource_0/trash/
> You can also set it aside.

You have saved my day! 

I have just started to change from Windows to Linux (Nobara Linux = Fedora with With KDE Plasma and optimizations for Gaming).
I have about 30 Years IT experience with Windows and I am a professional software developer writing applications in c#. So it might be a big step to switch the operating system on my private PC. 

The first steps with KMail are not easy. I wonder why everything was working on local folders and it took some time to sent my first e-mail from kmail into the world. So I made the set up with 3 IMAP Accounts and the last part to do was to configure kmail to put the deleted e-Mails into the IMAP Trash bucket. I don't want to handle all deleted e-mails in the local Trash folder.

And what happens next... Yes Kmail crashed on start up with a message I don't understand: 
"Could not create collection trash resourceId: 14"

Can you imagine how frustrating such an experience is? Searching for this error shows a lot of tipps but renaming or deleting the local trash folder was not helpful because I didn't know that it was moved into "akonadi_maildir_resource_4". This information was part of this Bug report and it is not nice to read about the 10th aniversary of this bug.

Changing the configuration from local Trash to IMAP Trash is not an unusual use case. So this should not happen. The normal user is lost if the mail system breaks down because of this error. 

After removing the trash folder in "~\.local\share\akonadi_maildir_resource_4\" kmail is starting again. 

I hope somebody could take a look on this issue. I am not ready to do this now. I need some time to learn more about the kde system, before I can change the code.

Kind regards 
Christof
Comment 41 Knut Hildebrandt 2024-05-03 12:59:00 UTC
Non of the workarounds worked for me, "~\.local\share\akonadi_maildir_resource_xy" did not exist in my installation and deleting "~/.local/share/local-mail/trash/" did not help. But I found my own. I just deleted "~\.local\share\.local-mail.directory/" which was greated anew and KMail started again.

Any how, this is a workaround and the underlying problem should be solved. Honestly, I do not know what happened, that KMail did not want to start anymore all of a sudden.
Comment 42 arran 2024-06-23 12:48:11 UTC
After testing it on mine, you don't have to delete it.. Close kmail. Rename ~/.local/share/local-mail/ to ~/.local/share/local-mail-old/. Open Kmail. Close Kmail. Rename the directory back worked for me.

% kmail --version
kmail2 5.24.5 (23.08.5)
Comment 43 hiphish 2024-07-08 09:39:30 UTC
(In reply to arran from comment #42)
> After testing it on mine, you don't have to delete it.. Close kmail. Rename
> ~/.local/share/local-mail/ to ~/.local/share/local-mail-old/. Open Kmail.
> Close Kmail. Rename the directory back worked for me.
> 
> % kmail --version
> kmail2 5.24.5 (23.08.5)

Renaming the `trash` folder is enough, you don't have to rename all of `local-mail`. As a bonus, the renamed trash folder remains available inside KMail, so you can still move the local mails somewhere else (e.g. the mailbox's trash folder). Tested in kmail2 6.1.1 (24.05.1)
Comment 44 Fabian Vogt 2024-07-27 12:48:50 UTC
Here's how to manually fix the weirdness in the database without folder remaining:

1. Start akonadiconsole
2. In the browser tab, right click on "Local Folders" -> "Trash"
3. Open the Folder properties window
4. In the "Attributes" tab, make sure it has "SpecialCollectionAttribute" set to "trash". If necessary, change or create it.
5. Start kmail again

This also applies if the error message is about drafts or other special folder, just set the attribute on the matching folder instead.
Comment 45 Fabian Vogt 2024-07-27 19:32:11 UTC
Here's a way to reliably trigger this through the KMail UI: Edit any IMAP account and on the advanced page set the trash folder to something like "Local Folders/Drafts" or other special collection. It'll remove the trash attribute from "Local Folders/Trash" and assign it to the selected folder instead. On the next start of kmail, it'll try to use "Local Folders/Drafts" as trash and fail to find anything to use for drafts. It'll try to create "Local Folders/Drafts", but that already exists, resulting in a fatal error.
Comment 46 Cynicus Rex 2024-09-19 13:07:34 UTC
(In reply to Freek de Kruijf from comment #4)
> I found a solution: remove folder ~/.local/share/local-mail/trash/
> Solved my problem. There are more elaborated solutions when you google for
> the error message.

10 years later this still works.
Comment 47 Knut Hildebrandt 2024-10-01 19:15:58 UTC
(In reply to Fabian Vogt from comment #44)
> Here's how to manually fix the weirdness in the database without folder
> remaining:
> 
> 1. Start akonadiconsole
> 2. In the browser tab, right click on "Local Folders" -> "Trash"
> 3. Open the Folder properties window
> 4. In the "Attributes" tab, make sure it has "SpecialCollectionAttribute"
> set to "trash". If necessary, change or create it.
> 5. Start kmail again
> 
> This also applies if the error message is about drafts or other special
> folder, just set the attribute on the matching folder instead.

Today I ran into that problem again, but can't solve it by either deleting the trash folder or following what these instructions. Thus I'm not sure, if it is caused by the same bug. 

Two things I did today. In an IMAP-Account I had set deleting trash after two weeks. I had done this before a while, but it was unset. And I upgraded the system and thus Kmail from 24.05.2 to 24.08.1 today.

BTW, when I set SpecialCollectionAttribute it is not persistent. After closing and reopening Akonadoconsole the had disappeared.

Any ideas how I get Kmail running again?
Comment 48 Fabian Vogt 2024-10-02 06:25:32 UTC
Resetting state to REPORTED, this clearly was not fixed.

(In reply to Knut Hildebrandt from comment #47)
> (In reply to Fabian Vogt from comment #44)
> > Here's how to manually fix the weirdness in the database without folder
> > remaining:
> > 
> > 1. Start akonadiconsole
> > 2. In the browser tab, right click on "Local Folders" -> "Trash"
> > 3. Open the Folder properties window
> > 4. In the "Attributes" tab, make sure it has "SpecialCollectionAttribute"
> > set to "trash". If necessary, change or create it.
> > 5. Start kmail again
> > 
> > This also applies if the error message is about drafts or other special
> > folder, just set the attribute on the matching folder instead.
> 
> Today I ran into that problem again, but can't solve it by either deleting
> the trash folder or following what these instructions. Thus I'm not sure, if
> it is caused by the same bug. 
> 
> Two things I did today. In an IMAP-Account I had set deleting trash after
> two weeks. I had done this before a while, but it was unset. And I upgraded
> the system and thus Kmail from 24.05.2 to 24.08.1 today.
> 
> BTW, when I set SpecialCollectionAttribute it is not persistent. After
> closing and reopening Akonadoconsole the had disappeared.

That's probably the issue, it needs to be properly saved. Any warnings or errors in the journal?
Comment 49 Knut Hildebrandt 2024-10-02 19:26:14 UTC
(In reply to Fabian Vogt from comment #48)
> Resetting state to REPORTED, this clearly was not fixed.
> 
> (In reply to Knut Hildebrandt from comment #47)
> > (In reply to Fabian Vogt from comment #44)
> > > Here's how to manually fix the weirdness in the database without folder
> > > remaining:
> > > 
> > > 1. Start akonadiconsole
> > > 2. In the browser tab, right click on "Local Folders" -> "Trash"
> > > 3. Open the Folder properties window
> > > 4. In the "Attributes" tab, make sure it has "SpecialCollectionAttribute"
> > > set to "trash". If necessary, change or create it.
> > > 5. Start kmail again
> > > 
> > > This also applies if the error message is about drafts or other special
> > > folder, just set the attribute on the matching folder instead.
> > 
> > Today I ran into that problem again, but can't solve it by either deleting
> > the trash folder or following what these instructions. Thus I'm not sure, if
> > it is caused by the same bug. 
> > 
> > Two things I did today. In an IMAP-Account I had set deleting trash after
> > two weeks. I had done this before a while, but it was unset. And I upgraded
> > the system and thus Kmail from 24.05.2 to 24.08.1 today.
> > 
> > BTW, when I set SpecialCollectionAttribute it is not persistent. After
> > closing and reopening Akonadoconsole the had disappeared.
> 
> That's probably the issue, it needs to be properly saved. Any warnings or
> errors in the journal?

Well, after starting Kmail - actually Kontact - I found this in Akonadi.error:

[CRITICAL] org.kde.pim.akonadiserver: DATABASE ERROR:
[CRITICAL] org.kde.pim.akonadiserver:   Error code: "1062"
[CRITICAL] org.kde.pim.akonadiserver:   DB error:  "Duplicate entry '6-trash' for key 'CollectionTable_parentAndNameIndex'"
[CRITICAL] org.kde.pim.akonadiserver:   Error text: "Duplicate entry '6-trash' for key 'CollectionTable_parentAndNameIndex' QMYSQL: Der Befehl konnte nicht ausgeführt werden"

That suggested that something with the database was wrong, thus I stopped Akonadi and renamed it. After restarting Akonadi the database was rebuild and I could start Kmail - actually Kontact - with the drawback, that all my settings were lost ;-( Since this is unaccaptable I got back to the old database looking for another solution. Any idea? A suggestion how to fix the database?
Comment 50 Fabian Vogt 2024-10-02 21:19:04 UTC
(In reply to Knut Hildebrandt from comment #49)
> (In reply to Fabian Vogt from comment #48)
> > Resetting state to REPORTED, this clearly was not fixed.
> > 
> > (In reply to Knut Hildebrandt from comment #47)
> > > (In reply to Fabian Vogt from comment #44)
> > > > Here's how to manually fix the weirdness in the database without folder
> > > > remaining:
> > > > 
> > > > 1. Start akonadiconsole
> > > > 2. In the browser tab, right click on "Local Folders" -> "Trash"
> > > > 3. Open the Folder properties window
> > > > 4. In the "Attributes" tab, make sure it has "SpecialCollectionAttribute"
> > > > set to "trash". If necessary, change or create it.
> > > > 5. Start kmail again
> > > > 
> > > > This also applies if the error message is about drafts or other special
> > > > folder, just set the attribute on the matching folder instead.
> > > 
> > > Today I ran into that problem again, but can't solve it by either deleting
> > > the trash folder or following what these instructions. Thus I'm not sure, if
> > > it is caused by the same bug. 
> > > 
> > > Two things I did today. In an IMAP-Account I had set deleting trash after
> > > two weeks. I had done this before a while, but it was unset. And I upgraded
> > > the system and thus Kmail from 24.05.2 to 24.08.1 today.
> > > 
> > > BTW, when I set SpecialCollectionAttribute it is not persistent. After
> > > closing and reopening Akonadoconsole the had disappeared.
> > 
> > That's probably the issue, it needs to be properly saved. Any warnings or
> > errors in the journal?
> 
> Well, after starting Kmail - actually Kontact - I found this in
> Akonadi.error:
> 
> [CRITICAL] org.kde.pim.akonadiserver: DATABASE ERROR:
> [CRITICAL] org.kde.pim.akonadiserver:   Error code: "1062"
> [CRITICAL] org.kde.pim.akonadiserver:   DB error:  "Duplicate entry
> '6-trash' for key 'CollectionTable_parentAndNameIndex'"
> [CRITICAL] org.kde.pim.akonadiserver:   Error text: "Duplicate entry
> '6-trash' for key 'CollectionTable_parentAndNameIndex' QMYSQL: Der Befehl
> konnte nicht ausgeführt werden"
> 
> That suggested that something with the database was wrong, thus I stopped
> Akonadi and renamed it. After restarting Akonadi the database was rebuild
> and I could start Kmail - actually Kontact - with the drawback, that all my
> settings were lost ;-( Since this is unaccaptable I got back to the old
> database looking for another solution. Any idea? A suggestion how to fix the
> database?

Using the DB browser in akonadiconsole you'll have to delete the entry with
"name" trash and "parentId" 6 that has the higher id. Then follow the instructions
to assign the specialcollectionattribute to the correct trash again.
Comment 51 Knut Hildebrandt 2024-10-03 06:41:00 UTC
(In reply to Fabian Vogt from comment #50)
> (In reply to Knut Hildebrandt from comment #49)
> > (In reply to Fabian Vogt from comment #48)
> > > Resetting state to REPORTED, this clearly was not fixed.
> > > 
> > > (In reply to Knut Hildebrandt from comment #47)
> > > > (In reply to Fabian Vogt from comment #44)
> > > > > Here's how to manually fix the weirdness in the database without folder
> > > > > remaining:
> > > > > 
> > > > > 1. Start akonadiconsole
> > > > > 2. In the browser tab, right click on "Local Folders" -> "Trash"
> > > > > 3. Open the Folder properties window
> > > > > 4. In the "Attributes" tab, make sure it has "SpecialCollectionAttribute"
> > > > > set to "trash". If necessary, change or create it.
> > > > > 5. Start kmail again
> > > > > 
> > > > > This also applies if the error message is about drafts or other special
> > > > > folder, just set the attribute on the matching folder instead.
> > > > 
> > > > Today I ran into that problem again, but can't solve it by either deleting
> > > > the trash folder or following what these instructions. Thus I'm not sure, if
> > > > it is caused by the same bug. 
> > > > 
> > > > Two things I did today. In an IMAP-Account I had set deleting trash after
> > > > two weeks. I had done this before a while, but it was unset. And I upgraded
> > > > the system and thus Kmail from 24.05.2 to 24.08.1 today.
> > > > 
> > > > BTW, when I set SpecialCollectionAttribute it is not persistent. After
> > > > closing and reopening Akonadoconsole the had disappeared.
> > > 
> > > That's probably the issue, it needs to be properly saved. Any warnings or
> > > errors in the journal?
> > 
> > Well, after starting Kmail - actually Kontact - I found this in
> > Akonadi.error:
> > 
> > [CRITICAL] org.kde.pim.akonadiserver: DATABASE ERROR:
> > [CRITICAL] org.kde.pim.akonadiserver:   Error code: "1062"
> > [CRITICAL] org.kde.pim.akonadiserver:   DB error:  "Duplicate entry
> > '6-trash' for key 'CollectionTable_parentAndNameIndex'"
> > [CRITICAL] org.kde.pim.akonadiserver:   Error text: "Duplicate entry
> > '6-trash' for key 'CollectionTable_parentAndNameIndex' QMYSQL: Der Befehl
> > konnte nicht ausgeführt werden"
> > 
> > That suggested that something with the database was wrong, thus I stopped
> > Akonadi and renamed it. After restarting Akonadi the database was rebuild
> > and I could start Kmail - actually Kontact - with the drawback, that all my
> > settings were lost ;-( Since this is unaccaptable I got back to the old
> > database looking for another solution. Any idea? A suggestion how to fix the
> > database?
> 
> Using the DB browser in akonadiconsole you'll have to delete the entry with
> "name" trash and "parentId" 6 that has the higher id. Then follow the
> instructions
> to assign the specialcollectionattribute to the correct trash again.

That did not work. In DB browser collectiontable there is only one entry with name trash, parentId 6 and resourceId 14 (the resourceId referred to in the popup error message before Kmail is closed), but there is no way to delete it, at least I can't find one. Do I right-click the selected row or any field independently no popup menu appears. And when clicking the Item menu in the menu bar all entries are greyed out. But if I go to the tab Browser I can delete the trash folder and recreate it. Then it appears in the DB browser with a new ID. To this I assigned the specialcollectionattribute as described in the instructions and saved it. But unfortunately the attribute disappears after restarting Akonadi and Kmail crashed again.
Comment 52 Knut Hildebrandt 2024-10-03 09:52:28 UTC
Problem solved!

After playing back various old databases and (only) deleting "~/.local/share/local-mail/trash", what both did not help, I eventually renamed "~/.local/share/local-mail" and "~/.local/share/.local-mail.directory" and restarted Akonadi - it might be, that I had stopped it before renaming and only started it after - and Kmail started without crashing. Both directories were recreated but empty. Having a closer look at the local-mail I noticed that the old version had next to the usual sub-folders cur, new and tmp some called trash, inbox, drafts etc. - named after the subfolders of the mailbox - whereas the new one did not hold any of these. Giving it a second thought I remembered that the latter folders should reside in .local-mail.directory and thus deleted them. After that Kmail started without any complaint. Now it's clear why only deleting trash did not help, since all of the wrongly placed folders caused the crash.

For me two things got clear. This is not one bug but a bunch of bugs that cause the same effect. And Akonadi needs a thorough rework, since it is full of bugs like this which arbitrarily can get activated after installing a new version, what happened various times to me. Please let the status of the bug report REPORTED and ideally split it into various due to it's causes. Now it only focuses on the effect.