Duplicating nested mailboxes

*** iMac (Retina 5K, 27-inch, 2017), macOS Mojave 10.14.6 ***

Is there a way in the Apple Mail app to duplicate a series of nested mailboxes? I have a prototype set of mailboxes that I want to propagate, illustrated by this example:

------------------------------ Begin example ------------------------------

Parent
Child 1
Grandchild 1.1
Great-grandchild 1.1.1
Great-grandchild 1.1.2
[…]
Great-grandchild 1.1.n
Grandchild 1.2
Great-grandchild 1.2.1
Great-grandchild 1.2.2
[…]
Great-grandchild 1.2.n
[…]
Grandchild 1.n
Great-grandchild 1.n.1
Great-grandchild 1.n.2
[…]
Great-grandchild 1.n.n
Child 2
Grandchild 2.1
Great-grandchild 2.1.1
Great-grandchild 2.1.2
[…]
Great-grandchild 2.1.n
Grandchild 2.2
Great-grandchild 2.2.1
Great-grandchild 2.2.2
[…]
Great-grandchild 2.2.n
[…]
Grandchild 2.n
Great-grandchild 2.n.1
Great-grandchild 2.n.2
[…]
Great-grandchild 2.n.n
[…]
Child n
[…]

------------------------------- End example -------------------------------

Altogether, there are more than 100 mailboxes in the set, so creating them manually is a pain I’d like to avoid. I’d prefer to copy “Parent” to another place among my mailboxes and have it and all its descendents duplicated in the new place in a single operation. Is there a way to accomplish this using Mail itself or some other set of macOS operations?

1 Like

Hey John,

This is doable with AppleScript, although Mail scripting is a bit creaky.

-Chris

--------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2021/12/23 16:02
# dMod: 2021/12/23 16:02 
# Appl: Mail (Mojave)
# Task: Create a Nested Stack of Mailboxes.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Mail, @Create, @Nested, @Stack, @Mailboxes
# Test: Tested only on macOS 10.14.6 Mojave
--------------------------------------------------------
(*

INSTRUCTIONS:	

   • Make sure you have a current backup of Mail before playing games with it.
   • Try out the current mailbox path list, and see if it works before attempting something more.
   • LEAVE the STUB item – it is required to allow the script to create child mailboxes.
   • The structure of the mailbox path list is #very# important.
   • Mailboxes are created in the On My Mac section.
      - That can probably be changed to a specific account but different syntax will be required.
   • Run from the Apple “Script Editor.app” or Late Night Software's Script Debugger.
      - The script may take some time to run – more with an increasing number of mailboxes.
         - Do NOT use either the Script Editor or Mail while the script is running!
         - A notification will display when the script ends.

*)
--------------------------------------------------------

set mailboxPathList to paragraphs 2 thru -2 of "
Parent/STUB/
Parent/Child 1/
Parent/Child 1/Grandchild 1/
Parent/Child 1/Grandchild 1/Great Grandchild 1/
Parent/Child 1/Grandchild 1/Great Grandchild 2/
Parent/Child 2/
Parent/Child 2/Grandchild 2/
Parent/Child 2/Grandchild 2/Great Grandchild 1/
Parent/Child 2/Grandchild 2/Great Grandchild 2/
"

tell application "Mail"
   activate
   repeat with mailboxPath in mailboxPathList
      make new mailbox with properties {name:contents of mailboxPath}
   end repeat
end tell

display notification "DONE!" with title "MAIL JOB" subtitle "················" sound name "Tink"

--------------------------------------------------------

Hi, Chris!

Is there a way in the Apple Mail app to duplicate a series of nested mailboxes? …

This is doable with AppleScript….

To someone whose use of AppleScript is the null set, combined with all the warnings of disaster in the script’s comments, plus the apparent need for every one of the mailbox names to be embedded in the script, this has all the attraction of prescribing the guillotine to cure a common head cold. Too many unknowns for me, with too many opportunities for destroying more than fifteen years of Mail archives in the process.

I appreciate the suggestion, but I need to look elsewhere for a solution. Anyone?

Onward,
john

The script is most likely perfectly safe to use, but when fooling with email and the possibility of data loss one errs on the side of caution.

The AppleScript could be adjusted to create mailbox paths on the fly, but I leave that exercise for the user.

Your only other option is Keyboard Maestro and brute-forcing the Mail UI.

That would be a royal pain for someone unfamiliar with KM…