Why doesn't this applescript work any more in ML mail.app (as a rule)

It works only when you right click on the mail message and choose “run rules”, but not on incoming messages (without interaction).

The first dialog is shown both when incoming or running manually, but the second dialog (with the id) is only shown when running manually. Nothing is shown in console.log

Any ideas?

using terms from application "Mail"
    on perform mail action with messages theMessages for rule theRule
        tell application "Mail"
            repeat with theMessage in theMessages
                display dialog "inside"

                set theId to id of theMessage

                display dialog "the id is " & theId

            end repeat
        end tell
    end perform mail action with messages
end using terms from

update: i added a try catch block around

and this is the error I get:

Any idea what this means? I don’t get the error when applying rules manually.

Ok I found out that incoming mails don’t have an id set yet. That’s a problem…

                    set theTest to (exists id of theMessage)
                display dialog theTest

Because I want to save the email to the disk :

                                        set theEmail to (do shell script "mdfind -onlyin ~/Library/Mail \"kMDItemFSName = '" & theId & ".emlx'\"")
                                        set archiveName to theId & "-" & (extract address from theMessage's sender) & ".emlx"
                                        set saveLocation to "Users:wesley:Documents:Incoming:"
 
                                                  do shell script "cp '" & theEmail & "' '" & POSIX path of saveLocation & "';"


Is there any way around this?

Hmm, it doesn’t seem to have anything to do with the ID, it happens on other fields also:

(same error)

					set theSubject to subject of theMessage