property subject_criteria : "request brochure"
property please_auto_send : false
property please_cc : false
property please_add_attchment : false
property file_attachment_path : (path to desktop folder) as string
property path_to_library : (path to library folder from user domain) as string -- this must be a string
on run
set targetMessages to {}
tell application "Mail"
set allunread to every message of inbox whose read status is false
ignoring case
repeat with thisunread in allunread
-- !!!! Modify this as needed! !!!!
if subject of thisunread contains subject_criteria then copy thisunread to the end of targetMessages
end repeat
end ignoring
if targetMessages is not {} then
set oldSignature to selected signature
-- !!!! This sets the signature !!!!
set selected signature to "Reply to Request Brochure"
repeat with thisMessage in targetMessages
set towho to reply to of thisMessage
set newone to make new outgoing message with properties {visible:true}
tell newone
set subject to "RE: " & subject_criteria
make new to recipient with properties {address:towho}
if please_cc then make new cc recipient with properties {address:cc_address}
if please_add_attchment then make new attachment with properties {file name:file_attachment_path}
if please_autosend then send it
end tell
set read status of thisMessage to true
end repeat
try
set selected signature to oldSignature
on error
-- if it reaches here then there's a bug where it returns the plist unique ID rather than the name ... workaround is here
set p_file to (path_to_library) & "Mail:Signatures:" & "SignaturesByAccount.plist"
set findnameofsig to ""
tell application "System Events"
tell property list file p_file
tell contents
set whatisinside to value of property list item "AllSignaturesKey"
repeat with thisone in whatisinside
if |SignatureUniqueId| of thisone is oldSignature then set findnameofsig to |SignatureName| of thisone
end repeat
end tell
end tell
end tell
if findnameofsig is not "" then
set selected signature to findnameofsig
else
error "Could not find signature"
end if
end try
end if
end tell
end run