How to do bulk Email imports with renaming?

I’m looking for some ideas on a workflow issue. I have a DEVONThink Database with thousands (approx 80K) of emails that were imported into it from out of multiple email clients over the years. I want to get them out of DT and into Obsidian.

If I export them as Markdown out of DT and then bring them into Obsidian I lose what the email addresses are for that message. Ditto for other file formats I can easily export.

What does work is to create a new blank note in Obsidian and drag the message out of DT into the body of the new note.

Issues are the notes are unnamed so I have to enter in a filename and it’s a single note at a time manual process and I have about 80,000 of them to do this to.

What I’d like is some sort of script or automation that would first create the notes in Obsidian giving them the name of the subject as they are in the .eml files. Allow an option to replace all spaces with _ for cross platform filename issues or else a later script that renames all the files that way and tells Obsidian to update them. Then import/drop into the body of the note the actual .eml file so the to and from addresses are preserved. Lastly sort those messages into Obsidian folders based on the date of the message which appears to be the date created for the .eml files in the DEVONThink package.

I can open the package that is the DEVONThink database and see all the individual .eml format files but I lose my own groups (folders). Within DT I have the messages sorted by years and I want that also in Obsidian as folders. A possible workaround is I could copy all the .eml files out of the DT package contents, then sort them based on date created and move them into folders for each year. It will be tedious but possible.

I have no clue how to start even writing such a script or program or whether it’s even possible.

Does anyone here have any ideas?