Mail.app - Open List-Serve Page in Safari

Hey Folks,

On a fairly regular basis I want to visit the list-serve page related to a list-mail-message I’ve received.

I hate having to fiddle around to get there, so I wrote a script and have bound it to Cmd-Opt-Ctrl-A with FastScripts.

My previous script was pretty hard-coded, but since Apple fixed headers in Mavericks Mail I rewrote it to be a bit more flexible.

It works with Yahoo Groups, Google Groups, and assorted other lists that have a list-archive header.

-------------------------------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2013-04-02 : 14:00
# dMod: 2013-12-15 : 10:04
# Appl: Apple Mail & Default browser
# Task: Visit List-Serve Page Related to List-Mail-Message if Available.
# Libs: None
# Osax: None
# Tags: @Applescript, @Mail, @List, @Archive, @Header, @Browser
-------------------------------------------------------------------------------------------

try
	
	set listArchiveUrl to {}
	set yahooGroupsBaseURL to "http://groups.yahoo.com/neo/groups/"
	
	tell application "Mail"
		set _msg to selection
		if length of _msg = 1 then
			set _msg to item 1 of _msg
		else
			error "No messages OR too many messages are seleced!"
		end if
		
		tell _msg
			
			set listID to content of (headers whose name is "List-Id")
			if listID ≠ {} then
				set listID to item 1 of listID
			end if
			
			set listArchiveUrl to content of (headers whose name is "List-Archive")
			if listArchiveUrl ≠ {} then
				set listArchiveUrl to item 1 of listArchiveUrl
			end if
			
			if listArchiveUrl = {} then
				
				if listID contains "applescript-users.lists.apple.com" then
					set listArchiveUrl to "http://lists.apple.com/archives/applescript-users"
					
				else if listID contains "yahoogroups.com" then
					set _cmd to "<<< " & (quoted form of listID) & " sed -E '
						s![<>]!!g
						s!\\.yahoogroups\\.com$!!
					'"
					set listID to do shell script _cmd
					set listArchiveUrl to yahooGroupsBaseURL & listID & "/"
					
				end if
			end if
		end tell
	end tell
	
	if listArchiveUrl is in {{}, ""} then
		beep
		return
	else
		set _cmd to "<<< " & (quoted form of listArchiveUrl) & " sed -E 's!^<|>$!!g'"
		set listArchiveUrl to do shell script _cmd
		tell application "Safari"
			make new document with properties {URL:listArchiveUrl}
			set bounds of front window to {228, 22, 1542, 1196}
			activate
		end tell
	end if
	
on error e number n
	stdErr(e, n, true, true) of me
end try

-------------------------------------------------------------------------------------------

on stdErr(e, n, beepFlag, ddFlag)
	set e to e & return & return & "Num: " & n
	if beepFlag = true then
		beep
	end if
	if ddFlag = true then
		tell me
			set dDlg to display dialog e with title "ERROR!" buttons {"Cancel", "Copy", "OK"} default button "OK"
		end tell
		if button returned of dDlg = "Copy" then set the clipboard to e
	else
		return e
	end if
end stdErr

-------------------------------------------------------------------------------------------

1 Like