>>>>By the way, is there any facility in the script editor that can help one to spot its mistake (e.g. a list of variables used in a script can let one spot spelling errors)?
There is, not a list of variables, for that you would need ScriptDebugger, but set your script so your variable are all colored bright red, and stand out very clearly, and applications keywords are a different font and/or color to make it easier to distinguish. (Preferences>Formatting)
using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
tell application "Mail"
say "Hello"
set text item delimiters to "[Caml-list] "
repeat with eachMessage in theMessages
say "This goes on and on"
set theSubject to the subject of eachMessage
set theAnswer to ""
repeat with thePart in text items of theSubject
set theAnswer to theAnswer & thePart
end repeat
set subject of eachMessage to (theAnswer)
end repeat
end tell
end perform mail action with messages
end using terms from
-- SCRIPT
When I ask Mail to apply rules, I can hear the "hello" that let me
know the script is triggered, but there is no iteration of the loop.
Someone else already suggested using display dialog rather than say. Good advice, in addition, when running the script from the script editor you should open the apple event log and, to check the value of a variable a point in the script enter the command
As for the script not entering the repeat loop, it's behaving as if theMessages is a list of 0 items {}.
That will tell you if theMessages is indeed a list and how many items are in the list.