Our University provides a URL in message headers from outside our network to report a message as SPAM.
I am attempting to write a script that will extract the header from a give message or messages and open it in Safari. While I can format a text sample properly and open it in safari, and I can extract the raw text from the headers and do a ‘display dialog’ with it, I cannot seem to do both of these with the desired result. For example, the header is something like this:
If I take out the parts of the script that deal with selected messages and working with mail and just set a variable to “<…>”, trim off the “<” and the “>” and send the result to Safari, it works fine. Likewise, if I leave in the business of talking to Safari and trimming the unwanted elements from the string, I can get the string by header name and display it but i cannot seem to do both.
Suggestions?
Thanks!! --mike
Here is the script that I have right now:
using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
repeat with eachMessage in theMessages
tell application "Mail"
tell eachMessage
set rawLink to (content of headers of eachMessage whose name is "X-Umn-Report-As-Spam")
--display dialog rawLink
--set rawLink to "<http://umn.edu/mc/s?DAX07MEOGvVrouX6kYEvK1ARnth2$paN5svKU55$H1zryXaovPh1sZy7cXpP6bB0e>"
set umnSpamLink to trim_line(rawLink, "<", 0)
set umnSpamLink to trim_line(rawLink, ">", 1)
tell application "Safari"
open location umnSpamLink
end tell
end tell
end tell
end repeat
end perform mail action with messages
end using terms from
on trim_line(this_text, trim_chars, trim_indicator)
-- 0 = beginning, 1 = end, 2 = both
set x to the length of the trim_chars
-- TRIM BEGINNING
if the trim_indicator is in {0, 2} then
repeat while this_text begins with the trim_chars
try
set this_text to characters (x + 1) thru -1 of this_text as string
on error
-- the text contains nothing but the trim characters
return ""
end try
end repeat
end if
-- TRIM ENDING
if the trim_indicator is in {1, 2} then
repeat while this_text ends with the trim_chars
try
set this_text to characters 1 thru -(x + 1) of this_text as string
on error
-- the text contains nothing but the trim characters
return ""
end try
end repeat
end if
return this_text
end trim_line