You can get the cc recipients
and the bcc recipients
in exactly the same way as the to recipients
.
- Get the list of all the recipients
- Copy the list as formatted text to a variable
- Integrate the variable into your header element
Here is a heavily commented form of the script (with cc and bcc), explaining each step:
tell application "Mail"
# Get the first selected message
set selMsg to the selection
try
set theMsg to first item of selMsg
on error
display alert "Probably No Message Selected!"
error number -128
end try
# Get the desired header elements
# Elements containing only one item
# Sender
set theSender to the sender of theMsg
# Subject
set theSubject to subject of theMsg
# Date received
set theDate to date string of (get date received of theMsg)
# Elements containing multiple items (recipients)
# Normal (βToβ) Recipients
set toAddresses to {}
repeat with i in to recipients of theMsg
set end of toAddresses to address of i
end repeat
# CC Recipients
set ccAddresses to {}
repeat with i in cc recipients of theMsg
set end of ccAddresses to address of i
end repeat
# BCC Recipients
set bccAddresses to {}
repeat with i in bcc recipients of theMsg
set end of bccAddresses to address of i
end repeat
# Format the recipients
# Save current text item delimiters
set saveTID to AppleScript's text item delimiters
# Set the desired delimiters for the representation, e.g. {", "}, {"; "}, {" β "}, {" | "}
set AppleScript's text item delimiters to {", "}
# Format the recipients lists as delimited text
set toRecipients to toAddresses as rich text
set ccRecipients to ccAddresses as rich text
set bccRecipients to bccAddresses as rich text
# Restore text item delimiters
set AppleScript's text item delimiters to saveTID
# Compose the header
set theHeader to "From: " & theSender & linefeed & "To: " & toRecipients & linefeed & "CC: " & ccRecipients & linefeed & "BCC: " & bccRecipients & linefeed & "Subject: " & theSubject & linefeed & "Date received: " & theDate
# Get the content
set theContent to the content of theMsg as rich text
# Compose complete message (header + content)
set finalMsg to theHeader & linefeed & linefeed & theContent
# Transfer it to the clipboard
set the clipboard to finalMsg
end tell