Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Solving AppleScript Error with Lion Mail in forwarding email

So I've long used a set of AppleScripts to do some spam-handling. I got these working little more than a week before Leopard was released, and they've survived the last two updates. Sadly, they break in Lion Mail. Upon selecting messages in Mail, the script is designed to use the source of each message to create a new message. The new message will have the subject and content to the source message and will be sent to spam@uce.gov (or spoof@paypal.com). The source message then gets marked as read and moved into a spam-learning folder with my mail provider. The forwarding may be of little value, but seeding known-spam into their folders will directly help my email experience.


tell application "Mail"

set theMessages to the selection

repeat with thisMessage in theMessages

set newMessage to make new outgoing message at end of outgoing messages

tell newMessage

set content to thisMessage's source

set subject to thisMessage's subject

make new to recipient with properties {address:"spam@uce.gov"}

end tell

send newMessage

set junk mail status of thisMessage to true

set read status of thisMessage to true

move thisMessage to mailbox "INBOX/ConfirmedJunk" of account "GFMorris.net"

end repeat

end tell


Here's the error I get:


Mail got an error: Can’t make source of message id 630957 of mailbox "INBOX/Junk Mail" of account "GFMorris.net" into type rich text.


I dinked around with preferences in Mail about rich v. plain text (I'm a plain text, fixed-width person), but that error seems to say that it can't get the source of the message at all. That tells me that the "repeat with thisMessage..." loop is broken, as it's not getting the source. I checked the AppleScript dictionary for Lion Mail and didn't see anything obvious.


Does anyone have any ideas? I'm just foregoing the script for now, but I'd love to have something that works.

27, Mac OS X (10.7)

Posted on Jul 23, 2011 5:51 PM

Reply
Question marked as Best reply

Posted on Jul 24, 2011 3:53 AM

Try replacing this one line:


set content to thisMessage's source


either with these two lines:


set theSource to thisMessage's source

set content to theSource


or with this one line:


set content to get thisMessage's source

Message was edited by: Pierre L.

19 replies

Apr 13, 2012 8:45 PM in response to gfmorris

I know this is an old thread but I wanted to modify this a bit to work better with my mobile devices and my IMAP mail setup.


Each of my IMAP accounts has it's own Spam folder and on my iPhone I can simply move junk mail to the Spam folder and the same happens across all of my devices.


So my plan is to schedule this script once a day to take all of the messages in my various Spam folders and forward them on as the original script does.


This is what I have so far:


tell application "Mail"

set everyIMAPAccount to every imap account

repeat with eachIMAPAccount in everyIMAPAccount

tell eachIMAPAccount

set theMessages to messages in mailbox "INBOX/Spam" of eachIMAPAccount

repeat with thisMessage in theMessages

set newMessage to makenewoutgoing messageat end of outgoing messages

tell newMessage

set content to get thisMessage's source

set subject to thisMessage's subject

makenewto recipientwith properties {address:"spam@uce.gov"}

end tell

sendnewMessage

deletethisMessage

end repeat

end tell

end repeat

end tell

So this is my problem, when the outgoing message is created I get a 1728 error saying, "Can’t get every outgoing message of account \"*myaccount*\"." number -1728 from every outgoing message of account "*myaccount*""


I'm assuming it is because I'm in the folder structure of a specific IMAP account which does not contain the outbox. So I need to set my outgoing message to the end of the outgoing messages of my top level outbox but I don't know how to do that.


I'm stumped. Does anyone have any suggestions?



Message was edited by: oba (cleaned up formatting of code)

Solving AppleScript Error with Lion Mail in forwarding email

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.