@NigelGarvey Thanks very much, that gives me the clues I needed.
OnMyMac for me is actually distributed among several different folders (possibly because I have done several different system upgrades, and Apple Mail has changed how it stores mail in each release, and none of my upgrades has gone smoothly for Mail).
This bit of your code
set mailboxPath to «class seld» of (theMailbox as record)
does not work for me, and I didn’t initially understand what class seld was doing. But if I run your code, set myrecord to (theMailbox as record) looks like the image below. So mailboxPath doesn’t end up with any useful text. I’m on Mail 14 on Big Sur, so maybe you get something else.
I have tried walking up the mailbox hierarchy (till I get an error because the account referenced by the container doesn’t exist). But this doesn’t find the right accountContainer. I will have to try re-importing the various mailboxes from previous versions of Mail/Mac OS, because they are in a mess.
Appreciate the warning about what I do with the storage. I am trying to use a shell find command to deal with duplicate email messages. I have tried to available Applescript (http://jollyroger.kicks-ass.org/software/RemoveDuplicateMessages-Mail.zip), but it thinks two messages are duplicates even though one has a whole load of the Received etc messages at the top which the other doesn’t. The Applescript looks at the text of the message and the from, to and subject. So I am thinking of adapting that script once I have checked the raw text with md5 or similar.