Forward Messages
Summary: Forwards the selected message in a single message.
Requires: Mailsmith
Suggested Key Binding: Command-Control-F
Last Modified: 2019-10-02
Description
Emailer-style forwards without quote characters. If multiple messages are selected, they are concatenated into one large message (with appropriate delimiters). Does not yet handle enclosures.
Installation Instructions · Download in Compiled Format · Download in Text Format
Script
property punctDelim : "-----"
on run
set theList to getList()
if theList is not {} then
my doAction(theList)
else
display dialog "No messages were selected" buttons "Ok"
end if
end run
on doAction(mList)
tell application "Mailsmith"
set theContents to ""
if length of mList > 1 then set theContents to my beginOuterDelim(mList)
set n to 1
repeat with m in mList
set theContents to theContents & my beginInnerDelim(n, mList)
set h to ""
set h to h & ("Subject: " & subject of m & return)
set h to h & "From: "
try
set h to h & originator of m & return
on error
set h to h & return
end try
set theRecipients to ""
repeat with r in to_recipients of m
set theRecipients to theRecipients & my addressString(r) & ", "
end repeat
if theRecipients is not equal to "" then
set theRecipients to characters 1 thru ((length of theRecipients) - 2) of theRecipients
set h to h & ("To: " & theRecipients)
end if
set theCCs to ""
repeat with c in cc_recipients of m
set theCCs to theCCs & my addressString(c) & ", "
end repeat
if theCCs is not equal to "" then
set theCCs to characters 1 thru ((length of theCCs) - 2) of theCCs
set h to h & ("CC: " & theCCs)
end if
set theContents to theContents & h & return & return
set theContents to theContents & contents of m
set theContents to theContents & my endInnerDelim(n, mList)
set forwarded of m to true
set n to n + 1
end repeat
set theSubject to "Fwd: " & subject of item 1 of mList
if length of mList > 1 then set theContents to theContents & my endOuterDelim(mList)
end tell
makeMessage(theSubject, theContents)
end doAction
on makeMessage(theSubject, theContents)
tell application "Mailsmith"
try
make new message window
set subject of window 1 to theSubject
set contents of window 1 to theContents
on error
beep
display dialog "Something went wrong." buttons {"Ok"} default button 1
end try
end tell
end makeMessage
on getList()
tell application "Mailsmith"
set retry to false
try
set mList to get selection as list
set m to item 1 of mList
if class of m is not message then set retry to true
on error
set retry to true
end try
if retry then
set retry to false
try
set mList to message of window 1 as list
on error
set retry to true
end try
end if
if retry then set mList to {}
end tell
return mList
end getList
on beginInnerDelim(n, mList)
if length of mList > 1 then
return return & punctDelim & "Begin Message " & n & punctDelim & return
else
return punctDelim & "Begin Forwarded Message" & punctDelim & return
end if
end beginInnerDelim
on endInnerDelim(n, mList)
if length of mList > 1 then
return return & punctDelim & "End Message " & n & punctDelim & return
else
return punctDelim & "End Forwarded Message" & punctDelim & return
end if
end endInnerDelim
on beginOuterDelim(mList)
return punctDelim & "Begin Forwarded Messages" & punctDelim & return
end beginOuterDelim
on endOuterDelim(mList)
if length of mList > 1 then
set s to "s"
else
set s to ""
end if
return return & punctDelim & "End Forwarded Messages" & punctDelim
end endOuterDelim
on addressString(r)
tell application "Mailsmith"
set s to display name of r
set theAddress to address string of r
if theAddress ≠ "" then
set s to s & " <" & theAddress & ">"
end if
end tell
return s
end addressString