How do I split mbox file into multiple text files with a custom filename (msg subject + counter)?

Aloha! I am running Mac OSX Yosemite. I have an mbox file exported from my mail system and I would like to run a script to split the file into individual text files, one for each message contained. I also would like the filename to be a customized text string containing the subject of the message and a numeric iterator to resolve the issue of duplicate subjects (I don't want to overwrite messages with identical subjects). I would expect the script to produce file output corresponding to below:
Subject A 1.txt
Subject B 2.txt
Subject C 3.txt
Subject A 4.txt


Mahalo!

It’s hard to offer concrete advice without knowing more about your requirements, foremost of which is what language your want to write your script in. If I were in your shoes I’d do this in Python, using the (built-in to macOS) mailbox module.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

WWDC runs Mon, 5 Jun through to Fri, 9 Jun. During that time all of DTS will be at the conference, helping folks out face-to-face. http://developer.apple.com/wwdc/

How do I split mbox file into multiple text files with a custom filename (msg subject + counter)?
 
 
Q