search using string in Mail

Apologies in advance as I am very new to this!

I am trying to find messages in Mail based on their message id. I have a list of message id’s that i have gathered from a field in file filemaker.

I am trying to copy each message in the list i have from filemaker into a mailbox. Here is my attempt…


tell application "FileMaker Pro Advanced"
	set everymessageid to cell "messageID" of every record
	repeat with eachmessageid in everymessageid
		set listofmessageids to eachmessageid as string
	end repeat
end tell

tell application "Mail"
	set myMailbox to mailbox "...../Inbox"
	set myMessages to messages of myMailbox
		repeat with eachMessage in myMessages

			if message id of eachMessage is in listofmessageids then
			copy eachMessage to mailbox "Found"
				
		end if
				
	end repeat
end tell 

The only message that get’s copied to “Found” is the last one in the list.

I’m sure I’m doing something very basically wrong here!

Would greatly appreciate any help…

Hi,

listofmessageids must be a list, you’ve just assigned the record value to the variable in each repeat iteration


set listofmessageids to {}
tell application "FileMaker Pro Advanced"
	set everymessageid to cell "messageID" of every record
	repeat with eachmessageid in everymessageid
		set end of listofmessageids to eachmessageid as string
	end repeat
end tell
.

thank you so much for that… Sorted!