"Unable to Fetch Item from Backend ... [LRCONFLICT]"

This problem is directly related to Akonadi bug #283682, which has been a thorn in the side of KMail since October, 2011. There is a timing / co-ordination problem with asynchronous processing of message filters. Once in a while, a filter rule that moves messages to a different folder "hiccups", and produces more than one database entry for a message that has been moved. When you try to open the second copy of such a message, the error message "Unable to fetch item from backend ...[LRCONFLICT]" appears. Such phantom messages cannot be deleted or moved to trash using KMail's built-in functions. But you can get rid of them. Here's how you do it.

  1. First, exit the KMail program. This may not be necessary, but better safe than sorry.

  2. You can learn how many corrupted messages are present by using akonadictl.

    ~ $ akonadictl fsck 2>&1 | grep ^Found
    Found 6 external files.
    Found 6 external parts.
    Found no unreferenced external files.
    Found 0 parts to be moved to external files
    Found 0 parts to be moved to database
    Found 6 collections without RID.
    Found 9 items without RID.
    Found 0 dirty items.

    In this instance, there are nine duplicated messages (without RID).


  3. You need to know how to connect directly to the mysql server. Use the ps and grep commands to do this.

    ~ $ ps ux | grep mysql
    david     8788  0.2  0.9 3736292 153936 ?      Sl   06:45   0:16 /usr/sbin/mysqld 
    david    24275  0.0  0.0   8056  2144 pts/1    S+   08:24   0:00 grep --colour=auto mysql


  4. Invoke the mysql server program using the socket information from step 3 and issue three mysql commands, as illustrated below.

    ~ $ mysql --socket=/run/user/1000/akonadi/mysql.socket                 <==
    Welcome to the MariaDB monitor.  Commands end with ; or \g.
    Your MariaDB connection id is 114
    Server version: 10.5.10-MariaDB Source distribution
    Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    MariaDB [(none)]> use akonadi;                                         <==
    Reading table information for completion of table and column names
    You can turn off this feature to get a quicker startup with -A
    Database changed
    MariaDB [akonadi]> delete from pimitemtable where remoteid is NULL;    <==
    Query OK, 9 rows affected (0.003 sec)
    MariaDB [akonadi]> \q                                                  <==

    The three mysql commands are "use akonadi;", "delete from pimitemtable where remoteid is NULL;", and "\q". After you say "mysql --socket= ..." you will be in a dialog with the mysql server (aka "MariaDB"), which provides a > prompt. The entire dialog is presented here, for clarity. User input lines are marked with <== in the preceding illustration.

When you restart KMail, those pesky duplicate messages will be gone. They were merely phantoms caused by the NULL pointers in the mysql database tables.