Invisible mail remains after moving mail with AppleScript in Mail.app

So I have this AppleScript I wrote to add the contents of a mail message in a certain folder into Omnifocus, then move that message into the Archive folder. It works fine adding it into Omnifocus.

But there is one big issue, that I just cannot find any info on online…

After the message is moved, it can not be seen in the folder in Apple mail, BUT running the script again adds the tasl to Omnifocus AGAIN. And it keeps adding it, everytime the script runs.

Its like the mail is still in the folder (because the script is only checking this folder) but its inviible.

I guess its in the mail database or something and just flagged as moved, not sure.

Its a Gmail account. If I login to Gmail its still in the GMail folder.

So I thought I would select the Archive folder after the move, using Applescript, to resynschronise. I thought it used to work I am sure, but its not now. There just seems nothing I can do to get Mail to re-synchronise with Gmail and get that mail message out of the folder and into Archive.

There are several scripts online to add Omnifocus tasks, I cant believe this is not a known issue, but just cant find any info about it.

Anyone experience this weird issue when moving messages using Applescript to another folder?

Thanks