Choosing relevant mail.app message to apply mail script to

Hi,

This probably a very straight forward query for someone. I’m trying to set up a system that extracts information from incoming emails as they arrive that i can use in Filemaker later. With a little help from people on this forum i have got a script that copies the the message text to the clipboard for use later. So far, so good. What i can’t seem to crack is making it choose the right message to apply this to.

It seems to acknowledge that the script should run bnut then apply it to the wrong email. Also, i am not sure what will happen if several emails arrive at the same time which i would like too extract information from.

The script I am using is…

tell application “Mail” to tell first message viewer
set theMessages to selected messages
set theContent to content of first item of theMessages
set the clipboard to theContent
end tell
tell application “FileMaker Pro”
activate
go to database “test”
do script “hello”
end tell

I am triggering the script using Mail’s rules. The second half of the script is irrelevant as is included just to demonstrate that the data is then used elsewhere. Unfortunately, as is, the script always returns data relelvant to the curtrently highlighed email message.
I am sure that it should be fairly simple but Applescript is not my string point. Is anyone able to help?

Many thanks

Rufus

Model: MacBook Pro
AppleScript: 2.1.1(81)
Browser: Firefox 1.5.0.9
Operating System: Mac OS X (10.4)

Hi rufus,

use a repeat block to affect all incoming messages.
To filter the messages you want, specify a condition in the rule’s definition

using terms from application "Mail"
	on perform mail action with messages theMessages for rule theRule
		repeat with eachMessage in theMessages
			tell application "Mail" to set theContent to content of eachMessage
			-- do something
		end repeat
	end perform mail action with messages
end using terms from

Thanks Stefan,

I’ll give it a go.

Regards

Rufus