Mail Rule Script in Mountain Lion no longer functions

I have been using the following AppleScript since 2006, through every OS upgrade, and I cannot discover why it will not function now:

using terms from application "Mail"
	on perform mail action with messages The_Messages
		my logit("PhoenixReportSave04 fired", "phxLog")
		try
			set today_folder to my CheckOrMakeFolder((current date)'s short date string)
			tell application "Mail" to repeat with This_Message in The_Messages
				set Report_name to ((every word of (get This_Message's subject)) as rich text) & ".pdf"
				set Report_file to my checkFileName(today_folder, Report_name)
				save first mail attachment of This_Message in Report_file
			end repeat
		on error errText number errNum
			my logit(("Error: " & errText & errNum), "phxLog")
		end try
	end perform mail action with messages
end using terms from

The purpose is to save PDF attachments of laboratory reports on patients into a specified folder based on the received date. I added the logit handler to find the problem, and here is what it returns:

2012-08-30 17:17:49: Error: Can't get «class mssg» 1 of «class mbxp» Incoming POP Messages of «class mact» Cathouse Main. Invalid index.-1719

Since it appears that the repeat is the problem, I put together a modification as a testing script with a conditional to test for the single message state, and process it in that fashion, but I get the exact same error, even though the conditional works as written:

using terms from application "Mail"
	on perform mail action with messages The_Messages
		set messageCount to (count The_Messages)
		my logit("MailSolutions fired with " & (messageCount as rich text) & " message(s)", "ScriptTestingLog")
		try
			if messageCount > 1 then
				tell application "Mail" to repeat with This_Message in The_Messages
					my logit("Accessing multiple conditional", "ScriptTestingLog")
					set Report_name to ((every word of (get This_Message's subject)) as rich text) & ".pdf"
				end repeat
			else
				tell application "Mail"
					my logit("Accessing singleMessage conditional", "ScriptTestingLog")
					set singleMessage to (item 1 of The_Messages)
					set Report_name to ((every word of (get singleMessage's subject)) as rich text) & ".txt"
				end tell
			end if
			my logit(Report_name, "ScriptTestingLog")
		on error errText number errNum
			my logit(("Error: " & errText & errNum), "ScriptTestingLog")
		end try
	end perform mail action with messages
end using terms from

----------------------------------------------------------------------
to logit(log_string, log_file)
	do shell script ¬
		"echo `date '+%Y-%m-%d %T: '`\"" & log_string & ¬
		"\" >> $HOME/Library/Logs/" & log_file & ".log"
end logit

Result:
2012-08-30 18:29:57: MailSolutions fired with 1 message(s)
2012-08-30 18:29:57: Accessing singleMessage conditional
2012-08-30 18:29:57: Error: Can't get «class mssg» 1 of «class mbxp» Incoming POP Messages of «class mact» Cathouse Main. Invalid index.-1719

Does anyone have any idea what to try next?

Hi.

A total shot in the dark, as I don1t have Mountain Lion. It seems to be one or two issues, either they have changed the class of messages from your pop account to POP message, or something, or that way of indexing your messages are broken, so you should really try to figure out if it is another class involved, or try to “get every message” into a list, and take it from there by looping over them, or getting the first by an integer reference.

That is what I would have tried.

Thank you for the idea. Here is what I tried:

on perform mail action with messages The_Messages
set allMessages to The_Messages's every message
		set messageCount to (count allMessages)
		my logit("MailSolutions fired with " & (messageCount as rich text) & " message(s)", "ScriptTestingLog")

Here is the result:

2012-08-31 10:22:09: MailSolutions fired with 0 message(s)
2012-08-31 10:22:09: Accessing singleMessage conditional
2012-08-31 10:22:09: Error: Can't get item 1 of {}.-1728

So, even though the script receives a list of 1 item, that one item is not recognizable as a message as far as Mail is concerned.

Hi!

Please see this thread: MacScripter / message being application class on incoming mail in Apple Mail, here the class of the message all of suddenly is application, when the message is from an MsExchange account, maybe the same culprit pertains to a pop account?

-I’d check the class of the message if I were you.