Returns are removed when reusing the content of a plain text mail.

Hi,

I am writing a script that will create a reply all of a message with an adjusted subject. I would like to do this in a ‘clean’ method (meaning without GUI scripting where possible. I can’t use the ‘reply to’ applescript function because it doesn’t allow me to change the subject, therefore I gather all info from the mail and create a new mail manually.

I now discovered a problem with this method. All the returns are removed if I get the content of a mail which is formatted in plain text, and use the same content to create the new message. Is there anyway I can resolve this?



tell application "Microsoft Outlook"
	-- listSelectedItems : a list of all items selected in Entourage
	set listMessages to current messages
	
	-- Check to make sure items are selected, if not then quit
	if ((count of listMessages) > 1) then
		display dialog "Please only select one message!"
		return
	end if
	if ((count of listMessages) is not 1) then return
	set theMail to item 1 of listMessages
	
	-- Gather info from the mail to be able to create the reply
	set theAccount to email address of (account of theMail)
	set toRecipientslist to email address of to recipients of theMail
	set ccRecipientslist to email address of cc recipients of theMail
	set theSubject to subject of theMail
	set theBody to content of theMail
	

	-- Create the Reply message and fill in to and cc fields
	set theReply to make new outgoing message with properties {subject:theSubject, content:theBody}
	repeat with i from 1 to number of items in the toRecipientslist
		set theRecipient to item i of toRecipientslist
		try
			set theRecipientName to (name of theRecipient)
		on error
			set theRecipientName to (address of theRecipient)
		end try
		make new recipient at theReply with properties {email address:{name:(theRecipientName), address:(address of theRecipient)}}
	end repeat
	repeat with i from 1 to number of items in the ccRecipientslist
		set theRecipient to item i of ccRecipientslist
		try
			set theRecipientName to (name of theRecipient)
		on error
			set theRecipientName to (address of theRecipient)
		end try
		make new recipient at theReply with properties {email address:{name:(theRecipientName), address:(address of theRecipient)}}
	end repeat
	open theReply
end tell

You can change the subject of a reply like this:

tell application "Microsoft Outlook"
	set theMail to selection
	set xxx to reply to theMail
	set subject of xxx to "Changed subject"
end tell

Here is another approach:

set the clipboard to read file "Mac OS X:Users:kiara:Desktop:mailer:technology:tech-en-content.rtf" as «class RTF »

tell application "Mail"
    activate
    set theMessage to make new outgoing message with properties {visible:true, subject:"mysubject"}
end tell

tell application "System Events"
    tell process "Mail"
        repeat until focused of UI element 1 of scroll area 4 of window 1
            keystroke tab
        end repeat
        keystroke "v" using command down
    end tell
end tell

Thanks adayzdone! That’s surprisingly easy. I don’t know why I didn’t try that before.