1

I am trying to import an IMAP account composed of many folders from Claws Mail internal cache. Claws is unfortunately unable to export all the folders by selecting the root account.

When checking the internal Claws cache folder, each mail is a plain text file named as following:

base_path/My Account/Folder ABC/1
base_path/My Account/Folder ABC/2
base_path/My Account/Folder ABC/3
base_path/My Account/Folder ABC/4

base_path/My Account/Folder DEF/1
base_path/My Account/Folder DEF/2
base_path/My Account/Folder DEF/3

base_path/My Account/Folder X/etc...

I tried to import this structure with different mails reader like KMail and Balsa, but each import failed. I just would like all these mails easily accessible and readable.

Which tool on Linux can I use to import such a structure?

calandoa
  • 219

1 Answers1

2

Since it's one file per message, containing just the original RFC 822-format data, it's easy to convert to Maildir++ layout by just renaming the files. Afterwards, it should be readable by at least Balsa and Mutt, as well as most IMAP servers (if you can upload files directly).

#!/usr/bin/env bash

inputroot=~/.claws-mail/imapcache

output=~/claws.maildir

find "$inputroot/" -mindepth 2 -type d | while read -r srcdir; do
    # Maildir++ uses <dir>/.a.b.c/ for subfolder hierarchy;
    # the "INBOX" itself is just <dir>/, having <dir>/{cur,new,tmp}/, but it
    # is not used during this conversion, which puts all mail in subfolders.
    folder=${srcdir#$inputroot}
    folder=/${folder#/}
    folder=${folder//./_}
    folder=${folder//"/"/.}
    dstdir=$output/$folder
    find "$srcdir" -maxdepth 1 -type f -not -name '.*' |
    while read -r srcfile; do
        if [ ! -d "$dstdir/cur" ]; then
            echo "creating: $dstdir"
            mkdir -p "$dstdir/cur" "$dstdir/new" "$dstdir/tmp"
        fi
        # in cur/, filenames are <unique>:2,<flags> (S for "seen")
        dstname="claws.${srcfile##*/}.$(stat -c %Y "$srcfile"):2,S"
        cp -a "$srcfile" "$dstdir/cur/$dstname"
    done
done
grawity
  • 501,077