Hi,
I’m trying to extract the subject line from an email in Mail app. I want to use a mail rule so that every time I recieve an email with a specified subject it performs a script. The script that I want to run needs to include the subject line of the email as a variable. I realise this has been covered before using “selected messages” and so on but I’m having trouble getting anything to work. I don’t want to have emails selected I just need the rule to run for every email that has the specified subject".
Many Thanks
Here is my code for the mail rule script:
tell application "Finder" to set sourcefolder to "Released_Ads" as alias
set sourcefolderpath to sourcefolder as string
set folderlist to list folder sourcefolder without invisibles
set mysubject to "test1-may-01-07" as string --> this is the part where I need to get the subject from the current email
set dateline to characters -1 thru -10 of mysubject as string
set magcode to characters 1 thru 4 of mysubject as string
set theissue to magcode & dateline
set alternateissue to characters 1 thru 9 of theissue & "00" & characters 12 thru end of theissue as string
set adnumber to characters 5 thru -11 of mysubject as string
set aditem1 to mysubject & ".eps"
set aditem2 to mysubject & ".pdf"
set aditem3 to adnumber & ".eps"
set aditem4 to adnumber & ".pdf"
repeat with i from 1 to number of items in folderlist
set this_item to item i of folderlist as string
tell application "Finder" to set mypath to sourcefolderpath & this_item as alias
tell application "Finder"
if this_item contains theissue then
set mypathstring to mypath as string
tell application "Finder" to set myfolderalias to mypathstring as alias
set adlist to list folder myfolderalias without invisibles
repeat with i from 1 to number of items in adlist
set this_ad_item to item i of adlist as string
if this_ad_item = aditem1 then
tell application "Finder" to set myadalias to mypathstring & aditem1 as alias
open myadalias
else if this_ad_item = aditem2 then
tell application "Finder" to set myadalias to mypathstring & aditem2 as alias
open myadalias
else if this_ad_item = aditem3 then
tell application "Finder" to set myadalias to mypathstring & aditem3 as alias
open myadalias
else if this_ad_item = aditem4 then
tell application "Finder" to set myadalias to mypathstring & aditem4 as alias
open myadalias
end if
end repeat
else if this_item contains alternateissue then
set mypathstring to mypath as string
tell application "Finder" to set myfolderalias to mypathstring as alias
set adlist to list folder myfolderalias without invisibles
repeat with i from 1 to number of items in adlist
set this_ad_item to item i of adlist as string
if this_ad_item = aditem1 then
tell application "Finder" to set myadalias to mypathstring & aditem1 as alias
open myadalias
else if this_ad_item = aditem2 then
tell application "Finder" to set myadalias to mypathstring & aditem2 as alias
open myadalias
else if this_ad_item = aditem3 then
tell application "Finder" to set myadalias to mypathstring & aditem3 as alias
open myadalias
else if this_ad_item = aditem4 then
tell application "Finder" to set myadalias to mypathstring & aditem4 as alias
open myadalias
end if
end repeat
end if
end tell
end repeat