selecting mailboxes

i’ve searched the forums (and relevent applescript dictionaries) extensively and not found the answer to this, any help appreciated.

is there a way in applescript to select a particular mailbox in mail.app? – mind you not simply the (accumulated) inbox or another of the 6 you can get to using the “mailbox” menu by…

tell application “System Events”
keystroke “1” using command down

no, i mean a local folder (found on the sidebar). i’m trying to write a script to select all the messages in only one of 3 IMAP mailboxes, copy them, and paste them into a local folder for safekeeping (but first deleting the ones that were there). (why? cuz i’ve had imap servers go down and lose my mail or revert to an old backup of my mail. yuk. so it’s important for me to have a ‘snapshot’ of my mailbox.)

also note that doing this in the finder, for whatever reason, does not work. so writing a script to move the .emlx and .plist files from one place to another won’t do it.

so basically i’m trying to write a script that will

activate mail
go to [local] mailbox A
selelct all messages
(which i know is done with… tell menu item “Select All” of menu “Edit” of menu bar 1 of application process “Mail” to click – yep that works fine! :slight_smile:
delete
go to [IMAP] mailbox A
select all [like above]
copy
go to [local] mailbox A
paste

and so on for 3 mailboxes.

thanks in advance for your help!

You do not need applescript.

You can create a new mail box.

make sure the location is set to on-my-mac

Before you set up the rule it most likely easier to manually select all the imap mail messages and drag and drop them into the new mailbox while holding down the option key.

Setting up the rule:

IF any
ACCOUNT: → the imap account

PERFORM THE FOLLOWING ACTIONS
COPY MESSAGE TO MAILBOX → your new local one.

thats it you can make other rules for the other imap accounts or if the all are going to the same local mail box then just use the + button in this one and add more accounts.

The one thing I do not understand is the delete bit.
If you want to back up your imap mail to you local computer why do you delete previous backup first before you copy new ones over??

Hi,

To answer your original question. This is how to open a mailbox:

set myMailbox to "Mailing Lists/Folder 1"
-- Where the mailbox Folder 1 is a sub folder of Mailing Lists 
tell application "Mail"
	activate
	set selected mailboxes of message viewers to {mailbox myMailbox}
	-- Opening a list of mailboxes
end tell

However you can do all of this without scripting the UI.

To delete all messages in a folder:

tell application "Mail"
	activate
	delete every message of mailbox "Mailing Lists/Folder 1"
-- Where the mailbox Folder 1 is a sub folder of Mailing Lists 
end tell

To move ervery message from one mailbox to another:

tell application "Mail"
	activate
	move every message of mailbox "Folder 1" to mailbox "Folder 2"
end tell

Best wishes

John M