Mail Bug?

I am trying to script a mail rule but it fails when triggered automatically.

If I select the email and hit apply rules it works

In my effort to debug the script I discovered this


using terms from application "Mail"
	
	on perform mail action with messages these_messages for rule this_rule
		tell application "Mail"
			set the message_count to the count of these_messages
			
			repeat with i from 1 to the message_count
				
				try
					set theMessage to item i of these_messages
					set thecontent to (content of item i of these_messages as string)
				on error errMsg
					display dialog "Error: " & errMsg
				end try

				
			
			end repeat
		end tell
	end perform mail action with messages
end using terms from

This returns when run automatically
Error: Can’t get «class mssg» 1 of «class mbxp» “Incoming POP Messages” of «class mact» “Appointments”. Invalid index.

It does not error out when run using Apply Rules

Is this a bug? Is there a workaround for a POP account. Someone over at Stackoverflow said that its OK with IMAP accounts

Seems to be a bug with Mail 7.2 as it works with Mail 5

It seems a lot of folk have had this problem with Mail. Whenever a rule was asked to extract content from the message automatically nothing would happen. When you applied rules to the message everything worked fine.

Well here is a work around. I’m sure someone will tell me why it works but for now



using terms from application "Mail"
	on perform mail action with messages these_messages for rule this_rule
		
		tell application "Mail"
			set the message_count to the count of these_messages
			
			repeat with i from 1 to the message_count
				set this_message to item i of these_messages
				set x to message 1 of mailbox "INBOX" of account "Info Work"
				set thecontent to (content of x as string)
				display dialog thecontent
			end repeat
		end tell
	end perform mail action with messages
end using terms from


So the trick is to get the last message from the mailbox you want the rule to work from.
When using this_message to get the content nothing happens.
Why the result of this_message should be different from x I don’t know

Hi weedinner,

what if you use:

set this_message to contents of (item i of these_messages)

Edited: disregard. ‘contents’ does nothing.

gl,
kel

Hi weedinner,

I think I found the problem. It may not be a bug!

Edited: no go. Thought that was it.

Later,
kel

Hi weedinner,

Think I’ve got it! Yay. Just a minute.

Edited: darn, I don’t know how to deal with this reference at the moment :/:

Edited: I don’t think it can be done now. “Incoming POP Messages” is a virtual mailbox on the server I think. Maybe you can move the incoming message to your own incoming mailbox and apply the script rule there.

gl,
kel

Hi weedinner,

What I ended in doing was create a new mailbox and called it “IncomingPopMessages”. Then the first action for the rule was to copy the incoming message(s) to the new folder. The second action would run this script:

using terms from application "Mail"
	on perform mail action with messages these_msgs
		tell application "Mail"
			set the_mailbox to first mailbox whose name is "IncomingPopMessages"
			set the_msgs to every message of the_mailbox
			repeat with this_msg in the_msgs
				set t to content of this_msg
				try
					display dialog t
					-- continue processing
					delete this_msg
				on error
					delete this_msg
				end try
			end repeat
		end tell
	end perform mail action with messages
end using terms from

Not sure if the first action would move all the messages before running the script. Needs testing.

gl,
kel

Hi weedinner,

Think I have the plan to get all references to new messages in the inbox:

  1. Add rule to inbox that copies all incoming mail with certain criteria to temporary mailbox “IncomingPopMessages”.
  2. Attach script rule to “incomingPopMesages” that gets ‘message id’ of every message of this mailbox, deletes the copy, and then the script gets every message of inbox whose ‘message id’ is in the list of 'message id’s.

That should work, because I am quite sure that the message id is unique. The id is given to the message when the message is sent. I posted something about the message id several years ago. If you’re interested in the script, then write back.

gl,
kel