Move message in Mail after given time.

I’m trying to set up a script to move messages from one folder to another after a given time. Once it’s running I will include it in Mail’s Rules. However I get an error "error

with this

set _ago to (current date) - (365 * days)

tell application "Mail"
	set _inbox to mailbox "failure notices"
	
	set oldFailedMessages to a reference to (messages of _inbox whose date received comes before _ago)
	if ((count oldFailedMessages) > 0) then move oldFailedMessages to mailbox "Failure Notices OLD"
	
end tell

Any ideas on how to get this to work? I’m running Mavericks on 10.9.3

Hi. Try:


set Ago to (current date) - (365 * days)

tell application "Mail"	 to move (mailbox "failure notices"'s messages whose date received comes before Ago) to mailbox "Failure Notices OLD"

Thanks for that Marc, but I am still getting this error message

is the reference to the mailbox(es) correct?
mailbox “something” is only valid for the first level of custom mailboxes On My Mac.
You can check this with


tell application "Mail" to exists mailbox "failure notices"

Other mailboxes belong to an account, for example


tell application "Mail" to exists mailbox "failure notices" of account "iCloud"

Thanks so much for that StefanK. I realised that one of the reasons it wasn’t working is that the folder “Failure Notices OLD” is a subfolder of the “Failure Notices” folder. I moved “Failure Notices OLD” folder to no longer be a subfolder, and hey presto, it worked. But how do you get Applescript to recognise a subfolder mailbox?

The hierarchy behaves like (POSIX) paths


tell application "Mail" to exists mailbox "failure notices/subfolder/subfolder2" of account "iCloud"

Thanks so much. It works a treat.