Help with importing from MailMate with tags

I wrote a variation on the MailMate bundle for DEVONthink based on the discussion here (Adding email with IMAP flags (keywords / tags)). The relevant AppleScript code is:

tell application id "DNtp"
set theRecord to import "{tmpfile}" from "MailMate" name "{name}"
set modification date of theRecord to creation date of theRecord
set tags of theRecord to "{MM_TAGS}" set the URL of theRecord to "{url}" # Allows it to be opened in MailMate using ⌃⌘O
display notification "Added message "${name}" with tags to DEVONthink" with title "MailMate"
end tell

My questions are:

  1. I don’t want to end up with a bunch of duplicates. How can I prevent this?
  2. Also, what is the definition of a duplicate in this context? If a message is already in the database and has no tags and I import it again, but with a tag this time, is that a duplicate? In that case, the preferred behavior would be to replace the existing tagless message with the new tagged one. This is not a hard requirement since it is likely to occur mostly during the transition from the current state to the use of my updated bundle.
    Thanks for any help you might give.
  1. Duplicate and modify the built-in Filter Duplicates smart rule to point at the email group/database and add the On Import event trigger to it.
  2. A duplicate is just that, a copy of something. Tags have nothing to do with it.