The whole script is (with some folders and account names changed):
on run
set _mywork_interesting_mailboxes to {"Inbox", "0TOOLS", "00Inbox - CC"}
set _omnifocus_followup to "1OMNIFOCUS"
with timeout of 90000 seconds
-- first find our Exchange account so we only store follow up items there
tell application "Mail"
repeat with _acct in accounts
set _acct_status to enabled of _acct
if _acct_status is true then
set _acct_type to account type of _acct
if _acct_type is unknown then
set _acct_server to server name of _acct
set _acct_name to name of _acct
if _acct_server contains ".mywork.domain" then
set mywork_exchange to _acct_name
end if
end if
end if
end repeat
end tell
tell application "Mail"
repeat with _acct in accounts
set _acct_status to enabled of _acct
if _acct_status is true then
--Look For Flagged Messages in the INBOX
set _acct_name to name of _acct
set _acct_type to account type of _acct
--if _acct_type is unknown then
if _acct_name is mywork_exchange then
#set _inbox to _acct's mailbox "Inbox"
set _mailbox_list to _mywork_interesting_mailboxes
else
#set _inbox to _acct's mailbox "INBOX"
if _acct_type is unknown then
set _mailbox_list to {"Inbox"}
else
set _mailbox_list to {"INBOX"}
end if
end if
repeat with _mbx in _mailbox_list
set _inbox to _acct's mailbox _mbx
set _msgs_to_capture to (every message of _inbox whose flagged status is true)
repeat with eachMessage in _msgs_to_capture
set theStart to missing value
set theDue to missing value
set theOmniTask to missing value
set theTitle to the subject of eachMessage
set theNotes to the content of eachMessage
set theCombinedBody to "message://%3c" & message id of eachMessage & "%3e" & return & return & theNotes
tell application "OmniFocus"
tell default document
set newTaskProps to {name:theTitle}
if theStart is not missing value then set newTaskProps to newTaskProps & {defer date:theStart}
if theDue is not missing value then set newTaskProps to newTaskProps & {due date:theDue}
if theCombinedBody is not missing value then set newTaskProps to newTaskProps & {note:theCombinedBody}
set newTask to make new inbox task with properties newTaskProps
end tell
end tell
set flagged status of eachMessage to false
move eachMessage to mailbox _omnifocus_followup of account mywork_exchange
end repeat
end repeat
end if
end repeat
end tell
end timeout
end run