Mail.app v2.0.5 - Smart Mailboxes not recognized by AppleScript?

I’ve got a Smart Mailbox in Mail which contains only those messages which have been marked as flagged, and I’m trying to set a variable to represent all of the messages in that mailbox. It seems however that AppleScript doesn’t recognize Smart Mailboxes as equal to regular mailboxes.

For example, the following script works just fine if the mailbox named “Flagged Messages” is a normal mailbox, but if it is a Smart Mailbox, I get the error: “Mail got an error: NSReceiverEvaluationScriptError: 4”

tell application "Mail"
	
	set theMessages to every message of mailbox "Flagged Messages"
	
end tell

Can anyone suggest a solution or workaround to this problem?

Is there any work around since?

Not that I’m aware of (for Mail.app 2.1.1).

I don’t think Smart Mailboxes are accessible via scripting; Also, note that they don’t actually contain messages:

tell application "Mail"
	-- Check the result when selecting items in a Smart Mailbox
	selection
end tell

Right!
Smart mailboxes are just virtual mailboxes which contain search results from certain search criteria.

But unfortunately Apple is not consistent. You can’t access smart folders in Finder as well,
but smart playlists in iTunes and smart albums in iPhoto are accessible :confused:

It’s not the first time I bang against a bug in Mail.app applescript dictionnary.
Hope Leopard will fix all of them.

It’s not really a bug. The function is just not provided

That’s right.

But I miss it anyway. :confused: