For years users, including me, waited for the option to sort mailboxes (not mails) alphabetically in Apple’s Mail. The fixed default is either by time of folder creation, or manually. A PITA if you have many subfolders. Based on partial advice “on the internet”, I put the below together, which still works in MacOS Ventura as tested today.

You need a program that can find / replace with a grep option, I’m using BBEdit. Quit Mail and find the account-specific containing mail folder. These sit at ~/Library/Mail/V10/; a typical one would be
~/Library/Mail/V10/4F681230-WHATEVER-300DC7FCCC14/. If you have several accounts, you can identify them via the contained mailbox names. Then open
with your grep-capable editor. Now we need to find all lines containing “MailboxDisplayIndex” with the following grep pattern
and replace them with nothing.

Usual caution applies, e.g. make a copy of that plist file first. Then re-open Mail, and, lo and behold, subfolders are now sorted alphabetically! Enjoy.

I like a few mail folders at top, not alphabetically. Rather then manually reordering them in Mail, I add blank(s) a the head of the mailbox name.

I’m not a grep wizard, I had to painstakingly compile the above pattern. Improvements welcome! I bet the replacement can also be done within grep, thus obviating BBedit. And wrap that in a nice shell script. Left as exercise to the gentle reader :). First to send me a working version will be added here.