I want to be able to move messages between mail applications (on different machines), preserving the mailbox hierarchy, as a rudimentary email archiving system. I hope to create a rule that will run on any message older than X days, and automatically move that message to a similar folder on another machine.
I got applescript to talk to the mail app on the remote machine okay, and I can create top-level mailboxes, but I can't work out how to dynamically check and recreate an entire hierarchy of mailboxes. Specifically,
(B) I can't get Mail.app to create a new mailbox within an existing mailbox (although I can create top-level mailboxes).
--- (A) ---
It is easy enough to iterate over all the mailboxes, but this is needlessly inefficient, if Mail will return all the top level mailboxes. The top level mailboxes use a nebulous parent container whose name is: account "On My Mac". For example, the 72nd mailbox is a top level mailbox... and the following is dumped from the event log:
get name of container of item 72 of every mailbox
account "On My Mac"
Now, if I get Mail.app to return all of the accounts, I don't get this "On My Mac" account... so how to I quickly get a handle to this account object? Is it impossible? If I can get a handle to this object, I can then to a hierarchical search to find out if a given mailbox exists in the right spot in a tree.
--- (B) ---
I can get Mail to create top-level mail boxes like so:
set theNewMailbox to make new mailbox with properties {name:"my_new_mailbox"}
Which is great, however, I can't find any way to create a mailbox that is a sub-mailbox of an existing mailbox.