Install maildir-utils and use
mu view -summary-len=<numberOFlinesOFmailfile> <MAILFILE>
to parse the files and write a json.
Use
cat <YOURSTUFF> | iconv -c -t <YOURCHARSET> | tr -d '\000-\011\013\014\016-\037' > <YOURJSONFILE>
to eliminate bad characters who do not fit into your charset.
Some (windows) mail clients (outlook?) put an CRLF at the end of to, cc, bcc or subject , so do something like an
echo "$to" | sed 's|\r$||'
Elasticsearch will not accept json files encapsulated in square brackets like
[{ "mykey":"myvqlue1"}, ...]
Drop the outer brackets. It should look like
{ "mykey":"myvqlue1"}, ...