Rather than let this go unanswered, here is some insight.
The Apple Mail scripting dictionary does not give you access to the URL behind the hyperlinked text in the mail body. You can get the entire raw source of the mail body which you would have to then parse to get the URL associated with the anchored text. There is no way to get Mail to click that URL in the email body either.
The scripting dictionary does support a move reserved word for transferring a message to another mail folder.
Suppose that I have this mail body view as a screen shot:
The actual HTML behind this view is:
<html><head><meta http-equiv="content-type" content="text/html; charset=us-ascii"></head><body style="overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;">Some text may have this <a href="https://www.apple.com">hyperlink-1</a> or other text may have <a href="https://discussions.apple.com/thread/255591449?sortBy=oldest_first">hyperlink-2</a> on it.</body></html>
The following AppleScript will work on the selected email message, extract the above HTML from the message raw source, extract the URL associated with "hyperlink-1" from the HTML, and then open the URL as a new tab in Safari.
use framework "Foundation"
use scripting additions
property ca : current application
tell application "Mail"
if not (get selection) is {} then
set theMsg to item 1 of (get selection)
tell theMsg to set theHTML to my justHTML(its source) as rich text
# tell theMsg to set theHTML to its source
else
display alert "No Mail message selected" giving up after 10
return
end if
end tell
tell application "Safari"
activate
open location my extractURL(theHTML, "hyperlink-1")
end tell
return
on justHTML(asrc)
-- get just the HTML content from the raw message source without using perl, etc.
set regex to ca's NSString's stringWithString:"(<html.*html>)"
set srcStr to ca's NSString's stringWithString:asrc
set match to srcStr's rangeOfString:regex options:(ca's NSRegularExpressionSearch)
return (srcStr's substringWithRange:match) as text
end justHTML
on extractURL(ahtml, akey)
-- extract the URL from <a href="https://www.apple.com">hyperlink-1</a>
-- using Positive Lookbehind and Lookahead regular expression pairing for URL capture
set regex to ca's NSString's stringWithString:("(?<=\\<a href=\")(.*)(?=\">" & akey & "<\\/a>)")
set shtml to ca's NSString's stringWithString:ahtml
set match to shtml's rangeOfString:regex options:(ca's NSRegularExpressionSearch)
return (shtml's substringWithRange:match) as text
end extractURL
Whether you can adapt this to a Mail rule or not is to be determined.
Tested: M2 Mac mini Pro w/Sonoma 14.4.1