I'm trying to modify an incoming email in Outlook 2011 for Mac using IMAP.
The algorithm is as follows:
- Get the source(raw text) of incoming message
- Write it to HTML file
- Modify the HTML file through a Python script
- Write back to Outlook email (this is where I'm facing a problem)
I'm not able to write back the HTML file to incoming email. What am I missing here? My code is here for your reference:
set urtext to string
set fileContents to string
tell application "Microsoft Outlook"
set theMessage to item 1 of (get current messages)
set urtext to source of theMessage
end tell
--write source to the file
set newFile to "/Users/mymac/Desktop/newTest1.html"
set eof of newFile to 0
open for access newFile with write permission
write urtext to newFile
close access newFile
--modifying the contents of the email
do shell script "/Users/mymac/Documents/'Microsoft User Data'/'Outlook Script
Menu Items'/test.py"
--read source from the file
set theFile to "/Users/mymac/Desktop/output3.html"
open for access theFile
set fileContents to (read theFile)
close access theFile
--problem here: how to write the source to the existing viewed message in
-- the main window without duplications
tell application "Microsoft Outlook"
set the_messages to selection
repeat with this_message in the_messages
--the line below modifies the contents, but I get two incoming mail messages
--[one modified and one unmodified]
set theMessage to make incoming message with properties {source:fileContents}
--the line below does not modify the source of the message in view pane,
--It gives an error 'Microsoft Outlook got an Errror: Applevent Handler Failed
--set source of this_message to fileContents
end repeat
end tell
Can this be done? Is there any other way whereby I can modify the contents of incoming message through Cocoa/Spamseive or creating a manual filter between the Exchange server and Outlook 2011 to do this process?