Email file name is the timestamp when the email is stored, moved (in microseconds). Example: 1466698612265640, start with From - Thu Jun 23 18:16:52 2016 (Thu Jun 23 2016 18:16:52 GMT+0200 (CEST))
Use NodeJS to convert mbox to maildir:
// Note: this script not work properly if an email contains "\n\nFrom - "constfs=require('fs');constpath=require('path');constreadline=require('readline');let file =process.argv[2];let tmpFile = file +".tmp";fs.renameSync(file, tmpFile);let folder = file;fs.mkdirSync(folder);let curFolder = folder +path.sep +"cur";fs.mkdirSync(curFolder);fs.mkdirSync(folder +path.sep +"tmp");let rl =readline.createInterface({ input:fs.createReadStream(tmpFile)});// each entry is separated by "\n\n" (or "\r\n", "\n\r", "\r\r")let emptyLines =0;//consecutive empty lineslet buffer ="";let count =0;functionwriteEntry(data =""){//if(!data.startWith("From - ")){if(!data.substr(0,7) ==="From - "){thrownewError(`Invalid entry "${data.substr(0,10)}…"`); } data +="\n";// newline at the endlet date =data.substring(7,data.indexOf("\n"));//"From - (.*)"let timestamp =Date.parse(date);// What about timezone?if(Number.isNaN(timestamp)){thrownewError(`Invalid entry date "${date}"`); } timestamp *=1000;// in microseconds timestamp +=Math.round(Math.random() *999999);//add random milliseconds + microsecondsfs.writeFile(curFolder +"/"+ timestamp, data,"utf8", error => error &&console.warn(error));}// Each linerl.on("line", (line) => {// If an empty lineif(line ===""){ emptyLines++; }// If previous lines are emptyelse{// End of previous entry// What happend a message contains "\n\nFrom - " ? like embedded emails//if(emptyLines >= 1 && line.startWith("From - ")){if(emptyLines >=1&&line.substr(0,7) ==="From - "){ count++;writeEntry(buffer.trim()); buffer =""; } emptyLines =0; } buffer += line +"\n";});rl.on("close", () => {// For the last entry buffer =buffer.trim();if(buffer !==""){ count++;writeEntry(buffer); }console.log(`${count} entrie(s) founded in "${file}"`);});