help for working this applescript in rule

hello, I want to work this script in mail rule, but I’m newbie in scripting

thanks !

tell application “Mail”
selected messages of message viewer 1
repeat with m in result
do shell script "find ~/Library/Mail/V2 -name " & (get id of m) & “.\* -exec cp {} ~/Documents/MailFichiersJoints/” & quoted form of my replace(subject of m, “/”, “”) & “.emlx \;”
end repeat
end tell

on replace(input, x, y)
set text item delimiters to x
set t to text items of input
set text item delimiters to y
t as text
end replace

I googled mail rule script