create mail rule from an applescript

I can’t see how this could happen but I will ask.

Is it possible to write an applescript that will create a permanent rule in mail?

I am trying to write an installer that will action a mail rule when an attachment in the correct format is posted.

All the code is done but can i through applescript write a mail rule that will install on someone elses machine?

I know I can install the file on their machine and through a read me tell them to create a mail rule but I wondered if there was a more elegant way


I haven’t tested it but according to Mail’s dictionary it should be possible.
There is one issue to consider: On many machines there is a final rule which stops evaluating rules.
If your new rule is placed after that rule, it will never be executed.
This is some sample code

tell application "Mail"
	set newRule to make new rule at end of rules with properties {name:"myRule", enabled:true}
	tell newRule
		make new rule condition at end of rule conditions with properties {rule type:subject header, expression:"mySubject", qualifier:does contain value}
		set run script to file "disk:path:to:script.scpt"
	end tell
end tell

Perfect Stefan. Thank You