I might try and implement this myself if I have the time, however I'll leave it here in case anyone wants to take it.
That gets a tad interesting as you can have a single notmuch store covering several mail dirs.
While you will be able to pretty easily grab the filenames, that won't actually tell you which account the message is from
Should be fairly easy to infer the account by looking at the source of an account and matching it with the filenames returned by notmuch. Am I missing something?