Analizing a Mail subject

Hi all,
I want to create a mail rule that triggers on SVN commit mails from five different projects. When these arrive the triggered AppleScript should figure out from which project this comes and then run a shell script depending on the project.

so far I have

set xu4 to "xU4"
set exult to "Exult"
set pent to "Pentagram"
set dos to "DOSBox"
set nuvie to "Nuvie"
using terms from application "Mail"
	on perform mail action with messages theMessages for rule theRule
         tell application "Mail"
		repeat with eachMessage in theMessages
			if the subject begins with "[" & xu4 and body contains "trunk/" & xu4 then
				set subj to xu4
			else if the subject begins with "[" & exult and body contains exult & "/trunk" then
				set subj to exult
			else if the subject begins with "[" & pent and body contains pent & "/trunk" then
				set subj to pent
			else if the subject begins with "[" & dos and body contains dos & "/trunk" then
				set subj to dos
			else if the subject begins with "[" & nuvie and body contains nuvie & "/trunk" then
				set subj to nuvie
			end if
		end repeat
           end tell
	end perform mail action with messages
end using terms from
tell application "Mail"
	activate
	set snapshotdialog to display dialog "TEST!!! Build " & subj & " snapshot?" buttons {"Cancel", "OK"} giving up after 2 with icon caution with title subj
	if button returned of snapshotdialog = "OK" or gave up of snapshotdialog is true then
		tell application "Terminal"
			activate
			tell application "System Events" to tell process "Terminal" to keystroke "t" using {command down}
			delay 1
			do script "cd ~/code/sh; . " & subj & "snapshot.sh" in selected tab of the front window
		end tell
	end if
end tell

or

set xu4 to "xU4"
set exult to "Exult"
set pent to "Pentagram"
set dos to "DOSBox"
set nuvie to "Nuvie"
using terms from application "Mail"
	on perform mail action with messages theMessages for rule theRule
		tell application "Mail"
			repeat with eachMessage in theMessages
				if the subject begins with "[" & xu4 and body contains "trunk/" & xu4 then
					set subj to xu4
				else if the subject begins with "[" & exult and body contains exult & "/trunk" then
					set subj to exult
				else if the subject begins with "[" & pent and body contains pent & "/trunk" then
					set subj to pent
				else if the subject begins with "[" & dos and body contains dos & "/trunk" then
					set subj to dos
				else if the subject begins with "[" & nuvie and body contains nuvie & "/trunk" then
					set subj to nuvie
				end if
				activate
				set snapshotdialog to display dialog "TEST!!! Build " & subj & " snapshot?" buttons {"Cancel", "OK"} giving up after 2 with icon caution with title subj
				if button returned of snapshotdialog = "OK" or gave up of snapshotdialog is true then
					tell application "Terminal"
						activate
						tell application "System Events" to tell process "Terminal" to keystroke "t" using {command down}
						delay 1
						do script "cd ~/code/sh; . " & subj & "snapshot.sh" in selected tab of the front window
					end tell
				end if
			end repeat
		end tell
	end perform mail action with messages
end using terms from

but I can’t get this to run, anyone got any pointers? Or how to slim down the long if/else if loop?

Hi,

user interaction like display dialog is not supported in Mail rules

Generally display dialog seems to work fine for me with a mail rule apple script. See http://macscripter.net/viewtopic.php?id=39264

Got it, the problem was with " if the subject begins with" ← that doesn’t work. subject needs to be a variable first.

so this script works as intended

using terms from application "Mail"
	on perform mail action with messages theMessages for rule Test
		tell application "Mail"
			repeat with eachMessage in theMessages
				set theSubject to the subject of eachMessage
				set theBody to the content of eachMessage
				set xu4 to "xU4"
				set exult to "Exult"
				set pent to "Pentagram"
				set dos to "DOSBox"
				set nuvie to "Nuvie"
				if theSubject begins with "[" & xu4 and theBody contains "trunk/" & xu4 then
					set subj to xu4
				else if theSubject begins with "[" & exult and theBody contains exult & "/trunk" then
					set subj to exult
				else if theSubject begins with "[" & pent and theBody contains pent & "/trunk" then
					set subj to pent
				else if theSubject begins with "[" & dos and theBody contains dos & "/trunk" then
					set subj to dos
				else if theSubject begins with "[" & nuvie and theBody contains nuvie & "/trunk" then
					set subj to nuvie
				end if
				activate
				set snapshotdialog to display dialog "TEST!!! Build " & subj & " snapshot?" buttons {"Cancel", "OK"} giving up after 2 with icon caution with title subj
				if button returned of snapshotdialog = "OK" or gave up of snapshotdialog is true then
					tell application "Terminal"
						activate
						tell application "System Events" to tell process "Terminal" to keystroke "t" using {command down}
						delay 1
						do script "cd ~/code/sh; . " & subj & "snapshot.sh" in selected tab of the front window
					end tell
				end if
			end repeat
		end tell
	end perform mail action with messages
end using terms from

Now I’d like to know if I can slim the long if thing down.