KMail: cannot import archived emails with PIM import program

Trying to retrieve emails archived from KMail, it turns out that a substantial number of archived emails cannot be retrieved by the PIM import program. The most frequent error message being:

Failed to commit transaction

Is there a way to save as many as possible emails from loss, e.g. by a script converting archived emails to eml-format ?

another annoying feature of the PIM import program is that every failure to import an email has to be quitted by clicking OKmanually, which means hundreds or thousands of manual clicks required when importing large archives, just in order to save as many as possible emails from the archive. If these problems are not fixed soon, Kmail would have to be considered as unusable and dangerous email client !

@osleap-mak:

Just a gentle reminder → KMail and the KDE Plasma PIM Suite are not maintained by openSUSE.

  • Please vent your frustration in the KDE Discuss Forum: <KDE Discuss>

But, do not expect a warm welcome – the reason is here: <KDE Schedules>


The Achilles Tendon of openSUSE Leap is the distributions policy regarding KDE Plasma 6 releases – KDE is updating with short, planned and documented release cycles. You can see in the KDE Schedules what is supported and, what is no longer supported.

  • There isn’t, «currently», any such such thing as Long Term Support of any KDE Plasma 6 release.
    Yes, yes, I am aware of some discussions around the theme of a possible, future, KDE Plasma 6 version which could, possibly, be a LTS candidate but, the KDE Developer community ain’t there yet.

So, now some questions and a comment:

  1. How did you archive your KMail directories?
  2. Did you use the KMail automatic archive feature or, did you manually archive each directory?
  3. If you used the KMail archive feature, the file containing the archived e-Mails is a BZ2 compressed tar archive; which you can inspect with the KDE Plasma application “Ark”.

BTW:

 > kinfo
Operating System: openSUSE Tumbleweed 20260821
KDE Plasma Version: 6.7.4
KDE Frameworks Version: 6.29.0
Qt Version: 6.11.2
Kernel Version: 7.1.8-1-default (64-bit)
Graphics Platform: Wayland
Processors: 12 × AMD Ryzen 5 8600G w/ Radeon 760M Graphics
Memory: 34 GB of RAM (32.8 GB usable)
Graphics Processor: AMD Radeon 760M Graphics
 > 
 > kmail --version
kmail2 6.7.3 (26.04.3)
 > 

1 Like

thank you for your informative response !

:~> kinfo
Operating System: openSUSE Leap 16.0
KDE Plasma Version: 6.4.2
KDE Frameworks Version: 6.16.0
Qt Version: 6.9.1
Kernel Version: 6.12.0-160000.37-default (64-bit)
Graphics Platform: X11
Processors: 4 × Intel® Core™ i5-6500 CPU @ 3.20GHz
Memory: 16 GiB of RAM (15.5 GiB usable)
Graphics Processor: NV106
:~> 
:~> 
:~> kmail --version
kmail2 6.4.3 (25.04.3)

re 1.-3.: I used the kmail archiving feature, archiving directories with subdirectories manually, which produced tar.bz2 archives, e.g. Archiv_inbox_2025-10-29.tar.bz2
KMail is able to import these tar.bz2 archives in principle, but failed with a big archive covering several years. I tried to unpack this archive and import from the unpacked directory, which partially worked now, but with numerous error messages [file cannot be added to kmail-import directory: ]transaction failed.
In addition each error message had to be “OKed” by manually clicking, probably several hundred times… For the user it is unknown which and how many emails may have been lost in the process.
A possible reason for the failures might be data corruption (from faulty hardware)
but that seem unlikely, because similar problems occurred with a newer archive also.

some speculations:
Another observation might indicate a potential sychronizing problem between the PIM import program and kmail: maybe kmail puts adding additional emails on hold, if there is already a big queue of emails to be imported from PIM import program.
This is based on the observation, that the kmail counter for new emails often starts to work again, if the OK-button for the error message transaction failed is clicked not immediately but with a larger time delay…

OK – possibly a known issue with the KMail archive feature which has been possibly resolved with a newer KMail version.

  • You could report this issue on the KDE Bug Reporting – <KDE Bugtracking System>.
    But, please explicitly ask if, the issue has been resolved in a newer KMail version.
    The version of KMail shipping with Leap 16.0 is, AFAIK, no longer being supported by the KDE Plasma developers.

What you could do is, to unpack the large .bz2 to a local user directory.

  • You’ll have to use KRename to add the suffix ‘.eml’ to each e-Mail file. :sunglasses:

Then, you can “divide and conquer” → split the e-Mail mass into useable goups of about 1 MB or 2 MB and then, import each group into your KMail instance.

  • You may have noticed that, I have a local e-Mail folder named “Z7-Imports”.
    When I have to restore e-Mails from my Archives, I import to a folder below that local Akonadi instance and then, if the import checks OK, I then move the needed missing e-Mails to the working directories.
    Any unneeded imported e-Mails are then, simply deleted …

From where/what/how were the emails exported ?

Yes, this is what I did !

Using KRename is an interesting tip. I used a bash script:

ext="eml"
files=( $(ls /home/user1/inbox/cur/))
for str in ${files[@]}; do
    bez="$str.$ext"
    echo $bez
    mv -- "$str" "$bez"
done

A useful extension of the script would be to extract from each email

from:
subject: 

So when searching through tens of thousands of emails, it is possible to find the one email that matters.

If these problems are not fixed soon, Kmail would have to be considered as unusable and dangerous email client !

It IS a dangerous app. Last time I tried, it deleted all my emails instead of a few some I intended to delete, without any warning, by one button pressed when I was in a very confused state. The delete was also unrecoverable. Yeah I have a grudge against this app, but if you do research you’ll see it doesn’t have a good reputation. So I advise against using it.

Stop spreading FUD like this. Kmail never removes mail unrecoverable, it moves them to it’s trashbin.

@osleap-mak Where did these mails come from, i.e. which client?

The incident was more than 10 years ago though.

I beg to disagree:

  • KMail is a fully featured e-Mail Client which strictly conforms to the applicable RFC requirements.

And yes, for the unwary, the strict compliance to the RFCs may well be a disturbing experience.

in order to find whether a particular email can be retrieved despite import problems with KMail and PIM import program, I used the following bash script:

files=( $(ls /home/user1/inbox/cur/))
for str in ${files[@]}; do
    FR=$(grep '^From: ' "$str")
    SB=$(grep '^Subject: ' "$str")
    DT=$(grep '^Date: ' "$str")
    echo "$str;$DT;$FR;$SB; "
    FR=''
    SB=''
    DT=''
done  > EmailList.csv

This creates a table of all emails. The csv-formatting works for most of the emails correctly.
If KMail fails to import any single email, one might try with other email clients.

Then, there is something wrong with that e-Mail’s Tags.

  1. Inspect RFC 5322 and the update in RFC 6854.
  2. Open the e-Mail file with an editor and, with the help of the KMail error message inspect the file.
  3. Correct anything which doesn’t conform to the RFCs mentioned above and save the changed file.
  4. Import the corrected e-Mail into KMail.

<RFC 5322: Internet Message Format> – First published October 2008 – the “Draft Standard” remark is “normal” RFC syntax.
<RFC 6854: Update to Internet Message Format to Allow Group Syntax in the “From:” and “Sender:” Header Fields> – First published March 2013 – current status “Proposed Standard” …