AppleScript to open POPFile links from Entourage X

Here's an AppleScript to open the link in the X-POPFile-Link header added by POPFile email filtering software in your default browser. This is useful when POPFile has done a classification error and you want to reclassify the message. You can open multiple messages at once, but it's usable only if your browser opens links in new windows.

You'll need a Mac OS X version of Microsoft Entourage (and POPFile, of course). Copy the code below to Script Editor and save the script into Entourage Script Menu Items folder.

Don't contact me for instructions on how to install POPFile on Mac OS X. Michael Artz has already written excellent step-by-step instructions for your pleasure.

Updated November 18, 2003: Now works with Mac OS X 10.3.x and POPFile 0.20.x.

on run
set openCount to 0
 
tell application "Microsoft Entourage"
set selectedMessages to current messages
 
repeat with theMessage in selectedMessages
set theHeaders to headers of theMessage
set headerlist to every paragraph of theHeaders
 
repeat with theHeader in reverse of headerlist
if theHeader contains "X-POPFile-Link" then
set theChars to every character of theHeader
set theUrl to ""
set start to false
 
repeat with theChar in theChars
if theChar contains ">" then
set start to false
exit repeat
end if
 
if theChar contains "h" then
set start to true
end if
 
if start is true then
set theUrl to theUrl & theChar
end if
end repeat
 
my openURL(theUrl)
set openCount to openCount + 1
end if
end repeat
end repeat
end tell
 
if openCount is 0 then display dialog "Sorry, the selected messages didn't contain X-POPFile-Link header." buttons {"OK"} default button 1 with icon stop
end run
 
on openURL(theUrl)
if theUrl is not "" then
tell application "Dock" to open location theUrl with error reporting
else
display dialog "The URL in X-POPFile-Link header was empty." buttons {"OK"} default button 1 with icon stop
end if
end openURL

© 2003 Visa Kopu, visa@visakopu.net