Help diagnosing what is causing this script to throw -1700 Type Specifier error

I use mailtags and mail act-on to substitute a special signature for people who are associated with a certain project, and need a quick way to add people who email me to the Contacts Group to which all outgoing messages are checked to see if their recipients are members of that group. The group is a smart group which includes everyone in the address book who has a certain piece of text in their note field.

The script will be run from a keystroke in Mail.

I can extract the email address of the sender from Mail but when I try and use that address to find a contact in Contacts and then edit the note to ensure they get made a member of the group, I get a problem - contacts throws an error saying:

 Contacts got an error: Can’t make "john@doe.com" into type specifier.

It would seem that the format in which mail is outputting the address is text, but I have no idea how to refer to the email address in a format that means Contacts can use it…

 tell application "Mail"
	set themessages to selection
	repeat with eachmessage in themessages
		set theaddress to (extract address from sender of eachmessage)
		tell application "Contacts" to set value of note of (first person whose value of email 1 is theaddress) to "my group"
	end repeat
end tell

Try this

person 1 whose value of emails contains theaddress

Thanks! A small tweak, and this seems to complete in Script Debugger.

tell application "Mail"
	set themessages to selection
	repeat with eachmessage in themessages
		set theaddress to (extract address from sender of eachmessage)
		tell application "Contacts" to set note of (person 1 whose value of emails contains theaddress) to "my group"
	end repeat
end tell

However, what is reported in Script Debugger, and what is actually shown in Contacts remains to distinct things - I can add the note to the contact card in applescript, but when I view the card in Contacts, it’s not showing…

I believe that Contacts requires you to call the save command in order to persist changes.