I solved my own question but feel free to offer better syntax. The code below requires a OO3 file with two named columns: "Subject" and "Date" and the date column should be defined as a date column. As many other columns may be added as required.
I plan to run the script from a button on the OO3 button bar. The script requires that Apple Mail is open and an email selected. When run the header and text of the email is copied across to the OO3 document. At present the script does not check if an email is selected (to do).
Code:
tell application "Mail"
-- get all the messages in the list with same subject
set tMessageList to selection
set tEmail to ""
set x to 1 -- Originally I grabbed all the emails in the selection
--From:
set tSender to the sender of (item x) of tMessageList
--Subject:
set tSubject to the subject of (item x) of tMessageList
--Date:
set tDateSent to the date sent of (item x) of tMessageList
--To:
set tRecipients to the recipients of (item x) of tMessageList
set tAddresseeList to ""
repeat with n from 1 to (count tRecipients)
set tAddressee to (item n) of tRecipients
set tAddresseeList to tAddresseeList & address of tAddressee & return
end repeat --list of recipients
-- Message Body
set tContent to the content of (item x) of tMessageList
-- end the loop through message list
-- build the data
set tEmail to tEmail & "From: " & tSender & return
set tEmail to tEmail & "Subject: " & tSubject & return
set tEmail to tEmail & "Date: " & tDateSent & return
set tEmail to tEmail & "To: " & tAddresseeList & return
set tEmail to tEmail & tContent & return
end tell -- Apple Mail
set tDocument to front document of application "OmniOutliner Professional"
tell front document of application "OmniOutliner Professional" --why does tell tDocument fail ?
-- check that script is applicable to the OO file should contain 2 columns
if title of every column does not contain {"Subject", "Date"} then
display dialog "You need two columns named 'Subject,Date,' to use this script " buttons "Cancel" default button 1
end if
-- Does cancel stop the script ? Yes
--If OO doc does not have a last section add one called E-Mails
try
set LastSection to last child of tDocument -- we only have one section at present named E-Mails
on error
tell tDocument --original
make new row at end of rows with properties {topic:"E-Mails"} -- this will become the email section
end tell
set LastSection to last child of tDocument
end try
-- add a new child row for the header of the email
set LastRow to make new child at end of rows of LastSection with properties {topic:tSubject}
set value of cell "Date" of LastRow to tDateSent -- probably syntax to add this in the topic list ?
-- Add a new child row to store the email body
set EmailBody to make new child at end of rows of LastRow with properties {topic:tEmail}
end tell
It is a simple matter to modify the script to write to more columns e.g. To: and From: if required.
Simon