I had an Entourage rule that edited the body of email according to rules and I’ve just switched to Mail.app and I’m struggling to migrate it. This rule triggers just fine and the value of newContent is correct, but the body of the message doesn’t get changed:
using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
tell application "Mail"
repeat with eachMsg in theMessages
tell eachMsg
tell content
set paragraphItems to every paragraph
set newContent to ""
repeat with theParagraph in paragraphItems
if theParagraph contains "mydomain.com/support" then
set newContent to my findReplace(theParagraph, "mydomain.com/support/task?id=", "otherdomain.com/othertask?id=")
end if
end repeat
set last paragraph to newContent
end tell
end tell
end repeat
end tell
end perform mail action with messages
end using terms from
on findReplace(the_string, search_string, replace_string)
tell (a reference to my text item delimiters)
set {old_tid, contents} to {contents, search_string}
set {the_string, contents} to {the_string's text items, replace_string}
set {the_string, contents} to {the_string as Unicode text, old_tid}
end tell
return the_string
end findReplace
I’m beginning to think this isn’t possible (changing the text of an email body). Am I right?
Jon