Export mailboxes with including subfolders

dear all,

I am looking for a script to export all mailboxes in my “iCloud” account, some of them have subfolder and thus I would like to have the option to select the “Export all subfolder” (rather than exporting each subfolder …).

I looked in the archives, but I didn’t find anything. And in the Mail dictionary I could not even find the command “export” …

Any suggestion?

Thanks

L.

This is what I have done so far …

set FilterFoldersOut to {"Archive", "Apple Mail To Do", "Notes", "INBOX", "Drafts", "Sent Messages", "Deleted Messages", "Junk"} -- I dont need those mailboxes
set TopLevelMailboxes to {}

tell application "Mail"
	set allMailboxes to every mailbox of account "iCloud"
	repeat with aMailboxes in allMailboxes
		set myName to (name of aMailboxes's container) as rich text
		if name of aMailboxes's container = missing value then -- it means that it is a top level folder, it might or might not have subfolder(s), but for sure IT IS NOT a subfolder
			if name of aMailboxes is not in FilterFoldersOut then --remove those folders I dont need
				set theM to mailbox (name of aMailboxes) of account "iCloud" -- I can select the folder in case I can trigger the "Export" command by UI...
				set end of TopLevelMailboxes to (name of aMailboxes)
			end if
		end if
	end repeat
end tell

I have now a list of folders I want to export. Some of them have subfolders, and for those I would like to have the “Export all subfolder” option activated.

Any suggestion on how to continue?

Thanks